361
361
// NewGetBootstrapConfigParamsFunc returns a function that, given a controller name,
362
362
// returns the params needed to bootstrap a fresh copy of that controller in the given client store.
363
func NewGetBootstrapConfigParamsFunc(store jujuclient.ClientStore) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
364
return bootstrapConfigGetter{store}.getBootstrapConfigParams
363
func NewGetBootstrapConfigParamsFunc(ctx *cmd.Context, store jujuclient.ClientStore) func(string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
364
return bootstrapConfigGetter{ctx, store}.getBootstrapConfigParams
367
367
type bootstrapConfigGetter struct {
368
jujuclient.ClientStore
369
store jujuclient.ClientStore
371
372
func (g bootstrapConfigGetter) getBootstrapConfig(controllerName string) (*config.Config, error) {
383
384
func (g bootstrapConfigGetter) getBootstrapConfigParams(controllerName string) (*jujuclient.BootstrapConfig, *environs.PrepareConfigParams, error) {
384
if _, err := g.ClientStore.ControllerByName(controllerName); err != nil {
385
if _, err := g.store.ControllerByName(controllerName); err != nil {
385
386
return nil, nil, errors.Annotate(err, "resolving controller name")
387
bootstrapConfig, err := g.BootstrapConfigForController(controllerName)
388
bootstrapConfig, err := g.store.BootstrapConfigForController(controllerName)
389
390
return nil, nil, errors.Annotate(err, "getting bootstrap config")
392
393
var credential *cloud.Credential
393
394
if bootstrapConfig.Credential != "" {
395
bootstrapCloud := cloud.Cloud{
396
Type: bootstrapConfig.CloudType,
397
Endpoint: bootstrapConfig.CloudEndpoint,
398
IdentityEndpoint: bootstrapConfig.CloudIdentityEndpoint,
400
if bootstrapConfig.CloudRegion != "" {
401
bootstrapCloud.Regions = []cloud.Region{{
402
Name: bootstrapConfig.CloudRegion,
403
Endpoint: bootstrapConfig.CloudEndpoint,
404
IdentityEndpoint: bootstrapConfig.CloudIdentityEndpoint,
394
407
credential, _, _, err = GetCredentials(
396
bootstrapConfig.CloudRegion,
397
bootstrapConfig.Credential,
398
bootstrapConfig.Cloud,
399
bootstrapConfig.CloudType,
409
GetCredentialsParams{
410
Cloud: bootstrapCloud,
411
CloudName: bootstrapConfig.Cloud,
412
CloudRegion: bootstrapConfig.CloudRegion,
413
CredentialName: bootstrapConfig.Credential,
402
417
return nil, nil, errors.Trace(err)
420
435
// Add attributes from the controller details.
421
controllerDetails, err := g.ControllerByName(controllerName)
436
controllerDetails, err := g.store.ControllerByName(controllerName)
423
438
return nil, nil, errors.Trace(err)