예제 #1
0
파일: adduser.go 프로젝트: jameinel/core
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)
}
예제 #2
0
파일: removeuser.go 프로젝트: jameinel/core
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)
}