Exemple #1
0
func (c *AddUserCommand) Run(ctx *cmd.Context) error {
	store, err := configstore.Default()
	if err != nil {
		return fmt.Errorf("cannot open environment info storage: %v", err)
	}
	storeInfo, err := store.ReadInfo(c.EnvName)
	if err != nil {
		return err
	}
	client, err := juju.NewUserManagerClient(c.EnvName)
	if err != nil {
		return err
	}
	defer client.Close()
	if c.GeneratePassword {
		c.Password, err = utils.RandomPassword()
		if err != nil {
			return fmt.Errorf("Failed to generate password: %v", err)
		}
	}
	outputInfo := configstore.EnvironInfoData{}
	outputInfo.User = c.User
	outputInfo.Password = c.Password
	outputInfo.StateServers = storeInfo.APIEndpoint().Addresses
	outputInfo.CACert = storeInfo.APIEndpoint().CACert
	err = c.out.Write(ctx, outputInfo)
	if err != nil {
		return err
	}
	return client.AddUser(c.User, c.Password)
}
Exemple #2
0
func (c *RemoveUserCommand) Run(_ *cmd.Context) error {
	client, err := juju.NewUserManagerClient(c.EnvName)
	if err != nil {
		return err
	}
	defer client.Close()
	return client.RemoveUser(c.User)
}