Account for gitea credentials in cache and watchers
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
b4e92a69c9
commit
08511e2e7f
6 changed files with 24 additions and 12 deletions
|
|
@ -14,7 +14,7 @@ func (f Filter) Validate() error {
|
|||
case common.RepositoryEntityType, common.OrganizationEntityType, common.EnterpriseEntityType,
|
||||
common.PoolEntityType, common.UserEntityType, common.InstanceEntityType,
|
||||
common.JobEntityType, common.ControllerEntityType, common.GithubCredentialsEntityType,
|
||||
common.GithubEndpointEntityType:
|
||||
common.GiteaCredentialsEntityType, common.ScaleSetEntityType, common.GithubEndpointEntityType:
|
||||
default:
|
||||
return common.ErrInvalidEntityType
|
||||
}
|
||||
|
|
|
|||
12
cache/entity_cache.go
vendored
12
cache/entity_cache.go
vendored
|
|
@ -231,13 +231,17 @@ func (e *EntityCache) GetEntityScaleSets(entityID string) []params.ScaleSet {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
|
||||
func (e *EntityCache) GetEntitiesUsingCredentials(creds params.ForgeCredentials) []params.ForgeEntity {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
var entities []params.ForgeEntity
|
||||
for _, cache := range e.entities {
|
||||
if cache.Entity.Credentials.GetID() == credsID {
|
||||
if cache.Entity.Credentials.ForgeType != creds.ForgeType {
|
||||
continue
|
||||
}
|
||||
|
||||
if cache.Entity.Credentials.GetID() == creds.GetID() {
|
||||
entities = append(entities, cache.Entity)
|
||||
}
|
||||
}
|
||||
|
|
@ -357,8 +361,8 @@ func UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
|
|||
entityCache.UpdateCredentialsInAffectedEntities(creds)
|
||||
}
|
||||
|
||||
func GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
|
||||
return entityCache.GetEntitiesUsingGredentials(credsID)
|
||||
func GetEntitiesUsingCredentials(creds params.ForgeCredentials) []params.ForgeEntity {
|
||||
return entityCache.GetEntitiesUsingCredentials(creds)
|
||||
}
|
||||
|
||||
func GetAllEntities() []params.ForgeEntity {
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ func WithForgeCredentialsFilter(creds params.ForgeCredentials) dbCommon.PayloadF
|
|||
var idGetter params.IDGetter
|
||||
var ok bool
|
||||
switch payload.EntityType {
|
||||
case dbCommon.GithubCredentialsEntityType:
|
||||
case dbCommon.GithubCredentialsEntityType, dbCommon.GiteaCredentialsEntityType:
|
||||
idGetter, ok = payload.Payload.(params.ForgeCredentials)
|
||||
default:
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.ForgeCreden
|
|||
func (r *basePoolManager) handleWatcherEvent(event common.ChangePayload) {
|
||||
dbEntityType := common.DatabaseEntityType(r.entity.EntityType)
|
||||
switch event.EntityType {
|
||||
case common.GithubCredentialsEntityType:
|
||||
case common.GithubCredentialsEntityType, common.GiteaCredentialsEntityType:
|
||||
credentials, ok := event.Payload.(params.ForgeCredentials)
|
||||
if !ok {
|
||||
slog.ErrorContext(r.ctx, "failed to cast payload to github credentials")
|
||||
|
|
|
|||
14
workers/cache/cache.go
vendored
14
workers/cache/cache.go
vendored
|
|
@ -386,8 +386,16 @@ func (w *Worker) handleCredentialsEvent(event common.ChangePayload) {
|
|||
}
|
||||
switch event.Operation {
|
||||
case common.CreateOperation, common.UpdateOperation:
|
||||
cache.SetGithubCredentials(credentials)
|
||||
entities := cache.GetEntitiesUsingGredentials(credentials.ID)
|
||||
switch credentials.ForgeType {
|
||||
case params.GithubEndpointType:
|
||||
cache.SetGithubCredentials(credentials)
|
||||
case params.GiteaEndpointType:
|
||||
cache.SetGiteaCredentials(credentials)
|
||||
default:
|
||||
slog.DebugContext(w.ctx, "invalid credentials type", "credentials_type", credentials.ForgeType)
|
||||
return
|
||||
}
|
||||
entities := cache.GetEntitiesUsingCredentials(credentials)
|
||||
for _, entity := range entities {
|
||||
worker, ok := w.toolsWorkes[entity.ID]
|
||||
if ok {
|
||||
|
|
@ -414,7 +422,7 @@ func (w *Worker) handleEvent(event common.ChangePayload) {
|
|||
w.handleOrgEvent(event)
|
||||
case common.EnterpriseEntityType:
|
||||
w.handleEnterpriseEvent(event)
|
||||
case common.GithubCredentialsEntityType:
|
||||
case common.GithubCredentialsEntityType, common.GiteaCredentialsEntityType:
|
||||
w.handleCredentialsEvent(event)
|
||||
default:
|
||||
slog.DebugContext(w.ctx, "unknown entity type", "entity_type", event.EntityType)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func (w *Worker) handleWorkerWatcherEvent(event dbCommon.ChangePayload) {
|
|||
case entityType:
|
||||
w.handleEntityEventPayload(event)
|
||||
return
|
||||
case dbCommon.GithubCredentialsEntityType:
|
||||
case dbCommon.GithubCredentialsEntityType, dbCommon.GiteaCredentialsEntityType:
|
||||
slog.DebugContext(w.ctx, "got github credentials payload event")
|
||||
w.handleEntityCredentialsEventPayload(event)
|
||||
default:
|
||||
|
|
@ -66,7 +66,7 @@ func (w *Worker) handleEntityCredentialsEventPayload(event dbCommon.ChangePayloa
|
|||
var creds params.ForgeCredentials
|
||||
var ok bool
|
||||
switch event.EntityType {
|
||||
case dbCommon.GithubCredentialsEntityType:
|
||||
case dbCommon.GithubCredentialsEntityType, dbCommon.GiteaCredentialsEntityType:
|
||||
creds, ok = event.Payload.(params.ForgeCredentials)
|
||||
default:
|
||||
slog.ErrorContext(w.ctx, "invalid entity type", "entity_type", event.EntityType)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue