mirror of https://github.com/harness/drone.git
feat: [CODE-2947]: add user events and metric handlers (#3597)
parent
60a182e515
commit
444aafdb0b
|
@ -22,8 +22,8 @@ import (
|
|||
"github.com/harness/gitness/app/api/usererror"
|
||||
"github.com/harness/gitness/app/auth"
|
||||
"github.com/harness/gitness/app/auth/authz"
|
||||
eventsgit "github.com/harness/gitness/app/events/git"
|
||||
eventsrepo "github.com/harness/gitness/app/events/repo"
|
||||
gitevents "github.com/harness/gitness/app/events/git"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
"github.com/harness/gitness/app/services/protection"
|
||||
"github.com/harness/gitness/app/services/refcache"
|
||||
"github.com/harness/gitness/app/services/settings"
|
||||
|
@ -44,8 +44,8 @@ type Controller struct {
|
|||
principalStore store.PrincipalStore
|
||||
repoStore store.RepoStore
|
||||
repoFinder refcache.RepoFinder
|
||||
gitReporter *eventsgit.Reporter
|
||||
repoReporter *eventsrepo.Reporter
|
||||
gitReporter *gitevents.Reporter
|
||||
repoReporter *repoevents.Reporter
|
||||
git git.Interface
|
||||
pullreqStore store.PullReqStore
|
||||
urlProvider url.Provider
|
||||
|
@ -64,8 +64,8 @@ func NewController(
|
|||
principalStore store.PrincipalStore,
|
||||
repoStore store.RepoStore,
|
||||
repoFinder refcache.RepoFinder,
|
||||
gitReporter *eventsgit.Reporter,
|
||||
repoReporter *eventsrepo.Reporter,
|
||||
gitReporter *gitevents.Reporter,
|
||||
repoReporter *repoevents.Reporter,
|
||||
git git.Interface,
|
||||
pullreqStore store.PullReqStore,
|
||||
urlProvider url.Provider,
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/harness/gitness/app/api/usererror"
|
||||
"github.com/harness/gitness/app/auth"
|
||||
"github.com/harness/gitness/app/bootstrap"
|
||||
events "github.com/harness/gitness/app/events/git"
|
||||
gitevents "github.com/harness/gitness/app/events/git"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
"github.com/harness/gitness/git/hook"
|
||||
"github.com/harness/gitness/types"
|
||||
|
@ -85,6 +85,13 @@ func (c *Controller) PostReceive(
|
|||
return hook.Output{}, fmt.Errorf("failed to extend post-receive hook: %w", err)
|
||||
}
|
||||
|
||||
c.repoReporter.Pushed(ctx, &repoevents.PushedPayload{
|
||||
Base: repoevents.Base{
|
||||
RepoID: in.RepoID,
|
||||
PrincipalID: in.PrincipalID,
|
||||
},
|
||||
})
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
@ -120,7 +127,7 @@ func (c *Controller) reportBranchEvent(
|
|||
) {
|
||||
switch {
|
||||
case branchUpdate.Old.IsNil():
|
||||
payload := &events.BranchCreatedPayload{
|
||||
payload := &gitevents.BranchCreatedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: branchUpdate.Ref,
|
||||
|
@ -132,7 +139,7 @@ func (c *Controller) reportBranchEvent(
|
|||
c.sseStreamer.Publish(ctx, repo.ParentID, enum.SSETypeBranchCreated, payload)
|
||||
|
||||
case branchUpdate.New.IsNil():
|
||||
payload := &events.BranchDeletedPayload{
|
||||
payload := &gitevents.BranchDeletedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: branchUpdate.Ref,
|
||||
|
@ -156,7 +163,7 @@ func (c *Controller) reportBranchEvent(
|
|||
Msg("failed to check ancestor")
|
||||
}
|
||||
|
||||
payload := &events.BranchUpdatedPayload{
|
||||
payload := &gitevents.BranchUpdatedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: branchUpdate.Ref,
|
||||
|
@ -179,7 +186,7 @@ func (c *Controller) reportTagEvent(
|
|||
) {
|
||||
switch {
|
||||
case tagUpdate.Old.IsNil():
|
||||
payload := &events.TagCreatedPayload{
|
||||
payload := &gitevents.TagCreatedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: tagUpdate.Ref,
|
||||
|
@ -191,7 +198,7 @@ func (c *Controller) reportTagEvent(
|
|||
c.sseStreamer.Publish(ctx, repo.ParentID, enum.SSETypeTagCreated, payload)
|
||||
|
||||
case tagUpdate.New.IsNil():
|
||||
payload := &events.TagDeletedPayload{
|
||||
payload := &gitevents.TagDeletedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: tagUpdate.Ref,
|
||||
|
@ -203,7 +210,7 @@ func (c *Controller) reportTagEvent(
|
|||
c.sseStreamer.Publish(ctx, repo.ParentID, enum.SSETypeTagDeleted, payload)
|
||||
|
||||
default:
|
||||
payload := &events.TagUpdatedPayload{
|
||||
payload := &gitevents.TagUpdatedPayload{
|
||||
RepoID: repo.ID,
|
||||
PrincipalID: principalID,
|
||||
Ref: tagUpdate.Ref,
|
||||
|
|
|
@ -173,7 +173,8 @@ func (c *Controller) CreateRepo(
|
|||
RepoID: repo.ID,
|
||||
PrincipalID: session.Principal.ID,
|
||||
},
|
||||
Type: "migrated",
|
||||
IsPublic: isRepoPublic,
|
||||
IsMigrated: true,
|
||||
})
|
||||
|
||||
return &repoCtrl.RepositoryOutput{
|
||||
|
|
|
@ -182,8 +182,8 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||
}
|
||||
|
||||
c.eventReporter.Created(ctx, &repoevents.CreatedPayload{
|
||||
Base: eventBase(repo.Core(), &session.Principal),
|
||||
Type: "created",
|
||||
Base: eventBase(repo.Core(), &session.Principal),
|
||||
IsPublic: in.IsPublic,
|
||||
})
|
||||
|
||||
// index repository if files are created
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/harness/gitness/app/auth/authz"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/store/database/dbtx"
|
||||
"github.com/harness/gitness/types"
|
||||
|
@ -35,6 +36,7 @@ type Controller struct {
|
|||
tokenStore store.TokenStore
|
||||
membershipStore store.MembershipStore
|
||||
publicKeyStore store.PublicKeyStore
|
||||
eventReporter *userevents.Reporter
|
||||
}
|
||||
|
||||
func NewController(
|
||||
|
@ -45,6 +47,7 @@ func NewController(
|
|||
tokenStore store.TokenStore,
|
||||
membershipStore store.MembershipStore,
|
||||
publicKeyStore store.PublicKeyStore,
|
||||
eventReporter *userevents.Reporter,
|
||||
) *Controller {
|
||||
return &Controller{
|
||||
tx: tx,
|
||||
|
@ -54,6 +57,7 @@ func NewController(
|
|||
tokenStore: tokenStore,
|
||||
membershipStore: membershipStore,
|
||||
publicKeyStore: publicKeyStore,
|
||||
eventReporter: eventReporter,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
apiauth "github.com/harness/gitness/app/api/auth"
|
||||
"github.com/harness/gitness/app/auth"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/check"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -50,15 +51,25 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return c.CreateNoAuth(ctx, in, false)
|
||||
user, err := c.CreateNoAuth(ctx, in, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create user: %w", err)
|
||||
}
|
||||
|
||||
c.eventReporter.Created(ctx, &userevents.CreatedPayload{
|
||||
Base: userevents.Base{
|
||||
PrincipalID: session.Principal.ID,
|
||||
},
|
||||
CreatedPrincipalID: user.ID,
|
||||
})
|
||||
|
||||
return user, nil
|
||||
}
|
||||
|
||||
/*
|
||||
* CreateNoAuth creates a new user without auth checks.
|
||||
* WARNING: Never call as part of user flow.
|
||||
*
|
||||
* Note: take admin separately to avoid potential vulnerabilities for user calls.
|
||||
*/
|
||||
// CreateNoAuth creates a new user without auth checks.
|
||||
// WARNING: Never call as part of user flow.
|
||||
//
|
||||
// Note: take admin separately to avoid potential vulnerabilities for user calls.
|
||||
func (c *Controller) CreateNoAuth(ctx context.Context, in *CreateInput, admin bool) (*types.User, error) {
|
||||
if err := c.sanitizeCreateInput(in); err != nil {
|
||||
return nil, fmt.Errorf("invalid input: %w", err)
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/harness/gitness/app/api/usererror"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/token"
|
||||
"github.com/harness/gitness/store"
|
||||
"github.com/harness/gitness/types"
|
||||
|
@ -32,9 +33,7 @@ type LoginInput struct {
|
|||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
/*
|
||||
* Login attempts to login as a specific user - returns the session token if successful.
|
||||
*/
|
||||
// Login attempts to login as a specific user - returns the session token if successful.
|
||||
func (c *Controller) Login(
|
||||
ctx context.Context,
|
||||
in *LoginInput,
|
||||
|
@ -72,5 +71,9 @@ func (c *Controller) Login(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
c.eventReporter.LoggedIn(ctx, &userevents.LoggedInPayload{
|
||||
Base: userevents.Base{PrincipalID: user.ID},
|
||||
})
|
||||
|
||||
return &types.TokenResponse{Token: *token, AccessToken: jwtToken}, nil
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
|
||||
"github.com/harness/gitness/app/api/controller/system"
|
||||
"github.com/harness/gitness/app/api/usererror"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/token"
|
||||
"github.com/harness/gitness/types"
|
||||
)
|
||||
|
@ -60,5 +61,9 @@ func (c *Controller) Register(ctx context.Context, sysCtrl *system.Controller,
|
|||
return nil, fmt.Errorf("failed to create token after successful user creation: %w", err)
|
||||
}
|
||||
|
||||
c.eventReporter.Registered(ctx, &userevents.RegisteredPayload{
|
||||
Base: userevents.Base{PrincipalID: user.ID},
|
||||
})
|
||||
|
||||
return &types.TokenResponse{Token: *token, AccessToken: jwtToken}, nil
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package user
|
|||
|
||||
import (
|
||||
"github.com/harness/gitness/app/auth/authz"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/store/database/dbtx"
|
||||
"github.com/harness/gitness/types/check"
|
||||
|
@ -36,6 +37,7 @@ func ProvideController(
|
|||
tokenStore store.TokenStore,
|
||||
membershipStore store.MembershipStore,
|
||||
publicKeyStore store.PublicKeyStore,
|
||||
eventReporter *userevents.Reporter,
|
||||
) *Controller {
|
||||
return NewController(
|
||||
tx,
|
||||
|
@ -44,5 +46,6 @@ func ProvideController(
|
|||
principalStore,
|
||||
tokenStore,
|
||||
membershipStore,
|
||||
publicKeyStore)
|
||||
publicKeyStore,
|
||||
eventReporter)
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ const CreatedEvent events.EventType = "created"
|
|||
|
||||
type CreatedPayload struct {
|
||||
Base
|
||||
Type string `json:"type"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
IsMigrated bool `json:"is_migrated"`
|
||||
ImportedFrom string `json:"imported_from"`
|
||||
}
|
||||
|
||||
func (r *Reporter) Created(ctx context.Context, payload *CreatedPayload) {
|
||||
|
@ -187,3 +189,26 @@ func (r *Reader) RegisterDefaultBranchUpdated(
|
|||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, DefaultBranchUpdatedEvent, fn, opts...)
|
||||
}
|
||||
|
||||
const PushedEvent events.EventType = "pushed"
|
||||
|
||||
type PushedPayload struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (r *Reporter) Pushed(ctx context.Context, payload *PushedPayload) {
|
||||
eventID, err := events.ReporterSendEvent(r.innerReporter, ctx, PushedEvent, payload)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Err(err).Msgf("failed to send pushed event")
|
||||
return
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("reported pushed event with id '%s'", eventID)
|
||||
}
|
||||
|
||||
func (r *Reader) RegisterPushed(
|
||||
fn events.HandlerFunc[*PushedPayload],
|
||||
opts ...events.HandlerOption,
|
||||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, PushedEvent, fn, opts...)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
const (
|
||||
// category defines the event category used for this package.
|
||||
category = "rule"
|
||||
)
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
type Base struct {
|
||||
RuleID int64 `json:"rule_id"`
|
||||
SpaceID *int64 `json:"space_id"`
|
||||
RepoID *int64 `json:"repo_id"`
|
||||
PrincipalID int64 `json:"principal_id"`
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/events"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const CreatedEvent events.EventType = "created"
|
||||
|
||||
type CreatedPayload struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (r *Reporter) Created(ctx context.Context, payload *CreatedPayload) {
|
||||
if payload == nil {
|
||||
return
|
||||
}
|
||||
|
||||
eventID, err := events.ReporterSendEvent(r.innerReporter, ctx, CreatedEvent, payload)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Err(err).Msgf("failed to send rule created event")
|
||||
return
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("reported rule created event with id '%s'", eventID)
|
||||
}
|
||||
|
||||
func (r *Reader) RegisterCreated(
|
||||
fn events.HandlerFunc[*CreatedPayload],
|
||||
opts ...events.HandlerOption,
|
||||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, CreatedEvent, fn, opts...)
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/events"
|
||||
)
|
||||
|
||||
func NewReaderFactory(eventsSystem *events.System) (*events.ReaderFactory[*Reader], error) {
|
||||
readerFactoryFunc := func(innerReader *events.GenericReader) (*Reader, error) {
|
||||
return &Reader{
|
||||
innerReader: innerReader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return events.NewReaderFactory(eventsSystem, category, readerFactoryFunc)
|
||||
}
|
||||
|
||||
// Reader is the event reader for this package.
|
||||
type Reader struct {
|
||||
innerReader *events.GenericReader
|
||||
}
|
||||
|
||||
func (r *Reader) Configure(opts ...events.ReaderOption) {
|
||||
r.innerReader.Configure(opts...)
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/harness/gitness/events"
|
||||
)
|
||||
|
||||
// Reporter is the event reporter for this package.
|
||||
type Reporter struct {
|
||||
innerReporter *events.GenericReporter
|
||||
}
|
||||
|
||||
func NewReporter(eventsSystem *events.System) (*Reporter, error) {
|
||||
innerReporter, err := events.NewReporter(eventsSystem, category)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to create new GenericReporter from event system")
|
||||
}
|
||||
|
||||
return &Reporter{
|
||||
innerReporter: innerReporter,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/events"
|
||||
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
// WireSet provides a wire set for this package.
|
||||
var WireSet = wire.NewSet(
|
||||
ProvideReaderFactory,
|
||||
ProvideReporter,
|
||||
)
|
||||
|
||||
func ProvideReaderFactory(eventsSystem *events.System) (*events.ReaderFactory[*Reader], error) {
|
||||
return NewReaderFactory(eventsSystem)
|
||||
}
|
||||
|
||||
func ProvideReporter(eventsSystem *events.System) (*Reporter, error) {
|
||||
return NewReporter(eventsSystem)
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
const (
|
||||
// category defines the event category used for this package.
|
||||
category = "user"
|
||||
)
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
type Base struct {
|
||||
PrincipalID int64 `json:"principal_id"`
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/events"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const RegisteredEvent events.EventType = "registered"
|
||||
|
||||
type RegisteredPayload struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (r *Reporter) Registered(ctx context.Context, payload *RegisteredPayload) {
|
||||
if payload == nil {
|
||||
return
|
||||
}
|
||||
|
||||
eventID, err := events.ReporterSendEvent(r.innerReporter, ctx, RegisteredEvent, payload)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Err(err).Msgf("failed to send user registered event")
|
||||
return
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("reported user registered event with id '%s'", eventID)
|
||||
}
|
||||
|
||||
func (r *Reader) RegisterRegistered(
|
||||
fn events.HandlerFunc[*RegisteredPayload],
|
||||
opts ...events.HandlerOption,
|
||||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, RegisteredEvent, fn, opts...)
|
||||
}
|
||||
|
||||
const CreatedEvent events.EventType = "created"
|
||||
|
||||
type CreatedPayload struct {
|
||||
Base
|
||||
|
||||
// CreatedPrincipalID is ID of the created user.
|
||||
CreatedPrincipalID int64 `json:"created_principal_id"`
|
||||
}
|
||||
|
||||
func (r *Reporter) Created(ctx context.Context, payload *CreatedPayload) {
|
||||
if payload == nil {
|
||||
return
|
||||
}
|
||||
|
||||
eventID, err := events.ReporterSendEvent(r.innerReporter, ctx, CreatedEvent, payload)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Err(err).Msgf("failed to send user created event")
|
||||
return
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("reported user created event with id '%s'", eventID)
|
||||
}
|
||||
|
||||
func (r *Reader) RegisterCreated(
|
||||
fn events.HandlerFunc[*CreatedPayload],
|
||||
opts ...events.HandlerOption,
|
||||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, CreatedEvent, fn, opts...)
|
||||
}
|
||||
|
||||
const LoggedInEvent events.EventType = "logged-in"
|
||||
|
||||
type LoggedInPayload struct {
|
||||
Base
|
||||
}
|
||||
|
||||
func (r *Reporter) LoggedIn(ctx context.Context, payload *LoggedInPayload) {
|
||||
if payload == nil {
|
||||
return
|
||||
}
|
||||
|
||||
eventID, err := events.ReporterSendEvent(r.innerReporter, ctx, LoggedInEvent, payload)
|
||||
if err != nil {
|
||||
log.Ctx(ctx).Err(err).Msgf("failed to send user logged-in event")
|
||||
return
|
||||
}
|
||||
|
||||
log.Ctx(ctx).Debug().Msgf("reported user logged-in event with id '%s'", eventID)
|
||||
}
|
||||
|
||||
func (r *Reader) RegisterLoggedIn(
|
||||
fn events.HandlerFunc[*LoggedInPayload],
|
||||
opts ...events.HandlerOption,
|
||||
) error {
|
||||
return events.ReaderRegisterEvent(r.innerReader, LoggedInEvent, fn, opts...)
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/events"
|
||||
)
|
||||
|
||||
func NewReaderFactory(eventsSystem *events.System) (*events.ReaderFactory[*Reader], error) {
|
||||
readerFactoryFunc := func(innerReader *events.GenericReader) (*Reader, error) {
|
||||
return &Reader{
|
||||
innerReader: innerReader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return events.NewReaderFactory(eventsSystem, category, readerFactoryFunc)
|
||||
}
|
||||
|
||||
// Reader is the event reader for this package.
|
||||
type Reader struct {
|
||||
innerReader *events.GenericReader
|
||||
}
|
||||
|
||||
func (r *Reader) Configure(opts ...events.ReaderOption) {
|
||||
r.innerReader.Configure(opts...)
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/harness/gitness/events"
|
||||
)
|
||||
|
||||
// Reporter is the event reporter for this package.
|
||||
type Reporter struct {
|
||||
innerReporter *events.GenericReporter
|
||||
}
|
||||
|
||||
func NewReporter(eventsSystem *events.System) (*Reporter, error) {
|
||||
innerReporter, err := events.NewReporter(eventsSystem, category)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to create new GenericReporter from event system")
|
||||
}
|
||||
|
||||
return &Reporter{
|
||||
innerReporter: innerReporter,
|
||||
}, nil
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2023 Harness, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/events"
|
||||
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
// WireSet provides a wire set for this package.
|
||||
var WireSet = wire.NewSet(
|
||||
ProvideReaderFactory,
|
||||
ProvideReporter,
|
||||
)
|
||||
|
||||
func ProvideReaderFactory(eventsSystem *events.System) (*events.ReaderFactory[*Reader], error) {
|
||||
return NewReaderFactory(eventsSystem)
|
||||
}
|
||||
|
||||
func ProvideReporter(eventsSystem *events.System) (*Reporter, error) {
|
||||
return NewReporter(eventsSystem)
|
||||
}
|
|
@ -377,7 +377,8 @@ func (r *Repository) Handle(ctx context.Context, data string, _ job.ProgressRepo
|
|||
RepoID: repo.ID,
|
||||
PrincipalID: bootstrap.NewSystemServiceSession().Principal.ID,
|
||||
},
|
||||
Type: "imported",
|
||||
IsPublic: input.Public,
|
||||
ImportedFrom: input.CloneURL,
|
||||
})
|
||||
|
||||
err = r.indexer.Index(ctx, repo)
|
||||
|
|
|
@ -23,46 +23,51 @@ import (
|
|||
type Object string
|
||||
|
||||
const (
|
||||
ObjectRepository Object = "repository"
|
||||
ObjectPullRequest Object = "pull_request"
|
||||
ObjectUser Object = "user"
|
||||
ObjectRepository Object = "repo"
|
||||
ObjectPullRequest Object = "pr"
|
||||
ObjectRule Object = "rule"
|
||||
)
|
||||
|
||||
type VerbRepo string
|
||||
type Verb string
|
||||
|
||||
// User verbs.
|
||||
const (
|
||||
VerbUserCreate Verb = "create"
|
||||
VerbUserLogin Verb = "login"
|
||||
)
|
||||
|
||||
// Repository verbs.
|
||||
const (
|
||||
VerbRepoCreate VerbRepo = "create"
|
||||
VerbRepoUpdate VerbRepo = "update"
|
||||
VerbRepoDelete VerbRepo = "delete"
|
||||
VerbRepoCreate Verb = "create"
|
||||
VerbRepoPush Verb = "push"
|
||||
VerbRepoDelete Verb = "delete"
|
||||
)
|
||||
|
||||
type VerbPullReq string
|
||||
|
||||
// Pull request verbs.
|
||||
const (
|
||||
VerbPullReqCreate VerbPullReq = "create"
|
||||
VerbPullReqMerge VerbPullReq = "merge"
|
||||
VerbPullReqClose VerbPullReq = "close"
|
||||
VerbPullReqReopen VerbPullReq = "reopen"
|
||||
VerbPullReqCreate Verb = "create"
|
||||
VerbPullReqMerge Verb = "merge"
|
||||
VerbPullReqClose Verb = "close"
|
||||
VerbPullReqReopen Verb = "reopen"
|
||||
VerbPullReqComment Verb = "comment"
|
||||
)
|
||||
|
||||
// Rule verbs.
|
||||
const (
|
||||
VerbRuleCreate Verb = "create"
|
||||
)
|
||||
|
||||
type Submitter interface {
|
||||
// SubmitGroups should be called once a day to update info about all the groups.
|
||||
SubmitGroups(ctx context.Context) error
|
||||
|
||||
// SubmitForRepo submits an event for a repository.
|
||||
SubmitForRepo(
|
||||
// Submit submits an event.
|
||||
Submit(
|
||||
ctx context.Context,
|
||||
user *types.PrincipalInfo,
|
||||
verb VerbRepo,
|
||||
properties map[string]any,
|
||||
) error
|
||||
|
||||
// SubmitForPullReq submits an event for a pull request.
|
||||
SubmitForPullReq(
|
||||
ctx context.Context,
|
||||
user *types.PrincipalInfo,
|
||||
verb VerbPullReq,
|
||||
object Object,
|
||||
verb Verb,
|
||||
properties map[string]any,
|
||||
) error
|
||||
}
|
||||
|
|
|
@ -21,11 +21,15 @@ import (
|
|||
|
||||
pullreqevents "github.com/harness/gitness/app/events/pullreq"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/services/publicaccess"
|
||||
"github.com/harness/gitness/app/services/refcache"
|
||||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/events"
|
||||
"github.com/harness/gitness/stream"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
)
|
||||
|
||||
func registerEventListeners(
|
||||
|
@ -33,9 +37,14 @@ func registerEventListeners(
|
|||
config *types.Config,
|
||||
principalInfoCache store.PrincipalInfoCache,
|
||||
pullReqStore store.PullReqStore,
|
||||
repoReaderFactory *events.ReaderFactory[*repoevents.Reader],
|
||||
ruleStore store.RuleStore,
|
||||
userEvReaderFactory *events.ReaderFactory[*userevents.Reader],
|
||||
repoEvReaderFactory *events.ReaderFactory[*repoevents.Reader],
|
||||
pullreqEvReaderFactory *events.ReaderFactory[*pullreqevents.Reader],
|
||||
ruleEvReaderFactory *events.ReaderFactory[*ruleevents.Reader],
|
||||
spaceFinder refcache.SpaceFinder,
|
||||
repoFinder refcache.RepoFinder,
|
||||
publicAccess publicaccess.Service,
|
||||
submitter Submitter,
|
||||
) error {
|
||||
if submitter == nil {
|
||||
|
@ -44,8 +53,34 @@ func registerEventListeners(
|
|||
|
||||
var err error
|
||||
|
||||
const groupMetricsUser = "gitness:metrics:user"
|
||||
_, err = userEvReaderFactory.Launch(ctx, groupMetricsUser, config.InstanceID,
|
||||
func(r *userevents.Reader) error {
|
||||
const idleTimeout = 10 * time.Second
|
||||
r.Configure(
|
||||
stream.WithConcurrency(1),
|
||||
stream.WithHandlerOptions(
|
||||
stream.WithIdleTimeout(idleTimeout),
|
||||
stream.WithMaxRetries(2),
|
||||
))
|
||||
|
||||
h := handlersUser{
|
||||
principalInfoCache: principalInfoCache,
|
||||
submitter: submitter,
|
||||
}
|
||||
|
||||
_ = r.RegisterCreated(h.Create)
|
||||
_ = r.RegisterRegistered(h.Register)
|
||||
_ = r.RegisterLoggedIn(h.Login)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
const groupMetricsRepo = "gitness:metrics:repo"
|
||||
_, err = repoReaderFactory.Launch(ctx, groupMetricsRepo, config.InstanceID,
|
||||
_, err = repoEvReaderFactory.Launch(ctx, groupMetricsRepo, config.InstanceID,
|
||||
func(r *repoevents.Reader) error {
|
||||
const idleTimeout = 10 * time.Second
|
||||
r.Configure(
|
||||
|
@ -58,13 +93,12 @@ func registerEventListeners(
|
|||
h := handlersRepo{
|
||||
principalInfoCache: principalInfoCache,
|
||||
repoFinder: repoFinder,
|
||||
publicAccess: publicAccess,
|
||||
submitter: submitter,
|
||||
}
|
||||
|
||||
_ = r.RegisterCreated(h.Create)
|
||||
_ = r.RegisterDefaultBranchUpdated(h.DefaultBranchUpdate)
|
||||
_ = r.RegisterStateChanged(h.StateChange)
|
||||
_ = r.RegisterPublicAccessChanged(h.PublicAccessChange)
|
||||
_ = r.RegisterPushed(h.Push)
|
||||
_ = r.RegisterSoftDeleted(h.SoftDelete)
|
||||
|
||||
return nil
|
||||
|
@ -88,6 +122,7 @@ func registerEventListeners(
|
|||
principalInfoCache: principalInfoCache,
|
||||
repoFinder: repoFinder,
|
||||
pullReqStore: pullReqStore,
|
||||
publicAccess: publicAccess,
|
||||
submitter: submitter,
|
||||
}
|
||||
|
||||
|
@ -95,6 +130,35 @@ func registerEventListeners(
|
|||
_ = r.RegisterReopened(h.Reopen)
|
||||
_ = r.RegisterClosed(h.Close)
|
||||
_ = r.RegisterMerged(h.Merge)
|
||||
_ = r.RegisterCommentCreated(h.CommentCreate)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
const groupMetricsRule = "gitness:metrics:rule"
|
||||
_, err = ruleEvReaderFactory.Launch(ctx, groupMetricsRule, config.InstanceID,
|
||||
func(r *ruleevents.Reader) error {
|
||||
const idleTimeout = 10 * time.Second
|
||||
r.Configure(
|
||||
stream.WithConcurrency(1),
|
||||
stream.WithHandlerOptions(
|
||||
stream.WithIdleTimeout(idleTimeout),
|
||||
stream.WithMaxRetries(2),
|
||||
))
|
||||
|
||||
h := handlersRule{
|
||||
principalInfoCache: principalInfoCache,
|
||||
spaceFinder: spaceFinder,
|
||||
repoFinder: repoFinder,
|
||||
ruleStore: ruleStore,
|
||||
publicAccess: publicAccess,
|
||||
submitter: submitter,
|
||||
}
|
||||
|
||||
_ = r.RegisterCreated(h.Create)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
@ -105,75 +169,147 @@ func registerEventListeners(
|
|||
return nil
|
||||
}
|
||||
|
||||
func prepareProps(m map[string]any) map[string]any {
|
||||
if m != nil {
|
||||
return m
|
||||
}
|
||||
return make(map[string]any, 8)
|
||||
}
|
||||
|
||||
// User fields.
|
||||
const (
|
||||
userID = "user_id"
|
||||
userName = "user_name"
|
||||
userEmail = "user_email"
|
||||
userCreatedByID = "user_created_by_id"
|
||||
userCreatedByName = "user_created_by_name"
|
||||
userCreatedByEmail = "user_created_by_email"
|
||||
)
|
||||
|
||||
type handlersUser struct {
|
||||
principalInfoCache store.PrincipalInfoCache
|
||||
submitter Submitter
|
||||
}
|
||||
|
||||
func (h handlersUser) Register(ctx context.Context, e *events.Event[*userevents.RegisteredPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PrincipalID, VerbUserCreate, nil)
|
||||
}
|
||||
|
||||
func (h handlersUser) Create(ctx context.Context, e *events.Event[*userevents.CreatedPayload]) error {
|
||||
principal, err := h.principalInfoCache.Get(ctx, e.Payload.PrincipalID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find principal who created a user: %w", err)
|
||||
}
|
||||
|
||||
props := prepareProps(nil)
|
||||
props[userCreatedByID] = principal.ID
|
||||
props[userCreatedByName] = principal.UID
|
||||
props[userCreatedByEmail] = principal.Email
|
||||
|
||||
return h.submit(ctx, e.Payload.CreatedPrincipalID, VerbUserCreate, props)
|
||||
}
|
||||
|
||||
func (h handlersUser) Login(ctx context.Context, e *events.Event[*userevents.LoggedInPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PrincipalID, VerbUserLogin, nil)
|
||||
}
|
||||
|
||||
func (h handlersUser) submit(
|
||||
ctx context.Context,
|
||||
principalID int64,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
principal, err := h.principalInfoCache.Get(ctx, principalID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find principal info")
|
||||
}
|
||||
|
||||
props = prepareProps(props)
|
||||
props[userID] = principal.ID
|
||||
props[userName] = principal.UID
|
||||
props[userEmail] = principal.Email
|
||||
|
||||
err = h.submitter.Submit(ctx, principal, ObjectUser, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit metric data for user: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Space fields.
|
||||
const (
|
||||
spaceID = "space_id"
|
||||
spaceName = "space_name"
|
||||
spacePath = "space_path"
|
||||
spaceParentID = "space_parent_id"
|
||||
spacePrivate = "space_private"
|
||||
)
|
||||
|
||||
// Repository fields.
|
||||
const (
|
||||
repoID = "repo_id"
|
||||
repoName = "repo_name"
|
||||
repoPath = "repo_path"
|
||||
repoParentID = "repo_parent_id"
|
||||
repoPrivate = "repo_private"
|
||||
repoMigrated = "repo_migrated"
|
||||
repoImported = "repo_imported"
|
||||
repoImportedFrom = "repo_imported_from"
|
||||
)
|
||||
|
||||
type handlersRepo struct {
|
||||
principalInfoCache store.PrincipalInfoCache
|
||||
repoFinder refcache.RepoFinder
|
||||
publicAccess publicaccess.Service
|
||||
submitter Submitter
|
||||
}
|
||||
|
||||
func (h handlersRepo) Create(ctx context.Context, e *events.Event[*repoevents.CreatedPayload]) error {
|
||||
props := map[string]any{
|
||||
"type": e.Payload.Type,
|
||||
props := prepareProps(nil)
|
||||
props[repoPrivate] = !e.Payload.IsPublic
|
||||
if e.Payload.IsMigrated {
|
||||
props[repoMigrated] = true
|
||||
}
|
||||
return h.submit(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoCreate, props)
|
||||
if e.Payload.ImportedFrom != "" {
|
||||
props[repoImported] = true
|
||||
props[repoImportedFrom] = e.Payload.ImportedFrom
|
||||
}
|
||||
return h.submitForActive(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoCreate, props)
|
||||
}
|
||||
|
||||
func (h handlersRepo) DefaultBranchUpdate(
|
||||
func (h handlersRepo) Push(
|
||||
ctx context.Context,
|
||||
e *events.Event[*repoevents.DefaultBranchUpdatedPayload],
|
||||
e *events.Event[*repoevents.PushedPayload],
|
||||
) error {
|
||||
props := map[string]any{
|
||||
"change": "default_branch",
|
||||
"repo_old_default_branch": e.Payload.OldName,
|
||||
"repo_new_default_branch": e.Payload.NewName,
|
||||
}
|
||||
return h.submit(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoUpdate, props)
|
||||
}
|
||||
|
||||
func (h handlersRepo) StateChange(
|
||||
ctx context.Context,
|
||||
e *events.Event[*repoevents.StateChangedPayload],
|
||||
) error {
|
||||
props := map[string]any{
|
||||
"change": "state",
|
||||
"repo_old_state": e.Payload.OldState,
|
||||
"repo_new_state": e.Payload.NewState,
|
||||
}
|
||||
return h.submit(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoUpdate, props)
|
||||
}
|
||||
|
||||
func (h handlersRepo) PublicAccessChange(
|
||||
ctx context.Context,
|
||||
e *events.Event[*repoevents.PublicAccessChangedPayload],
|
||||
) error {
|
||||
props := map[string]any{
|
||||
"change": "public_access",
|
||||
"repo_old_is_public": e.Payload.OldIsPublic,
|
||||
"repo_new_is_public": e.Payload.NewIsPublic,
|
||||
}
|
||||
return h.submit(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoUpdate, props)
|
||||
return h.submitForActive(ctx, e.Payload.RepoID, e.Payload.PrincipalID, VerbRepoPush, nil)
|
||||
}
|
||||
|
||||
func (h handlersRepo) SoftDelete(
|
||||
ctx context.Context,
|
||||
e *events.Event[*repoevents.SoftDeletedPayload],
|
||||
) error {
|
||||
return h.submitDeleted(ctx, e.Payload.RepoPath, e.Payload.Deleted, e.Payload.PrincipalID, VerbRepoDelete, nil)
|
||||
return h.submitForDeleted(ctx, e.Payload.RepoPath, e.Payload.Deleted, e.Payload.PrincipalID, VerbRepoDelete, nil)
|
||||
}
|
||||
|
||||
func (h handlersRepo) submit(
|
||||
func (h handlersRepo) submitForActive(
|
||||
ctx context.Context,
|
||||
repoID int64,
|
||||
id int64,
|
||||
principalID int64,
|
||||
verb VerbRepo,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
repo, err := h.repoFinder.FindByID(ctx, repoID)
|
||||
repo, err := h.repoFinder.FindByID(ctx, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find repository")
|
||||
}
|
||||
|
||||
err = h.submitMetric(ctx, repo, principalID, verb, props)
|
||||
props, err = fillRepoData(ctx, props, repo, h.publicAccess)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fill repo data: %w", err)
|
||||
}
|
||||
|
||||
err = h.submit(ctx, principalID, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit event: %w", err)
|
||||
}
|
||||
|
@ -181,32 +317,36 @@ func (h handlersRepo) submit(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h handlersRepo) submitDeleted(
|
||||
func (h handlersRepo) submitForDeleted(
|
||||
ctx context.Context,
|
||||
repoRef string,
|
||||
deletedAt int64,
|
||||
principalID int64,
|
||||
verb VerbRepo,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
repo, err := h.repoFinder.FindDeletedByRef(ctx, repoRef, deletedAt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find delete repo: %w", err)
|
||||
return fmt.Errorf("failed to find deleted repo: %w", err)
|
||||
}
|
||||
|
||||
err = h.submitMetric(ctx, repo.Core(), principalID, verb, props)
|
||||
props, err = fillRepoData(ctx, props, repo.Core(), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit event: %w", err)
|
||||
return fmt.Errorf("failed to fill deleted repo data: %w", err)
|
||||
}
|
||||
|
||||
err = h.submit(ctx, principalID, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit metric data for deleted repository: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h handlersRepo) submitMetric(
|
||||
func (h handlersRepo) submit(
|
||||
ctx context.Context,
|
||||
repo *types.RepositoryCore,
|
||||
principalID int64,
|
||||
verb VerbRepo,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
principal, err := h.principalInfoCache.Get(ctx, principalID)
|
||||
|
@ -214,15 +354,7 @@ func (h handlersRepo) submitMetric(
|
|||
return fmt.Errorf("failed to get principal info: %w", err)
|
||||
}
|
||||
|
||||
if props == nil {
|
||||
props = make(map[string]any)
|
||||
}
|
||||
|
||||
props["repo_id"] = repo.ID
|
||||
props["repo_path"] = repo.Path
|
||||
props["repo_parent_id"] = repo.ParentID
|
||||
|
||||
err = h.submitter.SubmitForRepo(ctx, principal, verb, props)
|
||||
err = h.submitter.Submit(ctx, principal, ObjectRepository, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit metric data for repositoy: %w", err)
|
||||
}
|
||||
|
@ -230,38 +362,65 @@ func (h handlersRepo) submitMetric(
|
|||
return nil
|
||||
}
|
||||
|
||||
// Pull request fields.
|
||||
const (
|
||||
prNumber = "pr_number"
|
||||
prTargetBranch = "pr_target_branch"
|
||||
prSourceBranch = "pr_source_branch"
|
||||
prSourceRepoID = "pr_source_repo_id"
|
||||
prSourceRepoName = "pr_source_repo_name"
|
||||
prSourceRepoPath = "pr_source_repo_path"
|
||||
prMergeMethod = "pr_merge_method"
|
||||
prCommentReply = "pr_comment_reply"
|
||||
)
|
||||
|
||||
type handlersPullReq struct {
|
||||
principalInfoCache store.PrincipalInfoCache
|
||||
repoFinder refcache.RepoFinder
|
||||
pullReqStore store.PullReqStore
|
||||
publicAccess publicaccess.Service
|
||||
submitter Submitter
|
||||
}
|
||||
|
||||
func (h handlersPullReq) Create(ctx context.Context, e *events.Event[*pullreqevents.CreatedPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqCreate)
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqCreate, nil)
|
||||
}
|
||||
|
||||
func (h handlersPullReq) Close(ctx context.Context, e *events.Event[*pullreqevents.ClosedPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqClose)
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqClose, nil)
|
||||
}
|
||||
|
||||
func (h handlersPullReq) Reopen(ctx context.Context, e *events.Event[*pullreqevents.ReopenedPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqReopen)
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqReopen, nil)
|
||||
}
|
||||
|
||||
func (h handlersPullReq) Merge(ctx context.Context, e *events.Event[*pullreqevents.MergedPayload]) error {
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqMerge)
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqMerge, nil)
|
||||
}
|
||||
|
||||
func (h handlersPullReq) submit(ctx context.Context, pullReqID, principalID int64, verb VerbPullReq) error {
|
||||
func (h handlersPullReq) CommentCreate(
|
||||
ctx context.Context,
|
||||
e *events.Event[*pullreqevents.CommentCreatedPayload],
|
||||
) error {
|
||||
props := prepareProps(nil)
|
||||
props[prCommentReply] = e.Payload.IsReply
|
||||
return h.submit(ctx, e.Payload.PullReqID, e.Payload.PrincipalID, VerbPullReqComment, props)
|
||||
}
|
||||
|
||||
func (h handlersPullReq) submit(
|
||||
ctx context.Context,
|
||||
pullReqID, principalID int64,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
pr, err := h.pullReqStore.Find(ctx, pullReqID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find pull request: %w", err)
|
||||
}
|
||||
|
||||
repo, err := h.repoFinder.FindByID(ctx, pr.TargetRepoID)
|
||||
props, err = fillPullReqProps(ctx, props, pr, h.repoFinder, h.publicAccess)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find pull request: %w", err)
|
||||
return fmt.Errorf("failed to fill pull request props: %w", err)
|
||||
}
|
||||
|
||||
principal, err := h.principalInfoCache.Get(ctx, principalID)
|
||||
|
@ -269,31 +428,183 @@ func (h handlersPullReq) submit(ctx context.Context, pullReqID, principalID int6
|
|||
return fmt.Errorf("failed to get principal info: %w", err)
|
||||
}
|
||||
|
||||
author, err := h.principalInfoCache.Get(ctx, pr.CreatedBy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get author principal info: %w", err)
|
||||
}
|
||||
|
||||
props := map[string]any{
|
||||
"repo_id": repo.ID,
|
||||
"repo_path": repo.Path,
|
||||
"repo_parent_id": repo.ParentID,
|
||||
"pullreq_author_email": author.Email,
|
||||
"pullreq_number": pr.Number,
|
||||
"pullreq_target_repo_id": pr.TargetRepoID,
|
||||
"pullreq_source_repo_id": pr.SourceRepoID,
|
||||
"pullreq_target_branch": pr.TargetBranch,
|
||||
"pullreq_source_branch": pr.SourceBranch,
|
||||
}
|
||||
|
||||
if pr.MergeMethod != nil {
|
||||
props["pullreq_merge_method"] = string(*pr.MergeMethod)
|
||||
}
|
||||
|
||||
err = h.submitter.SubmitForPullReq(ctx, principal, verb, props)
|
||||
err = h.submitter.Submit(ctx, principal, ObjectPullRequest, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit metric data for pull request: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Rule fields.
|
||||
const (
|
||||
ruleID = "rule_id"
|
||||
ruleName = "rule_name"
|
||||
ruleType = "rule_type"
|
||||
)
|
||||
|
||||
func (h handlersRule) Create(ctx context.Context, e *events.Event[*ruleevents.CreatedPayload]) error {
|
||||
return h.submit(ctx, e.Payload.RuleID, e.Payload.PrincipalID, VerbRuleCreate, nil)
|
||||
}
|
||||
|
||||
func (h handlersRule) submit(
|
||||
ctx context.Context,
|
||||
ruleID, principalID int64,
|
||||
verb Verb,
|
||||
props map[string]any,
|
||||
) error {
|
||||
rule, err := h.ruleStore.Find(ctx, ruleID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find pull request: %w", err)
|
||||
}
|
||||
|
||||
props, err = fillRuleProps(ctx, props, rule, h.spaceFinder, h.repoFinder, h.publicAccess)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fill pull request props: %w", err)
|
||||
}
|
||||
|
||||
principal, err := h.principalInfoCache.Get(ctx, principalID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get principal info: %w", err)
|
||||
}
|
||||
|
||||
err = h.submitter.Submit(ctx, principal, ObjectRule, verb, props)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to submit metric data for rule: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type handlersRule struct {
|
||||
principalInfoCache store.PrincipalInfoCache
|
||||
spaceFinder refcache.SpaceFinder
|
||||
repoFinder refcache.RepoFinder
|
||||
ruleStore store.RuleStore
|
||||
publicAccess publicaccess.Service
|
||||
submitter Submitter
|
||||
}
|
||||
|
||||
func fillSpaceData(
|
||||
ctx context.Context,
|
||||
props map[string]any,
|
||||
space *types.SpaceCore,
|
||||
publicAccess publicaccess.Service,
|
||||
) (map[string]any, error) {
|
||||
props = prepareProps(props)
|
||||
props[spaceID] = space.ID
|
||||
props[spaceName] = space.Identifier
|
||||
props[spacePath] = space.Path
|
||||
props[spaceParentID] = space.ParentID
|
||||
|
||||
if _, ok := props[spacePrivate]; !ok && publicAccess != nil {
|
||||
isRepoPublic, err := publicAccess.Get(ctx, enum.PublicResourceTypeSpace, space.Path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check public access for space: %w", err)
|
||||
}
|
||||
props[spacePrivate] = !isRepoPublic
|
||||
}
|
||||
|
||||
return props, nil
|
||||
}
|
||||
|
||||
func fillRepoData(
|
||||
ctx context.Context,
|
||||
props map[string]any,
|
||||
repo *types.RepositoryCore,
|
||||
publicAccess publicaccess.Service,
|
||||
) (map[string]any, error) {
|
||||
props = prepareProps(props)
|
||||
props[repoID] = repo.ID
|
||||
props[repoName] = repo.Identifier
|
||||
props[repoPath] = repo.Path
|
||||
props[repoParentID] = repo.ParentID
|
||||
|
||||
if _, ok := props[repoPrivate]; !ok && publicAccess != nil {
|
||||
isRepoPublic, err := publicAccess.Get(ctx, enum.PublicResourceTypeRepo, repo.Path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to check public access for repo: %w", err)
|
||||
}
|
||||
props[repoPrivate] = !isRepoPublic
|
||||
}
|
||||
|
||||
return props, nil
|
||||
}
|
||||
|
||||
func fillPullReqProps(
|
||||
ctx context.Context,
|
||||
props map[string]any,
|
||||
pr *types.PullReq,
|
||||
repoFinder refcache.RepoFinder,
|
||||
publicAccess publicaccess.Service,
|
||||
) (map[string]any, error) {
|
||||
props = prepareProps(props)
|
||||
props[prNumber] = pr.Number
|
||||
props[prSourceBranch] = pr.SourceBranch
|
||||
props[prTargetBranch] = pr.TargetBranch
|
||||
if pr.MergeMethod != nil {
|
||||
props[prMergeMethod] = string(*pr.MergeMethod)
|
||||
}
|
||||
|
||||
targetRepo, err := repoFinder.FindByID(ctx, pr.TargetRepoID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find target repo: %w", err)
|
||||
}
|
||||
|
||||
props, err = fillRepoData(ctx, props, targetRepo, publicAccess)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fill repo data for target repo: %w", err)
|
||||
}
|
||||
|
||||
if pr.SourceRepoID != pr.TargetRepoID {
|
||||
sourceRepo, err := repoFinder.FindByID(ctx, pr.SourceRepoID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find source repo: %w", err)
|
||||
}
|
||||
|
||||
props[prSourceRepoID] = pr.SourceRepoID
|
||||
props[prSourceRepoName] = sourceRepo.Identifier
|
||||
props[prSourceRepoPath] = sourceRepo.Path
|
||||
}
|
||||
|
||||
return props, nil
|
||||
}
|
||||
|
||||
func fillRuleProps(
|
||||
ctx context.Context,
|
||||
props map[string]any,
|
||||
rule *types.Rule,
|
||||
spaceFinder refcache.SpaceFinder,
|
||||
repoFinder refcache.RepoFinder,
|
||||
publicAccess publicaccess.Service,
|
||||
) (map[string]any, error) {
|
||||
props = prepareProps(props)
|
||||
props[ruleID] = rule.RepoID
|
||||
props[ruleName] = rule.Identifier
|
||||
props[ruleType] = string(rule.Type)
|
||||
|
||||
//nolint:nestif
|
||||
if rule.SpaceID != nil {
|
||||
space, err := spaceFinder.FindByID(ctx, *rule.SpaceID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find space: %w", err)
|
||||
}
|
||||
|
||||
props, err = fillSpaceData(ctx, props, space, publicAccess)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fill space data for rule: %w", err)
|
||||
}
|
||||
} else if rule.RepoID != nil {
|
||||
repo, err := repoFinder.FindByID(ctx, *rule.RepoID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to find repo: %w", err)
|
||||
}
|
||||
|
||||
props, err = fillRepoData(ctx, props, repo, publicAccess)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fill repo data for rule: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return props, nil
|
||||
}
|
||||
|
|
|
@ -92,33 +92,15 @@ func (ph *PostHog) SubmitGroups(context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (ph *PostHog) SubmitForRepo(
|
||||
ctx context.Context,
|
||||
user *types.PrincipalInfo,
|
||||
verb VerbRepo,
|
||||
properties map[string]any,
|
||||
) error {
|
||||
return ph.submit(ctx, user, ObjectRepository, string(verb), properties)
|
||||
}
|
||||
|
||||
func (ph *PostHog) SubmitForPullReq(
|
||||
ctx context.Context,
|
||||
user *types.PrincipalInfo,
|
||||
verb VerbPullReq,
|
||||
properties map[string]any,
|
||||
) error {
|
||||
return ph.submit(ctx, user, ObjectPullRequest, string(verb), properties)
|
||||
}
|
||||
|
||||
func (ph *PostHog) uniqueUserID(id string) string {
|
||||
return ph.installID + ":" + id
|
||||
}
|
||||
|
||||
func (ph *PostHog) submit(
|
||||
func (ph *PostHog) Submit(
|
||||
_ context.Context,
|
||||
user *types.PrincipalInfo,
|
||||
object Object,
|
||||
verb string,
|
||||
verb Verb,
|
||||
properties map[string]any,
|
||||
) error {
|
||||
if ph == nil {
|
||||
|
@ -135,7 +117,9 @@ func (ph *PostHog) submit(
|
|||
"created": user.Created,
|
||||
})
|
||||
p.Set("$set", map[string]any{
|
||||
"email": user.Email,
|
||||
"id": user.ID,
|
||||
"username": user.UID,
|
||||
"email": user.Email,
|
||||
})
|
||||
|
||||
properties = p
|
||||
|
@ -143,7 +127,7 @@ func (ph *PostHog) submit(
|
|||
|
||||
err := ph.client.Enqueue(posthog.Capture{
|
||||
DistinctId: distinctID,
|
||||
Event: string(object) + ":" + verb,
|
||||
Event: string(object) + ":" + string(verb),
|
||||
Groups: posthog.NewGroups().Set(postHogGroupInstall, ph.installID),
|
||||
Properties: properties,
|
||||
})
|
||||
|
|
|
@ -20,6 +20,9 @@ import (
|
|||
|
||||
pullreqevents "github.com/harness/gitness/app/events/pullreq"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/services/publicaccess"
|
||||
"github.com/harness/gitness/app/services/refcache"
|
||||
"github.com/harness/gitness/app/services/settings"
|
||||
"github.com/harness/gitness/app/store"
|
||||
|
@ -48,8 +51,13 @@ func ProvideSubmitter(
|
|||
principalStore store.PrincipalStore,
|
||||
principalInfoCache store.PrincipalInfoCache,
|
||||
pullReqStore store.PullReqStore,
|
||||
repoReaderFactory *events.ReaderFactory[*repoevents.Reader],
|
||||
ruleStore store.RuleStore,
|
||||
userEvReaderFactory *events.ReaderFactory[*userevents.Reader],
|
||||
repoEvReaderFactory *events.ReaderFactory[*repoevents.Reader],
|
||||
pullreqEvReaderFactory *events.ReaderFactory[*pullreqevents.Reader],
|
||||
ruleEvReaderFactory *events.ReaderFactory[*ruleevents.Reader],
|
||||
publicAccess publicaccess.Service,
|
||||
spaceFinder refcache.SpaceFinder,
|
||||
repoFinder refcache.RepoFinder,
|
||||
) (Submitter, error) {
|
||||
submitter, err := NewPostHog(appCtx, config, values, principalStore, principalInfoCache)
|
||||
|
@ -62,9 +70,14 @@ func ProvideSubmitter(
|
|||
config,
|
||||
principalInfoCache,
|
||||
pullReqStore,
|
||||
repoReaderFactory,
|
||||
ruleStore,
|
||||
userEvReaderFactory,
|
||||
repoEvReaderFactory,
|
||||
pullreqEvReaderFactory,
|
||||
ruleEvReaderFactory,
|
||||
spaceFinder,
|
||||
repoFinder,
|
||||
publicAccess,
|
||||
submitter,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/harness/gitness/app/api/usererror"
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
"github.com/harness/gitness/app/paths"
|
||||
"github.com/harness/gitness/app/services/instrument"
|
||||
"github.com/harness/gitness/app/services/protection"
|
||||
|
@ -169,6 +170,15 @@ func (s *Service) Create(ctx context.Context,
|
|||
|
||||
s.sendSSE(ctx, parentID, parentType, enum.SSETypeRuleCreated, rule)
|
||||
|
||||
s.eventReporter.Created(ctx, &ruleevents.CreatedPayload{
|
||||
Base: ruleevents.Base{
|
||||
RuleID: rule.ID,
|
||||
SpaceID: rule.SpaceID,
|
||||
RepoID: rule.RepoID,
|
||||
PrincipalID: rule.CreatedBy,
|
||||
},
|
||||
})
|
||||
|
||||
return rule, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
"github.com/harness/gitness/app/services/instrument"
|
||||
"github.com/harness/gitness/app/services/protection"
|
||||
"github.com/harness/gitness/app/services/usergroup"
|
||||
|
@ -37,6 +38,7 @@ type Service struct {
|
|||
principalInfoCache store.PrincipalInfoCache
|
||||
userGroupStore store.UserGroupStore
|
||||
userGroupService usergroup.SearchService
|
||||
eventReporter *ruleevents.Reporter
|
||||
|
||||
sseStreamer sse.Streamer
|
||||
}
|
||||
|
@ -52,6 +54,7 @@ func NewService(
|
|||
principalInfoCache store.PrincipalInfoCache,
|
||||
userGroupStore store.UserGroupStore,
|
||||
userGroupService usergroup.SearchService,
|
||||
eventReporter *ruleevents.Reporter,
|
||||
sseStreamer sse.Streamer,
|
||||
) *Service {
|
||||
return &Service{
|
||||
|
@ -65,6 +68,7 @@ func NewService(
|
|||
principalInfoCache: principalInfoCache,
|
||||
userGroupStore: userGroupStore,
|
||||
userGroupService: userGroupService,
|
||||
eventReporter: eventReporter,
|
||||
sseStreamer: sseStreamer,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package rules
|
||||
|
||||
import (
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
"github.com/harness/gitness/app/services/instrument"
|
||||
"github.com/harness/gitness/app/services/protection"
|
||||
"github.com/harness/gitness/app/services/usergroup"
|
||||
|
@ -42,6 +43,7 @@ func ProvideService(
|
|||
principalInfoCache store.PrincipalInfoCache,
|
||||
userGroupStore store.UserGroupStore,
|
||||
userGroupService usergroup.SearchService,
|
||||
eventReporter *ruleevents.Reporter,
|
||||
sseStreamer sse.Streamer,
|
||||
) *Service {
|
||||
return NewService(
|
||||
|
@ -55,6 +57,7 @@ func ProvideService(
|
|||
principalInfoCache,
|
||||
userGroupStore,
|
||||
userGroupService,
|
||||
eventReporter,
|
||||
sseStreamer,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ import (
|
|||
pipelineevents "github.com/harness/gitness/app/events/pipeline"
|
||||
pullreqevents "github.com/harness/gitness/app/events/pullreq"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
ruleevents "github.com/harness/gitness/app/events/rule"
|
||||
userevents "github.com/harness/gitness/app/events/user"
|
||||
infrastructure "github.com/harness/gitness/app/gitspace/infrastructure"
|
||||
"github.com/harness/gitness/app/gitspace/logutil"
|
||||
"github.com/harness/gitness/app/gitspace/orchestrator"
|
||||
|
@ -190,6 +192,8 @@ func initSystem(ctx context.Context, config *types.Config) (*cliserver.System, e
|
|||
gitevents.WireSet,
|
||||
pullreqevents.WireSet,
|
||||
repoevents.WireSet,
|
||||
ruleevents.WireSet,
|
||||
userevents.WireSet,
|
||||
storage.WireSet,
|
||||
api.WireSet,
|
||||
cliserver.ProvideGitConfig,
|
||||
|
|
|
@ -42,14 +42,16 @@ import (
|
|||
"github.com/harness/gitness/app/auth/authz"
|
||||
"github.com/harness/gitness/app/bootstrap"
|
||||
"github.com/harness/gitness/app/connector"
|
||||
events9 "github.com/harness/gitness/app/events/git"
|
||||
events3 "github.com/harness/gitness/app/events/gitspace"
|
||||
events6 "github.com/harness/gitness/app/events/gitspacedelete"
|
||||
events4 "github.com/harness/gitness/app/events/gitspaceinfra"
|
||||
events5 "github.com/harness/gitness/app/events/gitspaceoperations"
|
||||
events7 "github.com/harness/gitness/app/events/pipeline"
|
||||
events8 "github.com/harness/gitness/app/events/pullreq"
|
||||
events2 "github.com/harness/gitness/app/events/repo"
|
||||
events11 "github.com/harness/gitness/app/events/git"
|
||||
events5 "github.com/harness/gitness/app/events/gitspace"
|
||||
events8 "github.com/harness/gitness/app/events/gitspacedelete"
|
||||
events6 "github.com/harness/gitness/app/events/gitspaceinfra"
|
||||
events7 "github.com/harness/gitness/app/events/gitspaceoperations"
|
||||
events9 "github.com/harness/gitness/app/events/pipeline"
|
||||
events10 "github.com/harness/gitness/app/events/pullreq"
|
||||
events3 "github.com/harness/gitness/app/events/repo"
|
||||
events4 "github.com/harness/gitness/app/events/rule"
|
||||
events2 "github.com/harness/gitness/app/events/user"
|
||||
"github.com/harness/gitness/app/gitspace/infrastructure"
|
||||
"github.com/harness/gitness/app/gitspace/logutil"
|
||||
"github.com/harness/gitness/app/gitspace/orchestrator"
|
||||
|
@ -127,7 +129,7 @@ import (
|
|||
nuget2 "github.com/harness/gitness/registry/app/api/controller/pkg/nuget"
|
||||
python2 "github.com/harness/gitness/registry/app/api/controller/pkg/python"
|
||||
"github.com/harness/gitness/registry/app/api/router"
|
||||
events10 "github.com/harness/gitness/registry/app/events"
|
||||
events12 "github.com/harness/gitness/registry/app/events"
|
||||
"github.com/harness/gitness/registry/app/pkg"
|
||||
"github.com/harness/gitness/registry/app/pkg/base"
|
||||
"github.com/harness/gitness/registry/app/pkg/docker"
|
||||
|
@ -189,7 +191,16 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
principalStore := database.ProvidePrincipalStore(db, principalUIDTransformation)
|
||||
tokenStore := database.ProvideTokenStore(db)
|
||||
publicKeyStore := database.ProvidePublicKeyStore(db)
|
||||
controller := user.ProvideController(transactor, principalUID, authorizer, principalStore, tokenStore, membershipStore, publicKeyStore)
|
||||
eventsConfig := server.ProvideEventsConfig(config)
|
||||
eventsSystem, err := events.ProvideSystem(eventsConfig, universalClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reporter, err := events2.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
controller := user.ProvideController(transactor, principalUID, authorizer, principalStore, tokenStore, membershipStore, publicKeyStore, reporter)
|
||||
serviceController := service.NewController(principalUID, authorizer, principalStore)
|
||||
bootstrapBootstrap := bootstrap.ProvideBootstrap(config, controller, serviceController)
|
||||
authenticator := authn.ProvideAuthenticator(config, principalStore, tokenStore)
|
||||
|
@ -240,17 +251,12 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
streamer := sse.ProvideEventsStreaming(pubSub)
|
||||
localIndexSearcher := keywordsearch.ProvideLocalIndexSearcher()
|
||||
indexer := keywordsearch.ProvideIndexer(localIndexSearcher)
|
||||
eventsConfig := server.ProvideEventsConfig(config)
|
||||
eventsSystem, err := events.ProvideSystem(eventsConfig, universalClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reporter, err := events2.ProvideReporter(eventsSystem)
|
||||
eventsReporter, err := events3.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
auditService := audit.ProvideAuditService()
|
||||
repository, err := importer.ProvideRepoImporter(config, provider, gitInterface, transactor, repoStore, pipelineStore, triggerStore, repoFinder, encrypter, jobScheduler, executor, streamer, indexer, publicaccessService, reporter, auditService)
|
||||
repository, err := importer.ProvideRepoImporter(config, provider, gitInterface, transactor, repoStore, pipelineStore, triggerStore, repoFinder, encrypter, jobScheduler, executor, streamer, indexer, publicaccessService, eventsReporter, auditService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -271,8 +277,12 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
instrumentService := instrument.ProvideService()
|
||||
userGroupStore := database.ProvideUserGroupStore(db)
|
||||
searchService := usergroup.ProvideSearchService()
|
||||
rulesService := rules.ProvideService(transactor, ruleStore, repoStore, spaceStore, protectionManager, auditService, instrumentService, principalInfoCache, userGroupStore, searchService, streamer)
|
||||
repoController := repo.ProvideController(config, transactor, provider, authorizer, repoStore, spaceStore, pipelineStore, principalStore, executionStore, ruleStore, checkStore, pullReqStore, settingsService, principalInfoCache, protectionManager, gitInterface, spaceFinder, repoFinder, repository, codeownersService, reporter, indexer, resourceLimiter, lockerLocker, auditService, mutexManager, repoIdentifier, repoCheck, publicaccessService, labelService, instrumentService, userGroupStore, searchService, rulesService, streamer)
|
||||
reporter2, err := events4.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rulesService := rules.ProvideService(transactor, ruleStore, repoStore, spaceStore, protectionManager, auditService, instrumentService, principalInfoCache, userGroupStore, searchService, reporter2, streamer)
|
||||
repoController := repo.ProvideController(config, transactor, provider, authorizer, repoStore, spaceStore, pipelineStore, principalStore, executionStore, ruleStore, checkStore, pullReqStore, settingsService, principalInfoCache, protectionManager, gitInterface, spaceFinder, repoFinder, repository, codeownersService, eventsReporter, indexer, resourceLimiter, lockerLocker, auditService, mutexManager, repoIdentifier, repoCheck, publicaccessService, labelService, instrumentService, userGroupStore, searchService, rulesService, streamer)
|
||||
reposettingsController := reposettings.ProvideController(authorizer, repoFinder, settingsService, auditService)
|
||||
stageStore := database.ProvideStageStore(db)
|
||||
schedulerScheduler, err := scheduler.ProvideScheduler(stageStore, mutexManager)
|
||||
|
@ -303,7 +313,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
infraProviderResourceCache := cache.ProvideInfraProviderResourceCache(infraProviderResourceView)
|
||||
gitspaceConfigStore := database.ProvideGitspaceConfigStore(db, principalInfoCache, infraProviderResourceCache)
|
||||
gitspaceInstanceStore := database.ProvideGitspaceInstanceStore(db)
|
||||
eventsReporter, err := events3.ProvideReporter(eventsSystem)
|
||||
reporter3, err := events5.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -316,11 +326,11 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
return nil, err
|
||||
}
|
||||
dockerClientFactory := infraprovider.ProvideDockerClientFactory(dockerConfig)
|
||||
reporter2, err := events4.ProvideReporter(eventsSystem)
|
||||
reporter4, err := events6.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dockerProvider := infraprovider.ProvideDockerProvider(dockerConfig, dockerClientFactory, reporter2)
|
||||
dockerProvider := infraprovider.ProvideDockerProvider(dockerConfig, dockerClientFactory, reporter4)
|
||||
factory := infraprovider.ProvideFactory(dockerProvider)
|
||||
infraproviderService := infraprovider2.ProvideInfraProvider(transactor, gitspaceConfigStore, infraProviderResourceStore, infraProviderConfigStore, infraProviderTemplateStore, factory, spaceFinder)
|
||||
gitnessSCM := scm.ProvideGitnessSCM(repoStore, repoFinder, gitInterface, tokenStore, principalStore, provider)
|
||||
|
@ -340,11 +350,11 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reporter3, err := events5.ProvideReporter(eventsSystem)
|
||||
reporter5, err := events7.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
embeddedDockerOrchestrator := container.ProvideEmbeddedDockerOrchestrator(dockerClientFactory, statefulLogger, runargProvider, reporter3)
|
||||
embeddedDockerOrchestrator := container.ProvideEmbeddedDockerOrchestrator(dockerClientFactory, statefulLogger, runargProvider, reporter5)
|
||||
containerFactory := container.ProvideContainerOrchestratorFactory(embeddedDockerOrchestrator)
|
||||
orchestratorConfig := server.ProvideGitspaceOrchestratorConfig(config)
|
||||
vsCodeConfig := server.ProvideIDEVSCodeConfig(config)
|
||||
|
@ -356,19 +366,19 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
ideFactory := ide.ProvideIDEFactory(vsCode, vsCodeWeb, v)
|
||||
passwordResolver := secret.ProvidePasswordResolver()
|
||||
resolverFactory := secret.ProvideResolverFactory(passwordResolver)
|
||||
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, platformConnector, infraProvisioner, containerFactory, eventsReporter, orchestratorConfig, ideFactory, resolverFactory, gitspaceInstanceStore)
|
||||
reporter4, err := events6.ProvideReporter(eventsSystem)
|
||||
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, platformConnector, infraProvisioner, containerFactory, reporter3, orchestratorConfig, ideFactory, resolverFactory, gitspaceInstanceStore)
|
||||
reporter6, err := events8.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspaceService := gitspace.ProvideGitspace(transactor, gitspaceConfigStore, gitspaceInstanceStore, eventsReporter, gitspaceEventStore, spaceFinder, infraproviderService, orchestratorOrchestrator, scmSCM, config, reporter4)
|
||||
gitspaceService := gitspace.ProvideGitspace(transactor, gitspaceConfigStore, gitspaceInstanceStore, reporter3, gitspaceEventStore, spaceFinder, infraproviderService, orchestratorOrchestrator, scmSCM, config, reporter6)
|
||||
usageMetricStore := database.ProvideUsageMetricStore(db)
|
||||
spaceController := space.ProvideController(config, transactor, provider, streamer, spaceIdentifier, authorizer, spacePathStore, pipelineStore, secretStore, connectorStore, templateStore, spaceStore, repoStore, principalStore, repoController, membershipStore, listService, spaceFinder, repository, exporterRepository, resourceLimiter, publicaccessService, auditService, gitspaceService, labelService, instrumentService, executionStore, rulesService, usageMetricStore, repoIdentifier, infraproviderService)
|
||||
reporter5, err := events7.ProvideReporter(eventsSystem)
|
||||
reporter7, err := events9.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pipelineController := pipeline.ProvideController(triggerStore, authorizer, pipelineStore, reporter5, repoFinder)
|
||||
pipelineController := pipeline.ProvideController(triggerStore, authorizer, pipelineStore, reporter7, repoFinder)
|
||||
secretController := secret2.ProvideController(encrypter, secretStore, authorizer, spaceFinder)
|
||||
triggerController := trigger.ProvideController(authorizer, triggerStore, pipelineStore, repoFinder)
|
||||
scmService := connector.ProvideSCMConnectorHandler(secretStore)
|
||||
|
@ -382,25 +392,25 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
pullReqReviewerStore := database.ProvidePullReqReviewerStore(db, principalInfoCache)
|
||||
userGroupReviewersStore := database.ProvideUserGroupReviewerStore(db, principalInfoCache, userGroupStore)
|
||||
pullReqFileViewStore := database.ProvidePullReqFileViewStore(db)
|
||||
reporter6, err := events8.ProvideReporter(eventsSystem)
|
||||
reporter8, err := events10.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
migrator := codecomments.ProvideMigrator(gitInterface)
|
||||
readerFactory, err := events9.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory, err := events11.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
eventsReaderFactory, err := events8.ProvideReaderFactory(eventsSystem)
|
||||
eventsReaderFactory, err := events10.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pullreqService, err := pullreq.ProvideService(ctx, config, readerFactory, eventsReaderFactory, reporter6, gitInterface, repoFinder, repoStore, pullReqStore, pullReqActivityStore, principalInfoCache, codeCommentView, migrator, pullReqFileViewStore, pubSub, provider, streamer)
|
||||
pullreqService, err := pullreq.ProvideService(ctx, config, readerFactory, eventsReaderFactory, reporter8, gitInterface, repoFinder, repoStore, pullReqStore, pullReqActivityStore, principalInfoCache, codeCommentView, migrator, pullReqFileViewStore, pubSub, provider, streamer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pullReq := migrate.ProvidePullReqImporter(provider, gitInterface, principalStore, spaceStore, repoStore, pullReqStore, pullReqActivityStore, labelStore, labelValueStore, pullReqLabelAssignmentStore, repoFinder, transactor, mutexManager)
|
||||
pullreqController := pullreq2.ProvideController(transactor, provider, authorizer, auditService, pullReqStore, pullReqActivityStore, codeCommentView, pullReqReviewStore, pullReqReviewerStore, repoStore, principalStore, userGroupStore, userGroupReviewersStore, principalInfoCache, pullReqFileViewStore, membershipStore, checkStore, gitInterface, repoFinder, reporter6, migrator, pullreqService, listService, protectionManager, streamer, codeownersService, lockerLocker, pullReq, labelService, instrumentService, searchService)
|
||||
pullreqController := pullreq2.ProvideController(transactor, provider, authorizer, auditService, pullReqStore, pullReqActivityStore, codeCommentView, pullReqReviewStore, pullReqReviewerStore, repoStore, principalStore, userGroupStore, userGroupReviewersStore, principalInfoCache, pullReqFileViewStore, membershipStore, checkStore, gitInterface, repoFinder, reporter8, migrator, pullreqService, listService, protectionManager, streamer, codeownersService, lockerLocker, pullReq, labelService, instrumentService, searchService)
|
||||
webhookConfig := server.ProvideWebhookConfig(config)
|
||||
webhookStore := database.ProvideWebhookStore(db)
|
||||
webhookExecutionStore := database.ProvideWebhookExecutionStore(db)
|
||||
|
@ -412,7 +422,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
}
|
||||
preprocessor := webhook2.ProvidePreprocessor()
|
||||
webhookController := webhook2.ProvideController(authorizer, spaceFinder, repoFinder, webhookService, encrypter, preprocessor)
|
||||
reporter7, err := events9.ProvideReporter(eventsSystem)
|
||||
reporter9, err := events11.ProvideReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -429,7 +439,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
return nil, err
|
||||
}
|
||||
lfsObjectStore := database.ProvideLFSObjectStore(db)
|
||||
githookController := githook.ProvideController(authorizer, principalStore, repoStore, repoFinder, reporter7, reporter, gitInterface, pullReqStore, provider, protectionManager, clientFactory, resourceLimiter, settingsService, preReceiveExtender, updateExtender, postReceiveExtender, streamer, lfsObjectStore)
|
||||
githookController := githook.ProvideController(authorizer, principalStore, repoStore, repoFinder, reporter9, eventsReporter, gitInterface, pullReqStore, provider, protectionManager, clientFactory, resourceLimiter, settingsService, preReceiveExtender, updateExtender, postReceiveExtender, streamer, lfsObjectStore)
|
||||
serviceaccountController := serviceaccount.NewController(principalUID, authorizer, principalStore, spaceStore, repoStore, tokenStore)
|
||||
principalController := principal.ProvideController(principalStore, authorizer)
|
||||
usergroupController := usergroup2.ProvideController(userGroupStore, spaceStore, authorizer, searchService)
|
||||
|
@ -453,7 +463,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
rule := migrate.ProvideRuleImporter(ruleStore, transactor, principalStore)
|
||||
migrateWebhook := migrate.ProvideWebhookImporter(webhookConfig, transactor, webhookStore)
|
||||
migrateLabel := migrate.ProvideLabelImporter(transactor, labelStore, labelValueStore, spaceStore)
|
||||
migrateController := migrate2.ProvideController(authorizer, publicaccessService, gitInterface, provider, pullReq, rule, migrateWebhook, migrateLabel, resourceLimiter, auditService, repoIdentifier, transactor, spaceStore, repoStore, spaceFinder, repoFinder, reporter)
|
||||
migrateController := migrate2.ProvideController(authorizer, publicaccessService, gitInterface, provider, pullReq, rule, migrateWebhook, migrateLabel, resourceLimiter, auditService, repoIdentifier, transactor, spaceStore, repoStore, spaceFinder, repoFinder, eventsReporter)
|
||||
openapiService := openapi.ProvideOpenAPIService()
|
||||
storageDriver, err := api2.BlobStorageProvider(config)
|
||||
if err != nil {
|
||||
|
@ -474,11 +484,11 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
layerRepository := database2.ProvideLayerDao(db, mediaTypesRepository)
|
||||
eventReporter := docker.ProvideReporter()
|
||||
ociImageIndexMappingRepository := database2.ProvideOCIImageIndexMappingDao(db)
|
||||
reporter8, err := events10.ProvideArtifactReporter(eventsSystem)
|
||||
reporter10, err := events12.ProvideArtifactReporter(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
manifestService := docker.ManifestServiceProvider(registryRepository, manifestRepository, blobRepository, mediaTypesRepository, manifestReferenceRepository, tagRepository, imageRepository, artifactRepository, layerRepository, gcService, transactor, eventReporter, spaceFinder, ociImageIndexMappingRepository, reporter8, provider)
|
||||
manifestService := docker.ManifestServiceProvider(registryRepository, manifestRepository, blobRepository, mediaTypesRepository, manifestReferenceRepository, tagRepository, imageRepository, artifactRepository, layerRepository, gcService, transactor, eventReporter, spaceFinder, ociImageIndexMappingRepository, reporter10, provider)
|
||||
registryBlobRepository := database2.ProvideRegistryBlobDao(db)
|
||||
bandwidthStatRepository := database2.ProvideBandwidthStatDao(db)
|
||||
downloadStatRepository := database2.ProvideDownloadStatDao(db)
|
||||
|
@ -498,7 +508,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
cleanupPolicyRepository := database2.ProvideCleanupPolicyDao(db, transactor)
|
||||
webhooksRepository := database2.ProvideWebhookDao(db)
|
||||
webhooksExecutionRepository := database2.ProvideWebhookExecutionDao(db)
|
||||
readerFactory2, err := events10.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory2, err := events12.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -506,7 +516,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apiHandler := router.APIHandlerProvider(registryRepository, upstreamProxyConfigRepository, fileManager, tagRepository, manifestRepository, cleanupPolicyRepository, imageRepository, storageDriver, spaceFinder, transactor, authenticator, provider, authorizer, auditService, artifactRepository, webhooksRepository, webhooksExecutionRepository, service2, spacePathStore, reporter8)
|
||||
apiHandler := router.APIHandlerProvider(registryRepository, upstreamProxyConfigRepository, fileManager, tagRepository, manifestRepository, cleanupPolicyRepository, imageRepository, storageDriver, spaceFinder, transactor, authenticator, provider, authorizer, auditService, artifactRepository, webhooksRepository, webhooksExecutionRepository, service2, spacePathStore, reporter10)
|
||||
mavenDBStore := maven.DBStoreProvider(registryRepository, imageRepository, artifactRepository, spaceStore, bandwidthStatRepository, downloadStatRepository, nodesRepository, upstreamProxyConfigRepository)
|
||||
mavenLocalRegistry := maven.LocalRegistryProvider(mavenDBStore, transactor, fileManager)
|
||||
mavenController := maven.ProvideProxyController(mavenLocalRegistry, secretService, spaceFinder)
|
||||
|
@ -537,7 +547,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
serverServer := server2.ProvideServer(config, routerRouter)
|
||||
publickeyService := publickey.ProvidePublicKey(publicKeyStore, principalInfoCache)
|
||||
sshServer := ssh.ProvideServer(config, publickeyService, repoController, lfsController)
|
||||
executionManager := manager.ProvideExecutionManager(config, executionStore, pipelineStore, provider, streamer, fileService, converterService, logStore, logStream, checkStore, repoStore, schedulerScheduler, secretStore, stageStore, stepStore, principalStore, publicaccessService, reporter5)
|
||||
executionManager := manager.ProvideExecutionManager(config, executionStore, pipelineStore, provider, streamer, fileService, converterService, logStore, logStream, checkStore, repoStore, schedulerScheduler, secretStore, stageStore, stepStore, principalStore, publicaccessService, reporter7)
|
||||
client := manager.ProvideExecutionClient(executionManager, provider, config)
|
||||
resolverManager := resolver.ProvideResolver(config, pluginStore, templateStore, executionStore, repoStore)
|
||||
runtimeRunner, err := runner.ProvideExecutionRunner(config, client, resolverManager)
|
||||
|
@ -558,7 +568,15 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
submitter, err := metric.ProvideSubmitter(ctx, config, values, principalStore, principalInfoCache, pullReqStore, readerFactory3, eventsReaderFactory, repoFinder)
|
||||
readerFactory4, err := events3.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
readerFactory5, err := events4.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
submitter, err := metric.ProvideSubmitter(ctx, config, values, principalStore, principalInfoCache, pullReqStore, ruleStore, readerFactory3, readerFactory4, eventsReaderFactory, readerFactory5, publicaccessService, spaceFinder, repoFinder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -570,7 +588,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repoService, err := repo2.ProvideService(ctx, config, reporter, readerFactory3, repoStore, provider, gitInterface, lockerLocker)
|
||||
repoService, err := repo2.ProvideService(ctx, config, eventsReporter, readerFactory4, repoStore, provider, gitInterface, lockerLocker)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -587,41 +605,41 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
return nil, err
|
||||
}
|
||||
keywordsearchConfig := server.ProvideKeywordSearchConfig(config)
|
||||
keywordsearchService, err := keywordsearch.ProvideService(ctx, keywordsearchConfig, readerFactory, readerFactory3, repoStore, indexer)
|
||||
keywordsearchService, err := keywordsearch.ProvideService(ctx, keywordsearchConfig, readerFactory, readerFactory4, repoStore, indexer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspaceeventConfig := server.ProvideGitspaceEventConfig(config)
|
||||
readerFactory4, err := events3.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory6, err := events5.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspaceeventService, err := gitspaceevent.ProvideService(ctx, gitspaceeventConfig, readerFactory4, gitspaceEventStore)
|
||||
gitspaceeventService, err := gitspaceevent.ProvideService(ctx, gitspaceeventConfig, readerFactory6, gitspaceEventStore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspacedeleteeventConfig := server.ProvideGitspaceDeleteEventConfig(config)
|
||||
readerFactory5, err := events6.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory7, err := events8.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspacedeleteeventService, err := gitspacedeleteevent.ProvideService(ctx, gitspacedeleteeventConfig, readerFactory5, gitspaceService)
|
||||
gitspacedeleteeventService, err := gitspacedeleteevent.ProvideService(ctx, gitspacedeleteeventConfig, readerFactory7, gitspaceService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
readerFactory6, err := events4.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory8, err := events6.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspaceinfraeventService, err := gitspaceinfraevent.ProvideService(ctx, gitspaceeventConfig, readerFactory6, orchestratorOrchestrator, gitspaceService, eventsReporter)
|
||||
gitspaceinfraeventService, err := gitspaceinfraevent.ProvideService(ctx, gitspaceeventConfig, readerFactory8, orchestratorOrchestrator, gitspaceService, reporter3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
readerFactory7, err := events5.ProvideReaderFactory(eventsSystem)
|
||||
readerFactory9, err := events7.ProvideReaderFactory(eventsSystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gitspaceoperationseventService, err := gitspaceoperationsevent.ProvideService(ctx, gitspaceeventConfig, readerFactory7, orchestratorOrchestrator, gitspaceService, eventsReporter)
|
||||
gitspaceoperationseventService, err := gitspaceoperationsevent.ProvideService(ctx, gitspaceeventConfig, readerFactory9, orchestratorOrchestrator, gitspaceService, reporter3)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue