add missing commands and unify service / namespace options

This commit is contained in:
Willy Kloucek
2022-01-07 15:38:56 +00:00
committed by Jörn Friedrich Dreyer
parent 6621ac2ef6
commit 3b5a33590e
66 changed files with 516 additions and 218 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ func AddAccount(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.CreateAccount(c.Context, &accounts.CreateAccountRequest{
Account: a,
+1 -1
View File
@@ -22,7 +22,7 @@ func InspectAccount(cfg *config.Config) *cli.Command {
ArgsUsage: "id",
Flags: flagset.InspectAccountWithConfig(cfg),
Action: func(c *cli.Context) error {
accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name
accServiceID := cfg.GRPC.Namespace + "." + cfg.Service.Name
if c.NArg() != 1 {
fmt.Println("Please provide a user-id")
os.Exit(1)
+1 -1
View File
@@ -22,7 +22,7 @@ func ListAccounts(cfg *config.Config) *cli.Command {
Aliases: []string{"ls"},
Flags: flagset.ListAccountsWithConfig(cfg),
Action: func(c *cli.Context) error {
accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
resp, err := accSvc.ListAccounts(c.Context, &accounts.ListAccountsRequest{})
+1 -1
View File
@@ -21,7 +21,7 @@ func RemoveAccount(cfg *config.Config) *cli.Command {
Aliases: []string{"rm"},
Flags: flagset.RemoveAccountWithConfig(cfg),
Action: func(c *cli.Context) error {
accServiceID := cfg.GRPC.Namespace + "." + cfg.Server.Name
accServiceID := cfg.GRPC.Namespace + "." + cfg.Service.Name
if c.NArg() != 1 {
fmt.Println("Please provide a user-id")
os.Exit(1)
+1 -1
View File
@@ -27,7 +27,7 @@ func Execute(cfg *config.Config) error {
},
},
Before: func(c *cli.Context) error {
cfg.Server.Version = version.String
cfg.Service.Version = version.String
return ParseConfig(c, cfg)
},
+3 -3
View File
@@ -47,7 +47,7 @@ func Server(cfg *config.Config) *cli.Command {
defer cancel()
mtrcs.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1)
mtrcs.BuildInfo.WithLabelValues(cfg.Service.Version).Set(1)
handler, err := svc.New(svc.Logger(logger), svc.Config(cfg))
if err != nil {
@@ -58,7 +58,7 @@ func Server(cfg *config.Config) *cli.Command {
httpServer := http.Server(
http.Config(cfg),
http.Logger(logger),
http.Name(cfg.Server.Name),
http.Name(cfg.Service.Name),
http.Context(ctx),
http.Metrics(mtrcs),
http.Handler(handler),
@@ -72,7 +72,7 @@ func Server(cfg *config.Config) *cli.Command {
grpcServer := grpc.Server(
grpc.Config(cfg),
grpc.Logger(logger),
grpc.Name(cfg.Server.Name),
grpc.Name(cfg.Service.Name),
grpc.Context(ctx),
grpc.Metrics(mtrcs),
grpc.Handler(handler),
+1 -1
View File
@@ -40,7 +40,7 @@ func UpdateAccount(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
a.Id = c.Args().First()
accSvcID := cfg.GRPC.Namespace + "." + cfg.Server.Name
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.UpdateAccount(c.Context, &accounts.UpdateAccountRequest{
Account: a,
+1 -1
View File
@@ -18,7 +18,7 @@ func PrintVersion(cfg *config.Config) *cli.Command {
Usage: "Print the versions of the running instances",
Action: func(c *cli.Context) error {
reg := registry.GetRegistry()
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name)
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err))
return err
+21 -21
View File
@@ -56,12 +56,10 @@ type GRPC struct {
Namespace string `ocisConfig:"namespace"`
}
// Server configures a server.
type Server struct {
Version string `ocisConfig:"version"`
Name string `ocisConfig:"name"`
HashDifficulty int `ocisConfig:"hash_difficulty"`
DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"`
// Service defines the available service configuration.
type Service struct {
Name string `ocisConfig:"name"`
Version string `ocisConfig:"version"`
}
// Asset defines the available asset configuration.
@@ -125,17 +123,19 @@ type Tracing struct {
type Config struct {
*shared.Commons
LDAP LDAP `ocisConfig:"ldap"`
HTTP HTTP `ocisConfig:"http"`
GRPC GRPC `ocisConfig:"grpc"`
Server Server `ocisConfig:"server"`
Asset Asset `ocisConfig:"asset"`
Log *shared.Log `ocisConfig:"log"`
TokenManager TokenManager `ocisConfig:"token_manager"`
Repo Repo `ocisConfig:"repo"`
Index Index `ocisConfig:"index"`
ServiceUser ServiceUser `ocisConfig:"service_user"`
Tracing Tracing `ocisConfig:"tracing"`
LDAP LDAP `ocisConfig:"ldap"`
HTTP HTTP `ocisConfig:"http"`
GRPC GRPC `ocisConfig:"grpc"`
Service Service `ocisConfig:"service"`
Asset Asset `ocisConfig:"asset"`
Log *shared.Log `ocisConfig:"log"`
TokenManager TokenManager `ocisConfig:"token_manager"`
Repo Repo `ocisConfig:"repo"`
Index Index `ocisConfig:"index"`
ServiceUser ServiceUser `ocisConfig:"service_user"`
HashDifficulty int `ocisConfig:"hash_difficulty"`
DemoUsersAndGroups bool `ocisConfig:"demo_users_and_groups"`
Tracing Tracing `ocisConfig:"tracing"`
Context context.Context
Supervised bool
@@ -167,15 +167,15 @@ func DefaultConfig() *Config {
Addr: "127.0.0.1:9180",
Namespace: "com.owncloud.api",
},
Server: Server{
Name: "accounts",
HashDifficulty: 11,
DemoUsersAndGroups: true,
Service: Service{
Name: "accounts",
},
Asset: Asset{},
TokenManager: TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
HashDifficulty: 11,
DemoUsersAndGroups: true,
Repo: Repo{
Backend: "CS3",
Disk: Disk{
+4 -4
View File
@@ -69,16 +69,16 @@ func structMappings(cfg *Config) []shared.EnvBinding {
Destination: &cfg.GRPC.Addr,
},
{
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
EnvVars: []string{"ACCOUNTS_SERVICE_NAME"},
Destination: &cfg.Service.Name,
},
{
EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"},
Destination: &cfg.Server.HashDifficulty,
Destination: &cfg.HashDifficulty,
},
{
EnvVars: []string{"ACCOUNTS_DEMO_USERS_AND_GROUPS"},
Destination: &cfg.Server.DemoUsersAndGroups,
Destination: &cfg.DemoUsersAndGroups,
},
{
EnvVars: []string{"ACCOUNTS_ASSET_PATH"},
+10 -10
View File
@@ -23,10 +23,10 @@ func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag
},
&cli.StringFlag{
Name: "name",
Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"),
Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"),
Usage: "service name",
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
Destination: &cfg.Service.Name,
},
&cli.BoolFlag{
Name: "enabled",
@@ -107,10 +107,10 @@ func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag {
},
&cli.StringFlag{
Name: "name",
Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"),
Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"),
Usage: "service name",
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
Destination: &cfg.Service.Name,
},
&cli.BoolFlag{
Name: "enabled",
@@ -191,10 +191,10 @@ func ListAccountsWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "name",
Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"),
Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"),
Usage: "service name",
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
Destination: &cfg.Service.Name,
},
}
}
@@ -211,10 +211,10 @@ func RemoveAccountWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "name",
Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"),
Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"),
Usage: "service name",
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
Destination: &cfg.Service.Name,
},
}
}
@@ -231,10 +231,10 @@ func InspectAccountWithConfig(cfg *config.Config) []cli.Flag {
},
&cli.StringFlag{
Name: "name",
Value: flags.OverrideDefaultString(cfg.Server.Name, "accounts"),
Value: flags.OverrideDefaultString(cfg.Service.Name, "accounts"),
Usage: "service name",
EnvVars: []string{"ACCOUNTS_NAME"},
Destination: &cfg.Server.Name,
Destination: &cfg.Service.Name,
},
}
}
@@ -81,7 +81,7 @@ func init() {
cfg := config.New()
cfg.Repo.Backend = "disk"
cfg.Repo.Disk.Path = dataPath
cfg.Server.DemoUsersAndGroups = true
cfg.DemoUsersAndGroups = true
var hdlr *svc.Service
var err error
+2 -2
View File
@@ -11,13 +11,13 @@ func Server(opts ...Option) grpc.Service {
handler := options.Handler
service := grpc.NewService(
grpc.Name(options.Config.Server.Name),
grpc.Name(options.Config.Service.Name),
grpc.Context(options.Context),
grpc.Address(options.Config.GRPC.Addr),
grpc.Namespace(options.Config.GRPC.Namespace),
grpc.Logger(options.Logger),
grpc.Flags(options.Flags...),
grpc.Version(options.Config.Server.Version),
grpc.Version(options.Config.Service.Version),
)
if err := proto.RegisterAccountsServiceHandler(service.Server(), handler); err != nil {
+1 -1
View File
@@ -21,7 +21,7 @@ func Server(opts ...Option) http.Service {
service := http.NewService(
http.Logger(options.Logger),
http.Name(options.Name),
http.Version(options.Config.Server.Version),
http.Version(options.Config.Service.Version),
http.Address(options.Config.HTTP.Addr),
http.Namespace(options.Config.HTTP.Namespace),
http.Context(options.Context),
+2 -2
View File
@@ -381,7 +381,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
if out.PasswordProfile != nil {
if out.PasswordProfile.Password != "" {
// encrypt password
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty)
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.HashDifficulty)
if err != nil {
s.log.Error().Err(err).Str("id", id).Msg("could not hash password")
return merrors.InternalServerError(s.id, "could not hash password: %v", err.Error())
@@ -572,7 +572,7 @@ func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountReque
}
if in.Account.PasswordProfile.Password != "" {
// encrypt password
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty)
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.HashDifficulty)
if err != nil {
in.Account.PasswordProfile.Password = ""
s.log.Error().Err(err).Str("id", id).Msg("could not hash password")
@@ -32,7 +32,7 @@ var (
func init() {
cfg := config.New()
cfg.Server.Name = "accounts"
cfg.Service.Name = "accounts"
cfg.Repo.Backend = "disk"
cfg.Repo.Disk.Path = dataPath
logger := olog.NewLogger(olog.Color(true), olog.Pretty(true))
+3 -3
View File
@@ -57,7 +57,7 @@ func New(opts ...Option) (s *Service, err error) {
}
s = &Service{
id: cfg.GRPC.Namespace + "." + cfg.Server.Name,
id: cfg.GRPC.Namespace + "." + cfg.Service.Name,
log: logger,
Config: cfg,
RoleService: roleService,
@@ -81,11 +81,11 @@ func New(opts ...Option) (s *Service, err error) {
return nil, err
}
if err = s.createDefaultAccounts(cfg.Server.DemoUsersAndGroups); err != nil {
if err = s.createDefaultAccounts(cfg.DemoUsersAndGroups); err != nil {
return nil, err
}
if err = s.createDefaultGroups(cfg.Server.DemoUsersAndGroups); err != nil {
if err = s.createDefaultGroups(cfg.DemoUsersAndGroups); err != nil {
return nil, err
}
return