Skip to content

Commit

Permalink
Merge pull request #2960 from owncloud/proto_refactor
Browse files Browse the repository at this point in the history
Proto refactor
  • Loading branch information
wkloucek authored Feb 1, 2022
2 parents 8ebe1c7 + 7d8e334 commit d1d242f
Show file tree
Hide file tree
Showing 143 changed files with 12,148 additions and 14,980 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ vendor-bin/**/composer.lock

**/l10n/locale
**/l10n/template.pot

# protogen autogenerated
protogen/buf.sha1.lock
12 changes: 10 additions & 2 deletions .make/protobuf.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHA1_LOCK_FILE := $(abspath $(CURDIR)/../protogen/buf.sha1.lock)

# bingo creates symlinks from the -l option in GOBIN, from where
# we can easily use it with buf. To have the symlinks inside this
# repo and on a known location, we set GOBIN to .bingo in the root
Expand All @@ -11,6 +13,12 @@ protoc-deps: $(BINGO)
@cd .. && GOPATH="" GOBIN=".bingo" $(BINGO) get -l github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

.PHONY: buf-generate
buf-generate: $(BUF) protoc-deps
$(BUF) generate
buf-generate: $(BUF) protoc-deps $(SHA1_LOCK_FILE)
@find $(abspath $(CURDIR)/../protogen/proto/) -type f -print0 | sort -z | xargs -0 sha1sum > buf.sha1.lock.tmp
@cmp $(SHA1_LOCK_FILE) buf.sha1.lock.tmp --quiet || $(MAKE) -B $(SHA1_LOCK_FILE)
@rm -f buf.sha1.lock.tmp

$(SHA1_LOCK_FILE):
@echo "generating protobuf content"
cd ../protogen/proto && $(BUF) generate
find $(abspath $(CURDIR)/../protogen/proto/) -type f -print0 | sort -z | xargs -0 sha1sum > $(SHA1_LOCK_FILE)
3 changes: 0 additions & 3 deletions accounts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ node_modules:
yarn install --immutable

############ protobuf ############
PROTO_VERSION := v0
PROTO_SRC := pkg/proto/$(PROTO_VERSION)

include ../.make/protobuf.mk

.PHONY: protobuf
Expand Down
29 changes: 0 additions & 29 deletions accounts/buf.gen.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions accounts/buf.lock

This file was deleted.

12 changes: 7 additions & 5 deletions accounts/pkg/command/add_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package command
import (
"fmt"

accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v0"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/asim/go-micro/plugins/client/grpc/v4"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/flagset"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
)

