Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 36c55c7

Browse files
author
Noah Lee
authored
Fix to resynchronize the org entires (#430)
* Add resync the perms logic * Implement methods for the store * Fix to eager load edges * Fix the bugs
1 parent e1e0ef7 commit 36c55c7

File tree

8 files changed

+291
-177
lines changed

8 files changed

+291
-177
lines changed

Diff for: cmd/server/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func newChatConfig(c *Config) *server.ChatConfig {
131131
}
132132

133133
func NewInteractor(c *Config) server.Interactor {
134-
return interactor.NewInteractor(
134+
i := interactor.NewInteractor(
135135
&interactor.InteractorConfig{
136136
// Server Configurations:
137137
ServerHost: c.ServerHost,
@@ -150,6 +150,10 @@ func NewInteractor(c *Config) server.Interactor {
150150
SCM: newSCM(c),
151151
},
152152
)
153+
154+
i.Init()
155+
156+
return i
153157
}
154158

155159
func newStore(c *Config) interactor.Store {

Diff for: internal/interactor/_mock.sh

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mockgen \
22
-aux_files \
33
github.com/gitploy-io/gitploy/internal/interactor=user.go\
44
,github.com/gitploy-io/gitploy/internal/interactor=repo.go\
5+
,github.com/gitploy-io/gitploy/internal/interactor=perm.go\
56
,github.com/gitploy-io/gitploy/internal/interactor=config.go\
67
,github.com/gitploy-io/gitploy/internal/interactor=deployment.go\
78
,github.com/gitploy-io/gitploy/internal/interactor=deploymentstatistics.go\

Diff for: internal/interactor/interactor.go

+80-61
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,86 @@
11
package interactor
22

33
import (
4+
"context"
45
"fmt"
6+
"time"
57

68
evbus "github.com/asaskevich/EventBus"
79
"go.uber.org/zap"
810
)
911

10-
type (
11-
Interactor struct {
12-
Store
13-
SCM
14-
15-
// The channel to stop background workers.
16-
stopCh chan struct{}
17-
18-
common *service
19-
20-
// services used for talking to different parts of the entities.
21-
*ConfigInteractor
22-
*DeploymentInteractor
23-
*DeploymentStatisticsInteractor
24-
*EventInteractor
25-
*LicenseInteractor
26-
*LockInteractor
27-
*RepoInteractor
28-
*ReviewInteractor
29-
*UserInteractor
30-
}
12+
type InteractorConfig struct {
13+
ServerHost string
14+
ServerProto string
15+
ServerProxyHost string
16+
ServerProxyProto string
3117

32-
InteractorConfig struct {
33-
ServerHost string
34-
ServerProto string
35-
ServerProxyHost string
36-
ServerProxyProto string
18+
OrgEntries []string
19+
MemberEntries []string
20+
AdminUsers []string
3721

38-
OrgEntries []string
39-
MemberEntries []string
40-
AdminUsers []string
22+
WebhookSecret string
4123

42-
WebhookSecret string
24+
LicenseKey string
4325

44-
LicenseKey string
26+
Store
27+
SCM
28+
}
4529

46-
Store
47-
SCM
30+
func (c *InteractorConfig) BuildWebhookURL() string {
31+
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
32+
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
4833
}
4934

50-
service struct {
51-
store Store
52-
scm SCM
53-
log *zap.Logger
35+
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
36+
}
37+
38+
func (c *InteractorConfig) CheckWebhookSSL() bool {
39+
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
40+
return c.ServerProxyProto == "https"
5441
}
55-
)
42+
43+
return c.ServerProto == "https"
44+
}
45+
46+
type service struct {
47+
store Store
48+
scm SCM
49+
log *zap.Logger
50+
}
51+
52+
type Interactor struct {
53+
Store
54+
SCM
55+
56+
// The channel to stop background workers.
57+
stopCh chan struct{}
58+
59+
common *service
60+
61+
// services used for talking to different parts of the entities.
62+
*ConfigInteractor
63+
*DeploymentInteractor
64+
*DeploymentStatisticsInteractor
65+
*EventInteractor
66+
*LicenseInteractor
67+
*LockInteractor
68+
*RepoInteractor
69+
*ReviewInteractor
70+
*UserInteractor
71+
*PermInteractor
72+
}
5673

5774
func NewInteractor(c *InteractorConfig) *Interactor {
75+
log := zap.L().Named("interactor")
76+
defer log.Sync()
77+
5878
i := &Interactor{
5979
Store: c.Store,
6080
SCM: c.SCM,
6181
stopCh: make(chan struct{}),
6282
}
6383

64-
log := zap.L().Named("interactor")
65-
6684
i.common = &service{
6785
store: c.Store,
6886
scm: c.SCM,
@@ -94,37 +112,38 @@ func NewInteractor(c *InteractorConfig) *Interactor {
94112
orgEntries: c.OrgEntries,
95113
memberEntries: c.MemberEntries,
96114
}
115+
i.PermInteractor = &PermInteractor{
116+
service: i.common,
117+
orgEntries: c.OrgEntries,
118+
}
119+
120+
return i
121+
}
122+
123+
func (i *Interactor) Init() {
124+
log := zap.L().Named("interactor")
125+
defer log.Sync()
126+
127+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
128+
defer cancel()
129+
130+
log.Debug("Resync organization entries.")
131+
if err := i.ResyncPerms(ctx); err != nil {
132+
log.Fatal("Failed to resynchronize with the perms.", zap.Error(err))
133+
}
97134

98135
go func() {
99-
log.Info("Start the working publishing events.")
136+
log.Debug("Start the working publishing events.")
100137
i.runPublishingEvents(i.stopCh)
101138
}()
102139

103140
go func() {
104-
log.Info("Start the worker canceling inactive deployments.")
141+
log.Debug("Start the worker canceling inactive deployments.")
105142
i.runClosingInactiveDeployment(i.stopCh)
106143
}()
107144

108145
go func() {
109-
log.Info("Start the worker for the auto unlock.")
146+
log.Debug("Start the worker for the auto unlock.")
110147
i.runAutoUnlock(i.stopCh)
111148
}()
112-
113-
return i
114-
}
115-
116-
func (c *InteractorConfig) BuildWebhookURL() string {
117-
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
118-
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
119-
}
120-
121-
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
122-
}
123-
124-
func (c *InteractorConfig) CheckWebhookSSL() bool {
125-
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
126-
return c.ServerProxyProto == "https"
127-
}
128-
129-
return c.ServerProto == "https"
130149
}

Diff for: internal/interactor/interface.go

-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package interactor
44

55
import (
66
"context"
7-
"time"
87

98
"github.com/gitploy-io/gitploy/model/ent"
109
"github.com/gitploy-io/gitploy/model/extent"
@@ -24,22 +23,6 @@ type (
2423
EventStore
2524
}
2625

27-
// PermStore defines operations for working with perms.
28-
PermStore interface {
29-
ListPermsOfRepo(ctx context.Context, r *ent.Repo, opt *ListPermsOfRepoOptions) ([]*ent.Perm, error)
30-
FindPermOfRepo(ctx context.Context, r *ent.Repo, u *ent.User) (*ent.Perm, error)
31-
CreatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
32-
UpdatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
33-
DeletePermsOfUserLessThanSyncedAt(ctx context.Context, u *ent.User, t time.Time) (int, error)
34-
}
35-
36-
ListPermsOfRepoOptions struct {
37-
ListOptions
38-
39-
// Query search the 'login' contains the query.
40-
Query string
41-
}
42-
4326
// PermStore defines operations for working with deployment_statuses.
4427
DeploymentStatusStore interface {
4528
ListDeploymentStatuses(ctx context.Context, d *ent.Deployment) ([]*ent.DeploymentStatus, error)

Diff for: internal/interactor/mock/pkg.go

+29-98
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)