// Add an User on Etcd
func EtcdAddUser(c client.Client, utente client.User) (string, string) {

	uapi := client.NewAuthUserAPI(c)

	err := uapi.AddUser(context.Background(), utente.User, utente.Password)

	if err != nil {
		log.Printf("Errore: %v", err)
		return "", err.Error()
	}

	if utente.User == "root" {
		aapi := client.NewAuthAPI(c)
		err = aapi.Enable(context.Background())
		if err != nil {
			log.Fatal("Errore: %v", err)
		}

		return SUCCESS_ADMIN, ""
	}

	if len(utente.Roles) > 0 {
		_, err = uapi.GrantUser(context.Background(), utente.User, utente.Roles)

		if err != nil {
			log.Printf("Errore: %v", err)
			return "", err.Error()
		}
	}

	return SUCCESS_USER, ""
}
Beispiel #2
0
func mustNewAuthAPI(c *cli.Context) client.AuthAPI {
	hc := mustNewClient(c)

	if c.GlobalBool("debug") {
		fmt.Fprintf(os.Stderr, "Cluster-Endpoints: %s\n", strings.Join(hc.Endpoints(), ", "))
	}

	return client.NewAuthAPI(hc)
}