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 { if len(args) > 0 {
chartpath = filepath.Clean(args[0]) chartpath = filepath.Clean(args[0])
} }
man := &downloader.Manager{
Out: out, verify := downloader.VerifyNever
ChartPath: chartpath,
Keyring: client.Keyring,
SkipUpdate: client.SkipRefresh,
Getters: getter.All(settings),
RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
}
if client.Verify { 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() err := man.Build()
if e, ok := err.(downloader.ErrRepoNotFound); ok { if e, ok := err.(downloader.ErrRepoNotFound); ok {
return fmt.Errorf("%s. Please add the missing repos via 'helm repo add'", e.Error()) 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 { if len(args) > 0 {
chartpath = filepath.Clean(args[0]) chartpath = filepath.Clean(args[0])
} }
man := &downloader.Manager{
Out: out, verify := downloader.VerifyNever
ChartPath: chartpath,
Keyring: client.Keyring,
SkipUpdate: client.SkipRefresh,
Getters: getter.All(settings),
RegistryClient: cfg.RegistryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
}
if client.Verify { 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() 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 { 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") 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 { if client.DependencyUpdate {
man := &downloader.Manager{ man := downloader.NewManager(
Out: out, out,
ChartPath: cp, cp,
Keyring: client.ChartPathOptions.Keyring, downloader.VerifyNever,
SkipUpdate: false, settings.Debug,
Getters: p, client.ChartPathOptions.Keyring,
RegistryClient: client.RegistryClient, false,
RepositoryConfig: settings.RepositoryConfig, p,
RepositoryCache: settings.RepositoryCache, client.RegistryClient,
Debug: settings.Debug, settings.RepositoryConfig,
} settings.RepositoryCache,
)
if err := man.Update(); err != nil { if err := man.Update(); err != nil {
return nil, err return nil, err
} }

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

@ -78,6 +78,32 @@ type Manager struct {
RepositoryCache string 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. // Build rebuilds a local charts directory from a lockfile.
// //
// If the lockfile is not present, this will run a Manager.Update() // If the lockfile is not present, this will run a Manager.Update()

Loading…
Cancel
Save