57
57
// SetFlags implements Command.SetFlags.
58
58
func (c *showControllerCommand) SetFlags(f *gnuflag.FlagSet) {
59
59
c.JujuCommandBase.SetFlags(f)
60
f.BoolVar(&c.showPasswords, "show-passwords", false, "Show passwords for displayed accounts")
60
f.BoolVar(&c.showPasswords, "show-password", false, "Show password for logged in user")
61
61
c.out.AddFlags(f, "yaml", map[string]cmd.Formatter{
62
62
"yaml": cmd.FormatYaml,
63
63
"json": cmd.FormatJson,
91
91
// Details contains the same details that client store caches for this controller.
92
92
Details ControllerDetails `yaml:"details,omitempty" json:"details,omitempty"`
94
// Accounts is a collection of accounts for this controller.
95
Accounts map[string]*AccountDetails `yaml:"accounts,omitempty" json:"accounts,omitempty"`
97
// CurrentAccount is the name of the current account for this controller.
98
CurrentAccount string `yaml:"current-account,omitempty" json:"current-account,omitempty"`
94
// Models is a collection of all models for this controller.
95
Models map[string]ModelDetails `yaml:"models,omitempty" json:"models,omitempty"`
97
// CurrentModel is the name of the current model for this controller
98
CurrentModel string `yaml:"current-model,omitempty" json:"current-model,omitempty"`
100
// Account is the account details for the user logged into this controller.
101
Account *AccountDetails `yaml:"account,omitempty" json:"account,omitempty"`
100
103
// BootstrapConfig contains the bootstrap configuration for this controller.
101
104
// This is only available on the client that bootstrapped the controller.
137
140
// Password is the password for the account.
138
141
Password string `yaml:"password,omitempty" json:"password,omitempty"`
140
// Models is a collection of all models for this controller.
141
Models map[string]ModelDetails `yaml:"models,omitempty" json:"models,omitempty"`
143
// CurrentModel is the name of the current model for this controller
144
CurrentModel string `yaml:"current-model,omitempty" json:"current-model,omitempty"`
147
144
// BootstrapConfig holds the configuration used to bootstrap a controller.
165
162
CloudRegion: details.CloudRegion,
165
c.convertModelsForShow(controllerName, &controller)
168
166
c.convertAccountsForShow(controllerName, &controller)
169
167
c.convertBootstrapConfigForShow(controllerName, &controller)
170
168
return controller
173
171
func (c *showControllerCommand) convertAccountsForShow(controllerName string, controller *ShowControllerDetails) {
174
accounts, err := c.store.AllAccounts(controllerName)
175
if err != nil && !errors.IsNotFound(err) {
176
controller.Errors = append(controller.Errors, err.Error())
179
if len(accounts) > 0 {
180
controller.Accounts = make(map[string]*AccountDetails)
181
for accountName, account := range accounts {
182
details := &AccountDetails{User: account.User}
183
controller.Accounts[accountName] = details
185
details.Password = account.Password
187
if err := c.convertModelsForShow(controllerName, accountName, details); err != nil {
188
controller.Errors = append(controller.Errors, err.Error())
193
controller.CurrentAccount, err = c.store.CurrentAccount(controllerName)
194
if err != nil && !errors.IsNotFound(err) {
195
controller.Errors = append(controller.Errors, err.Error())
172
storeDetails, err := c.store.AccountDetails(controllerName)
173
if err != nil && !errors.IsNotFound(err) {
174
controller.Errors = append(controller.Errors, err.Error())
176
if storeDetails == nil {
179
details := &AccountDetails{
180
User: storeDetails.User,
183
details.Password = storeDetails.Password
185
controller.Account = details
199
func (c *showControllerCommand) convertModelsForShow(controllerName, accountName string, account *AccountDetails) error {
200
models, err := c.store.AllModels(controllerName, accountName)
188
func (c *showControllerCommand) convertModelsForShow(controllerName string, controller *ShowControllerDetails) {
189
models, err := c.store.AllModels(controllerName)
201
190
if errors.IsNotFound(err) {
203
192
} else if err != nil {
193
controller.Errors = append(controller.Errors, err.Error())
206
196
if len(models) > 0 {
207
account.Models = make(map[string]ModelDetails)
197
controller.Models = make(map[string]ModelDetails)
208
198
for modelName, model := range models {
209
account.Models[modelName] = ModelDetails{model.ModelUUID}
199
controller.Models[modelName] = ModelDetails{model.ModelUUID}
212
account.CurrentModel, err = c.store.CurrentModel(controllerName, accountName)
202
controller.CurrentModel, err = c.store.CurrentModel(controllerName)
213
203
if err != nil && !errors.IsNotFound(err) {
204
controller.Errors = append(controller.Errors, err.Error())
219
209
func (c *showControllerCommand) convertBootstrapConfigForShow(controllerName string, controller *ShowControllerDetails) {