Skip to content

Commit

Permalink
add missing commands and unify service / namespace options
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek committed Nov 24, 2021
1 parent 38d670f commit 2e0f480
Show file tree
Hide file tree
Showing 66 changed files with 546 additions and 217 deletions.
2 changes: 1 addition & 1 deletion accounts/pkg/command/add_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/inspect_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/list_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/remove_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},

Expand Down
6 changes: 3 additions & 3 deletions accounts/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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 {
Expand All @@ -60,7 +60,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),
Expand All @@ -74,7 +74,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),
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/update_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions accounts/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -127,17 +125,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
Expand Down Expand Up @@ -169,15 +169,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{
Expand Down
8 changes: 4 additions & 4 deletions accounts/pkg/config/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
20 changes: 10 additions & 10 deletions accounts/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
}
}
Expand All @@ -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,
},
}
}
Expand All @@ -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,
},
}
}
2 changes: 1 addition & 1 deletion accounts/pkg/proto/v0/accounts.pb.micro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions accounts/pkg/server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/server/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions accounts/pkg/service/v0/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion accounts/pkg/service/v0/accounts_permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions accounts/pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion glauth/pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Execute(cfg *config.Config) error {
},
},
Before: func(c *cli.Context) error {
cfg.Version = version.String
cfg.Service.Version = version.String
return nil
},
Commands: []*cli.Command{
Expand Down
4 changes: 0 additions & 4 deletions glauth/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"strings"

glauthcfg "github.com/glauth/glauth/v2/pkg/config"
"github.com/oklog/run"
Expand All @@ -24,9 +23,6 @@ func Server(cfg *config.Config) *cli.Command {
Name: "server",
Usage: "Start integrated server",
Before: func(ctx *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}

if err := ParseConfig(ctx, cfg); err != nil {
return err
Expand Down
Loading

0 comments on commit 2e0f480

Please sign in to comment.