Rename GitHub specific types
This change renames a lot of variables, types and functions to be more generic. The goal is to allow GARM to add more forges in the future. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
4890eb4732
commit
40e6581a75
72 changed files with 896 additions and 700 deletions
60
cache/entity_cache.go
vendored
60
cache/entity_cache.go
vendored
|
|
@ -16,7 +16,7 @@ func init() {
|
|||
}
|
||||
|
||||
type EntityItem struct {
|
||||
Entity params.GithubEntity
|
||||
Entity params.ForgeEntity
|
||||
Pools map[string]params.Pool
|
||||
ScaleSets map[uint]params.ScaleSet
|
||||
}
|
||||
|
|
@ -27,34 +27,42 @@ type EntityCache struct {
|
|||
entities map[string]EntityItem
|
||||
}
|
||||
|
||||
func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) {
|
||||
func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
for entityID, cache := range e.entities {
|
||||
if cache.Entity.Credentials.ID == creds.ID {
|
||||
if cache.Entity.Credentials.GetID() == creds.GetID() {
|
||||
cache.Entity.Credentials = creds
|
||||
e.entities[entityID] = cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EntityCache) GetEntity(entityID string) (params.GithubEntity, bool) {
|
||||
func (e *EntityCache) GetEntity(entityID string) (params.ForgeEntity, bool) {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
if cache, ok := e.entities[entityID]; ok {
|
||||
// Get the credentials from the credentials cache.
|
||||
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID)
|
||||
if ok {
|
||||
cache.Entity.Credentials = creds
|
||||
var forgeCredsGetter params.ForgeCredentialsGetter
|
||||
var credsOk bool
|
||||
switch cache.Entity.Credentials.ForgeType {
|
||||
case params.GithubEndpointType:
|
||||
forgeCredsGetter, credsOk = GetGithubCredentials(cache.Entity.Credentials.GetID())
|
||||
case params.GiteaEndpointType:
|
||||
// add gitea credentials getter
|
||||
return cache.Entity, false
|
||||
}
|
||||
if credsOk {
|
||||
cache.Entity.Credentials = forgeCredsGetter.GetForgeCredentials()
|
||||
}
|
||||
return cache.Entity, true
|
||||
}
|
||||
return params.GithubEntity{}, false
|
||||
return params.ForgeEntity{}, false
|
||||
}
|
||||
|
||||
func (e *EntityCache) SetEntity(entity params.GithubEntity) {
|
||||
func (e *EntityCache) SetEntity(entity params.ForgeEntity) {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
|
|
@ -225,13 +233,13 @@ func (e *EntityCache) GetEntityScaleSets(entityID string) []params.ScaleSet {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity {
|
||||
func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
var entities []params.GithubEntity
|
||||
var entities []params.ForgeEntity
|
||||
for _, cache := range e.entities {
|
||||
if cache.Entity.Credentials.ID == credsID {
|
||||
if cache.Entity.Credentials.GetID() == credsID {
|
||||
entities = append(entities, cache.Entity)
|
||||
}
|
||||
}
|
||||
|
|
@ -239,16 +247,24 @@ func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubE
|
|||
return entities
|
||||
}
|
||||
|
||||
func (e *EntityCache) GetAllEntities() []params.GithubEntity {
|
||||
func (e *EntityCache) GetAllEntities() []params.ForgeEntity {
|
||||
e.mux.Lock()
|
||||
defer e.mux.Unlock()
|
||||
|
||||
var entities []params.GithubEntity
|
||||
var entities []params.ForgeEntity
|
||||
for _, cache := range e.entities {
|
||||
// Get the credentials from the credentials cache.
|
||||
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID)
|
||||
if ok {
|
||||
cache.Entity.Credentials = creds
|
||||
var forgeCredsGetter params.ForgeCredentialsGetter
|
||||
var credsOk bool
|
||||
switch cache.Entity.Credentials.ForgeType {
|
||||
case params.GithubEndpointType:
|
||||
forgeCredsGetter, credsOk = GetGithubCredentials(cache.Entity.Credentials.GetID())
|
||||
case params.GiteaEndpointType:
|
||||
// add gitea credentials getter
|
||||
return nil
|
||||
}
|
||||
if credsOk {
|
||||
cache.Entity.Credentials = forgeCredsGetter.GetForgeCredentials()
|
||||
}
|
||||
entities = append(entities, cache.Entity)
|
||||
}
|
||||
|
|
@ -284,11 +300,11 @@ func (e *EntityCache) GetAllScaleSets() []params.ScaleSet {
|
|||
return scaleSets
|
||||
}
|
||||
|
||||
func GetEntity(entityID string) (params.GithubEntity, bool) {
|
||||
func GetEntity(entityID string) (params.ForgeEntity, bool) {
|
||||
return entityCache.GetEntity(entityID)
|
||||
}
|
||||
|
||||
func SetEntity(entity params.GithubEntity) {
|
||||
func SetEntity(entity params.ForgeEntity) {
|
||||
entityCache.SetEntity(entity)
|
||||
}
|
||||
|
||||
|
|
@ -340,15 +356,15 @@ func GetEntityScaleSets(entityID string) []params.ScaleSet {
|
|||
return entityCache.GetEntityScaleSets(entityID)
|
||||
}
|
||||
|
||||
func UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) {
|
||||
func UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
|
||||
entityCache.UpdateCredentialsInAffectedEntities(creds)
|
||||
}
|
||||
|
||||
func GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity {
|
||||
func GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
|
||||
return entityCache.GetEntitiesUsingGredentials(credsID)
|
||||
}
|
||||
|
||||
func GetAllEntities() []params.GithubEntity {
|
||||
func GetAllEntities() []params.ForgeEntity {
|
||||
return entityCache.GetAllEntities()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue