Skip to content

Commit

Permalink
feat: upgrade proto to v0.4.20
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Aug 7, 2024
1 parent 9d3835b commit 7f5ba6d
Show file tree
Hide file tree
Showing 41 changed files with 1,542 additions and 444 deletions.
32 changes: 26 additions & 6 deletions app/sephirah/internal/biz/biztiphereth/porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/tuihub/librarian/app/sephirah/internal/biz/bizutils"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/internal/lib/libauth"
"github.com/tuihub/librarian/internal/lib/logger"
Expand All @@ -29,7 +30,7 @@ func (t *Tiphereth) updatePorters(ctx context.Context) error {
}
for i, porter := range newPorters {
porter.ID = ids[i]
porter.Status = modeltiphereth.PorterInstanceStatusBlocked
porter.Status = modeltiphereth.UserStatusBlocked
}
err = t.repo.UpsertPorters(ctx, newPorters)
if err != nil {
Expand All @@ -42,7 +43,7 @@ func (t *Tiphereth) updatePorters(ctx context.Context) error {
func (t *Tiphereth) ListPorters(
ctx context.Context,
paging model.Paging,
) ([]*modeltiphereth.PorterInstance, int64, *errors.Error) {
) ([]*modelsupervisor.PorterInstance, int64, *errors.Error) {
if libauth.FromContextAssertUserType(ctx, libauth.UserTypeAdmin) == nil {
return nil, 0, bizutils.NoPermissionError()
}
Expand All @@ -56,7 +57,7 @@ func (t *Tiphereth) ListPorters(
func (t *Tiphereth) UpdatePorterStatus(
ctx context.Context,
id model.InternalID,
status modeltiphereth.PorterInstanceStatus,
status modeltiphereth.UserStatus,
) *errors.Error {
if libauth.FromContextAssertUserType(ctx, libauth.UserTypeAdmin) == nil {
return bizutils.NoPermissionError()
Expand All @@ -69,7 +70,7 @@ func (t *Tiphereth) UpdatePorterStatus(
return nil
}

func (t *Tiphereth) CreatePorterContext(ctx context.Context, context *modeltiphereth.PorterContext) (model.InternalID, *errors.Error) {
func (t *Tiphereth) CreatePorterContext(ctx context.Context, context *modelsupervisor.PorterContext) (model.InternalID, *errors.Error) {
claims := libauth.FromContextAssertUserType(ctx)
if claims == nil {
return 0, bizutils.NoPermissionError()
Expand All @@ -86,7 +87,7 @@ func (t *Tiphereth) CreatePorterContext(ctx context.Context, context *modeltiphe
return id, nil
}

func (t *Tiphereth) ListPorterContexts(ctx context.Context, paging model.Paging) ([]*modeltiphereth.PorterContext, int64, *errors.Error) {
func (t *Tiphereth) ListPorterContexts(ctx context.Context, paging model.Paging) ([]*modelsupervisor.PorterContext, int64, *errors.Error) {
claims := libauth.FromContextAssertUserType(ctx)
if claims == nil {
return nil, 0, bizutils.NoPermissionError()
Expand All @@ -100,7 +101,7 @@ func (t *Tiphereth) ListPorterContexts(ctx context.Context, paging model.Paging)

func (t *Tiphereth) UpdatePorterContext(
ctx context.Context,
context *modeltiphereth.PorterContext,
context *modelsupervisor.PorterContext,
) *errors.Error {
claims := libauth.FromContextAssertUserType(ctx)
if claims == nil {
Expand All @@ -112,3 +113,22 @@ func (t *Tiphereth) UpdatePorterContext(
}
return nil
}

func (t *Tiphereth) ListPorterGroups(
ctx context.Context,
paging model.Paging,
status []modeltiphereth.UserStatus,
) ([]*modelsupervisor.PorterGroup, int64, *errors.Error) {
claims := libauth.FromContextAssertUserType(ctx)
if claims == nil {
return nil, 0, bizutils.NoPermissionError()
}
if claims.UserType != libauth.UserTypeAdmin {
status = []modeltiphereth.UserStatus{modeltiphereth.UserStatusActive}
}
groups, err := t.repo.ListPorterGroups(ctx, status)
if err != nil {
return nil, 0, pb.ErrorErrorReasonUnspecified("%s", err.Error())
}
return groups, int64(len(groups)), nil
}
26 changes: 14 additions & 12 deletions app/sephirah/internal/biz/biztiphereth/tiphereth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/tuihub/librarian/app/sephirah/internal/client"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/app/sephirah/internal/supervisor"
"github.com/tuihub/librarian/internal/lib/libapp"
Expand Down Expand Up @@ -36,14 +37,14 @@ type TipherethRepo interface {
UnLinkAccount(context.Context, modeltiphereth.Account, model.InternalID) error
ListLinkAccounts(context.Context, model.InternalID) ([]*modeltiphereth.Account, error)
GetUser(context.Context, model.InternalID) (*modeltiphereth.User, error)
UpsertPorters(context.Context, []*modeltiphereth.PorterInstance) error
ListPorters(context.Context, model.Paging) ([]*modeltiphereth.PorterInstance, int64, error)
FetchPorterByAddress(context.Context, string) (*modeltiphereth.PorterInstance, error)
UpsertPorters(context.Context, []*modelsupervisor.PorterInstance) error
ListPorters(context.Context, model.Paging) ([]*modelsupervisor.PorterInstance, int64, error)
FetchPorterByAddress(context.Context, string) (*modelsupervisor.PorterInstance, error)
UpdatePorterStatus(context.Context, model.InternalID,
modeltiphereth.PorterInstanceStatus) (*modeltiphereth.PorterInstance, error)
CreatePorterContext(context.Context, model.InternalID, *modeltiphereth.PorterContext) error
ListPorterContexts(context.Context, model.InternalID, model.Paging) ([]*modeltiphereth.PorterContext, int64, error)
UpdatePorterContext(context.Context, model.InternalID, *modeltiphereth.PorterContext) error
modeltiphereth.UserStatus) (*modelsupervisor.PorterInstance, error)
CreatePorterContext(context.Context, model.InternalID, *modelsupervisor.PorterContext) error
ListPorterContexts(context.Context, model.InternalID, model.Paging) ([]*modelsupervisor.PorterContext, int64, error)
UpdatePorterContext(context.Context, model.InternalID, *modelsupervisor.PorterContext) error
CreateDevice(context.Context, *modeltiphereth.DeviceInfo) error
ListUserSessions(context.Context, model.InternalID) ([]*modeltiphereth.UserSession, error)
DeleteUserSession(context.Context, model.InternalID, model.InternalID) error
Expand All @@ -52,6 +53,7 @@ type TipherethRepo interface {
FetchUserSession(context.Context, model.InternalID, string) (*modeltiphereth.UserSession, error)
UpdateUserSession(context.Context, *modeltiphereth.UserSession) error
ListDevices(context.Context, model.InternalID) ([]*modeltiphereth.DeviceInfo, error)
ListPorterGroups(context.Context, []modeltiphereth.UserStatus) ([]*modelsupervisor.PorterGroup, error)
}

type Tiphereth struct {
Expand All @@ -63,7 +65,7 @@ type Tiphereth struct {
searcher *client.Searcher
pullAccount *libmq.Topic[modeltiphereth.PullAccountInfo]
userCountCache *libcache.Key[modeltiphereth.UserCount]
porterInstanceCache *libcache.Map[string, modeltiphereth.PorterInstance]
porterInstanceCache *libcache.Map[string, modelsupervisor.PorterInstance]
}

func NewTiphereth(
Expand All @@ -76,7 +78,7 @@ func NewTiphereth(
pullAccount *libmq.Topic[modeltiphereth.PullAccountInfo],
cron *libcron.Cron,
userCountCache *libcache.Key[modeltiphereth.UserCount],
porterInstanceCache *libcache.Map[string, modeltiphereth.PorterInstance],
porterInstanceCache *libcache.Map[string, modelsupervisor.PorterInstance],
) (*Tiphereth, error) {
t := &Tiphereth{
app: app,
Expand Down Expand Up @@ -170,14 +172,14 @@ func NewUserCountCache(
func NewPorterInstanceCache(
t TipherethRepo,
store libcache.Store,
) *libcache.Map[string, modeltiphereth.PorterInstance] {
return libcache.NewMap[string, modeltiphereth.PorterInstance](
) *libcache.Map[string, modelsupervisor.PorterInstance] {
return libcache.NewMap[string, modelsupervisor.PorterInstance](
store,
"PorterInstanceCache",
func(s string) string {
return s
},
func(ctx context.Context, s string) (*modeltiphereth.PorterInstance, error) {
func(ctx context.Context, s string) (*modelsupervisor.PorterInstance, error) {
return t.FetchPorterByAddress(ctx, s)
},
libcache.WithExpiration(libtime.SevenDays),
Expand Down
16 changes: 8 additions & 8 deletions app/sephirah/internal/biz/bizyesod/builtin_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/url"
"strings"

"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod"
"github.com/tuihub/librarian/internal/lib/libcodec"
"github.com/tuihub/librarian/internal/model/modelfeed"
Expand All @@ -25,15 +25,15 @@ func RequiredStartAction(ctx context.Context, item *modelfeed.Item) (*modelfeed.

func GetBuiltinActionMap(
ctx context.Context,
) map[string]func(context.Context, *modeltiphereth.FeatureRequest, *modelfeed.Item) (*modelfeed.Item, error) {
return map[string]func(context.Context, *modeltiphereth.FeatureRequest, *modelfeed.Item) (*modelfeed.Item, error){
) map[string]func(context.Context, *modelsupervisor.FeatureRequest, *modelfeed.Item) (*modelfeed.Item, error) {
return map[string]func(context.Context, *modelsupervisor.FeatureRequest, *modelfeed.Item) (*modelfeed.Item, error){
simpleKeywordFilterActionID: simpleKeywordFilterAction,
keywordFilterActionID: keywordFilterAction,
descriptionGeneratorActionID: descriptionGeneratorAction,
}
}

func getBuiltinActionFeatureFlags() ([]*modeltiphereth.FeatureFlag, error) {
func getBuiltinActionFeatureFlags() ([]*modelsupervisor.FeatureFlag, error) {
simple, err := modelyesod.GetSimpleKeywordFilterActionConfigSchema()
if err != nil {
return nil, err
Expand All @@ -46,7 +46,7 @@ func getBuiltinActionFeatureFlags() ([]*modeltiphereth.FeatureFlag, error) {
if err != nil {
return nil, err
}
return []*modeltiphereth.FeatureFlag{
return []*modelsupervisor.FeatureFlag{
{
ID: simpleKeywordFilterActionID,
Name: "Simple Keyword Filter",
Expand Down Expand Up @@ -121,7 +121,7 @@ func parseDigestAction(_ context.Context, item *modelfeed.Item) (*modelfeed.Item

func simpleKeywordFilterAction(
_ context.Context,
request *modeltiphereth.FeatureRequest,
request *modelsupervisor.FeatureRequest,
item *modelfeed.Item,
) (*modelfeed.Item, error) {
config := new(modelyesod.SimpleKeywordFilterActionConfig)
Expand Down Expand Up @@ -151,12 +151,12 @@ func simpleKeywordFilterAction(
return item, nil
}

func keywordFilterAction(ctx context.Context, _ *modeltiphereth.FeatureRequest, item *modelfeed.Item) (*modelfeed.Item, error) {
func keywordFilterAction(ctx context.Context, _ *modelsupervisor.FeatureRequest, item *modelfeed.Item) (*modelfeed.Item, error) {
// TODO: impl
return item, nil
}

func descriptionGeneratorAction(_ context.Context, _ *modeltiphereth.FeatureRequest, item *modelfeed.Item) (*modelfeed.Item, error) {
func descriptionGeneratorAction(_ context.Context, _ *modelsupervisor.FeatureRequest, item *modelfeed.Item) (*modelfeed.Item, error) {
if len(item.Description) > 0 {
return item, nil
}
Expand Down
5 changes: 3 additions & 2 deletions app/sephirah/internal/biz/bizyesod/yesod.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/tuihub/librarian/app/sephirah/internal/client"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelnetzach"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod"
"github.com/tuihub/librarian/app/sephirah/internal/supervisor"
Expand Down Expand Up @@ -66,7 +67,7 @@ type Yesod struct {
pullFeed *libmq.Topic[modelyesod.PullFeed]
systemNotify *libmq.Topic[modelnetzach.SystemNotify]
feedOwner *libcache.Map[modelyesod.FeedConfig, modeltiphereth.User]
builtinFeedActions []*modeltiphereth.FeatureFlag
builtinFeedActions []*modelsupervisor.FeatureFlag
}

func NewYesod(
Expand Down Expand Up @@ -100,7 +101,7 @@ func NewYesod(
return y, nil
}

func (y *Yesod) GetBuiltInFeedActions() []*modeltiphereth.FeatureFlag {
func (y *Yesod) GetBuiltInFeedActions() []*modelsupervisor.FeatureFlag {
return y.builtinFeedActions
}

Expand Down
12 changes: 7 additions & 5 deletions app/sephirah/internal/data/internal/converter/biz_to_ent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/tuihub/librarian/app/sephirah/internal/model/modelchesed"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelnetzach"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod"
"github.com/tuihub/librarian/internal/lib/libauth"
Expand Down Expand Up @@ -53,16 +54,17 @@ type toEntConverter interface { //nolint:unused // used by generator
ToEntSystemType(modeltiphereth.SystemType) deviceinfo.SystemType

// goverter:enum:unknown @ignore
// goverter:enum:map PorterInstanceStatusUnspecified @ignore
// goverter:enum:map PorterInstanceStatusActive StatusActive
// goverter:enum:map PorterInstanceStatusBlocked StatusBlocked
ToEntPorterInstanceStatus(modeltiphereth.PorterInstanceStatus) porterinstance.Status
// goverter:enum:map UserStatusUnspecified @ignore
// goverter:enum:map UserStatusActive StatusActive
// goverter:enum:map UserStatusBlocked StatusBlocked
ToEntPorterInstanceStatus(modeltiphereth.UserStatus) porterinstance.Status
ToEntPorterInstanceStatusList([]modeltiphereth.UserStatus) []porterinstance.Status

// goverter:enum:unknown @ignore
// goverter:enum:map PorterContextStatusUnspecified @ignore
// goverter:enum:map PorterContextStatusActive StatusActive
// goverter:enum:map PorterContextStatusDisabled StatusDisabled
ToEntPorterContextStatus(modeltiphereth.PorterContextStatus) portercontext.Status
ToEntPorterContextStatus(modelsupervisor.PorterContextStatus) portercontext.Status

// goverter:autoMap Details
// goverter:useZeroValueOnPointerInconsistency
Expand Down
20 changes: 11 additions & 9 deletions app/sephirah/internal/data/internal/converter/ent_to_biz.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/tuihub/librarian/app/sephirah/internal/model/modelchesed"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelgebura"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelnetzach"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelsupervisor"
"github.com/tuihub/librarian/app/sephirah/internal/model/modeltiphereth"
"github.com/tuihub/librarian/app/sephirah/internal/model/modelyesod"
"github.com/tuihub/librarian/internal/lib/libauth"
Expand Down Expand Up @@ -67,21 +68,22 @@ type toBizConverter interface { //nolint:unused // used by generator
ToBizAccount(*ent.Account) *modeltiphereth.Account
ToBizAccountList([]*ent.Account) []*modeltiphereth.Account

ToBizPorter(*ent.PorterInstance) *modeltiphereth.PorterInstance
ToBizPorterList([]*ent.PorterInstance) []*modeltiphereth.PorterInstance
// goverter:enum:unknown PorterInstanceStatusUnspecified
// goverter:enum:map StatusActive PorterInstanceStatusActive
// goverter:enum:map StatusBlocked PorterInstanceStatusBlocked
ToBizPorterStatus(porterinstance.Status) modeltiphereth.PorterInstanceStatus
// goverter:map . BinarySummary
ToBizPorter(*ent.PorterInstance) *modelsupervisor.PorterInstance
ToBizPorterList([]*ent.PorterInstance) []*modelsupervisor.PorterInstance
// goverter:enum:unknown UserStatusUnspecified
// goverter:enum:map StatusActive UserStatusActive
// goverter:enum:map StatusBlocked UserStatusBlocked
ToBizPorterStatus(porterinstance.Status) modeltiphereth.UserStatus

// goverter:ignore HandleStatus
// goverter:ignore HandleStatusMessage
ToBizPorterContext(*ent.PorterContext) *modeltiphereth.PorterContext
ToBizPorterContextList([]*ent.PorterContext) []*modeltiphereth.PorterContext
ToBizPorterContext(*ent.PorterContext) *modelsupervisor.PorterContext
ToBizPorterContextList([]*ent.PorterContext) []*modelsupervisor.PorterContext
// goverter:enum:unknown PorterContextStatusUnspecified
// goverter:enum:map StatusActive PorterContextStatusActive
// goverter:enum:map StatusDisabled PorterContextStatusDisabled
ToBizPorterContextStatus(portercontext.Status) modeltiphereth.PorterContextStatus
ToBizPorterContextStatus(portercontext.Status) modelsupervisor.PorterContextStatus

// goverter:map . Details
// goverter:map UpdatedAt LatestUpdateTime
Expand Down
Loading

0 comments on commit 7f5ba6d

Please sign in to comment.