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

Fix to resynchronize the org entires #430

Merged
merged 4 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func newChatConfig(c *Config) *server.ChatConfig {
}

func NewInteractor(c *Config) server.Interactor {
return interactor.NewInteractor(
i := interactor.NewInteractor(
&interactor.InteractorConfig{
// Server Configurations:
ServerHost: c.ServerHost,
Expand All @@ -150,6 +150,10 @@ func NewInteractor(c *Config) server.Interactor {
SCM: newSCM(c),
},
)

i.Init()

return i
}

func newStore(c *Config) interactor.Store {
Expand Down
1 change: 1 addition & 0 deletions internal/interactor/_mock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mockgen \
-aux_files \
github.com/gitploy-io/gitploy/internal/interactor=user.go\
,github.com/gitploy-io/gitploy/internal/interactor=repo.go\
,github.com/gitploy-io/gitploy/internal/interactor=perm.go\
,github.com/gitploy-io/gitploy/internal/interactor=config.go\
,github.com/gitploy-io/gitploy/internal/interactor=deployment.go\
,github.com/gitploy-io/gitploy/internal/interactor=deploymentstatistics.go\
Expand Down
141 changes: 80 additions & 61 deletions internal/interactor/interactor.go
Original file line number Diff line number Diff line change
@@ -1,68 +1,86 @@
package interactor

import (
"context"
"fmt"
"time"

evbus "github.com/asaskevich/EventBus"
"go.uber.org/zap"
)

type (
Interactor struct {
Store
SCM

// The channel to stop background workers.
stopCh chan struct{}

common *service

// services used for talking to different parts of the entities.
*ConfigInteractor
*DeploymentInteractor
*DeploymentStatisticsInteractor
*EventInteractor
*LicenseInteractor
*LockInteractor
*RepoInteractor
*ReviewInteractor
*UserInteractor
}
type InteractorConfig struct {
ServerHost string
ServerProto string
ServerProxyHost string
ServerProxyProto string

InteractorConfig struct {
ServerHost string
ServerProto string
ServerProxyHost string
ServerProxyProto string
OrgEntries []string
MemberEntries []string
AdminUsers []string

OrgEntries []string
MemberEntries []string
AdminUsers []string
WebhookSecret string

WebhookSecret string
LicenseKey string

LicenseKey string
Store
SCM
}

Store
SCM
func (c *InteractorConfig) BuildWebhookURL() string {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
}

service struct {
store Store
scm SCM
log *zap.Logger
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
}

func (c *InteractorConfig) CheckWebhookSSL() bool {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return c.ServerProxyProto == "https"
}
)

return c.ServerProto == "https"
}

type service struct {
store Store
scm SCM
log *zap.Logger
}

type Interactor struct {
Store
SCM

// The channel to stop background workers.
stopCh chan struct{}

common *service

// services used for talking to different parts of the entities.
*ConfigInteractor
*DeploymentInteractor
*DeploymentStatisticsInteractor
*EventInteractor
*LicenseInteractor
*LockInteractor
*RepoInteractor
*ReviewInteractor
*UserInteractor
*PermInteractor
}

func NewInteractor(c *InteractorConfig) *Interactor {
log := zap.L().Named("interactor")
defer log.Sync()

i := &Interactor{
Store: c.Store,
SCM: c.SCM,
stopCh: make(chan struct{}),
}

log := zap.L().Named("interactor")

i.common = &service{
store: c.Store,
scm: c.SCM,
Expand Down Expand Up @@ -94,37 +112,38 @@ func NewInteractor(c *InteractorConfig) *Interactor {
orgEntries: c.OrgEntries,
memberEntries: c.MemberEntries,
}
i.PermInteractor = &PermInteractor{
service: i.common,
orgEntries: c.OrgEntries,
}

return i
}

func (i *Interactor) Init() {
log := zap.L().Named("interactor")
defer log.Sync()

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

log.Debug("Resync organization entries.")
if err := i.ResyncPerms(ctx); err != nil {
log.Fatal("Failed to resynchronize with the perms.", zap.Error(err))
}

go func() {
log.Info("Start the working publishing events.")
log.Debug("Start the working publishing events.")
i.runPublishingEvents(i.stopCh)
}()

go func() {
log.Info("Start the worker canceling inactive deployments.")
log.Debug("Start the worker canceling inactive deployments.")
i.runClosingInactiveDeployment(i.stopCh)
}()

go func() {
log.Info("Start the worker for the auto unlock.")
log.Debug("Start the worker for the auto unlock.")
i.runAutoUnlock(i.stopCh)
}()

return i
}

func (c *InteractorConfig) BuildWebhookURL() string {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
}

return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
}

func (c *InteractorConfig) CheckWebhookSSL() bool {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return c.ServerProxyProto == "https"
}

return c.ServerProto == "https"
}
17 changes: 0 additions & 17 deletions internal/interactor/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package interactor

import (
"context"
"time"

"github.com/gitploy-io/gitploy/model/ent"
"github.com/gitploy-io/gitploy/model/extent"
Expand All @@ -24,22 +23,6 @@ type (
EventStore
}

// PermStore defines operations for working with perms.
PermStore interface {
ListPermsOfRepo(ctx context.Context, r *ent.Repo, opt *ListPermsOfRepoOptions) ([]*ent.Perm, error)
FindPermOfRepo(ctx context.Context, r *ent.Repo, u *ent.User) (*ent.Perm, error)
CreatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
UpdatePerm(ctx context.Context, p *ent.Perm) (*ent.Perm, error)
DeletePermsOfUserLessThanSyncedAt(ctx context.Context, u *ent.User, t time.Time) (int, error)
}

ListPermsOfRepoOptions struct {
ListOptions

// Query search the 'login' contains the query.
Query string
}

// PermStore defines operations for working with deployment_statuses.
DeploymentStatusStore interface {
ListDeploymentStatuses(ctx context.Context, d *ent.Deployment) ([]*ent.DeploymentStatus, error)
Expand Down
127 changes: 29 additions & 98 deletions internal/interactor/mock/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading