mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-26 23:12:06 -05:00
ocis-accounts [list|delete|update|add|inspect] Implements UpdateMask for the update request. Changed server-handler accordingly. The commands use service-discovery to discover the backend.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/micro/cli/v2"
|
|
"github.com/micro/go-micro/v2/client/grpc"
|
|
"github.com/owncloud/ocis-accounts/pkg/config"
|
|
"github.com/owncloud/ocis-accounts/pkg/flagset"
|
|
accounts "github.com/owncloud/ocis-accounts/pkg/proto/v0"
|
|
)
|
|
|
|
// AddAccount command creates a new account
|
|
func AddAccount(cfg *config.Config) *cli.Command {
|
|
a := &accounts.Account{
|
|
PasswordProfile: &accounts.PasswordProfile{},
|
|
}
|
|
return &cli.Command{
|
|
Name: "add",
|
|
Usage: "Create a new account",
|
|
Aliases: []string{"create", "a"},
|
|
Flags: flagset.AddAccountWithConfig(cfg, a),
|
|
Before: func(c *cli.Context) error {
|
|
// Write value of username to the flags beneath, as preferred name
|
|
// and on-premises-sam-account-name is probably confusing for users.
|
|
if username := c.String("username"); username != "" {
|
|
if !c.IsSet("on-premises-sam-account-name") {
|
|
if err := c.Set("on-premises-sam-account-name", username); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if !c.IsSet("preferred-name") {
|
|
if err := c.Set("preferred-name", username); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
Action: func(c *cli.Context) error {
|
|
accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name
|
|
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
|
|
_, err := accSvc.CreateAccount(c.Context, &accounts.CreateAccountRequest{
|
|
Account: a,
|
|
})
|
|
|
|
if err != nil {
|
|
fmt.Println(fmt.Errorf("could not create account %w", err))
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}}
|
|
}
|