refactor: create an explicit constructor for downloader.Manager

Signed-off-by: Theo Chupp <tclchiam@gmail.com>
pull/9539/head
Theo Chupp 5 years ago committed by Theo Chupp
parent 8f637137dc
commit 8da8c7109c

@ -54,20 +54,23 @@ func newDependencyBuildCmd(cfg *action.Configuration, out io.Writer) *cobra.Comm
if len(args) > 0 {
chartpath = filepath.Clean(args[0])
}
man := &downloader.Manager{
Out: out,
ChartPath: chartpath,
Keyring: client.Keyring,
SkipUpdate: client.SkipRefresh,
Getters: getter.All(settings),
RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
}
verify := downloader.VerifyNever
if client.Verify {
man.Verify = downloader.VerifyIfPossible
verify = downloader.VerifyIfPossible
}
man := downloader.NewManager(
out,
chartpath,
verify,
settings.Debug,
client.Keyring,
client.SkipRefresh,
getter.All(settings),
cfg.RegistryClient,
settings.RepositoryConfig,
settings.RepositoryCache,
)
err := man.Build()
if e, ok := err.(downloader.ErrRepoNotFound); ok {
return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error())

@ -57,20 +57,23 @@ func newDependencyUpdateCmd(cfg *action.Configuration, out io.Writer) *cobra.Com
if len(args) > 0 {
chartpath = filepath.Clean(args[0])
}
man := &downloader.Manager{
Out: out,
ChartPath: chartpath,
Keyring: client.Keyring,
SkipUpdate: client.SkipRefresh,
Getters: getter.All(settings),
RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
}
verify := downloader.VerifyNever
if client.Verify {
man.Verify = downloader.VerifyAlways
verify = downloader.VerifyAlways
}
man := downloader.NewManager(
out,
chartpath,
verify,
settings.Debug,
client.Keyring,
client.SkipRefresh,
getter.All(settings),
cfg.RegistryClient,
settings.RepositoryConfig,
settings.RepositoryCache,
)
return man.Update()
},
}

@ -235,17 +235,18 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
if err := action.CheckDependencies(chartRequested, req); err != nil {
err = errors.Wrap(err, "An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies")
if client.DependencyUpdate {
man := &downloader.Manager{
Out: out,
ChartPath: cp,
Keyring: client.ChartPathOptions.Keyring,
SkipUpdate: false,
Getters: p,
RegistryClient: client.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
}
man := downloader.NewManager(
out,
cp,
downloader.VerifyNever,
settings.Debug,
client.ChartPathOptions.Keyring,
false,
p,
client.RegistryClient,
settings.RepositoryConfig,
settings.RepositoryCache,
)
if err := man.Update(); err != nil {
return nil, err
}

@ -86,16 +86,18 @@ func newPackageCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}
if client.DependencyUpdate {
downloadManager := &downloader.Manager{
Out: ioutil.Discard,
ChartPath: path,
Keyring: client.Keyring,
Getters: p,
Debug: settings.Debug,
RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
}
downloadManager := downloader.NewManager(
ioutil.Discard,
path,
downloader.VerifyNever,
settings.Debug,
client.Keyring,
false,
p,
nil,
settings.RepositoryConfig,
settings.RepositoryCache,
)
if err := downloadManager.Update(); err != nil {
return err

@ -78,6 +78,32 @@ type Manager struct {
RepositoryCache string
}
func NewManager(
out io.Writer,
chartPath string,
verify VerificationStrategy,
debug bool,
keyring string,
skipUpdate bool,
getters []getter.Provider,
registryClient *registry.Client,
repositoryConfig string,
repositoryCache string,
) *Manager {
return &Manager{
Out: out,
ChartPath: chartPath,
Verify: verify,
Debug: debug,
Keyring: keyring,
SkipUpdate: skipUpdate,
Getters: getters,
RegistryClient: registryClient,
RepositoryConfig: repositoryConfig,
RepositoryCache: repositoryCache,
}
}
// Build rebuilds a local charts directory from a lockfile.
//
// If the lockfile is not present, this will run a Manager.Update()

Loading…
Cancel
Save