// AddAccount command creates a new account
func AddAccount(cfg *config.Config) *cli.Command {
a := &accounts.Account{
PasswordProfile: &accounts.PasswordProfile{},
a := &accountsmsg.Account{
PasswordProfile: &accountsmsg.PasswordProfile{},
}
return &cli.Command{
Name: "add",
Expand Down Expand Up @@ -43,8 +45,8 @@ func AddAccount(cfg *config.Config) *cli.Command {
},
Action: func(c *cli.Context) error {
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.CreateAccount(c.Context, &accounts.CreateAccountRequest{
accSvc := accountssvc.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.CreateAccount(c.Context, &accountssvc.CreateAccountRequest{
Account: a,
})

Expand Down
10 changes: 6 additions & 4 deletions accounts/pkg/command/inspect_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"os"
"strconv"

accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v0"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/owncloud/ocis/accounts/pkg/flagset"

"github.com/asim/go-micro/plugins/client/grpc/v4"
tw "github.com/olekukonko/tablewriter"
"github.com/owncloud/ocis/accounts/pkg/config"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
)

Expand All @@ -30,8 +32,8 @@ func InspectAccount(cfg *config.Config) *cli.Command {
}

uid := c.Args().First()
accSvc := accounts.NewAccountsService(accServiceID, grpc.NewClient())
acc, err := accSvc.GetAccount(c.Context, &accounts.GetAccountRequest{
accSvc := accountssvc.NewAccountsService(accServiceID, grpc.NewClient())
acc, err := accSvc.GetAccount(c.Context, &accountssvc.GetAccountRequest{
Id: uid,
})

Expand All @@ -45,7 +47,7 @@ func InspectAccount(cfg *config.Config) *cli.Command {
}}
}

func buildAccountInspectTable(acc *accounts.Account) *tw.Table {
func buildAccountInspectTable(acc *accountsmsg.Account) *tw.Table {
table := tw.NewWriter(os.Stdout)
table.SetAutoMergeCells(true)
table.AppendBulk([][]string{
Expand Down
10 changes: 6 additions & 4 deletions accounts/pkg/command/list_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"os"
"strconv"

accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v0"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/owncloud/ocis/accounts/pkg/flagset"

"github.com/asim/go-micro/plugins/client/grpc/v4"
tw "github.com/olekukonko/tablewriter"
"github.com/owncloud/ocis/accounts/pkg/config"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
)

Expand All @@ -24,8 +26,8 @@ func ListAccounts(cfg *config.Config) *cli.Command {
Flags: flagset.ListAccountsWithConfig(cfg),
Action: func(c *cli.Context) error {
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
resp, err := accSvc.ListAccounts(c.Context, &accounts.ListAccountsRequest{})
accSvc := accountssvc.NewAccountsService(accSvcID, grpc.NewClient())
resp, err := accSvc.ListAccounts(c.Context, &accountssvc.ListAccountsRequest{})

if err != nil {
fmt.Println(fmt.Errorf("could not list accounts %w", err))
Expand All @@ -38,7 +40,7 @@ func ListAccounts(cfg *config.Config) *cli.Command {
}

// buildAccountsListTable creates an ascii table for printing on the cli
func buildAccountsListTable(accs []*accounts.Account) *tw.Table {
func buildAccountsListTable(accs []*accountsmsg.Account) *tw.Table {
table := tw.NewWriter(os.Stdout)
table.SetHeader([]string{"Id", "DisplayName", "Mail", "AccountEnabled"})
table.SetAutoFormatHeaders(false)
Expand Down
7 changes: 4 additions & 3 deletions accounts/pkg/command/rebuild_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"fmt"

accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/asim/go-micro/plugins/client/grpc/v4"
"github.com/owncloud/ocis/accounts/pkg/config"
index "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
merrors "go-micro.dev/v4/errors"
)
Expand All @@ -20,9 +21,9 @@ func RebuildIndex(cdf *config.Config) *cli.Command {
Aliases: []string{"rebuild", "ri"},
Action: func(ctx *cli.Context) error {
idxSvcID := "com.owncloud.api.accounts"
idxSvc := index.NewIndexService(idxSvcID, grpc.NewClient())
idxSvc := accountssvc.NewIndexService(idxSvcID, grpc.NewClient())

_, err := idxSvc.RebuildIndex(context.Background(), &index.RebuildIndexRequest{})
_, err := idxSvc.RebuildIndex(context.Background(), &accountssvc.RebuildIndexRequest{})
if err != nil {
fmt.Println(merrors.FromError(err).Detail)
return err
Expand Down
7 changes: 4 additions & 3 deletions accounts/pkg/command/remove_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"os"

accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/owncloud/ocis/accounts/pkg/flagset"

"github.com/asim/go-micro/plugins/client/grpc/v4"
"github.com/owncloud/ocis/accounts/pkg/config"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
)

Expand All @@ -29,8 +30,8 @@ func RemoveAccount(cfg *config.Config) *cli.Command {
}

uid := c.Args().First()
accSvc := accounts.NewAccountsService(accServiceID, grpc.NewClient())
_, err := accSvc.DeleteAccount(c.Context, &accounts.DeleteAccountRequest{Id: uid})
accSvc := accountssvc.NewAccountsService(accServiceID, grpc.NewClient())
_, err := accSvc.DeleteAccount(c.Context, &accountssvc.DeleteAccountRequest{Id: uid})

if err != nil {
fmt.Println(fmt.Errorf("could not delete account %w", err))
Expand Down
12 changes: 7 additions & 5 deletions accounts/pkg/command/update_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import (
"errors"
"fmt"

accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v0"
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v0"

"github.com/owncloud/ocis/accounts/pkg/flagset"

"github.com/asim/go-micro/plugins/client/grpc/v4"
"github.com/owncloud/ocis/accounts/pkg/config"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/urfave/cli/v2"
"google.golang.org/genproto/protobuf/field_mask"
)

// UpdateAccount command for modifying accounts including password policies
func UpdateAccount(cfg *config.Config) *cli.Command {
a := &accounts.Account{
PasswordProfile: &accounts.PasswordProfile{},
a := &accountsmsg.Account{
PasswordProfile: &accountsmsg.PasswordProfile{},
}
return &cli.Command{
Name: "update",
Expand All @@ -42,8 +44,8 @@ func UpdateAccount(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error {
a.Id = c.Args().First()
accSvcID := cfg.GRPC.Namespace + "." + cfg.Service.Name
accSvc := accounts.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.UpdateAccount(c.Context, &accounts.UpdateAccountRequest{
accSvc := accountssvc.NewAccountsService(accSvcID, grpc.NewClient())
_, err := accSvc.UpdateAccount(c.Context, &accountssvc.UpdateAccountRequest{
Account: a,
UpdateMask: buildAccUpdateMask(c.FlagNames()),
})
Expand Down
11 changes: 6 additions & 5 deletions accounts/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package flagset

import (
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v0"

"github.com/owncloud/ocis/accounts/pkg/config"
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/flags"
"github.com/urfave/cli/v2"
)

// UpdateAccountWithConfig applies update command flags to cfg
func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag {
func UpdateAccountWithConfig(cfg *config.Config, a *accountsmsg.Account) []cli.Flag {
if a.PasswordProfile == nil {
a.PasswordProfile = &accounts.PasswordProfile{}
a.PasswordProfile = &accountsmsg.PasswordProfile{}
}

return []cli.Flag{
Expand Down Expand Up @@ -92,9 +93,9 @@ func UpdateAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag
}

// AddAccountWithConfig applies create command flags to cfg
func AddAccountWithConfig(cfg *config.Config, a *accounts.Account) []cli.Flag {
func AddAccountWithConfig(cfg *config.Config, a *accountsmsg.Account) []cli.Flag {
if a.PasswordProfile == nil {
a.PasswordProfile = &accounts.PasswordProfile{}
a.PasswordProfile = &accountsmsg.PasswordProfile{}
}

return []cli.Flag{
Expand Down
Loading

0 comments on commit d1d242f

Please sign in to comment.