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:
Gabriel Adrian Samfira 2025-05-12 21:47:13 +00:00
parent 4890eb4732
commit 40e6581a75
72 changed files with 896 additions and 700 deletions

View file

@ -320,7 +320,7 @@ func (a *APIController) CreateEnterpriseScaleSetHandler(w http.ResponseWriter, r
return return
} }
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeEnterprise, enterpriseID, scaleSetData) scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeEnterprise, enterpriseID, scaleSetData)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating enterprise scale set") slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating enterprise scale set")
handleError(ctx, w, err) handleError(ctx, w, err)
@ -404,7 +404,7 @@ func (a *APIController) ListEnterpriseScaleSetsHandler(w http.ResponseWriter, r
return return
} }
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeEnterprise, enterpriseID) scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeEnterprise, enterpriseID)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets") slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err) handleError(ctx, w, err)

View file

@ -330,7 +330,7 @@ func (a *APIController) CreateOrgScaleSetHandler(w http.ResponseWriter, r *http.
return return
} }
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeOrganization, orgID, scalesetData) scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeOrganization, orgID, scalesetData)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating organization scale set") slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating organization scale set")
handleError(ctx, w, err) handleError(ctx, w, err)
@ -414,7 +414,7 @@ func (a *APIController) ListOrgScaleSetsHandler(w http.ResponseWriter, r *http.R
return return
} }
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeOrganization, orgID) scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeOrganization, orgID)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets") slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err) handleError(ctx, w, err)

View file

@ -329,7 +329,7 @@ func (a *APIController) CreateRepoScaleSetHandler(w http.ResponseWriter, r *http
return return
} }
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeRepository, repoID, scaleSetData) scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeRepository, repoID, scaleSetData)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating repository scale set") slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating repository scale set")
handleError(ctx, w, err) handleError(ctx, w, err)
@ -413,7 +413,7 @@ func (a *APIController) ListRepoScaleSetsHandler(w http.ResponseWriter, r *http.
return return
} }
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeRepository, repoID) scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeRepository, repoID)
if err != nil { if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets") slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err) handleError(ctx, w, err)

View file

@ -40,7 +40,7 @@ type InstanceJWTClaims struct {
Name string `json:"name"` Name string `json:"name"`
PoolID string `json:"provider_id"` PoolID string `json:"provider_id"`
// Scope is either repository or organization // Scope is either repository or organization
Scope params.GithubEntityType `json:"scope"` Scope params.ForgeEntityType `json:"scope"`
// Entity is the repo or org name // Entity is the repo or org name
Entity string `json:"entity"` Entity string `json:"entity"`
CreateAttempt int `json:"create_attempt"` CreateAttempt int `json:"create_attempt"`
@ -60,7 +60,7 @@ type instanceToken struct {
jwtSecret string jwtSecret string
} }
func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity string, entityType params.GithubEntityType, ttlMinutes uint) (string, error) { func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity string, entityType params.ForgeEntityType, ttlMinutes uint) (string, error) {
// Token expiration is equal to the bootstrap timeout set on the pool plus the polling // Token expiration is equal to the bootstrap timeout set on the pool plus the polling
// interval garm uses to check for timed out runners. Runners that have not sent their info // interval garm uses to check for timed out runners. Runners that have not sent their info
// by the end of this interval are most likely failed and will be reaped by garm anyway. // by the end of this interval are most likely failed and will be reaped by garm anyway.

View file

@ -26,5 +26,5 @@ type Middleware interface {
} }
type InstanceTokenGetter interface { type InstanceTokenGetter interface {
NewInstanceJWTToken(instance params.Instance, entity string, poolType params.GithubEntityType, ttlMinutes uint) (string, error) NewInstanceJWTToken(instance params.Instance, entity string, poolType params.ForgeEntityType, ttlMinutes uint) (string, error)
} }

69
cache/cache_test.go vendored
View file

@ -13,13 +13,13 @@ import (
type CacheTestSuite struct { type CacheTestSuite struct {
suite.Suite suite.Suite
entity params.GithubEntity entity params.ForgeEntity
} }
func (c *CacheTestSuite) SetupTest() { func (c *CacheTestSuite) SetupTest() {
c.entity = params.GithubEntity{ c.entity = params.ForgeEntity{
ID: "1234", ID: "1234",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -254,9 +254,9 @@ func (c *CacheTestSuite) TestGetInstancesForScaleSet() {
} }
func (c *CacheTestSuite) TestSetGetEntityCache() { func (c *CacheTestSuite) TestSetGetEntityCache() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -265,22 +265,25 @@ func (c *CacheTestSuite) TestSetGetEntityCache() {
c.Require().True(ok) c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID) c.Require().Equal(entity.ID, cachedEntity.ID)
entity.Credentials.Description = "test description" entity.Credentials.GithubCredentials.Description = "test description"
SetEntity(entity) SetEntity(entity)
cachedEntity, ok = GetEntity("test-entity") cachedEntity, ok = GetEntity("test-entity")
c.Require().True(ok) c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID) c.Require().Equal(entity.ID, cachedEntity.ID)
c.Require().Equal(entity.Credentials.Description, cachedEntity.Credentials.Description) c.Require().Equal(entity.Credentials.GithubCredentials.Description, cachedEntity.Credentials.GithubCredentials.Description)
} }
func (c *CacheTestSuite) TestReplaceEntityPools() { func (c *CacheTestSuite) TestReplaceEntityPools() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
Credentials: params.GithubCredentials{ Credentials: params.ForgeCredentials{
ID: 1, ForgeType: params.GithubEndpointType,
GithubCredentials: params.GithubCredentials{
ID: 1,
},
}, },
} }
pool1 := params.Pool{ pool1 := params.Pool{
@ -301,7 +304,7 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
cachedEntity, ok := GetEntity(entity.ID) cachedEntity, ok := GetEntity(entity.ID)
c.Require().True(ok) c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID) c.Require().Equal(entity.ID, cachedEntity.ID)
c.Require().Equal("test", cachedEntity.Credentials.Name) c.Require().Equal("test", cachedEntity.Credentials.GithubCredentials.Name)
pools := GetEntityPools(entity.ID) pools := GetEntityPools(entity.ID)
c.Require().Len(pools, 2) c.Require().Len(pools, 2)
@ -310,9 +313,9 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
} }
func (c *CacheTestSuite) TestReplaceEntityScaleSets() { func (c *CacheTestSuite) TestReplaceEntityScaleSets() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -336,9 +339,9 @@ func (c *CacheTestSuite) TestReplaceEntityScaleSets() {
} }
func (c *CacheTestSuite) TestDeleteEntity() { func (c *CacheTestSuite) TestDeleteEntity() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -350,13 +353,13 @@ func (c *CacheTestSuite) TestDeleteEntity() {
DeleteEntity(entity.ID) DeleteEntity(entity.ID)
cachedEntity, ok = GetEntity(entity.ID) cachedEntity, ok = GetEntity(entity.ID)
c.Require().False(ok) c.Require().False(ok)
c.Require().Equal(params.GithubEntity{}, cachedEntity) c.Require().Equal(params.ForgeEntity{}, cachedEntity)
} }
func (c *CacheTestSuite) TestSetEntityPool() { func (c *CacheTestSuite) TestSetEntityPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -387,9 +390,9 @@ func (c *CacheTestSuite) TestSetEntityPool() {
} }
func (c *CacheTestSuite) TestSetEntityScaleSet() { func (c *CacheTestSuite) TestSetEntityScaleSet() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -417,9 +420,9 @@ func (c *CacheTestSuite) TestSetEntityScaleSet() {
} }
func (c *CacheTestSuite) TestDeleteEntityPool() { func (c *CacheTestSuite) TestDeleteEntityPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -440,9 +443,9 @@ func (c *CacheTestSuite) TestDeleteEntityPool() {
} }
func (c *CacheTestSuite) TestDeleteEntityScaleSet() { func (c *CacheTestSuite) TestDeleteEntityScaleSet() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -463,9 +466,9 @@ func (c *CacheTestSuite) TestDeleteEntityScaleSet() {
} }
func (c *CacheTestSuite) TestFindPoolsMatchingAllTags() { func (c *CacheTestSuite) TestFindPoolsMatchingAllTags() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -520,9 +523,9 @@ func (c *CacheTestSuite) TestFindPoolsMatchingAllTags() {
} }
func (c *CacheTestSuite) TestGetEntityPools() { func (c *CacheTestSuite) TestGetEntityPools() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -562,9 +565,9 @@ func (c *CacheTestSuite) TestGetEntityPools() {
} }
func (c *CacheTestSuite) TestGetEntityScaleSet() { func (c *CacheTestSuite) TestGetEntityScaleSet() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }
@ -584,9 +587,9 @@ func (c *CacheTestSuite) TestGetEntityScaleSet() {
} }
func (c *CacheTestSuite) TestGetEntityPool() { func (c *CacheTestSuite) TestGetEntityPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "test-entity", ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
Name: "test", Name: "test",
Owner: "test", Owner: "test",
} }

View file

@ -36,7 +36,7 @@ func (g *GithubCredentials) SetCredentials(credentials params.GithubCredentials)
defer g.mux.Unlock() defer g.mux.Unlock()
g.cache[credentials.ID] = credentials g.cache[credentials.ID] = credentials
UpdateCredentialsInAffectedEntities(credentials) UpdateCredentialsInAffectedEntities(credentials.GetForgeCredentials())
} }
func (g *GithubCredentials) GetCredentials(id uint) (params.GithubCredentials, bool) { func (g *GithubCredentials) GetCredentials(id uint) (params.GithubCredentials, bool) {

60
cache/entity_cache.go vendored
View file

@ -16,7 +16,7 @@ func init() {
} }
type EntityItem struct { type EntityItem struct {
Entity params.GithubEntity Entity params.ForgeEntity
Pools map[string]params.Pool Pools map[string]params.Pool
ScaleSets map[uint]params.ScaleSet ScaleSets map[uint]params.ScaleSet
} }
@ -27,34 +27,42 @@ type EntityCache struct {
entities map[string]EntityItem entities map[string]EntityItem
} }
func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) { func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
e.mux.Lock() e.mux.Lock()
defer e.mux.Unlock() defer e.mux.Unlock()
for entityID, cache := range e.entities { for entityID, cache := range e.entities {
if cache.Entity.Credentials.ID == creds.ID { if cache.Entity.Credentials.GetID() == creds.GetID() {
cache.Entity.Credentials = creds cache.Entity.Credentials = creds
e.entities[entityID] = cache 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() e.mux.Lock()
defer e.mux.Unlock() defer e.mux.Unlock()
if cache, ok := e.entities[entityID]; ok { if cache, ok := e.entities[entityID]; ok {
// Get the credentials from the credentials cache. // Get the credentials from the credentials cache.
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID) var forgeCredsGetter params.ForgeCredentialsGetter
if ok { var credsOk bool
cache.Entity.Credentials = creds 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 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() e.mux.Lock()
defer e.mux.Unlock() defer e.mux.Unlock()
@ -225,13 +233,13 @@ func (e *EntityCache) GetEntityScaleSets(entityID string) []params.ScaleSet {
return nil return nil
} }
func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity { func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
e.mux.Lock() e.mux.Lock()
defer e.mux.Unlock() defer e.mux.Unlock()
var entities []params.GithubEntity var entities []params.ForgeEntity
for _, cache := range e.entities { for _, cache := range e.entities {
if cache.Entity.Credentials.ID == credsID { if cache.Entity.Credentials.GetID() == credsID {
entities = append(entities, cache.Entity) entities = append(entities, cache.Entity)
} }
} }
@ -239,16 +247,24 @@ func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubE
return entities return entities
} }
func (e *EntityCache) GetAllEntities() []params.GithubEntity { func (e *EntityCache) GetAllEntities() []params.ForgeEntity {
e.mux.Lock() e.mux.Lock()
defer e.mux.Unlock() defer e.mux.Unlock()
var entities []params.GithubEntity var entities []params.ForgeEntity
for _, cache := range e.entities { for _, cache := range e.entities {
// Get the credentials from the credentials cache. // Get the credentials from the credentials cache.
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID) var forgeCredsGetter params.ForgeCredentialsGetter
if ok { var credsOk bool
cache.Entity.Credentials = creds 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) entities = append(entities, cache.Entity)
} }
@ -284,11 +300,11 @@ func (e *EntityCache) GetAllScaleSets() []params.ScaleSet {
return scaleSets return scaleSets
} }
func GetEntity(entityID string) (params.GithubEntity, bool) { func GetEntity(entityID string) (params.ForgeEntity, bool) {
return entityCache.GetEntity(entityID) return entityCache.GetEntity(entityID)
} }
func SetEntity(entity params.GithubEntity) { func SetEntity(entity params.ForgeEntity) {
entityCache.SetEntity(entity) entityCache.SetEntity(entity)
} }
@ -340,15 +356,15 @@ func GetEntityScaleSets(entityID string) []params.ScaleSet {
return entityCache.GetEntityScaleSets(entityID) return entityCache.GetEntityScaleSets(entityID)
} }
func UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) { func UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
entityCache.UpdateCredentialsInAffectedEntities(creds) entityCache.UpdateCredentialsInAffectedEntities(creds)
} }
func GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity { func GetEntitiesUsingGredentials(credsID uint) []params.ForgeEntity {
return entityCache.GetEntitiesUsingGredentials(credsID) return entityCache.GetEntitiesUsingGredentials(credsID)
} }
func GetAllEntities() []params.GithubEntity { func GetAllEntities() []params.ForgeEntity {
return entityCache.GetAllEntities() return entityCache.GetAllEntities()
} }

View file

@ -19,7 +19,7 @@ func init() {
type GithubEntityTools struct { type GithubEntityTools struct {
updatedAt time.Time updatedAt time.Time
entity params.GithubEntity entity params.ForgeEntity
tools []commonParams.RunnerApplicationDownload tools []commonParams.RunnerApplicationDownload
} }
@ -44,7 +44,7 @@ func (g *GithubToolsCache) Get(entityID string) ([]commonParams.RunnerApplicatio
return nil, false return nil, false
} }
func (g *GithubToolsCache) Set(entity params.GithubEntity, tools []commonParams.RunnerApplicationDownload) { func (g *GithubToolsCache) Set(entity params.ForgeEntity, tools []commonParams.RunnerApplicationDownload) {
g.mux.Lock() g.mux.Lock()
defer g.mux.Unlock() defer g.mux.Unlock()
@ -55,7 +55,7 @@ func (g *GithubToolsCache) Set(entity params.GithubEntity, tools []commonParams.
} }
} }
func SetGithubToolsCache(entity params.GithubEntity, tools []commonParams.RunnerApplicationDownload) { func SetGithubToolsCache(entity params.ForgeEntity, tools []commonParams.RunnerApplicationDownload) {
githubToolsCache.Set(entity, tools) githubToolsCache.Set(entity, tools)
} }

View file

@ -54,7 +54,7 @@ CreateGithubEndpointOK describes a response with status code 200, with default h
GithubEndpoint GithubEndpoint
*/ */
type CreateGithubEndpointOK struct { type CreateGithubEndpointOK struct {
Payload garm_params.GithubEndpoint Payload garm_params.ForgeEndpoint
} }
// IsSuccess returns true when this create github endpoint o k response has a 2xx status code // IsSuccess returns true when this create github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *CreateGithubEndpointOK) String() string {
return fmt.Sprintf("[POST /github/endpoints][%d] createGithubEndpointOK %s", 200, payload) return fmt.Sprintf("[POST /github/endpoints][%d] createGithubEndpointOK %s", 200, payload)
} }
func (o *CreateGithubEndpointOK) GetPayload() garm_params.GithubEndpoint { func (o *CreateGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload return o.Payload
} }

View file

@ -54,7 +54,7 @@ GetGithubEndpointOK describes a response with status code 200, with default head
GithubEndpoint GithubEndpoint
*/ */
type GetGithubEndpointOK struct { type GetGithubEndpointOK struct {
Payload garm_params.GithubEndpoint Payload garm_params.ForgeEndpoint
} }
// IsSuccess returns true when this get github endpoint o k response has a 2xx status code // IsSuccess returns true when this get github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *GetGithubEndpointOK) String() string {
return fmt.Sprintf("[GET /github/endpoints/{name}][%d] getGithubEndpointOK %s", 200, payload) return fmt.Sprintf("[GET /github/endpoints/{name}][%d] getGithubEndpointOK %s", 200, payload)
} }
func (o *GetGithubEndpointOK) GetPayload() garm_params.GithubEndpoint { func (o *GetGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload return o.Payload
} }

View file

@ -54,7 +54,7 @@ ListGithubEndpointsOK describes a response with status code 200, with default he
GithubEndpoints GithubEndpoints
*/ */
type ListGithubEndpointsOK struct { type ListGithubEndpointsOK struct {
Payload garm_params.GithubEndpoints Payload garm_params.ForgeEndpoints
} }
// IsSuccess returns true when this list github endpoints o k response has a 2xx status code // IsSuccess returns true when this list github endpoints o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *ListGithubEndpointsOK) String() string {
return fmt.Sprintf("[GET /github/endpoints][%d] listGithubEndpointsOK %s", 200, payload) return fmt.Sprintf("[GET /github/endpoints][%d] listGithubEndpointsOK %s", 200, payload)
} }
func (o *ListGithubEndpointsOK) GetPayload() garm_params.GithubEndpoints { func (o *ListGithubEndpointsOK) GetPayload() garm_params.ForgeEndpoints {
return o.Payload return o.Payload
} }

View file

@ -54,7 +54,7 @@ UpdateGithubEndpointOK describes a response with status code 200, with default h
GithubEndpoint GithubEndpoint
*/ */
type UpdateGithubEndpointOK struct { type UpdateGithubEndpointOK struct {
Payload garm_params.GithubEndpoint Payload garm_params.ForgeEndpoint
} }
// IsSuccess returns true when this update github endpoint o k response has a 2xx status code // IsSuccess returns true when this update github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *UpdateGithubEndpointOK) String() string {
return fmt.Sprintf("[PUT /github/endpoints/{name}][%d] updateGithubEndpointOK %s", 200, payload) return fmt.Sprintf("[PUT /github/endpoints/{name}][%d] updateGithubEndpointOK %s", 200, payload)
} }
func (o *UpdateGithubEndpointOK) GetPayload() garm_params.GithubEndpoint { func (o *UpdateGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload return o.Payload
} }

View file

@ -283,12 +283,12 @@ func parsePrivateKeyFromPath(path string) ([]byte, error) {
func parseCredentialsAddParams() (ret params.CreateGithubCredentialsParams, err error) { func parseCredentialsAddParams() (ret params.CreateGithubCredentialsParams, err error) {
ret.Name = credentialsName ret.Name = credentialsName
ret.Description = credentialsDescription ret.Description = credentialsDescription
ret.AuthType = params.GithubAuthType(credentialsType) ret.AuthType = params.ForgeAuthType(credentialsType)
ret.Endpoint = credentialsEndpoint ret.Endpoint = credentialsEndpoint
switch ret.AuthType { switch ret.AuthType {
case params.GithubAuthTypePAT: case params.ForgeAuthTypePAT:
ret.PAT.OAuth2Token = credentialsOAuthToken ret.PAT.OAuth2Token = credentialsOAuthToken
case params.GithubAuthTypeApp: case params.ForgeAuthTypeApp:
ret.App.InstallationID = credentialsAppInstallationID ret.App.InstallationID = credentialsAppInstallationID
ret.App.AppID = credentialsAppID ret.App.AppID = credentialsAppID
keyContents, err := parsePrivateKeyFromPath(credentialsPrivateKeyPath) keyContents, err := parsePrivateKeyFromPath(credentialsPrivateKeyPath)

View file

@ -252,7 +252,7 @@ func parseCreateParams() (params.CreateGithubEndpointParams, error) {
return ret, nil return ret, nil
} }
func formatEndpoints(endpoints params.GithubEndpoints) { func formatEndpoints(endpoints params.ForgeEndpoints) {
if outputFormat == common.OutputFormatJSON { if outputFormat == common.OutputFormatJSON {
printAsJSON(endpoints) printAsJSON(endpoints)
return return
@ -274,7 +274,7 @@ func formatEndpoints(endpoints params.GithubEndpoints) {
fmt.Println(t.Render()) fmt.Println(t.Render())
} }
func formatOneEndpoint(endpoint params.GithubEndpoint) { func formatOneEndpoint(endpoint params.ForgeEndpoint) {
if outputFormat == common.OutputFormatJSON { if outputFormat == common.OutputFormatJSON {
printAsJSON(endpoint) printAsJSON(endpoint)
return return

View file

@ -15,7 +15,7 @@ type Store struct {
} }
// AddEntityEvent provides a mock function with given fields: ctx, entity, event, eventLevel, statusMessage, maxEvents // AddEntityEvent provides a mock function with given fields: ctx, entity, event, eventLevel, statusMessage, maxEvents
func (_m *Store) AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error { func (_m *Store) AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
ret := _m.Called(ctx, entity, event, eventLevel, statusMessage, maxEvents) ret := _m.Called(ctx, entity, event, eventLevel, statusMessage, maxEvents)
if len(ret) == 0 { if len(ret) == 0 {
@ -23,7 +23,7 @@ func (_m *Store) AddEntityEvent(ctx context.Context, entity params.GithubEntity,
} }
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.EventType, params.EventLevel, string, int) error); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.EventType, params.EventLevel, string, int) error); ok {
r0 = rf(ctx, entity, event, eventLevel, statusMessage, maxEvents) r0 = rf(ctx, entity, event, eventLevel, statusMessage, maxEvents)
} else { } else {
r0 = ret.Error(0) r0 = ret.Error(0)
@ -125,7 +125,7 @@ func (_m *Store) CreateEnterprise(ctx context.Context, name string, credentialsN
} }
// CreateEntityPool provides a mock function with given fields: ctx, entity, param // CreateEntityPool provides a mock function with given fields: ctx, entity, param
func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error) { func (_m *Store) CreateEntityPool(ctx context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (params.Pool, error) {
ret := _m.Called(ctx, entity, param) ret := _m.Called(ctx, entity, param)
if len(ret) == 0 { if len(ret) == 0 {
@ -134,16 +134,16 @@ func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool var r0 params.Pool
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreatePoolParams) (params.Pool, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) (params.Pool, error)); ok {
return rf(ctx, entity, param) return rf(ctx, entity, param)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreatePoolParams) params.Pool); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) params.Pool); ok {
r0 = rf(ctx, entity, param) r0 = rf(ctx, entity, param)
} else { } else {
r0 = ret.Get(0).(params.Pool) r0 = ret.Get(0).(params.Pool)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, params.CreatePoolParams) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) error); ok {
r1 = rf(ctx, entity, param) r1 = rf(ctx, entity, param)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -153,7 +153,7 @@ func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntit
} }
// CreateEntityScaleSet provides a mock function with given fields: _a0, entity, param // CreateEntityScaleSet provides a mock function with given fields: _a0, entity, param
func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (params.ScaleSet, error) { func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (params.ScaleSet, error) {
ret := _m.Called(_a0, entity, param) ret := _m.Called(_a0, entity, param)
if len(ret) == 0 { if len(ret) == 0 {
@ -162,16 +162,16 @@ func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet var r0 params.ScaleSet
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) (params.ScaleSet, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) (params.ScaleSet, error)); ok {
return rf(_a0, entity, param) return rf(_a0, entity, param)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) params.ScaleSet); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) params.ScaleSet); ok {
r0 = rf(_a0, entity, param) r0 = rf(_a0, entity, param)
} else { } else {
r0 = ret.Get(0).(params.ScaleSet) r0 = ret.Get(0).(params.ScaleSet)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) error); ok {
r1 = rf(_a0, entity, param) r1 = rf(_a0, entity, param)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -209,22 +209,22 @@ func (_m *Store) CreateGithubCredentials(ctx context.Context, param params.Creat
} }
// CreateGithubEndpoint provides a mock function with given fields: ctx, param // CreateGithubEndpoint provides a mock function with given fields: ctx, param
func (_m *Store) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error) { func (_m *Store) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, param) ret := _m.Called(ctx, param)
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for CreateGithubEndpoint") panic("no return value specified for CreateGithubEndpoint")
} }
var r0 params.GithubEndpoint var r0 params.ForgeEndpoint
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) (params.GithubEndpoint, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(ctx, param) return rf(ctx, param)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) params.GithubEndpoint); ok { if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(ctx, param) r0 = rf(ctx, param)
} else { } else {
r0 = ret.Get(0).(params.GithubEndpoint) r0 = ret.Get(0).(params.ForgeEndpoint)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.CreateGithubEndpointParams) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.CreateGithubEndpointParams) error); ok {
@ -441,7 +441,7 @@ func (_m *Store) DeleteEnterprise(ctx context.Context, enterpriseID string) erro
} }
// DeleteEntityPool provides a mock function with given fields: ctx, entity, poolID // DeleteEntityPool provides a mock function with given fields: ctx, entity, poolID
func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error { func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) error {
ret := _m.Called(ctx, entity, poolID) ret := _m.Called(ctx, entity, poolID)
if len(ret) == 0 { if len(ret) == 0 {
@ -449,7 +449,7 @@ func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntit
} }
var r0 error var r0 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) error); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) error); ok {
r0 = rf(ctx, entity, poolID) r0 = rf(ctx, entity, poolID)
} else { } else {
r0 = ret.Error(0) r0 = ret.Error(0)
@ -621,7 +621,7 @@ func (_m *Store) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) error
} }
// FindPoolsMatchingAllTags provides a mock function with given fields: ctx, entityType, entityID, tags // FindPoolsMatchingAllTags provides a mock function with given fields: ctx, entityType, entityID, tags
func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error) { func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error) {
ret := _m.Called(ctx, entityType, entityID, tags) ret := _m.Called(ctx, entityType, entityID, tags)
if len(ret) == 0 { if len(ret) == 0 {
@ -630,10 +630,10 @@ func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params
var r0 []params.Pool var r0 []params.Pool
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, []string) ([]params.Pool, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, []string) ([]params.Pool, error)); ok {
return rf(ctx, entityType, entityID, tags) return rf(ctx, entityType, entityID, tags)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, []string) []params.Pool); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, []string) []params.Pool); ok {
r0 = rf(ctx, entityType, entityID, tags) r0 = rf(ctx, entityType, entityID, tags)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
@ -641,7 +641,7 @@ func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string, []string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string, []string) error); ok {
r1 = rf(ctx, entityType, entityID, tags) r1 = rf(ctx, entityType, entityID, tags)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -735,7 +735,7 @@ func (_m *Store) GetEnterpriseByID(ctx context.Context, enterpriseID string) (pa
} }
// GetEntityPool provides a mock function with given fields: ctx, entity, poolID // GetEntityPool provides a mock function with given fields: ctx, entity, poolID
func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) { func (_m *Store) GetEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error) {
ret := _m.Called(ctx, entity, poolID) ret := _m.Called(ctx, entity, poolID)
if len(ret) == 0 { if len(ret) == 0 {
@ -744,16 +744,16 @@ func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity,
var r0 params.Pool var r0 params.Pool
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) (params.Pool, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) (params.Pool, error)); ok {
return rf(ctx, entity, poolID) return rf(ctx, entity, poolID)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) params.Pool); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) params.Pool); ok {
r0 = rf(ctx, entity, poolID) r0 = rf(ctx, entity, poolID)
} else { } else {
r0 = ret.Get(0).(params.Pool) r0 = ret.Get(0).(params.Pool)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, string) error); ok {
r1 = rf(ctx, entity, poolID) r1 = rf(ctx, entity, poolID)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -819,22 +819,22 @@ func (_m *Store) GetGithubCredentialsByName(ctx context.Context, name string, de
} }
// GetGithubEndpoint provides a mock function with given fields: ctx, name // GetGithubEndpoint provides a mock function with given fields: ctx, name
func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error) { func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, name) ret := _m.Called(ctx, name)
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for GetGithubEndpoint") panic("no return value specified for GetGithubEndpoint")
} }
var r0 params.GithubEndpoint var r0 params.ForgeEndpoint
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (params.GithubEndpoint, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, string) (params.ForgeEndpoint, error)); ok {
return rf(ctx, name) return rf(ctx, name)
} }
if rf, ok := ret.Get(0).(func(context.Context, string) params.GithubEndpoint); ok { if rf, ok := ret.Get(0).(func(context.Context, string) params.ForgeEndpoint); ok {
r0 = rf(ctx, name) r0 = rf(ctx, name)
} else { } else {
r0 = ret.Get(0).(params.GithubEndpoint) r0 = ret.Get(0).(params.ForgeEndpoint)
} }
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
@ -846,26 +846,26 @@ func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.Git
return r0, r1 return r0, r1
} }
// GetGithubEntity provides a mock function with given fields: _a0, entityType, entityID // GetForgeEntity provides a mock function with given fields: _a0, entityType, entityID
func (_m *Store) GetGithubEntity(_a0 context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) { func (_m *Store) GetForgeEntity(_a0 context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error) {
ret := _m.Called(_a0, entityType, entityID) ret := _m.Called(_a0, entityType, entityID)
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for GetGithubEntity") panic("no return value specified for GetForgeEntity")
} }
var r0 params.GithubEntity var r0 params.ForgeEntity
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string) (params.GithubEntity, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string) (params.ForgeEntity, error)); ok {
return rf(_a0, entityType, entityID) return rf(_a0, entityType, entityID)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string) params.GithubEntity); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string) params.ForgeEntity); ok {
r0 = rf(_a0, entityType, entityID) r0 = rf(_a0, entityType, entityID)
} else { } else {
r0 = ret.Get(0).(params.GithubEntity) r0 = ret.Get(0).(params.ForgeEntity)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string) error); ok {
r1 = rf(_a0, entityType, entityID) r1 = rf(_a0, entityType, entityID)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1379,7 +1379,7 @@ func (_m *Store) ListEnterprises(ctx context.Context) ([]params.Enterprise, erro
} }
// ListEntityInstances provides a mock function with given fields: ctx, entity // ListEntityInstances provides a mock function with given fields: ctx, entity
func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error) { func (_m *Store) ListEntityInstances(ctx context.Context, entity params.ForgeEntity) ([]params.Instance, error) {
ret := _m.Called(ctx, entity) ret := _m.Called(ctx, entity)
if len(ret) == 0 { if len(ret) == 0 {
@ -1388,10 +1388,10 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
var r0 []params.Instance var r0 []params.Instance
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.Instance, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.Instance, error)); ok {
return rf(ctx, entity) return rf(ctx, entity)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.Instance); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.Instance); ok {
r0 = rf(ctx, entity) r0 = rf(ctx, entity)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
@ -1399,7 +1399,7 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(ctx, entity) r1 = rf(ctx, entity)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1409,7 +1409,7 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
} }
// ListEntityJobsByStatus provides a mock function with given fields: ctx, entityType, entityID, status // ListEntityJobsByStatus provides a mock function with given fields: ctx, entityType, entityID, status
func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error) { func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
ret := _m.Called(ctx, entityType, entityID, status) ret := _m.Called(ctx, entityType, entityID, status)
if len(ret) == 0 { if len(ret) == 0 {
@ -1418,10 +1418,10 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
var r0 []params.Job var r0 []params.Job
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, params.JobStatus) ([]params.Job, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) ([]params.Job, error)); ok {
return rf(ctx, entityType, entityID, status) return rf(ctx, entityType, entityID, status)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, params.JobStatus) []params.Job); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) []params.Job); ok {
r0 = rf(ctx, entityType, entityID, status) r0 = rf(ctx, entityType, entityID, status)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
@ -1429,7 +1429,7 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string, params.JobStatus) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) error); ok {
r1 = rf(ctx, entityType, entityID, status) r1 = rf(ctx, entityType, entityID, status)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1439,7 +1439,7 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
} }
// ListEntityPools provides a mock function with given fields: ctx, entity // ListEntityPools provides a mock function with given fields: ctx, entity
func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity) ([]params.Pool, error) { func (_m *Store) ListEntityPools(ctx context.Context, entity params.ForgeEntity) ([]params.Pool, error) {
ret := _m.Called(ctx, entity) ret := _m.Called(ctx, entity)
if len(ret) == 0 { if len(ret) == 0 {
@ -1448,10 +1448,10 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
var r0 []params.Pool var r0 []params.Pool
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.Pool, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.Pool, error)); ok {
return rf(ctx, entity) return rf(ctx, entity)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.Pool); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.Pool); ok {
r0 = rf(ctx, entity) r0 = rf(ctx, entity)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
@ -1459,7 +1459,7 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(ctx, entity) r1 = rf(ctx, entity)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1469,7 +1469,7 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
} }
// ListEntityScaleSets provides a mock function with given fields: _a0, entity // ListEntityScaleSets provides a mock function with given fields: _a0, entity
func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEntity) ([]params.ScaleSet, error) { func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error) {
ret := _m.Called(_a0, entity) ret := _m.Called(_a0, entity)
if len(ret) == 0 { if len(ret) == 0 {
@ -1478,10 +1478,10 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
var r0 []params.ScaleSet var r0 []params.ScaleSet
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.ScaleSet, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.ScaleSet, error)); ok {
return rf(_a0, entity) return rf(_a0, entity)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.ScaleSet); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.ScaleSet); ok {
r0 = rf(_a0, entity) r0 = rf(_a0, entity)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
@ -1489,7 +1489,7 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
} }
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(_a0, entity) r1 = rf(_a0, entity)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1529,23 +1529,23 @@ func (_m *Store) ListGithubCredentials(ctx context.Context) ([]params.GithubCred
} }
// ListGithubEndpoints provides a mock function with given fields: ctx // ListGithubEndpoints provides a mock function with given fields: ctx
func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) { func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
ret := _m.Called(ctx) ret := _m.Called(ctx)
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for ListGithubEndpoints") panic("no return value specified for ListGithubEndpoints")
} }
var r0 []params.GithubEndpoint var r0 []params.ForgeEndpoint
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]params.GithubEndpoint, error)); ok { if rf, ok := ret.Get(0).(func(context.Context) ([]params.ForgeEndpoint, error)); ok {
return rf(ctx) return rf(ctx)
} }
if rf, ok := ret.Get(0).(func(context.Context) []params.GithubEndpoint); ok { if rf, ok := ret.Get(0).(func(context.Context) []params.ForgeEndpoint); ok {
r0 = rf(ctx) r0 = rf(ctx)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).([]params.GithubEndpoint) r0 = ret.Get(0).([]params.ForgeEndpoint)
} }
} }
@ -1865,7 +1865,7 @@ func (_m *Store) UpdateEnterprise(ctx context.Context, enterpriseID string, para
} }
// UpdateEntityPool provides a mock function with given fields: ctx, entity, poolID, param // UpdateEntityPool provides a mock function with given fields: ctx, entity, poolID, param
func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) { func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
ret := _m.Called(ctx, entity, poolID, param) ret := _m.Called(ctx, entity, poolID, param)
if len(ret) == 0 { if len(ret) == 0 {
@ -1874,16 +1874,16 @@ func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool var r0 params.Pool
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) (params.Pool, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) (params.Pool, error)); ok {
return rf(ctx, entity, poolID, param) return rf(ctx, entity, poolID, param)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) params.Pool); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) params.Pool); ok {
r0 = rf(ctx, entity, poolID, param) r0 = rf(ctx, entity, poolID, param)
} else { } else {
r0 = ret.Get(0).(params.Pool) r0 = ret.Get(0).(params.Pool)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) error); ok {
r1 = rf(ctx, entity, poolID, param) r1 = rf(ctx, entity, poolID, param)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1893,7 +1893,7 @@ func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntit
} }
// UpdateEntityScaleSet provides a mock function with given fields: _a0, entity, scaleSetID, param, callback // UpdateEntityScaleSet provides a mock function with given fields: _a0, entity, scaleSetID, param, callback
func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error) { func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error) {
ret := _m.Called(_a0, entity, scaleSetID, param, callback) ret := _m.Called(_a0, entity, scaleSetID, param, callback)
if len(ret) == 0 { if len(ret) == 0 {
@ -1902,16 +1902,16 @@ func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet var r0 params.ScaleSet
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error)); ok {
return rf(_a0, entity, scaleSetID, param, callback) return rf(_a0, entity, scaleSetID, param, callback)
} }
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) params.ScaleSet); ok { if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) params.ScaleSet); ok {
r0 = rf(_a0, entity, scaleSetID, param, callback) r0 = rf(_a0, entity, scaleSetID, param, callback)
} else { } else {
r0 = ret.Get(0).(params.ScaleSet) r0 = ret.Get(0).(params.ScaleSet)
} }
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) error); ok { if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) error); ok {
r1 = rf(_a0, entity, scaleSetID, param, callback) r1 = rf(_a0, entity, scaleSetID, param, callback)
} else { } else {
r1 = ret.Error(1) r1 = ret.Error(1)
@ -1949,22 +1949,22 @@ func (_m *Store) UpdateGithubCredentials(ctx context.Context, id uint, param par
} }
// UpdateGithubEndpoint provides a mock function with given fields: ctx, name, param // UpdateGithubEndpoint provides a mock function with given fields: ctx, name, param
func (_m *Store) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error) { func (_m *Store) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, name, param) ret := _m.Called(ctx, name, param)
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for UpdateGithubEndpoint") panic("no return value specified for UpdateGithubEndpoint")
} }
var r0 params.GithubEndpoint var r0 params.ForgeEndpoint
var r1 error var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) (params.GithubEndpoint, error)); ok { if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(ctx, name, param) return rf(ctx, name, param)
} }
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) params.GithubEndpoint); ok { if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(ctx, name, param) r0 = rf(ctx, name, param)
} else { } else {
r0 = ret.Get(0).(params.GithubEndpoint) r0 = ret.Get(0).(params.ForgeEndpoint)
} }
if rf, ok := ret.Get(1).(func(context.Context, string, params.UpdateGithubEndpointParams) error); ok { if rf, ok := ret.Get(1).(func(context.Context, string, params.UpdateGithubEndpointParams) error); ok {

View file

@ -21,10 +21,10 @@ import (
) )
type GithubEndpointStore interface { type GithubEndpointStore interface {
CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error)
GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error) GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error)
ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error)
UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error)
DeleteGithubEndpoint(ctx context.Context, name string) error DeleteGithubEndpoint(ctx context.Context, name string) error
} }
@ -76,7 +76,7 @@ type PoolStore interface {
PoolInstanceCount(ctx context.Context, poolID string) (int64, error) PoolInstanceCount(ctx context.Context, poolID string) (int64, error)
GetPoolInstanceByName(ctx context.Context, poolID string, instanceName string) (params.Instance, error) GetPoolInstanceByName(ctx context.Context, poolID string, instanceName string) (params.Instance, error)
FindPoolsMatchingAllTags(ctx context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error) FindPoolsMatchingAllTags(ctx context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error)
} }
type UserStore interface { type UserStore interface {
@ -107,7 +107,7 @@ type InstanceStore interface {
type JobsStore interface { type JobsStore interface {
CreateOrUpdateJob(ctx context.Context, job params.Job) (params.Job, error) CreateOrUpdateJob(ctx context.Context, job params.Job) (params.Job, error)
ListEntityJobsByStatus(ctx context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error) ListEntityJobsByStatus(ctx context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error)
ListJobsByStatus(ctx context.Context, status params.JobStatus) ([]params.Job, error) ListJobsByStatus(ctx context.Context, status params.JobStatus) ([]params.Job, error)
ListAllJobs(ctx context.Context) ([]params.Job, error) ListAllJobs(ctx context.Context) ([]params.Job, error)
@ -121,13 +121,13 @@ type JobsStore interface {
} }
type EntityPoolStore interface { type EntityPoolStore interface {
CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error) CreateEntityPool(ctx context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (params.Pool, error)
GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) GetEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error)
DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error DeleteEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) error
UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) UpdateEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error)
ListEntityPools(ctx context.Context, entity params.GithubEntity) ([]params.Pool, error) ListEntityPools(ctx context.Context, entity params.ForgeEntity) ([]params.Pool, error)
ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error) ListEntityInstances(ctx context.Context, entity params.ForgeEntity) ([]params.Instance, error)
} }
type ControllerStore interface { type ControllerStore interface {
@ -138,9 +138,9 @@ type ControllerStore interface {
type ScaleSetsStore interface { type ScaleSetsStore interface {
ListAllScaleSets(ctx context.Context) ([]params.ScaleSet, error) ListAllScaleSets(ctx context.Context) ([]params.ScaleSet, error)
CreateEntityScaleSet(_ context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error) CreateEntityScaleSet(_ context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error)
ListEntityScaleSets(_ context.Context, entity params.GithubEntity) ([]params.ScaleSet, error) ListEntityScaleSets(_ context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error)
UpdateEntityScaleSet(_ context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error) UpdateEntityScaleSet(_ context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error)
GetScaleSetByID(ctx context.Context, scaleSet uint) (params.ScaleSet, error) GetScaleSetByID(ctx context.Context, scaleSet uint) (params.ScaleSet, error)
DeleteScaleSetByID(ctx context.Context, scaleSetID uint) (err error) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) (err error)
SetScaleSetLastMessageID(ctx context.Context, scaleSetID uint, lastMessageID int64) error SetScaleSetLastMessageID(ctx context.Context, scaleSetID uint, lastMessageID int64) error
@ -170,6 +170,6 @@ type Store interface {
ControllerInfo() (params.ControllerInfo, error) ControllerInfo() (params.ControllerInfo, error)
InitController() (params.ControllerInfo, error) InitController() (params.ControllerInfo, error)
GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) GetForgeEntity(_ context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error)
AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error
} }

View file

@ -55,7 +55,7 @@ type EnterpriseTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *EnterpriseTestSuite) equalInstancesByName(expected, actual []params.Instance) { func (s *EnterpriseTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -490,9 +490,9 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolMissingTags() {
} }
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestCreateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams) _, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -637,9 +637,9 @@ func (s *EnterpriseTestSuite) TestListEnterprisePools() {
} }
func (s *EnterpriseTestSuite) TestListEnterprisePoolsInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestListEnterprisePoolsInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
_, err := s.Store.ListEntityPools(s.adminCtx, entity) _, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -662,9 +662,9 @@ func (s *EnterpriseTestSuite) TestGetEnterprisePool() {
} }
func (s *EnterpriseTestSuite) TestGetEnterprisePoolInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestGetEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id") _, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -688,9 +688,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
} }
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id") err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +743,9 @@ func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
} }
func (s *EnterpriseTestSuite) TestListEnterpriseInstancesInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestListEnterpriseInstancesInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
_, err := s.Store.ListEntityInstances(s.adminCtx, entity) _, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -771,9 +771,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
} }
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolInvalidEnterpriseID() { func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-enterprise-id", ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams) _, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams)

View file

@ -88,8 +88,8 @@ func (s *sqlDatabase) sqlToCommonGithubCredentials(creds GithubCredentials) (par
return commonCreds, nil return commonCreds, nil
} }
func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.GithubEndpoint, error) { func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.ForgeEndpoint, error) {
return params.GithubEndpoint{ return params.ForgeEndpoint{
Name: ep.Name, Name: ep.Name,
Description: ep.Description, Description: ep.Description,
APIBaseURL: ep.APIBaseURL, APIBaseURL: ep.APIBaseURL,
@ -115,7 +115,7 @@ func getUIDFromContext(ctx context.Context) (uuid.UUID, error) {
return asUUID, nil return asUUID, nil
} }
func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.CreateGithubEndpointParams) (ghEndpoint params.GithubEndpoint, err error) { func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.CreateGithubEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
defer func() { defer func() {
if err == nil { if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.CreateOperation, ghEndpoint) s.sendNotify(common.GithubEndpointEntityType, common.CreateOperation, ghEndpoint)
@ -141,23 +141,23 @@ func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.Creat
return nil return nil
}) })
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "creating github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "creating github endpoint")
} }
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint) ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
} }
return ghEndpoint, nil return ghEndpoint, nil
} }
func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEndpoint, error) { func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.ForgeEndpoint, error) {
var endpoints []GithubEndpoint var endpoints []GithubEndpoint
err := s.conn.Find(&endpoints).Error err := s.conn.Find(&endpoints).Error
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching github endpoints") return nil, errors.Wrap(err, "fetching github endpoints")
} }
var ret []params.GithubEndpoint var ret []params.ForgeEndpoint
for _, ep := range endpoints { for _, ep := range endpoints {
commonEp, err := s.sqlToCommonGithubEndpoint(ep) commonEp, err := s.sqlToCommonGithubEndpoint(ep)
if err != nil { if err != nil {
@ -168,9 +168,9 @@ func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEnd
return ret, nil return ret, nil
} }
func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.GithubEndpoint, err error) { func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
if name == defaultGithubEndpoint { if name == defaultGithubEndpoint {
return params.GithubEndpoint{}, errors.Wrap(runnerErrors.ErrBadRequest, "cannot update default github endpoint") return params.ForgeEndpoint{}, errors.Wrap(runnerErrors.ErrBadRequest, "cannot update default github endpoint")
} }
defer func() { defer func() {
@ -213,24 +213,24 @@ func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param
return nil return nil
}) })
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "updating github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "updating github endpoint")
} }
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint) ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
} }
return ghEndpoint, nil return ghEndpoint, nil
} }
func (s *sqlDatabase) GetGithubEndpoint(_ context.Context, name string) (params.GithubEndpoint, error) { func (s *sqlDatabase) GetGithubEndpoint(_ context.Context, name string) (params.ForgeEndpoint, error) {
var endpoint GithubEndpoint var endpoint GithubEndpoint
err := s.conn.Where("name = ?", name).First(&endpoint).Error err := s.conn.Where("name = ?", name).First(&endpoint).Error
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return params.GithubEndpoint{}, errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found") return params.ForgeEndpoint{}, errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found")
} }
return params.GithubEndpoint{}, errors.Wrap(err, "fetching github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "fetching github endpoint")
} }
return s.sqlToCommonGithubEndpoint(endpoint) return s.sqlToCommonGithubEndpoint(endpoint)
@ -243,7 +243,7 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
defer func() { defer func() {
if err == nil { if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.GithubEndpoint{Name: name}) s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.ForgeEndpoint{Name: name})
} }
}() }()
err = s.conn.Transaction(func(tx *gorm.DB) error { err = s.conn.Transaction(func(tx *gorm.DB) error {
@ -329,9 +329,9 @@ func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.
var data []byte var data []byte
var err error var err error
switch param.AuthType { switch param.AuthType {
case params.GithubAuthTypePAT: case params.ForgeAuthTypePAT:
data, err = s.marshalAndSeal(param.PAT) data, err = s.marshalAndSeal(param.PAT)
case params.GithubAuthTypeApp: case params.ForgeAuthTypeApp:
data, err = s.marshalAndSeal(param.App) data, err = s.marshalAndSeal(param.App)
default: default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid auth type") return errors.Wrap(runnerErrors.ErrBadRequest, "invalid auth type")
@ -495,7 +495,7 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
var data []byte var data []byte
var err error var err error
switch creds.AuthType { switch creds.AuthType {
case params.GithubAuthTypePAT: case params.ForgeAuthTypePAT:
if param.PAT != nil { if param.PAT != nil {
data, err = s.marshalAndSeal(param.PAT) data, err = s.marshalAndSeal(param.PAT)
} }
@ -503,7 +503,7 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
if param.App != nil { if param.App != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot update app credentials for PAT") return errors.Wrap(runnerErrors.ErrBadRequest, "cannot update app credentials for PAT")
} }
case params.GithubAuthTypeApp: case params.ForgeAuthTypeApp:
if param.App != nil { if param.App != nil {
data, err = s.marshalAndSeal(param.App) data, err = s.marshalAndSeal(param.App)
} }

View file

@ -266,7 +266,7 @@ func (s *GithubTestSuite) TestCreateCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -290,7 +290,7 @@ func (s *GithubTestSuite) TestCreateCredentialsFailsOnDuplicateCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -320,7 +320,7 @@ func (s *GithubTestSuite) TestNormalUsersCanOnlySeeTheirOwnCredentialsAdminCanSe
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -376,7 +376,7 @@ func (s *GithubTestSuite) TestGetGithubCredentialsByNameReturnsOnlyCurrentUserCr
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -421,7 +421,7 @@ func (s *GithubTestSuite) TestGetGithubCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -451,7 +451,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -478,7 +478,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentialsByNonAdminUser() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test-creds4", OAuth2Token: "test-creds4",
}, },
@ -523,7 +523,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -581,7 +581,7 @@ func (s *GithubTestSuite) TestUpdateCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -616,7 +616,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test", OAuth2Token: "test",
}, },
@ -643,7 +643,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: "test-credsApp", Name: "test-credsApp",
Description: "test credsApp", Description: "test credsApp",
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypeApp, AuthType: params.ForgeAuthTypeApp,
App: params.GithubApp{ App: params.GithubApp{
AppID: 1, AppID: 1,
InstallationID: 2, InstallationID: 2,
@ -688,7 +688,7 @@ func (s *GithubTestSuite) TestUpdateCredentialsFailsIfCredentialsAreOwnedByNonAd
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test-creds5", OAuth2Token: "test-creds5",
}, },
@ -717,7 +717,7 @@ func (s *GithubTestSuite) TestAdminUserCanUpdateAnyGithubCredentials() {
Name: testCredsName, Name: testCredsName,
Description: testCredsDescription, Description: testCredsDescription,
Endpoint: defaultGithubEndpoint, Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test-creds5", OAuth2Token: "test-creds5",
}, },
@ -836,10 +836,10 @@ func TestCredentialsAndEndpointMigration(t *testing.T) {
t.Fatalf("expected ghes-test to be associated with example.com endpoint, got %s", creds[1].Endpoint.Name) t.Fatalf("expected ghes-test to be associated with example.com endpoint, got %s", creds[1].Endpoint.Name)
} }
if creds[0].AuthType != params.GithubAuthTypePAT { if creds[0].AuthType != params.ForgeAuthTypePAT {
t.Fatalf("expected test-creds to have PAT auth type, got %s", creds[0].AuthType) t.Fatalf("expected test-creds to have PAT auth type, got %s", creds[0].AuthType)
} }
if creds[1].AuthType != params.GithubAuthTypeApp { if creds[1].AuthType != params.ForgeAuthTypeApp {
t.Fatalf("expected ghes-test to have App auth type, got %s", creds[1].AuthType) t.Fatalf("expected ghes-test to have App auth type, got %s", creds[1].AuthType)
} }
if len(creds[0].CredentialsPayload) == 0 { if len(creds[0].CredentialsPayload) == 0 {

View file

@ -306,7 +306,7 @@ func (s *sqlDatabase) ListJobsByStatus(_ context.Context, status params.JobStatu
} }
// ListEntityJobsByStatus lists all jobs for a given entity type and id. // ListEntityJobsByStatus lists all jobs for a given entity type and id.
func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error) { func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
u, err := uuid.Parse(entityID) u, err := uuid.Parse(entityID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -316,11 +316,11 @@ func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType param
query := s.conn.Model(&WorkflowJob{}).Preload("Instance").Where("status = ?", status) query := s.conn.Model(&WorkflowJob{}).Preload("Instance").Where("status = ?", status)
switch entityType { switch entityType {
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
query = query.Where("org_id = ?", u) query = query.Where("org_id = ?", u)
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
query = query.Where("repo_id = ?", u) query = query.Where("repo_id = ?", u)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
query = query.Where("enterprise_id = ?", u) query = query.Where("enterprise_id = ?", u)
} }

View file

@ -397,9 +397,9 @@ type GithubCredentials struct {
UserID *uuid.UUID `gorm:"index:idx_github_credentials,unique"` UserID *uuid.UUID `gorm:"index:idx_github_credentials,unique"`
User User `gorm:"foreignKey:UserID"` User User `gorm:"foreignKey:UserID"`
Description string `gorm:"type:text"` Description string `gorm:"type:text"`
AuthType params.GithubAuthType `gorm:"index"` AuthType params.ForgeAuthType `gorm:"index"`
Payload []byte `gorm:"type:longblob"` Payload []byte `gorm:"type:longblob"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"` Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
EndpointName *string `gorm:"index"` EndpointName *string `gorm:"index"`

View file

@ -55,7 +55,7 @@ type OrgTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *OrgTestSuite) equalInstancesByName(expected, actual []params.Instance) { func (s *OrgTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -492,9 +492,9 @@ func (s *OrgTestSuite) TestCreateOrganizationPoolMissingTags() {
} }
func (s *OrgTestSuite) TestCreateOrganizationPoolInvalidOrgID() { func (s *OrgTestSuite) TestCreateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams) _, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -640,9 +640,9 @@ func (s *OrgTestSuite) TestListOrgPools() {
} }
func (s *OrgTestSuite) TestListOrgPoolsInvalidOrgID() { func (s *OrgTestSuite) TestListOrgPoolsInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
_, err := s.Store.ListEntityPools(s.adminCtx, entity) _, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -665,9 +665,9 @@ func (s *OrgTestSuite) TestGetOrganizationPool() {
} }
func (s *OrgTestSuite) TestGetOrganizationPoolInvalidOrgID() { func (s *OrgTestSuite) TestGetOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id") _, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -691,9 +691,9 @@ func (s *OrgTestSuite) TestDeleteOrganizationPool() {
} }
func (s *OrgTestSuite) TestDeleteOrganizationPoolInvalidOrgID() { func (s *OrgTestSuite) TestDeleteOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id") err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -748,9 +748,9 @@ func (s *OrgTestSuite) TestListOrgInstances() {
} }
func (s *OrgTestSuite) TestListOrgInstancesInvalidOrgID() { func (s *OrgTestSuite) TestListOrgInstancesInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
_, err := s.Store.ListEntityInstances(s.adminCtx, entity) _, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -776,9 +776,9 @@ func (s *OrgTestSuite) TestUpdateOrganizationPool() {
} }
func (s *OrgTestSuite) TestUpdateOrganizationPoolInvalidOrgID() { func (s *OrgTestSuite) TestUpdateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-org-id", ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams) _, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams)

View file

@ -86,7 +86,7 @@ func (s *sqlDatabase) DeletePoolByID(_ context.Context, poolID string) (err erro
return nil return nil
} }
func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityType, entityID, poolID string, preload ...string) (Pool, error) { func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.ForgeEntityType, entityID, poolID string, preload ...string) (Pool, error) {
if entityID == "" { if entityID == "" {
return Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id") return Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id")
} }
@ -99,13 +99,13 @@ func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityT
var fieldName string var fieldName string
var entityField string var entityField string
switch entityType { switch entityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
entityField = repositoryFieldName entityField = repositoryFieldName
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
entityField = organizationFieldName entityField = organizationFieldName
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
entityField = enterpriseFieldName entityField = enterpriseFieldName
default: default:
@ -135,7 +135,7 @@ func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityT
return pool, nil return pool, nil
} }
func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntityType, entityID string, preload ...string) ([]Pool, error) { func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, preload ...string) ([]Pool, error) {
if _, err := uuid.Parse(entityID); err != nil { if _, err := uuid.Parse(entityID); err != nil {
return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id") return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
} }
@ -147,13 +147,13 @@ func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntit
var preloadEntity string var preloadEntity string
var fieldName string var fieldName string
switch entityType { switch entityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
preloadEntity = "Repository" preloadEntity = "Repository"
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
preloadEntity = "Organization" preloadEntity = "Organization"
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
preloadEntity = "Enterprise" preloadEntity = "Enterprise"
default: default:
@ -184,7 +184,7 @@ func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntit
return pools, nil return pools, nil
} }
func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType, tags []string) ([]params.Pool, error) { func (s *sqlDatabase) findPoolByTags(id string, poolType params.ForgeEntityType, tags []string) ([]params.Pool, error) {
if len(tags) == 0 { if len(tags) == 0 {
return nil, runnerErrors.NewBadRequestError("missing tags") return nil, runnerErrors.NewBadRequestError("missing tags")
} }
@ -195,11 +195,11 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
var fieldName string var fieldName string
switch poolType { switch poolType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
default: default:
return nil, fmt.Errorf("invalid poolType: %v", poolType) return nil, fmt.Errorf("invalid poolType: %v", poolType)
@ -238,7 +238,7 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
return ret, nil return ret, nil
} }
func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error) { func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error) {
if len(tags) == 0 { if len(tags) == 0 {
return nil, runnerErrors.NewBadRequestError("missing tags") return nil, runnerErrors.NewBadRequestError("missing tags")
} }
@ -254,7 +254,7 @@ func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType par
return pools, nil return pools, nil
} }
func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEntity, param params.CreatePoolParams) (pool params.Pool, err error) { func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (pool params.Pool, err error) {
if len(param.Tags) == 0 { if len(param.Tags) == 0 {
return params.Pool{}, runnerErrors.NewBadRequestError("no tags specified") return params.Pool{}, runnerErrors.NewBadRequestError("no tags specified")
} }
@ -289,11 +289,11 @@ func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEn
} }
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
newPool.RepoID = &entityID newPool.RepoID = &entityID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
newPool.OrgID = &entityID newPool.OrgID = &entityID
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
newPool.EnterpriseID = &entityID newPool.EnterpriseID = &entityID
} }
err = s.conn.Transaction(func(tx *gorm.DB) error { err = s.conn.Transaction(func(tx *gorm.DB) error {
@ -334,7 +334,7 @@ func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEn
return s.sqlToCommonPool(dbPool) return s.sqlToCommonPool(dbPool)
} }
func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) { func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error) {
pool, err := s.getEntityPool(s.conn, entity.EntityType, entity.ID, poolID, "Tags", "Instances") pool, err := s.getEntityPool(s.conn, entity.EntityType, entity.ID, poolID, "Tags", "Instances")
if err != nil { if err != nil {
return params.Pool{}, fmt.Errorf("fetching pool: %w", err) return params.Pool{}, fmt.Errorf("fetching pool: %w", err)
@ -342,7 +342,7 @@ func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.GithubEntit
return s.sqlToCommonPool(pool) return s.sqlToCommonPool(pool)
} }
func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEntity, poolID string) (err error) { func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.ForgeEntity, poolID string) (err error) {
entityID, err := uuid.Parse(entity.ID) entityID, err := uuid.Parse(entity.ID)
if err != nil { if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id") return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
@ -363,11 +363,11 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
} }
var fieldName string var fieldName string
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
default: default:
return fmt.Errorf("invalid entityType: %v", entity.EntityType) return fmt.Errorf("invalid entityType: %v", entity.EntityType)
@ -379,7 +379,7 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
return nil return nil
} }
func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (updatedPool params.Pool, err error) { func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (updatedPool params.Pool, err error) {
defer func() { defer func() {
if err == nil { if err == nil {
s.sendNotify(common.PoolEntityType, common.UpdateOperation, updatedPool) s.sendNotify(common.PoolEntityType, common.UpdateOperation, updatedPool)
@ -403,7 +403,7 @@ func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEn
return updatedPool, nil return updatedPool, nil
} }
func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEntity) ([]params.Pool, error) { func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.ForgeEntity) ([]params.Pool, error) {
pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Tags") pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Tags")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching pools") return nil, errors.Wrap(err, "fetching pools")
@ -420,7 +420,7 @@ func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEnt
return ret, nil return ret, nil
} }
func (s *sqlDatabase) ListEntityInstances(_ context.Context, entity params.GithubEntity) ([]params.Instance, error) { func (s *sqlDatabase) ListEntityInstances(_ context.Context, entity params.ForgeEntity) ([]params.Instance, error) {
pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Instances", "Instances.Job") pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Instances", "Instances.Job")
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching entity") return nil, errors.Wrap(err, "fetching entity")

View file

@ -60,7 +60,7 @@ type RepoTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *RepoTestSuite) equalReposByName(expected, actual []params.Repository) { func (s *RepoTestSuite) equalReposByName(expected, actual []params.Repository) {
@ -541,9 +541,9 @@ func (s *RepoTestSuite) TestCreateRepositoryPoolMissingTags() {
} }
func (s *RepoTestSuite) TestCreateRepositoryPoolInvalidRepoID() { func (s *RepoTestSuite) TestCreateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams) _, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -692,9 +692,9 @@ func (s *RepoTestSuite) TestListRepoPools() {
} }
func (s *RepoTestSuite) TestListRepoPoolsInvalidRepoID() { func (s *RepoTestSuite) TestListRepoPoolsInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
_, err := s.Store.ListEntityPools(s.adminCtx, entity) _, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -717,9 +717,9 @@ func (s *RepoTestSuite) TestGetRepositoryPool() {
} }
func (s *RepoTestSuite) TestGetRepositoryPoolInvalidRepoID() { func (s *RepoTestSuite) TestGetRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id") _, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +743,9 @@ func (s *RepoTestSuite) TestDeleteRepositoryPool() {
} }
func (s *RepoTestSuite) TestDeleteRepositoryPoolInvalidRepoID() { func (s *RepoTestSuite) TestDeleteRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id") err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -799,9 +799,9 @@ func (s *RepoTestSuite) TestListRepoInstances() {
} }
func (s *RepoTestSuite) TestListRepoInstancesInvalidRepoID() { func (s *RepoTestSuite) TestListRepoInstancesInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
_, err := s.Store.ListEntityInstances(s.adminCtx, entity) _, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -827,9 +827,9 @@ func (s *RepoTestSuite) TestUpdateRepositoryPool() {
} }
func (s *RepoTestSuite) TestUpdateRepositoryPoolInvalidRepoID() { func (s *RepoTestSuite) TestUpdateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: "dummy-repo-id", ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-repo-id", s.Fixtures.UpdatePoolParams) _, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-repo-id", s.Fixtures.UpdatePoolParams)

View file

@ -53,7 +53,7 @@ func (s *sqlDatabase) ListAllScaleSets(_ context.Context) ([]params.ScaleSet, er
return ret, nil return ret, nil
} }
func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error) { func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error) {
if err := param.Validate(); err != nil { if err := param.Validate(); err != nil {
return params.ScaleSet{}, fmt.Errorf("failed to validate create params: %w", err) return params.ScaleSet{}, fmt.Errorf("failed to validate create params: %w", err)
} }
@ -92,11 +92,11 @@ func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.Gith
} }
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
newScaleSet.RepoID = &entityID newScaleSet.RepoID = &entityID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
newScaleSet.OrgID = &entityID newScaleSet.OrgID = &entityID
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
newScaleSet.EnterpriseID = &entityID newScaleSet.EnterpriseID = &entityID
} }
err = s.conn.Transaction(func(tx *gorm.DB) error { err = s.conn.Transaction(func(tx *gorm.DB) error {
@ -123,7 +123,7 @@ func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.Gith
return s.sqlToCommonScaleSet(dbScaleSet) return s.sqlToCommonScaleSet(dbScaleSet)
} }
func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubEntityType, entityID string, preload ...string) ([]ScaleSet, error) { func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, preload ...string) ([]ScaleSet, error) {
if _, err := uuid.Parse(entityID); err != nil { if _, err := uuid.Parse(entityID); err != nil {
return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id") return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
} }
@ -135,13 +135,13 @@ func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubE
var preloadEntity string var preloadEntity string
var fieldName string var fieldName string
switch entityType { switch entityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
preloadEntity = repositoryFieldName preloadEntity = repositoryFieldName
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
preloadEntity = organizationFieldName preloadEntity = organizationFieldName
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
preloadEntity = enterpriseFieldName preloadEntity = enterpriseFieldName
default: default:
@ -173,7 +173,7 @@ func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubE
return scaleSets, nil return scaleSets, nil
} }
func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.GithubEntity) ([]params.ScaleSet, error) { func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error) {
scaleSets, err := s.listEntityScaleSets(s.conn, entity.EntityType, entity.ID) scaleSets, err := s.listEntityScaleSets(s.conn, entity.EntityType, entity.ID)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching scale sets") return nil, errors.Wrap(err, "fetching scale sets")
@ -190,7 +190,7 @@ func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.Githu
return ret, nil return ret, nil
} }
func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error) { func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error) {
defer func() { defer func() {
if err == nil { if err == nil {
s.sendNotify(common.ScaleSetEntityType, common.UpdateOperation, updatedScaleSet) s.sendNotify(common.ScaleSetEntityType, common.UpdateOperation, updatedScaleSet)
@ -225,7 +225,7 @@ func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.Gith
return updatedScaleSet, nil return updatedScaleSet, nil
} }
func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.GithubEntityType, entityID string, scaleSetID uint, preload ...string) (ScaleSet, error) { func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, scaleSetID uint, preload ...string) (ScaleSet, error) {
if entityID == "" { if entityID == "" {
return ScaleSet{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id") return ScaleSet{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id")
} }
@ -237,13 +237,13 @@ func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.GithubEnt
var fieldName string var fieldName string
var entityField string var entityField string
switch entityType { switch entityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName fieldName = entityTypeRepoName
entityField = "Repository" entityField = "Repository"
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName fieldName = entityTypeOrgName
entityField = "Organization" entityField = "Organization"
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName fieldName = entityTypeEnterpriseName
entityField = "Enterprise" entityField = "Enterprise"
default: default:

View file

@ -25,9 +25,9 @@ type ScaleSetsTestSuite struct {
repo params.Repository repo params.Repository
enterprise params.Enterprise enterprise params.Enterprise
orgEntity params.GithubEntity orgEntity params.ForgeEntity
repoEntity params.GithubEntity repoEntity params.ForgeEntity
enterpriseEntity params.GithubEntity enterpriseEntity params.ForgeEntity
} }
func (s *ScaleSetsTestSuite) SetupTest() { func (s *ScaleSetsTestSuite) SetupTest() {
@ -298,7 +298,7 @@ func (s *ScaleSetsTestSuite) TestScaleSetOperations() {
}) })
s.T().Run("update scaleset with invalid entity", func(_ *testing.T) { s.T().Run("update scaleset with invalid entity", func(_ *testing.T) {
_, err = s.Store.UpdateEntityScaleSet(s.adminCtx, params.GithubEntity{}, enterpriseScaleSet.ID, params.UpdateScaleSetParams{}, nil) _, err = s.Store.UpdateEntityScaleSet(s.adminCtx, params.ForgeEntity{}, enterpriseScaleSet.ID, params.UpdateScaleSetParams{}, nil)
s.Require().Error(err) s.Require().Error(err)
s.Require().Contains(err.Error(), "missing entity id") s.Require().Contains(err.Error(), "missing entity id")
}) })

View file

@ -299,7 +299,7 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
CACertBundle: certBundle, CACertBundle: certBundle,
} }
var endpoint params.GithubEndpoint var endpoint params.ForgeEndpoint
endpoint, err = s.GetGithubEndpoint(adminCtx, hostname) endpoint, err = s.GetGithubEndpoint(adminCtx, hostname)
if err != nil { if err != nil {
if !errors.Is(err, runnerErrors.ErrNotFound) { if !errors.Is(err, runnerErrors.ErrNotFound) {
@ -315,10 +315,10 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
Name: cred.Name, Name: cred.Name,
Description: cred.Description, Description: cred.Description,
Endpoint: endpoint.Name, Endpoint: endpoint.Name,
AuthType: params.GithubAuthType(cred.GetAuthType()), AuthType: params.ForgeAuthType(cred.GetAuthType()),
} }
switch credParams.AuthType { switch credParams.AuthType {
case params.GithubAuthTypeApp: case params.ForgeAuthTypeApp:
keyBytes, err := cred.App.PrivateKeyBytes() keyBytes, err := cred.App.PrivateKeyBytes()
if err != nil { if err != nil {
return errors.Wrap(err, "getting private key bytes") return errors.Wrap(err, "getting private key bytes")
@ -332,7 +332,7 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
if err := credParams.App.Validate(); err != nil { if err := credParams.App.Validate(); err != nil {
return errors.Wrap(err, "validating app credentials") return errors.Wrap(err, "validating app credentials")
} }
case params.GithubAuthTypePAT: case params.ForgeAuthTypePAT:
token := cred.PAT.OAuth2Token token := cred.PAT.OAuth2Token
if token == "" { if token == "" {
token = cred.OAuth2Token token = cred.OAuth2Token

View file

@ -546,18 +546,18 @@ func (s *sqlDatabase) getScaleSetByID(tx *gorm.DB, scaleSetID uint, preload ...s
return scaleSet, nil return scaleSet, nil
} }
func (s *sqlDatabase) hasGithubEntity(tx *gorm.DB, entityType params.GithubEntityType, entityID string) error { func (s *sqlDatabase) hasGithubEntity(tx *gorm.DB, entityType params.ForgeEntityType, entityID string) error {
u, err := uuid.Parse(entityID) u, err := uuid.Parse(entityID)
if err != nil { if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id") return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
} }
var q *gorm.DB var q *gorm.DB
switch entityType { switch entityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
q = tx.Model(&Repository{}).Where("id = ?", u) q = tx.Model(&Repository{}).Where("id = ?", u)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
q = tx.Model(&Organization{}).Where("id = ?", u) q = tx.Model(&Organization{}).Where("id = ?", u)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
q = tx.Model(&Enterprise{}).Where("id = ?", u) q = tx.Model(&Enterprise{}).Where("id = ?", u)
default: default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type") return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
@ -608,26 +608,26 @@ func (s *sqlDatabase) sendNotify(entityType dbCommon.DatabaseEntityType, op dbCo
return s.producer.Notify(message) return s.producer.Notify(message)
} }
func (s *sqlDatabase) GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) { func (s *sqlDatabase) GetForgeEntity(_ context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error) {
var ghEntity params.EntityGetter var ghEntity params.EntityGetter
var err error var err error
switch entityType { switch entityType {
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
ghEntity, err = s.GetEnterpriseByID(s.ctx, entityID) ghEntity, err = s.GetEnterpriseByID(s.ctx, entityID)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ghEntity, err = s.GetOrganizationByID(s.ctx, entityID) ghEntity, err = s.GetOrganizationByID(s.ctx, entityID)
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ghEntity, err = s.GetRepositoryByID(s.ctx, entityID) ghEntity, err = s.GetRepositoryByID(s.ctx, entityID)
default: default:
return params.GithubEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type") return params.ForgeEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
} }
if err != nil { if err != nil {
return params.GithubEntity{}, errors.Wrap(err, "failed to get ") return params.ForgeEntity{}, errors.Wrap(err, "failed to get ")
} }
entity, err := ghEntity.GetEntity() entity, err := ghEntity.GetEntity()
if err != nil { if err != nil {
return params.GithubEntity{}, errors.Wrap(err, "failed to get entity") return params.ForgeEntity{}, errors.Wrap(err, "failed to get entity")
} }
return entity, nil return entity, nil
} }
@ -747,17 +747,17 @@ func (s *sqlDatabase) addEnterpriseEvent(ctx context.Context, entID string, even
return nil return nil
} }
func (s *sqlDatabase) AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error { func (s *sqlDatabase) AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
if maxEvents == 0 { if maxEvents == 0 {
return errors.Wrap(runnerErrors.ErrBadRequest, "max events cannot be 0") return errors.Wrap(runnerErrors.ErrBadRequest, "max events cannot be 0")
} }
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
return s.addRepositoryEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents) return s.addRepositoryEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
return s.addOrgEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents) return s.addOrgEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
return s.addEnterpriseEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents) return s.addEnterpriseEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
default: default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type") return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")

View file

@ -63,7 +63,7 @@ func WithOperationTypeFilter(operationType dbCommon.OperationType) dbCommon.Payl
// WithEntityPoolFilter returns true if the change payload is a pool that belongs to the // WithEntityPoolFilter returns true if the change payload is a pool that belongs to the
// supplied Github entity. This is useful when an entity worker wants to watch for changes // supplied Github entity. This is useful when an entity worker wants to watch for changes
// in pools that belong to it. // in pools that belong to it.
func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc { func WithEntityPoolFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool { return func(payload dbCommon.ChangePayload) bool {
switch payload.EntityType { switch payload.EntityType {
case dbCommon.PoolEntityType: case dbCommon.PoolEntityType:
@ -72,11 +72,11 @@ func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFu
return false return false
} }
switch ghEntity.EntityType { switch ghEntity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
return pool.RepoID == ghEntity.ID return pool.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
return pool.OrgID == ghEntity.ID return pool.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
return pool.EnterpriseID == ghEntity.ID return pool.EnterpriseID == ghEntity.ID
default: default:
return false return false
@ -90,7 +90,7 @@ func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFu
// WithEntityPoolFilter returns true if the change payload is a pool that belongs to the // WithEntityPoolFilter returns true if the change payload is a pool that belongs to the
// supplied Github entity. This is useful when an entity worker wants to watch for changes // supplied Github entity. This is useful when an entity worker wants to watch for changes
// in pools that belong to it. // in pools that belong to it.
func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc { func WithEntityScaleSetFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool { return func(payload dbCommon.ChangePayload) bool {
switch payload.EntityType { switch payload.EntityType {
case dbCommon.ScaleSetEntityType: case dbCommon.ScaleSetEntityType:
@ -99,11 +99,11 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
return false return false
} }
switch ghEntity.EntityType { switch ghEntity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
return scaleSet.RepoID == ghEntity.ID return scaleSet.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
return scaleSet.OrgID == ghEntity.ID return scaleSet.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
return scaleSet.EnterpriseID == ghEntity.ID return scaleSet.EnterpriseID == ghEntity.ID
default: default:
return false return false
@ -116,26 +116,26 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
// WithEntityFilter returns a filter function that filters payloads by entity. // WithEntityFilter returns a filter function that filters payloads by entity.
// Change payloads that match the entity type and ID will return true. // Change payloads that match the entity type and ID will return true.
func WithEntityFilter(entity params.GithubEntity) dbCommon.PayloadFilterFunc { func WithEntityFilter(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool { return func(payload dbCommon.ChangePayload) bool {
if params.GithubEntityType(payload.EntityType) != entity.EntityType { if params.ForgeEntityType(payload.EntityType) != entity.EntityType {
return false return false
} }
var ent IDGetter var ent IDGetter
var ok bool var ok bool
switch payload.EntityType { switch payload.EntityType {
case dbCommon.RepositoryEntityType: case dbCommon.RepositoryEntityType:
if entity.EntityType != params.GithubEntityTypeRepository { if entity.EntityType != params.ForgeEntityTypeRepository {
return false return false
} }
ent, ok = payload.Payload.(params.Repository) ent, ok = payload.Payload.(params.Repository)
case dbCommon.OrganizationEntityType: case dbCommon.OrganizationEntityType:
if entity.EntityType != params.GithubEntityTypeOrganization { if entity.EntityType != params.ForgeEntityTypeOrganization {
return false return false
} }
ent, ok = payload.Payload.(params.Organization) ent, ok = payload.Payload.(params.Organization)
case dbCommon.EnterpriseEntityType: case dbCommon.EnterpriseEntityType:
if entity.EntityType != params.GithubEntityTypeEnterprise { if entity.EntityType != params.ForgeEntityTypeEnterprise {
return false return false
} }
ent, ok = payload.Payload.(params.Enterprise) ent, ok = payload.Payload.(params.Enterprise)
@ -149,7 +149,7 @@ func WithEntityFilter(entity params.GithubEntity) dbCommon.PayloadFilterFunc {
} }
} }
func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc { func WithEntityJobFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool { return func(payload dbCommon.ChangePayload) bool {
switch payload.EntityType { switch payload.EntityType {
case dbCommon.JobEntityType: case dbCommon.JobEntityType:
@ -159,15 +159,15 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
} }
switch ghEntity.EntityType { switch ghEntity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
if job.RepoID != nil && job.RepoID.String() != ghEntity.ID { if job.RepoID != nil && job.RepoID.String() != ghEntity.ID {
return false return false
} }
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
if job.OrgID != nil && job.OrgID.String() != ghEntity.ID { if job.OrgID != nil && job.OrgID.String() != ghEntity.ID {
return false return false
} }
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
if job.EnterpriseID != nil && job.EnterpriseID.String() != ghEntity.ID { if job.EnterpriseID != nil && job.EnterpriseID.String() != ghEntity.ID {
return false return false
} }
@ -183,16 +183,20 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
} }
// WithGithubCredentialsFilter returns a filter function that filters payloads by Github credentials. // WithGithubCredentialsFilter returns a filter function that filters payloads by Github credentials.
func WithGithubCredentialsFilter(creds params.GithubCredentials) dbCommon.PayloadFilterFunc { func WithForgeCredentialsFilter(creds params.ForgeCredentials) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool { return func(payload dbCommon.ChangePayload) bool {
if payload.EntityType != dbCommon.GithubCredentialsEntityType { var idGetter params.IDGetter
var ok bool
switch payload.EntityType {
case dbCommon.GithubCredentialsEntityType:
idGetter, ok = payload.Payload.(params.GithubCredentials)
default:
return false return false
} }
credsPayload, ok := payload.Payload.(params.GithubCredentials)
if !ok { if !ok {
return false return false
} }
return credsPayload.ID == creds.ID return idGetter.GetID() == creds.GetID()
} }
} }

View file

@ -848,7 +848,7 @@ func (s *WatcherStoreTestSuite) TestGithubCredentialsWatcher() {
Name: "test-creds", Name: "test-creds",
Description: "test credentials", Description: "test credentials",
Endpoint: "github.com", Endpoint: "github.com",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "bogus", OAuth2Token: "bogus",
}, },
@ -971,7 +971,7 @@ func (s *WatcherStoreTestSuite) TestGithubEndpointWatcher() {
EntityType: common.GithubEndpointEntityType, EntityType: common.GithubEndpointEntityType,
Operation: common.DeleteOperation, Operation: common.DeleteOperation,
// We only get the name of the deleted entity // We only get the name of the deleted entity
Payload: params.GithubEndpoint{Name: ghEp.Name}, Payload: params.ForgeEndpoint{Name: ghEp.Name},
}, event) }, event)
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received") s.T().Fatal("expected payload not received")

View file

@ -85,7 +85,7 @@ func CreateGARMTestUser(ctx context.Context, username string, db common.Store, s
return user return user
} }
func CreateDefaultGithubEndpoint(ctx context.Context, db common.Store, s *testing.T) params.GithubEndpoint { func CreateDefaultGithubEndpoint(ctx context.Context, db common.Store, s *testing.T) params.ForgeEndpoint {
endpointParams := params.CreateGithubEndpointParams{ endpointParams := params.CreateGithubEndpointParams{
Name: "github.com", Name: "github.com",
Description: "github endpoint", Description: "github endpoint",
@ -110,11 +110,11 @@ func CreateDefaultGithubEndpoint(ctx context.Context, db common.Store, s *testin
return ep return ep
} }
func CreateTestGithubCredentials(ctx context.Context, credsName string, db common.Store, s *testing.T, endpoint params.GithubEndpoint) params.GithubCredentials { func CreateTestGithubCredentials(ctx context.Context, credsName string, db common.Store, s *testing.T, endpoint params.ForgeEndpoint) params.GithubCredentials {
newCredsParams := params.CreateGithubCredentialsParams{ newCredsParams := params.CreateGithubCredentialsParams{
Name: credsName, Name: credsName,
Description: "Test creds", Description: "Test creds",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
Endpoint: endpoint.Name, Endpoint: endpoint.Name,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "test-token", OAuth2Token: "test-token",

View file

@ -5,7 +5,7 @@ import "time"
// EntityGetter is implemented by all github entities (repositories, organizations and enterprises). // EntityGetter is implemented by all github entities (repositories, organizations and enterprises).
// It defines the GetEntity() function which returns a github entity. // It defines the GetEntity() function which returns a github entity.
type EntityGetter interface { type EntityGetter interface {
GetEntity() (GithubEntity, error) GetEntity() (ForgeEntity, error)
} }
type IDGetter interface { type IDGetter interface {
@ -15,3 +15,7 @@ type IDGetter interface {
type CreationDateGetter interface { type CreationDateGetter interface {
GetCreatedAt() time.Time GetCreatedAt() time.Time
} }
type ForgeCredentialsGetter interface {
GetForgeCredentials() ForgeCredentials
}

View file

@ -36,14 +36,14 @@ import (
) )
type ( type (
GithubEntityType string ForgeEntityType string
EventType string EventType string
EventLevel string EventLevel string
ProviderType string ProviderType string
JobStatus string JobStatus string
RunnerStatus string RunnerStatus string
WebhookEndpointType string WebhookEndpointType string
GithubAuthType string ForgeAuthType string
EndpointType string EndpointType string
PoolBalancerType string PoolBalancerType string
ScaleSetState string ScaleSetState string
@ -106,9 +106,9 @@ const (
) )
const ( const (
GithubEntityTypeRepository GithubEntityType = "repository" ForgeEntityTypeRepository ForgeEntityType = "repository"
GithubEntityTypeOrganization GithubEntityType = "organization" ForgeEntityTypeOrganization ForgeEntityType = "organization"
GithubEntityTypeEnterprise GithubEntityType = "enterprise" ForgeEntityTypeEnterprise ForgeEntityType = "enterprise"
) )
const ( const (
@ -141,13 +141,13 @@ const (
) )
const ( const (
// GithubAuthTypePAT is the OAuth token based authentication // ForgeAuthTypePAT is the OAuth token based authentication
GithubAuthTypePAT GithubAuthType = "pat" ForgeAuthTypePAT ForgeAuthType = "pat"
// GithubAuthTypeApp is the GitHub App based authentication // ForgeAuthTypeApp is the GitHub App based authentication
GithubAuthTypeApp GithubAuthType = "app" ForgeAuthTypeApp ForgeAuthType = "app"
) )
func (e GithubEntityType) String() string { func (e ForgeEntityType) String() string {
return string(e) return string(e)
} }
@ -380,13 +380,13 @@ type Pool struct {
Priority uint `json:"priority,omitempty"` Priority uint `json:"priority,omitempty"`
} }
func (p Pool) BelongsTo(entity GithubEntity) bool { func (p Pool) BelongsTo(entity ForgeEntity) bool {
switch p.PoolType() { switch p.PoolType() {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return p.RepoID == entity.ID return p.RepoID == entity.ID
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return p.OrgID == entity.ID return p.OrgID == entity.ID
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return p.EnterpriseID == entity.ID return p.EnterpriseID == entity.ID
} }
return false return false
@ -411,25 +411,25 @@ func (p Pool) MaxRunnersAsInt() int {
return int(p.MaxRunners) return int(p.MaxRunners)
} }
func (p Pool) GetEntity() (GithubEntity, error) { func (p Pool) GetEntity() (ForgeEntity, error) {
switch p.PoolType() { switch p.PoolType() {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return GithubEntity{ return ForgeEntity{
ID: p.RepoID, ID: p.RepoID,
EntityType: GithubEntityTypeRepository, EntityType: ForgeEntityTypeRepository,
}, nil }, nil
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return GithubEntity{ return ForgeEntity{
ID: p.OrgID, ID: p.OrgID,
EntityType: GithubEntityTypeOrganization, EntityType: ForgeEntityTypeOrganization,
}, nil }, nil
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return GithubEntity{ return ForgeEntity{
ID: p.EnterpriseID, ID: p.EnterpriseID,
EntityType: GithubEntityTypeEnterprise, EntityType: ForgeEntityTypeEnterprise,
}, nil }, nil
} }
return GithubEntity{}, fmt.Errorf("pool has no associated entity") return ForgeEntity{}, fmt.Errorf("pool has no associated entity")
} }
func (p Pool) GetID() string { func (p Pool) GetID() string {
@ -443,14 +443,14 @@ func (p *Pool) RunnerTimeout() uint {
return p.RunnerBootstrapTimeout return p.RunnerBootstrapTimeout
} }
func (p *Pool) PoolType() GithubEntityType { func (p *Pool) PoolType() ForgeEntityType {
switch { switch {
case p.RepoID != "": case p.RepoID != "":
return GithubEntityTypeRepository return ForgeEntityTypeRepository
case p.OrgID != "": case p.OrgID != "":
return GithubEntityTypeOrganization return ForgeEntityTypeOrganization
case p.EnterpriseID != "": case p.EnterpriseID != "":
return GithubEntityTypeEnterprise return ForgeEntityTypeEnterprise
} }
return "" return ""
} }
@ -519,13 +519,13 @@ type ScaleSet struct {
LastMessageID int64 `json:"-"` LastMessageID int64 `json:"-"`
} }
func (p ScaleSet) BelongsTo(entity GithubEntity) bool { func (p ScaleSet) BelongsTo(entity ForgeEntity) bool {
switch p.ScaleSetType() { switch p.ScaleSetType() {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return p.RepoID == entity.ID return p.RepoID == entity.ID
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return p.OrgID == entity.ID return p.OrgID == entity.ID
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return p.EnterpriseID == entity.ID return p.EnterpriseID == entity.ID
} }
return false return false
@ -535,35 +535,35 @@ func (p ScaleSet) GetID() uint {
return p.ID return p.ID
} }
func (p ScaleSet) GetEntity() (GithubEntity, error) { func (p ScaleSet) GetEntity() (ForgeEntity, error) {
switch p.ScaleSetType() { switch p.ScaleSetType() {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return GithubEntity{ return ForgeEntity{
ID: p.RepoID, ID: p.RepoID,
EntityType: GithubEntityTypeRepository, EntityType: ForgeEntityTypeRepository,
}, nil }, nil
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return GithubEntity{ return ForgeEntity{
ID: p.OrgID, ID: p.OrgID,
EntityType: GithubEntityTypeOrganization, EntityType: ForgeEntityTypeOrganization,
}, nil }, nil
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return GithubEntity{ return ForgeEntity{
ID: p.EnterpriseID, ID: p.EnterpriseID,
EntityType: GithubEntityTypeEnterprise, EntityType: ForgeEntityTypeEnterprise,
}, nil }, nil
} }
return GithubEntity{}, fmt.Errorf("pool has no associated entity") return ForgeEntity{}, fmt.Errorf("pool has no associated entity")
} }
func (p *ScaleSet) ScaleSetType() GithubEntityType { func (p *ScaleSet) ScaleSetType() ForgeEntityType {
switch { switch {
case p.RepoID != "": case p.RepoID != "":
return GithubEntityTypeRepository return ForgeEntityTypeRepository
case p.OrgID != "": case p.OrgID != "":
return GithubEntityTypeOrganization return ForgeEntityTypeOrganization
case p.EnterpriseID != "": case p.EnterpriseID != "":
return GithubEntityTypeEnterprise return ForgeEntityTypeEnterprise
} }
return "" return ""
} }
@ -591,7 +591,7 @@ type Repository struct {
Credentials GithubCredentials `json:"credentials,omitempty"` Credentials GithubCredentials `json:"credentials,omitempty"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"` PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"` PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"`
Endpoint GithubEndpoint `json:"endpoint,omitempty"` Endpoint ForgeEndpoint `json:"endpoint,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
// Do not serialize sensitive info. // Do not serialize sensitive info.
@ -602,19 +602,23 @@ func (r Repository) CreationDateGetter() time.Time {
return r.CreatedAt return r.CreatedAt
} }
func (r Repository) GetEntity() (GithubEntity, error) { func (r Repository) GetEntity() (ForgeEntity, error) {
if r.ID == "" { if r.ID == "" {
return GithubEntity{}, fmt.Errorf("repository has no ID") return ForgeEntity{}, fmt.Errorf("repository has no ID")
} }
return GithubEntity{ return ForgeEntity{
ID: r.ID, ID: r.ID,
EntityType: GithubEntityTypeRepository, EntityType: ForgeEntityTypeRepository,
Owner: r.Owner, Owner: r.Owner,
Name: r.Name, Name: r.Name,
PoolBalancerType: r.PoolBalancerType, PoolBalancerType: r.PoolBalancerType,
Credentials: r.Credentials, Credentials: ForgeCredentials{
WebhookSecret: r.WebhookSecret, ForgeType: GithubEndpointType,
CreatedAt: r.CreatedAt, GithubCredentials: r.Credentials,
},
WebhookSecret: r.WebhookSecret,
CreatedAt: r.CreatedAt,
UpdatedAt: r.UpdatedAt,
}, nil }, nil
} }
@ -652,7 +656,7 @@ type Organization struct {
CredentialsID uint `json:"credentials_id,omitempty"` CredentialsID uint `json:"credentials_id,omitempty"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"` PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"` PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"`
Endpoint GithubEndpoint `json:"endpoint,omitempty"` Endpoint ForgeEndpoint `json:"endpoint,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
// Do not serialize sensitive info. // Do not serialize sensitive info.
@ -663,18 +667,22 @@ func (o Organization) GetCreatedAt() time.Time {
return o.CreatedAt return o.CreatedAt
} }
func (o Organization) GetEntity() (GithubEntity, error) { func (o Organization) GetEntity() (ForgeEntity, error) {
if o.ID == "" { if o.ID == "" {
return GithubEntity{}, fmt.Errorf("organization has no ID") return ForgeEntity{}, fmt.Errorf("organization has no ID")
} }
return GithubEntity{ return ForgeEntity{
ID: o.ID, ID: o.ID,
EntityType: GithubEntityTypeOrganization, EntityType: ForgeEntityTypeOrganization,
Owner: o.Name, Owner: o.Name,
WebhookSecret: o.WebhookSecret, WebhookSecret: o.WebhookSecret,
PoolBalancerType: o.PoolBalancerType, PoolBalancerType: o.PoolBalancerType,
Credentials: o.Credentials, Credentials: ForgeCredentials{
CreatedAt: o.CreatedAt, ForgeType: GithubEndpointType,
GithubCredentials: o.Credentials,
},
CreatedAt: o.CreatedAt,
UpdatedAt: o.UpdatedAt,
}, nil }, nil
} }
@ -708,7 +716,7 @@ type Enterprise struct {
CredentialsID uint `json:"credentials_id,omitempty"` CredentialsID uint `json:"credentials_id,omitempty"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"` PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"` PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"`
Endpoint GithubEndpoint `json:"endpoint,omitempty"` Endpoint ForgeEndpoint `json:"endpoint,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
// Do not serialize sensitive info. // Do not serialize sensitive info.
@ -719,18 +727,22 @@ func (e Enterprise) GetCreatedAt() time.Time {
return e.CreatedAt return e.CreatedAt
} }
func (e Enterprise) GetEntity() (GithubEntity, error) { func (e Enterprise) GetEntity() (ForgeEntity, error) {
if e.ID == "" { if e.ID == "" {
return GithubEntity{}, fmt.Errorf("enterprise has no ID") return ForgeEntity{}, fmt.Errorf("enterprise has no ID")
} }
return GithubEntity{ return ForgeEntity{
ID: e.ID, ID: e.ID,
EntityType: GithubEntityTypeEnterprise, EntityType: ForgeEntityTypeEnterprise,
Owner: e.Name, Owner: e.Name,
WebhookSecret: e.WebhookSecret, WebhookSecret: e.WebhookSecret,
PoolBalancerType: e.PoolBalancerType, PoolBalancerType: e.PoolBalancerType,
Credentials: e.Credentials, Credentials: ForgeCredentials{
CreatedAt: e.CreatedAt, ForgeType: GithubEndpointType,
GithubCredentials: e.Credentials,
},
CreatedAt: e.CreatedAt,
UpdatedAt: e.UpdatedAt,
}, nil }, nil
} }
@ -843,20 +855,113 @@ func (g GithubRateLimit) ResetAt() time.Time {
return time.Unix(g.Reset, 0) return time.Unix(g.Reset, 0)
} }
type ForgeCredentials struct {
ForgeType EndpointType `json:"type,omitempty"`
GithubCredentials GithubCredentials `json:"github,omitempty"`
}
func (f ForgeCredentials) CABundle() []byte {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.CABundle
case GiteaEndpointType:
return nil
default:
return nil
}
}
func (f ForgeCredentials) Endpoint() ForgeEndpoint {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.Endpoint
case GiteaEndpointType:
return ForgeEndpoint{}
default:
return ForgeEndpoint{}
}
}
func (f ForgeCredentials) APIBaseURL() string {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.APIBaseURL
case GiteaEndpointType:
return ""
default:
return ""
}
}
func (f ForgeCredentials) UploadBaseURL() string {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.UploadBaseURL
case GiteaEndpointType:
return ""
default:
return ""
}
}
func (f ForgeCredentials) BaseURL() string {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.BaseURL
case GiteaEndpointType:
return ""
default:
return ""
}
}
func (f ForgeCredentials) GetHTTPClient(ctx context.Context) (*http.Client, error) {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.GetHTTPClient(ctx)
case GiteaEndpointType:
return nil, fmt.Errorf("gitea credentials not supported")
default:
return nil, fmt.Errorf("unknown credentials type")
}
}
func (f ForgeCredentials) GetID() uint {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.ID
case GiteaEndpointType:
return 0
default:
return 0
}
}
func (f ForgeCredentials) RootCertificateBundle() (CertificateBundle, error) {
switch f.ForgeType {
case GithubEndpointType:
return f.GithubCredentials.RootCertificateBundle()
case GiteaEndpointType:
return CertificateBundle{}, fmt.Errorf("gitea credentials not supported")
default:
return CertificateBundle{}, fmt.Errorf("unknown credentials type")
}
}
type GithubCredentials struct { type GithubCredentials struct {
ID uint `json:"id,omitempty"` ID uint `json:"id,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
APIBaseURL string `json:"api_base_url,omitempty"` APIBaseURL string `json:"api_base_url,omitempty"`
UploadBaseURL string `json:"upload_base_url,omitempty"` UploadBaseURL string `json:"upload_base_url,omitempty"`
BaseURL string `json:"base_url,omitempty"` BaseURL string `json:"base_url,omitempty"`
CABundle []byte `json:"ca_bundle,omitempty"` CABundle []byte `json:"ca_bundle,omitempty"`
AuthType GithubAuthType `json:"auth-type,omitempty"` AuthType ForgeAuthType `json:"auth-type,omitempty"`
Repositories []Repository `json:"repositories,omitempty"` Repositories []Repository `json:"repositories,omitempty"`
Organizations []Organization `json:"organizations,omitempty"` Organizations []Organization `json:"organizations,omitempty"`
Enterprises []Enterprise `json:"enterprises,omitempty"` Enterprises []Enterprise `json:"enterprises,omitempty"`
Endpoint GithubEndpoint `json:"endpoint,omitempty"` Endpoint ForgeEndpoint `json:"endpoint,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
RateLimit GithubRateLimit `json:"rate_limit,omitempty"` RateLimit GithubRateLimit `json:"rate_limit,omitempty"`
@ -869,6 +974,13 @@ func (g GithubCredentials) GetID() uint {
return g.ID return g.ID
} }
func (g GithubCredentials) GetForgeCredentials() ForgeCredentials {
return ForgeCredentials{
ForgeType: GithubEndpointType,
GithubCredentials: g,
}
}
func (g GithubCredentials) GetHTTPClient(ctx context.Context) (*http.Client, error) { func (g GithubCredentials) GetHTTPClient(ctx context.Context) (*http.Client, error) {
var roots *x509.CertPool var roots *x509.CertPool
if g.CABundle != nil { if g.CABundle != nil {
@ -888,7 +1000,7 @@ func (g GithubCredentials) GetHTTPClient(ctx context.Context) (*http.Client, err
var tc *http.Client var tc *http.Client
switch g.AuthType { switch g.AuthType {
case GithubAuthTypeApp: case ForgeAuthTypeApp:
var app GithubApp var app GithubApp
if err := json.Unmarshal(g.CredentialsPayload, &app); err != nil { if err := json.Unmarshal(g.CredentialsPayload, &app); err != nil {
return nil, fmt.Errorf("failed to unmarshal github app credentials: %w", err) return nil, fmt.Errorf("failed to unmarshal github app credentials: %w", err)
@ -1063,64 +1175,65 @@ type UpdateSystemInfoParams struct {
AgentID *int64 `json:"agent_id,omitempty"` AgentID *int64 `json:"agent_id,omitempty"`
} }
type GithubEntity struct { type ForgeEntity struct {
Owner string `json:"owner,omitempty"` Owner string `json:"owner,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
EntityType GithubEntityType `json:"entity_type,omitempty"` EntityType ForgeEntityType `json:"entity_type,omitempty"`
Credentials GithubCredentials `json:"credentials,omitempty"` Credentials ForgeCredentials `json:"credentials,omitempty"`
PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"` PoolBalancerType PoolBalancerType `json:"pool_balancing_type,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
WebhookSecret string `json:"-"` WebhookSecret string `json:"-"`
} }
func (g GithubEntity) GetCreatedAt() time.Time { func (g ForgeEntity) GetCreatedAt() time.Time {
return g.CreatedAt return g.CreatedAt
} }
func (g GithubEntity) GithubURL() string { func (g ForgeEntity) ForgeURL() string {
switch g.EntityType { switch g.EntityType {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return fmt.Sprintf("%s/%s/%s", g.Credentials.BaseURL, g.Owner, g.Name) return fmt.Sprintf("%s/%s/%s", g.Credentials.BaseURL(), g.Owner, g.Name)
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return fmt.Sprintf("%s/%s", g.Credentials.BaseURL, g.Owner) return fmt.Sprintf("%s/%s", g.Credentials.BaseURL(), g.Owner)
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return fmt.Sprintf("%s/enterprises/%s", g.Credentials.BaseURL, g.Owner) return fmt.Sprintf("%s/enterprises/%s", g.Credentials.BaseURL(), g.Owner)
} }
return "" return ""
} }
func (g GithubEntity) GetPoolBalancerType() PoolBalancerType { func (g ForgeEntity) GetPoolBalancerType() PoolBalancerType {
if g.PoolBalancerType == "" { if g.PoolBalancerType == "" {
return PoolBalancerTypeRoundRobin return PoolBalancerTypeRoundRobin
} }
return g.PoolBalancerType return g.PoolBalancerType
} }
func (g GithubEntity) LabelScope() string { func (g ForgeEntity) LabelScope() string {
switch g.EntityType { switch g.EntityType {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return MetricsLabelRepositoryScope return MetricsLabelRepositoryScope
case GithubEntityTypeOrganization: case ForgeEntityTypeOrganization:
return MetricsLabelOrganizationScope return MetricsLabelOrganizationScope
case GithubEntityTypeEnterprise: case ForgeEntityTypeEnterprise:
return MetricsLabelEnterpriseScope return MetricsLabelEnterpriseScope
} }
return "" return ""
} }
func (g GithubEntity) String() string { func (g ForgeEntity) String() string {
switch g.EntityType { switch g.EntityType {
case GithubEntityTypeRepository: case ForgeEntityTypeRepository:
return fmt.Sprintf("%s/%s", g.Owner, g.Name) return fmt.Sprintf("%s/%s", g.Owner, g.Name)
case GithubEntityTypeOrganization, GithubEntityTypeEnterprise: case ForgeEntityTypeOrganization, ForgeEntityTypeEnterprise:
return g.Owner return g.Owner
} }
return "" return ""
} }
func (g GithubEntity) GetIDAsUUID() (uuid.UUID, error) { func (g ForgeEntity) GetIDAsUUID() (uuid.UUID, error) {
if g.ID == "" { if g.ID == "" {
return uuid.Nil, nil return uuid.Nil, nil
} }
@ -1132,9 +1245,9 @@ func (g GithubEntity) GetIDAsUUID() (uuid.UUID, error) {
} }
// used by swagger client generated code // used by swagger client generated code
type GithubEndpoints []GithubEndpoint type ForgeEndpoints []ForgeEndpoint
type GithubEndpoint struct { type ForgeEndpoint struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
APIBaseURL string `json:"api_base_url,omitempty"` APIBaseURL string `json:"api_base_url,omitempty"`
@ -1145,6 +1258,4 @@ type GithubEndpoint struct {
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
EndpointType EndpointType `json:"endpoint_type,omitempty"` EndpointType EndpointType `json:"endpoint_type,omitempty"`
Credentials []GithubCredentials `json:"credentials,omitempty"`
} }

View file

@ -448,12 +448,12 @@ func (g GithubApp) Validate() error {
} }
type CreateGithubCredentialsParams struct { type CreateGithubCredentialsParams struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Endpoint string `json:"endpoint,omitempty"` Endpoint string `json:"endpoint,omitempty"`
AuthType GithubAuthType `json:"auth_type,omitempty"` AuthType ForgeAuthType `json:"auth_type,omitempty"`
PAT GithubPAT `json:"pat,omitempty"` PAT GithubPAT `json:"pat,omitempty"`
App GithubApp `json:"app,omitempty"` App GithubApp `json:"app,omitempty"`
} }
func (c CreateGithubCredentialsParams) Validate() error { func (c CreateGithubCredentialsParams) Validate() error {
@ -466,18 +466,18 @@ func (c CreateGithubCredentialsParams) Validate() error {
} }
switch c.AuthType { switch c.AuthType {
case GithubAuthTypePAT, GithubAuthTypeApp: case ForgeAuthTypePAT, ForgeAuthTypeApp:
default: default:
return runnerErrors.NewBadRequestError("invalid auth_type") return runnerErrors.NewBadRequestError("invalid auth_type")
} }
if c.AuthType == GithubAuthTypePAT { if c.AuthType == ForgeAuthTypePAT {
if c.PAT.OAuth2Token == "" { if c.PAT.OAuth2Token == "" {
return runnerErrors.NewBadRequestError("missing oauth2_token") return runnerErrors.NewBadRequestError("missing oauth2_token")
} }
} }
if c.AuthType == GithubAuthTypeApp { if c.AuthType == ForgeAuthTypeApp {
if err := c.App.Validate(); err != nil { if err := c.App.Validate(); err != nil {
return errors.Wrap(err, "invalid app") return errors.Wrap(err, "invalid app")
} }

View file

@ -118,18 +118,18 @@ func (_m *GithubClient) DeleteEntityHook(ctx context.Context, id int64) (*github
} }
// GetEntity provides a mock function with no fields // GetEntity provides a mock function with no fields
func (_m *GithubClient) GetEntity() params.GithubEntity { func (_m *GithubClient) GetEntity() params.ForgeEntity {
ret := _m.Called() ret := _m.Called()
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for GetEntity") panic("no return value specified for GetEntity")
} }
var r0 params.GithubEntity var r0 params.ForgeEntity
if rf, ok := ret.Get(0).(func() params.GithubEntity); ok { if rf, ok := ret.Get(0).(func() params.ForgeEntity); ok {
r0 = rf() r0 = rf()
} else { } else {
r0 = ret.Get(0).(params.GithubEntity) r0 = ret.Get(0).(params.ForgeEntity)
} }
return r0 return r0

View file

@ -118,18 +118,18 @@ func (_m *GithubEntityOperations) DeleteEntityHook(ctx context.Context, id int64
} }
// GetEntity provides a mock function with no fields // GetEntity provides a mock function with no fields
func (_m *GithubEntityOperations) GetEntity() params.GithubEntity { func (_m *GithubEntityOperations) GetEntity() params.ForgeEntity {
ret := _m.Called() ret := _m.Called()
if len(ret) == 0 { if len(ret) == 0 {
panic("no return value specified for GetEntity") panic("no return value specified for GetEntity")
} }
var r0 params.GithubEntity var r0 params.ForgeEntity
if rf, ok := ret.Get(0).(func() params.GithubEntity); ok { if rf, ok := ret.Get(0).(func() params.ForgeEntity); ok {
r0 = rf() r0 = rf()
} else { } else {
r0 = ret.Get(0).(params.GithubEntity) r0 = ret.Get(0).(params.ForgeEntity)
} }
return r0 return r0

View file

@ -23,7 +23,7 @@ type GithubEntityOperations interface {
GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error) GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error)
// GetEntity returns the GitHub entity for which the github client was instanciated. // GetEntity returns the GitHub entity for which the github client was instanciated.
GetEntity() params.GithubEntity GetEntity() params.ForgeEntity
// GithubBaseURL returns the base URL for the github or GHES API. // GithubBaseURL returns the base URL for the github or GHES API.
GithubBaseURL() *url.URL GithubBaseURL() *url.URL
} }

View file

@ -206,9 +206,9 @@ func (r *Runner) CreateEnterprisePool(ctx context.Context, enterpriseID string,
param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams) pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -223,9 +223,9 @@ func (r *Runner) GetEnterprisePoolByID(ctx context.Context, enterpriseID, poolID
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil { if err != nil {
@ -239,9 +239,9 @@ func (r *Runner) DeleteEnterprisePool(ctx context.Context, enterpriseID, poolID
return runnerErrors.ErrUnauthorized return runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -270,9 +270,9 @@ func (r *Runner) ListEnterprisePools(ctx context.Context, enterpriseID string) (
return []params.Pool{}, runnerErrors.ErrUnauthorized return []params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pools, err := r.store.ListEntityPools(ctx, entity) pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil { if err != nil {
@ -286,9 +286,9 @@ func (r *Runner) UpdateEnterprisePool(ctx context.Context, enterpriseID, poolID
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil { if err != nil {
@ -320,9 +320,9 @@ func (r *Runner) ListEnterpriseInstances(ctx context.Context, enterpriseID strin
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized return nil, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: enterpriseID, ID: enterpriseID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
instances, err := r.store.ListEntityInstances(ctx, entity) instances, err := r.store.ListEntityInstances(ctx, entity)
if err != nil { if err != nil {

View file

@ -58,7 +58,7 @@ type EnterpriseTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint forgeEndpoint params.ForgeEndpoint
} }
func (s *EnterpriseTestSuite) SetupTest() { func (s *EnterpriseTestSuite) SetupTest() {
@ -70,9 +70,9 @@ func (s *EnterpriseTestSuite) SetupTest() {
} }
adminCtx := garmTesting.ImpersonateAdminContext(context.Background(), db, s.T()) adminCtx := garmTesting.ImpersonateAdminContext(context.Background(), db, s.T())
s.githubEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T()) s.forgeEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.githubEndpoint) s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.forgeEndpoint)
s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.githubEndpoint) s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.forgeEndpoint)
// create some organization objects in the database, for testing purposes // create some organization objects in the database, for testing purposes
enterprises := map[string]params.Enterprise{} enterprises := map[string]params.Enterprise{}
@ -270,9 +270,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterpriseErrUnauthorized() {
} }
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolDefinedFailed() { func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolDefinedFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -377,9 +377,9 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolFetchPoolParamsFailed() {
} }
func (s *EnterpriseTestSuite) TestGetEnterprisePoolByID() { func (s *EnterpriseTestSuite) TestGetEnterprisePoolByID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -399,9 +399,9 @@ func (s *EnterpriseTestSuite) TestGetEnterprisePoolByIDErrUnauthorized() {
} }
func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() { func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -423,9 +423,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolErrUnauthorized() {
} }
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolRunnersFailed() { func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolRunnersFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -442,9 +442,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolRunnersFailed() {
} }
func (s *EnterpriseTestSuite) TestListEnterprisePools() { func (s *EnterpriseTestSuite) TestListEnterprisePools() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
enterprisePools := []params.Pool{} enterprisePools := []params.Pool{}
for i := 1; i <= 2; i++ { for i := 1; i <= 2; i++ {
@ -469,9 +469,9 @@ func (s *EnterpriseTestSuite) TestListOrgPoolsErrUnauthorized() {
} }
func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() { func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) enterprisePool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -492,9 +492,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolErrUnauthorized() {
} }
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMinIdleGreaterThanMax() { func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -511,9 +511,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMinIdleGreaterThanMax() {
} }
func (s *EnterpriseTestSuite) TestListEnterpriseInstances() { func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, ID: s.Fixtures.StoreEnterprises["test-enterprise-1"].ID,
EntityType: params.GithubEntityTypeEnterprise, EntityType: params.ForgeEntityTypeEnterprise,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {

View file

@ -10,30 +10,30 @@ import (
"github.com/cloudbase/garm/params" "github.com/cloudbase/garm/params"
) )
func (r *Runner) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error) { func (r *Runner) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
} }
if err := param.Validate(); err != nil { if err := param.Validate(); err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params") return params.ForgeEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
} }
ep, err := r.store.CreateGithubEndpoint(ctx, param) ep, err := r.store.CreateGithubEndpoint(ctx, param)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to create github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "failed to create github endpoint")
} }
return ep, nil return ep, nil
} }
func (r *Runner) GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error) { func (r *Runner) GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
} }
endpoint, err := r.store.GetGithubEndpoint(ctx, name) endpoint, err := r.store.GetGithubEndpoint(ctx, name)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to get github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "failed to get github endpoint")
} }
return endpoint, nil return endpoint, nil
@ -52,23 +52,23 @@ func (r *Runner) DeleteGithubEndpoint(ctx context.Context, name string) error {
return nil return nil
} }
func (r *Runner) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error) { func (r *Runner) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
} }
if err := param.Validate(); err != nil { if err := param.Validate(); err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params") return params.ForgeEndpoint{}, errors.Wrap(err, "failed to validate github endpoint params")
} }
newEp, err := r.store.UpdateGithubEndpoint(ctx, name, param) newEp, err := r.store.UpdateGithubEndpoint(ctx, name, param)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "failed to update github endpoint") return params.ForgeEndpoint{}, errors.Wrap(err, "failed to update github endpoint")
} }
return newEp, nil return newEp, nil
} }
func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) { func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized return nil, runnerErrors.ErrUnauthorized
} }

View file

@ -56,7 +56,7 @@ func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
ctx, "failed to get instance params") ctx, "failed to get instance params")
return "", runnerErrors.ErrUnauthorized return "", runnerErrors.ErrUnauthorized
} }
var entity params.GithubEntity var entity params.ForgeEntity
switch { switch {
case instance.PoolID != "": case instance.PoolID != "":
@ -96,11 +96,11 @@ func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
tpl := "actions.runner.%s.%s" tpl := "actions.runner.%s.%s"
var serviceName string var serviceName string
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name) serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name) serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name)
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
serviceName = fmt.Sprintf(tpl, fmt.Sprintf("%s-%s", entity.Owner, entity.Name), instance.Name) serviceName = fmt.Sprintf(tpl, fmt.Sprintf("%s-%s", entity.Owner, entity.Name), instance.Name)
} }
return serviceName, nil return serviceName, nil

View file

@ -235,9 +235,9 @@ func (r *Runner) CreateOrgPool(ctx context.Context, orgID string, param params.C
param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout param.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams) pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -253,9 +253,9 @@ func (r *Runner) GetOrgPoolByID(ctx context.Context, orgID, poolID string) (para
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -271,9 +271,9 @@ func (r *Runner) DeleteOrgPool(ctx context.Context, orgID, poolID string) error
return runnerErrors.ErrUnauthorized return runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -304,9 +304,9 @@ func (r *Runner) ListOrgPools(ctx context.Context, orgID string) ([]params.Pool,
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return []params.Pool{}, runnerErrors.ErrUnauthorized return []params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pools, err := r.store.ListEntityPools(ctx, entity) pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil { if err != nil {
@ -320,9 +320,9 @@ func (r *Runner) UpdateOrgPool(ctx context.Context, orgID, poolID string, param
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -356,9 +356,9 @@ func (r *Runner) ListOrgInstances(ctx context.Context, orgID string) ([]params.I
return nil, runnerErrors.ErrUnauthorized return nil, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: orgID, ID: orgID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
instances, err := r.store.ListEntityInstances(ctx, entity) instances, err := r.store.ListEntityInstances(ctx, entity)

View file

@ -58,7 +58,7 @@ type OrgTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *OrgTestSuite) SetupTest() { func (s *OrgTestSuite) SetupTest() {
@ -284,9 +284,9 @@ func (s *OrgTestSuite) TestDeleteOrganizationErrUnauthorized() {
} }
func (s *OrgTestSuite) TestDeleteOrganizationPoolDefinedFailed() { func (s *OrgTestSuite) TestDeleteOrganizationPoolDefinedFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -402,9 +402,9 @@ func (s *OrgTestSuite) TestCreateOrgPoolFetchPoolParamsFailed() {
} }
func (s *OrgTestSuite) TestGetOrgPoolByID() { func (s *OrgTestSuite) TestGetOrgPoolByID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -424,9 +424,9 @@ func (s *OrgTestSuite) TestGetOrgPoolByIDErrUnauthorized() {
} }
func (s *OrgTestSuite) TestDeleteOrgPool() { func (s *OrgTestSuite) TestDeleteOrgPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -448,9 +448,9 @@ func (s *OrgTestSuite) TestDeleteOrgPoolErrUnauthorized() {
} }
func (s *OrgTestSuite) TestDeleteOrgPoolRunnersFailed() { func (s *OrgTestSuite) TestDeleteOrgPoolRunnersFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -467,9 +467,9 @@ func (s *OrgTestSuite) TestDeleteOrgPoolRunnersFailed() {
} }
func (s *OrgTestSuite) TestListOrgPools() { func (s *OrgTestSuite) TestListOrgPools() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
orgPools := []params.Pool{} orgPools := []params.Pool{}
for i := 1; i <= 2; i++ { for i := 1; i <= 2; i++ {
@ -494,9 +494,9 @@ func (s *OrgTestSuite) TestListOrgPoolsErrUnauthorized() {
} }
func (s *OrgTestSuite) TestUpdateOrgPool() { func (s *OrgTestSuite) TestUpdateOrgPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) orgPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -517,9 +517,9 @@ func (s *OrgTestSuite) TestUpdateOrgPoolErrUnauthorized() {
} }
func (s *OrgTestSuite) TestUpdateOrgPoolMinIdleGreaterThanMax() { func (s *OrgTestSuite) TestUpdateOrgPoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -536,9 +536,9 @@ func (s *OrgTestSuite) TestUpdateOrgPoolMinIdleGreaterThanMax() {
} }
func (s *OrgTestSuite) TestListOrgInstances() { func (s *OrgTestSuite) TestListOrgInstances() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreOrgs["test-org-1"].ID, ID: s.Fixtures.StoreOrgs["test-org-1"].ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {

View file

@ -67,7 +67,7 @@ const (
maxCreateAttempts = 5 maxCreateAttempts = 5
) )
func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) { func NewEntityPoolManager(ctx context.Context, entity params.ForgeEntity, instanceTokenGetter auth.InstanceTokenGetter, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error) {
ctx = garmUtil.WithSlogContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", entity.EntityType)) ctx = garmUtil.WithSlogContext(ctx, slog.Any("pool_mgr", entity.String()), slog.Any("pool_type", entity.EntityType))
ghc, err := ghClient.Client(ctx, entity) ghc, err := ghClient.Client(ctx, entity)
if err != nil { if err != nil {
@ -83,7 +83,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
return nil, errors.Wrap(err, "getting controller info") return nil, errors.Wrap(err, "getting controller info")
} }
consumerID := fmt.Sprintf("pool-manager-%s-%s", entity.String(), entity.Credentials.Endpoint.Name) consumerID := fmt.Sprintf("pool-manager-%s-%s", entity.String(), entity.Credentials.Endpoint().Name)
slog.InfoContext(ctx, "registering consumer", "consumer_id", consumerID) slog.InfoContext(ctx, "registering consumer", "consumer_id", consumerID)
consumer, err := watcher.RegisterConsumer( consumer, err := watcher.RegisterConsumer(
ctx, consumerID, ctx, consumerID,
@ -120,7 +120,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
type basePoolManager struct { type basePoolManager struct {
ctx context.Context ctx context.Context
consumerID string consumerID string
entity params.GithubEntity entity params.ForgeEntity
ghcli common.GithubClient ghcli common.GithubClient
controllerInfo params.ControllerInfo controllerInfo params.ControllerInfo
instanceTokenGetter auth.InstanceTokenGetter instanceTokenGetter auth.InstanceTokenGetter
@ -877,7 +877,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
bootstrapArgs := commonParams.BootstrapInstance{ bootstrapArgs := commonParams.BootstrapInstance{
Name: instance.Name, Name: instance.Name,
Tools: r.tools, Tools: r.tools,
RepoURL: r.entity.GithubURL(), RepoURL: r.entity.ForgeURL(),
MetadataURL: instance.MetadataURL, MetadataURL: instance.MetadataURL,
CallbackURL: instance.CallbackURL, CallbackURL: instance.CallbackURL,
InstanceToken: jwtToken, InstanceToken: jwtToken,
@ -887,7 +887,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
Image: pool.Image, Image: pool.Image,
ExtraSpecs: pool.ExtraSpecs, ExtraSpecs: pool.ExtraSpecs,
PoolID: instance.PoolID, PoolID: instance.PoolID,
CACertBundle: r.entity.Credentials.CABundle, CACertBundle: r.entity.Credentials.CABundle(),
GitHubRunnerGroup: instance.GitHubRunnerGroup, GitHubRunnerGroup: instance.GitHubRunnerGroup,
JitConfigEnabled: hasJITConfig, JitConfigEnabled: hasJITConfig,
} }
@ -981,11 +981,11 @@ func (r *basePoolManager) paramsWorkflowJobToParamsJob(job params.WorkflowJob) (
} }
switch r.entity.EntityType { switch r.entity.EntityType {
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
jobParams.EnterpriseID = &asUUID jobParams.EnterpriseID = &asUUID
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
jobParams.RepoID = &asUUID jobParams.RepoID = &asUUID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
jobParams.OrgID = &asUUID jobParams.OrgID = &asUUID
default: default:
return jobParams, errors.Errorf("unknown pool type: %s", r.entity.EntityType) return jobParams, errors.Errorf("unknown pool type: %s", r.entity.EntityType)
@ -1931,15 +1931,15 @@ func (r *basePoolManager) InstallWebhook(ctx context.Context, param params.Insta
func (r *basePoolManager) ValidateOwner(job params.WorkflowJob) error { func (r *basePoolManager) ValidateOwner(job params.WorkflowJob) error {
switch r.entity.EntityType { switch r.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
if !strings.EqualFold(job.Repository.Name, r.entity.Name) || !strings.EqualFold(job.Repository.Owner.Login, r.entity.Owner) { if !strings.EqualFold(job.Repository.Name, r.entity.Name) || !strings.EqualFold(job.Repository.Owner.Login, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager") return runnerErrors.NewBadRequestError("job not meant for this pool manager")
} }
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
if !strings.EqualFold(job.Organization.Login, r.entity.Owner) { if !strings.EqualFold(job.Organization.Login, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager") return runnerErrors.NewBadRequestError("job not meant for this pool manager")
} }
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
if !strings.EqualFold(job.Enterprise.Slug, r.entity.Owner) { if !strings.EqualFold(job.Enterprise.Slug, r.entity.Owner) {
return runnerErrors.NewBadRequestError("job not meant for this pool manager") return runnerErrors.NewBadRequestError("job not meant for this pool manager")
} }

View file

@ -57,8 +57,8 @@ func (s *stubGithubClient) GetWorkflowJobByID(_ context.Context, _, _ string, _
return nil, nil, s.err return nil, nil, s.err
} }
func (s *stubGithubClient) GetEntity() params.GithubEntity { func (s *stubGithubClient) GetEntity() params.ForgeEntity {
return params.GithubEntity{} return params.ForgeEntity{}
} }
func (s *stubGithubClient) GithubBaseURL() *url.URL { func (s *stubGithubClient) GithubBaseURL() *url.URL {

View file

@ -119,7 +119,7 @@ func isManagedRunner(labels []string, controllerID string) bool {
return runnerControllerID == controllerID return runnerControllerID == controllerID
} }
func composeWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFunc { func composeWatcherFilters(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
// We want to watch for changes in either the controller or the // We want to watch for changes in either the controller or the
// entity itself. // entity itself.
return watcher.WithAny( return watcher.WithAny(
@ -131,6 +131,6 @@ func composeWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFun
// Any operation on the entity we're managing the pool for. // Any operation on the entity we're managing the pool for.
watcher.WithEntityFilter(entity), watcher.WithEntityFilter(entity),
// Watch for changes to the github credentials // Watch for changes to the github credentials
watcher.WithGithubCredentialsFilter(entity.Credentials), watcher.WithForgeCredentialsFilter(entity.Credentials),
) )
} }

View file

@ -14,7 +14,7 @@ import (
// entityGetter is implemented by all github entities (repositories, organizations and enterprises) // entityGetter is implemented by all github entities (repositories, organizations and enterprises)
type entityGetter interface { type entityGetter interface {
GetEntity() (params.GithubEntity, error) GetEntity() (params.ForgeEntity, error)
} }
func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.ControllerInfo) { func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.ControllerInfo) {
@ -38,7 +38,7 @@ func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient {
return ghc return ghc
} }
func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operation common.OperationType) { func (r *basePoolManager) handleEntityUpdate(entity params.ForgeEntity, operation common.OperationType) {
slog.DebugContext(r.ctx, "received entity operation", "entity", entity.ID, "operation", operation) slog.DebugContext(r.ctx, "received entity operation", "entity", entity.ID, "operation", operation)
if r.entity.ID != entity.ID { if r.entity.ID != entity.ID {
slog.WarnContext(r.ctx, "entity ID mismatch; stale event? refusing to update", "entity", entity.ID) slog.WarnContext(r.ctx, "entity ID mismatch; stale event? refusing to update", "entity", entity.ID)
@ -56,7 +56,7 @@ func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operati
return return
} }
credentialsUpdate := r.entity.Credentials.ID != entity.Credentials.ID credentialsUpdate := r.entity.Credentials.GetID() != entity.Credentials.GetID()
defer func() { defer func() {
slog.DebugContext(r.ctx, "deferred tools update", "credentials_update", credentialsUpdate) slog.DebugContext(r.ctx, "deferred tools update", "credentials_update", credentialsUpdate)
if !credentialsUpdate { if !credentialsUpdate {
@ -85,7 +85,7 @@ func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operati
slog.DebugContext(r.ctx, "lock released", "entity", entity.ID) slog.DebugContext(r.ctx, "lock released", "entity", entity.ID)
} }
func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCredentials) { func (r *basePoolManager) handleCredentialsUpdate(credentials params.ForgeCredentials) {
// when we switch credentials on an entity (like from one app to another or from an app // when we switch credentials on an entity (like from one app to another or from an app
// to a PAT), we may still get events for the previous credentials as the channel is buffered. // to a PAT), we may still get events for the previous credentials as the channel is buffered.
// The watcher will watch for changes to the entity itself, which includes events that // The watcher will watch for changes to the entity itself, which includes events that
@ -97,12 +97,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
// test-repo. This function would handle situations where "org_pat" is updated. // test-repo. This function would handle situations where "org_pat" is updated.
// If "test-repo" is updated with new credentials, that event is handled above in // If "test-repo" is updated with new credentials, that event is handled above in
// handleEntityUpdate. // handleEntityUpdate.
shouldUpdateTools := r.entity.Credentials.ID == credentials.ID shouldUpdateTools := r.entity.Credentials.GetID() == credentials.GetID()
defer func() { defer func() {
if !shouldUpdateTools { if !shouldUpdateTools {
return return
} }
slog.DebugContext(r.ctx, "deferred tools update", "credentials_id", credentials.ID) slog.DebugContext(r.ctx, "deferred tools update", "credentials_id", credentials.GetID())
if err := r.updateTools(); err != nil { if err := r.updateTools(); err != nil {
slog.ErrorContext(r.ctx, "failed to update tools", "error", err) slog.ErrorContext(r.ctx, "failed to update tools", "error", err)
} }
@ -110,12 +110,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
r.mux.Lock() r.mux.Lock()
if !shouldUpdateTools { if !shouldUpdateTools {
slog.InfoContext(r.ctx, "credential ID mismatch; stale event?", "credentials_id", credentials.ID) slog.InfoContext(r.ctx, "credential ID mismatch; stale event?", "credentials_id", credentials.GetID())
r.mux.Unlock() r.mux.Unlock()
return return
} }
slog.DebugContext(r.ctx, "updating credentials", "credentials_id", credentials.ID) slog.DebugContext(r.ctx, "updating credentials", "credentials_id", credentials.GetID())
r.entity.Credentials = credentials r.entity.Credentials = credentials
r.ghcli = r.getClientOrStub() r.ghcli = r.getClientOrStub()
r.mux.Unlock() r.mux.Unlock()
@ -130,7 +130,7 @@ func (r *basePoolManager) handleWatcherEvent(event common.ChangePayload) {
slog.ErrorContext(r.ctx, "failed to cast payload to github credentials") slog.ErrorContext(r.ctx, "failed to cast payload to github credentials")
return return
} }
r.handleCredentialsUpdate(credentials) r.handleCredentialsUpdate(credentials.GetForgeCredentials())
case common.ControllerEntityType: case common.ControllerEntityType:
controllerInfo, ok := event.Payload.(params.ControllerInfo) controllerInfo, ok := event.Payload.(params.ControllerInfo)
if !ok { if !ok {

View file

@ -49,7 +49,7 @@ type PoolTestSuite struct {
adminCtx context.Context adminCtx context.Context
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *PoolTestSuite) SetupTest() { func (s *PoolTestSuite) SetupTest() {
@ -75,9 +75,9 @@ func (s *PoolTestSuite) SetupTest() {
} }
// create some pool objects in the database, for testing purposes // create some pool objects in the database, for testing purposes
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: org.ID, ID: org.ID,
EntityType: params.GithubEntityTypeOrganization, EntityType: params.ForgeEntityTypeOrganization,
} }
orgPools := []params.Pool{} orgPools := []params.Pool{}
for i := 1; i <= 3; i++ { for i := 1; i <= 3; i++ {

View file

@ -235,9 +235,9 @@ func (r *Runner) CreateRepoPool(ctx context.Context, repoID string, param params
createPoolParams.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout createPoolParams.RunnerBootstrapTimeout = appdefaults.DefaultRunnerBootstrapTimeout
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams) pool, err := r.store.CreateEntityPool(ctx, entity, createPoolParams)
@ -253,9 +253,9 @@ func (r *Runner) GetRepoPoolByID(ctx context.Context, repoID, poolID string) (pa
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
@ -271,9 +271,9 @@ func (r *Runner) DeleteRepoPool(ctx context.Context, repoID, poolID string) erro
return runnerErrors.ErrUnauthorized return runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil { if err != nil {
@ -300,9 +300,9 @@ func (r *Runner) ListRepoPools(ctx context.Context, repoID string) ([]params.Poo
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return []params.Pool{}, runnerErrors.ErrUnauthorized return []params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pools, err := r.store.ListEntityPools(ctx, entity) pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil { if err != nil {
@ -328,9 +328,9 @@ func (r *Runner) UpdateRepoPool(ctx context.Context, repoID, poolID string, para
return params.Pool{}, runnerErrors.ErrUnauthorized return params.Pool{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := r.store.GetEntityPool(ctx, entity, poolID) pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil { if err != nil {
@ -362,9 +362,9 @@ func (r *Runner) ListRepoInstances(ctx context.Context, repoID string) ([]params
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized return nil, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: repoID, ID: repoID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
instances, err := r.store.ListEntityInstances(ctx, entity) instances, err := r.store.ListEntityInstances(ctx, entity)
if err != nil { if err != nil {

View file

@ -62,7 +62,7 @@ type RepoTestSuite struct {
testCreds params.GithubCredentials testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint githubEndpoint params.ForgeEndpoint
} }
func (s *RepoTestSuite) SetupTest() { func (s *RepoTestSuite) SetupTest() {
@ -299,9 +299,9 @@ func (s *RepoTestSuite) TestDeleteRepositoryErrUnauthorized() {
} }
func (s *RepoTestSuite) TestDeleteRepositoryPoolDefinedFailed() { func (s *RepoTestSuite) TestDeleteRepositoryPoolDefinedFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -419,9 +419,9 @@ func (s *RepoTestSuite) TestCreateRepoPoolFetchPoolParamsFailed() {
} }
func (s *RepoTestSuite) TestGetRepoPoolByID() { func (s *RepoTestSuite) TestGetRepoPoolByID() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -441,9 +441,9 @@ func (s *RepoTestSuite) TestGetRepoPoolByIDErrUnauthorized() {
} }
func (s *RepoTestSuite) TestDeleteRepoPool() { func (s *RepoTestSuite) TestDeleteRepoPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -465,9 +465,9 @@ func (s *RepoTestSuite) TestDeleteRepoPoolErrUnauthorized() {
} }
func (s *RepoTestSuite) TestDeleteRepoPoolRunnersFailed() { func (s *RepoTestSuite) TestDeleteRepoPoolRunnersFailed() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -484,9 +484,9 @@ func (s *RepoTestSuite) TestDeleteRepoPoolRunnersFailed() {
} }
func (s *RepoTestSuite) TestListRepoPools() { func (s *RepoTestSuite) TestListRepoPools() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
repoPools := []params.Pool{} repoPools := []params.Pool{}
for i := 1; i <= 2; i++ { for i := 1; i <= 2; i++ {
@ -511,9 +511,9 @@ func (s *RepoTestSuite) TestListRepoPoolsErrUnauthorized() {
} }
func (s *RepoTestSuite) TestListPoolInstances() { func (s *RepoTestSuite) TestListPoolInstances() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -542,9 +542,9 @@ func (s *RepoTestSuite) TestListPoolInstancesErrUnauthorized() {
} }
func (s *RepoTestSuite) TestUpdateRepoPool() { func (s *RepoTestSuite) TestUpdateRepoPool() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) repoPool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -565,9 +565,9 @@ func (s *RepoTestSuite) TestUpdateRepoPoolErrUnauthorized() {
} }
func (s *RepoTestSuite) TestUpdateRepoPoolMinIdleGreaterThanMax() { func (s *RepoTestSuite) TestUpdateRepoPoolMinIdleGreaterThanMax() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {
@ -584,9 +584,9 @@ func (s *RepoTestSuite) TestUpdateRepoPoolMinIdleGreaterThanMax() {
} }
func (s *RepoTestSuite) TestListRepoInstances() { func (s *RepoTestSuite) TestListRepoInstances() {
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: s.Fixtures.StoreRepos["test-repo-1"].ID, ID: s.Fixtures.StoreRepos["test-repo-1"].ID,
EntityType: params.GithubEntityTypeRepository, EntityType: params.ForgeEntityTypeRepository,
} }
pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams) pool, err := s.Fixtures.Store.CreateEntityPool(s.Fixtures.AdminContext, entity, s.Fixtures.CreatePoolParams)
if err != nil { if err != nil {

View file

@ -602,10 +602,10 @@ func (r *Runner) validateHookBody(signature, secret string, body []byte) error {
return nil return nil
} }
func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoint, error) { func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.ForgeEndpoint, error) {
uri, err := url.ParseRequestURI(job.WorkflowJob.HTMLURL) uri, err := url.ParseRequestURI(job.WorkflowJob.HTMLURL)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "parsing job URL") return params.ForgeEndpoint{}, errors.Wrap(err, "parsing job URL")
} }
baseURI := fmt.Sprintf("%s://%s", uri.Scheme, uri.Host) baseURI := fmt.Sprintf("%s://%s", uri.Scheme, uri.Host)
@ -616,7 +616,7 @@ func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoi
// that much about the performance of this function. // that much about the performance of this function.
endpoints, err := r.store.ListGithubEndpoints(r.ctx) endpoints, err := r.store.ListGithubEndpoints(r.ctx)
if err != nil { if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "fetching github endpoints") return params.ForgeEndpoint{}, errors.Wrap(err, "fetching github endpoints")
} }
for _, ep := range endpoints { for _, ep := range endpoints {
if ep.BaseURL == baseURI { if ep.BaseURL == baseURI {
@ -624,7 +624,7 @@ func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoi
} }
} }
return params.GithubEndpoint{}, runnerErrors.NewNotFoundError("no endpoint found for job") return params.ForgeEndpoint{}, runnerErrors.NewNotFoundError("no endpoint found for job")
} }
func (r *Runner) DispatchWorkflowJob(hookTargetType, signature string, jobData []byte) error { func (r *Runner) DispatchWorkflowJob(hookTargetType, signature string, jobData []byte) error {
@ -928,7 +928,7 @@ func (r *Runner) getGHCliFromInstance(ctx context.Context, instance params.Insta
} }
// Fetching the entity from the database will populate all fields, including credentials. // Fetching the entity from the database will populate all fields, including credentials.
entity, err = r.store.GetGithubEntity(ctx, entity.EntityType, entity.ID) entity, err = r.store.GetForgeEntity(ctx, entity.EntityType, entity.ID)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "fetching entity") return nil, nil, errors.Wrap(err, "fetching entity")
} }

View file

@ -80,7 +80,7 @@ func (r *Runner) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) error
return errors.Wrap(err, "getting entity") return errors.Wrap(err, "getting entity")
} }
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID) entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil { if err != nil {
return errors.Wrap(err, "getting entity") return errors.Wrap(err, "getting entity")
} }
@ -143,7 +143,7 @@ func (r *Runner) UpdateScaleSetByID(ctx context.Context, scaleSetID uint, param
return params.ScaleSet{}, errors.Wrap(err, "getting entity") return params.ScaleSet{}, errors.Wrap(err, "getting entity")
} }
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID) entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil { if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "getting entity") return params.ScaleSet{}, errors.Wrap(err, "getting entity")
} }
@ -198,7 +198,7 @@ func (r *Runner) UpdateScaleSetByID(ctx context.Context, scaleSetID uint, param
return newScaleSet, nil return newScaleSet, nil
} }
func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.GithubEntityType, entityID string, param params.CreateScaleSetParams) (scaleSetRet params.ScaleSet, err error) { func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.ForgeEntityType, entityID string, param params.CreateScaleSetParams) (scaleSetRet params.ScaleSet, err error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return params.ScaleSet{}, runnerErrors.ErrUnauthorized return params.ScaleSet{}, runnerErrors.ErrUnauthorized
} }
@ -211,7 +211,7 @@ func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.Git
param.GitHubRunnerGroup = "Default" param.GitHubRunnerGroup = "Default"
} }
entity, err := r.store.GetGithubEntity(ctx, entityType, entityID) entity, err := r.store.GetForgeEntity(ctx, entityType, entityID)
if err != nil { if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "getting entity") return params.ScaleSet{}, errors.Wrap(err, "getting entity")
} }
@ -287,11 +287,11 @@ func (r *Runner) ListScaleSetInstances(ctx context.Context, scalesetID uint) ([]
return instances, nil return instances, nil
} }
func (r *Runner) ListEntityScaleSets(ctx context.Context, entityType params.GithubEntityType, entityID string) ([]params.ScaleSet, error) { func (r *Runner) ListEntityScaleSets(ctx context.Context, entityType params.ForgeEntityType, entityID string) ([]params.ScaleSet, error) {
if !auth.IsAdmin(ctx) { if !auth.IsAdmin(ctx) {
return []params.ScaleSet{}, runnerErrors.ErrUnauthorized return []params.ScaleSet{}, runnerErrors.ErrUnauthorized
} }
entity := params.GithubEntity{ entity := params.ForgeEntity{
ID: entityID, ID: entityID,
EntityType: entityType, EntityType: entityType,
} }

View file

@ -77,7 +77,7 @@ func updateGithubCredentials(apiCli *client.GarmAPI, apiAuthToken runtime.Client
return &updateCredentialsResponse.Payload, nil return &updateCredentialsResponse.Payload, nil
} }
func createGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointParams params.CreateGithubEndpointParams) (*params.GithubEndpoint, error) { func createGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointParams params.CreateGithubEndpointParams) (*params.ForgeEndpoint, error) {
createEndpointResponse, err := apiCli.Endpoints.CreateGithubEndpoint( createEndpointResponse, err := apiCli.Endpoints.CreateGithubEndpoint(
clientEndpoints.NewCreateGithubEndpointParams().WithBody(endpointParams), clientEndpoints.NewCreateGithubEndpointParams().WithBody(endpointParams),
apiAuthToken) apiAuthToken)
@ -87,7 +87,7 @@ func createGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAut
return &createEndpointResponse.Payload, nil return &createEndpointResponse.Payload, nil
} }
func listGithubEndpoints(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter) (params.GithubEndpoints, error) { func listGithubEndpoints(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter) (params.ForgeEndpoints, error) {
listEndpointsResponse, err := apiCli.Endpoints.ListGithubEndpoints( listEndpointsResponse, err := apiCli.Endpoints.ListGithubEndpoints(
clientEndpoints.NewListGithubEndpointsParams(), clientEndpoints.NewListGithubEndpointsParams(),
apiAuthToken) apiAuthToken)
@ -97,7 +97,7 @@ func listGithubEndpoints(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuth
return listEndpointsResponse.Payload, nil return listEndpointsResponse.Payload, nil
} }
func getGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointName string) (*params.GithubEndpoint, error) { func getGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointName string) (*params.ForgeEndpoint, error) {
getEndpointResponse, err := apiCli.Endpoints.GetGithubEndpoint( getEndpointResponse, err := apiCli.Endpoints.GetGithubEndpoint(
clientEndpoints.NewGetGithubEndpointParams().WithName(endpointName), clientEndpoints.NewGetGithubEndpointParams().WithName(endpointName),
apiAuthToken) apiAuthToken)
@ -113,7 +113,7 @@ func deleteGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAut
apiAuthToken) apiAuthToken)
} }
func updateGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointName string, endpointParams params.UpdateGithubEndpointParams) (*params.GithubEndpoint, error) { func updateGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuthInfoWriter, endpointName string, endpointParams params.UpdateGithubEndpointParams) (*params.ForgeEndpoint, error) {
updateEndpointResponse, err := apiCli.Endpoints.UpdateGithubEndpoint( updateEndpointResponse, err := apiCli.Endpoints.UpdateGithubEndpoint(
clientEndpoints.NewUpdateGithubEndpointParams().WithName(endpointName).WithBody(endpointParams), clientEndpoints.NewUpdateGithubEndpointParams().WithName(endpointName).WithBody(endpointParams),
apiAuthToken) apiAuthToken)

View file

@ -25,7 +25,7 @@ func (suite *GarmSuite) TestGithubCredentialsErrorOnDuplicateCredentialsName() {
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "dummy", OAuth2Token: "dummy",
}, },
@ -68,7 +68,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsOnInvalidAuthType() {
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthType("invalid"), AuthType: params.ForgeAuthType("invalid"),
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "dummy", OAuth2Token: "dummy",
}, },
@ -87,7 +87,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsWhenAuthTypeParamsAreIncorrect
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
App: params.GithubApp{ App: params.GithubApp{
AppID: 123, AppID: 123,
InstallationID: 456, InstallationID: 456,
@ -107,7 +107,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsWhenAuthTypeParamsAreMissing()
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypeApp, AuthType: params.ForgeAuthTypeApp,
} }
_, err := createGithubCredentials(suite.cli, suite.authToken, createCredsParams) _, err := createGithubCredentials(suite.cli, suite.authToken, createCredsParams)
suite.Error(err, "expected error when creating credentials with missing auth type params") suite.Error(err, "expected error when creating credentials with missing auth type params")
@ -147,7 +147,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailWhenAppKeyIsInvalid() {
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypeApp, AuthType: params.ForgeAuthTypeApp,
App: params.GithubApp{ App: params.GithubApp{
AppID: 123, AppID: 123,
InstallationID: 456, InstallationID: 456,
@ -166,7 +166,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailWhenEndpointDoesntExist() {
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: "iDontExist.example.com", Endpoint: "iDontExist.example.com",
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "dummy", OAuth2Token: "dummy",
}, },
@ -189,7 +189,7 @@ func (suite *GarmSuite) TestGithubCredentialsFailsOnDuplicateName() {
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: defaultEndpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "dummy", OAuth2Token: "dummy",
}, },
@ -204,7 +204,7 @@ func (suite *GarmSuite) createDummyCredentials(name, endpointName string) (*para
Name: name, Name: name,
Endpoint: endpointName, Endpoint: endpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: "dummy", OAuth2Token: "dummy",
}, },

View file

@ -8,7 +8,7 @@ import (
"github.com/cloudbase/garm/params" "github.com/cloudbase/garm/params"
) )
func checkEndpointParamsAreEqual(a, b params.GithubEndpoint) error { func checkEndpointParamsAreEqual(a, b params.ForgeEndpoint) error {
if a.Name != b.Name { if a.Name != b.Name {
return fmt.Errorf("endpoint name mismatch") return fmt.Errorf("endpoint name mismatch")
} }

View file

@ -163,7 +163,7 @@ func (suite *GarmSuite) MustDefaultGithubEndpoint() {
suite.Equal(ep.Name, "github.com", "default GitHub endpoint name mismatch") suite.Equal(ep.Name, "github.com", "default GitHub endpoint name mismatch")
} }
func (suite *GarmSuite) GetGithubEndpoint(name string) *params.GithubEndpoint { func (suite *GarmSuite) GetGithubEndpoint(name string) *params.ForgeEndpoint {
t := suite.T() t := suite.T()
t.Log("Get GitHub endpoint") t.Log("Get GitHub endpoint")
endpoint, err := getGithubEndpoint(suite.cli, suite.authToken, name) endpoint, err := getGithubEndpoint(suite.cli, suite.authToken, name)
@ -172,7 +172,7 @@ func (suite *GarmSuite) GetGithubEndpoint(name string) *params.GithubEndpoint {
return endpoint return endpoint
} }
func (suite *GarmSuite) CreateGithubEndpoint(params params.CreateGithubEndpointParams) (*params.GithubEndpoint, error) { func (suite *GarmSuite) CreateGithubEndpoint(params params.CreateGithubEndpointParams) (*params.ForgeEndpoint, error) {
t := suite.T() t := suite.T()
t.Log("Create GitHub endpoint") t.Log("Create GitHub endpoint")
endpoint, err := createGithubEndpoint(suite.cli, suite.authToken, params) endpoint, err := createGithubEndpoint(suite.cli, suite.authToken, params)
@ -190,7 +190,7 @@ func (suite *GarmSuite) DeleteGithubEndpoint(name string) error {
return nil return nil
} }
func (suite *GarmSuite) ListGithubEndpoints() params.GithubEndpoints { func (suite *GarmSuite) ListGithubEndpoints() params.ForgeEndpoints {
t := suite.T() t := suite.T()
t.Log("List GitHub endpoints") t.Log("List GitHub endpoints")
endpoints, err := listGithubEndpoints(suite.cli, suite.authToken) endpoints, err := listGithubEndpoints(suite.cli, suite.authToken)
@ -199,7 +199,7 @@ func (suite *GarmSuite) ListGithubEndpoints() params.GithubEndpoints {
return endpoints return endpoints
} }
func (suite *GarmSuite) createDummyEndpoint(name string) (*params.GithubEndpoint, error) { func (suite *GarmSuite) createDummyEndpoint(name string) (*params.ForgeEndpoint, error) {
endpointParams := params.CreateGithubEndpointParams{ endpointParams := params.CreateGithubEndpointParams{
Name: name, Name: name,
Description: "Dummy endpoint", Description: "Dummy endpoint",

View file

@ -22,7 +22,7 @@ func (suite *GarmSuite) EnsureTestCredentials(name string, oauthToken string, en
Name: name, Name: name,
Endpoint: endpointName, Endpoint: endpointName,
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{
OAuth2Token: oauthToken, OAuth2Token: oauthToken,
}, },

View file

@ -22,6 +22,7 @@ import (
"log/slog" "log/slog"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"github.com/google/go-github/v71/github" "github.com/google/go-github/v71/github"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -39,7 +40,7 @@ type githubClient struct {
enterprise *github.EnterpriseService enterprise *github.EnterpriseService
rateLimit *github.RateLimitService rateLimit *github.RateLimitService
entity params.GithubEntity entity params.ForgeEntity
cli *github.Client cli *github.Client
} }
@ -57,9 +58,9 @@ func (g *githubClient) ListEntityHooks(ctx context.Context, opts *github.ListOpt
} }
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, response, err = g.repo.ListHooks(ctx, g.entity.Owner, g.entity.Name, opts) ret, response, err = g.repo.ListHooks(ctx, g.entity.Owner, g.entity.Name, opts)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, response, err = g.org.ListHooks(ctx, g.entity.Owner, opts) ret, response, err = g.org.ListHooks(ctx, g.entity.Owner, opts)
default: default:
return nil, nil, fmt.Errorf("invalid entity type: %s", g.entity.EntityType) return nil, nil, fmt.Errorf("invalid entity type: %s", g.entity.EntityType)
@ -81,9 +82,9 @@ func (g *githubClient) GetEntityHook(ctx context.Context, id int64) (ret *github
} }
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, _, err = g.repo.GetHook(ctx, g.entity.Owner, g.entity.Name, id) ret, _, err = g.repo.GetHook(ctx, g.entity.Owner, g.entity.Name, id)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, _, err = g.org.GetHook(ctx, g.entity.Owner, id) ret, _, err = g.org.GetHook(ctx, g.entity.Owner, id)
default: default:
return nil, errors.New("invalid entity type") return nil, errors.New("invalid entity type")
@ -105,9 +106,9 @@ func (g *githubClient) CreateEntityHook(ctx context.Context, hook *github.Hook)
} }
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, _, err = g.repo.CreateHook(ctx, g.entity.Owner, g.entity.Name, hook) ret, _, err = g.repo.CreateHook(ctx, g.entity.Owner, g.entity.Name, hook)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, _, err = g.org.CreateHook(ctx, g.entity.Owner, hook) ret, _, err = g.org.CreateHook(ctx, g.entity.Owner, hook)
default: default:
return nil, errors.New("invalid entity type") return nil, errors.New("invalid entity type")
@ -129,9 +130,9 @@ func (g *githubClient) DeleteEntityHook(ctx context.Context, id int64) (ret *git
} }
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, err = g.repo.DeleteHook(ctx, g.entity.Owner, g.entity.Name, id) ret, err = g.repo.DeleteHook(ctx, g.entity.Owner, g.entity.Name, id)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, err = g.org.DeleteHook(ctx, g.entity.Owner, id) ret, err = g.org.DeleteHook(ctx, g.entity.Owner, id)
default: default:
return nil, errors.New("invalid entity type") return nil, errors.New("invalid entity type")
@ -153,9 +154,9 @@ func (g *githubClient) PingEntityHook(ctx context.Context, id int64) (ret *githu
} }
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, err = g.repo.PingHook(ctx, g.entity.Owner, g.entity.Name, id) ret, err = g.repo.PingHook(ctx, g.entity.Owner, g.entity.Name, id)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, err = g.org.PingHook(ctx, g.entity.Owner, id) ret, err = g.org.PingHook(ctx, g.entity.Owner, id)
default: default:
return nil, errors.New("invalid entity type") return nil, errors.New("invalid entity type")
@ -182,11 +183,11 @@ func (g *githubClient) ListEntityRunners(ctx context.Context, opts *github.ListR
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, response, err = g.ListRunners(ctx, g.entity.Owner, g.entity.Name, opts) ret, response, err = g.ListRunners(ctx, g.entity.Owner, g.entity.Name, opts)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, response, err = g.ListOrganizationRunners(ctx, g.entity.Owner, opts) ret, response, err = g.ListOrganizationRunners(ctx, g.entity.Owner, opts)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.ListRunners(ctx, g.entity.Owner, opts) ret, response, err = g.enterprise.ListRunners(ctx, g.entity.Owner, opts)
default: default:
return nil, nil, errors.New("invalid entity type") return nil, nil, errors.New("invalid entity type")
@ -214,11 +215,11 @@ func (g *githubClient) ListEntityRunnerApplicationDownloads(ctx context.Context)
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, response, err = g.ListRunnerApplicationDownloads(ctx, g.entity.Owner, g.entity.Name) ret, response, err = g.ListRunnerApplicationDownloads(ctx, g.entity.Owner, g.entity.Name)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, response, err = g.ListOrganizationRunnerApplicationDownloads(ctx, g.entity.Owner) ret, response, err = g.ListOrganizationRunnerApplicationDownloads(ctx, g.entity.Owner)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.ListRunnerApplicationDownloads(ctx, g.entity.Owner) ret, response, err = g.enterprise.ListRunnerApplicationDownloads(ctx, g.entity.Owner)
default: default:
return nil, nil, errors.New("invalid entity type") return nil, nil, errors.New("invalid entity type")
@ -277,11 +278,11 @@ func (g *githubClient) RemoveEntityRunner(ctx context.Context, runnerID int64) e
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
response, err = g.RemoveRunner(ctx, g.entity.Owner, g.entity.Name, runnerID) response, err = g.RemoveRunner(ctx, g.entity.Owner, g.entity.Name, runnerID)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
response, err = g.RemoveOrganizationRunner(ctx, g.entity.Owner, runnerID) response, err = g.RemoveOrganizationRunner(ctx, g.entity.Owner, runnerID)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
response, err = g.enterprise.RemoveRunner(ctx, g.entity.Owner, runnerID) response, err = g.enterprise.RemoveRunner(ctx, g.entity.Owner, runnerID)
default: default:
return errors.New("invalid entity type") return errors.New("invalid entity type")
@ -313,11 +314,11 @@ func (g *githubClient) CreateEntityRegistrationToken(ctx context.Context) (*gith
}() }()
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, response, err = g.CreateRegistrationToken(ctx, g.entity.Owner, g.entity.Name) ret, response, err = g.CreateRegistrationToken(ctx, g.entity.Owner, g.entity.Name)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, response, err = g.CreateOrganizationRegistrationToken(ctx, g.entity.Owner) ret, response, err = g.CreateOrganizationRegistrationToken(ctx, g.entity.Owner)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.CreateRegistrationToken(ctx, g.entity.Owner) ret, response, err = g.enterprise.CreateRegistrationToken(ctx, g.entity.Owner)
default: default:
return nil, nil, errors.New("invalid entity type") return nil, nil, errors.New("invalid entity type")
@ -326,7 +327,7 @@ func (g *githubClient) CreateEntityRegistrationToken(ctx context.Context) (*gith
return ret, response, err return ret, response, err
} }
func (g *githubClient) getOrganizationRunnerGroupIDByName(ctx context.Context, entity params.GithubEntity, rgName string) (int64, error) { func (g *githubClient) getOrganizationRunnerGroupIDByName(ctx context.Context, entity params.ForgeEntity, rgName string) (int64, error) {
opts := github.ListOrgRunnerGroupOptions{ opts := github.ListOrgRunnerGroupOptions{
ListOptions: github.ListOptions{ ListOptions: github.ListOptions{
PerPage: 100, PerPage: 100,
@ -362,7 +363,7 @@ func (g *githubClient) getOrganizationRunnerGroupIDByName(ctx context.Context, e
return 0, runnerErrors.NewNotFoundError("runner group %s not found", rgName) return 0, runnerErrors.NewNotFoundError("runner group %s not found", rgName)
} }
func (g *githubClient) getEnterpriseRunnerGroupIDByName(ctx context.Context, entity params.GithubEntity, rgName string) (int64, error) { func (g *githubClient) getEnterpriseRunnerGroupIDByName(ctx context.Context, entity params.ForgeEntity, rgName string) (int64, error) {
opts := github.ListEnterpriseRunnerGroupOptions{ opts := github.ListEnterpriseRunnerGroupOptions{
ListOptions: github.ListOptions{ ListOptions: github.ListOptions{
PerPage: 100, PerPage: 100,
@ -405,9 +406,9 @@ func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string,
if pool.GitHubRunnerGroup != "" { if pool.GitHubRunnerGroup != "" {
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
rgID, err = g.getEnterpriseRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup) rgID, err = g.getEnterpriseRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup)
} }
@ -434,11 +435,11 @@ func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string,
var response *github.Response var response *github.Response
switch g.entity.EntityType { switch g.entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
ret, response, err = g.GenerateRepoJITConfig(ctx, g.entity.Owner, g.entity.Name, &req) ret, response, err = g.GenerateRepoJITConfig(ctx, g.entity.Owner, g.entity.Name, &req)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
ret, response, err = g.GenerateOrgJITConfig(ctx, g.entity.Owner, &req) ret, response, err = g.GenerateOrgJITConfig(ctx, g.entity.Owner, &req)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.GenerateEnterpriseJITConfig(ctx, g.entity.Owner, &req) ret, response, err = g.enterprise.GenerateEnterpriseJITConfig(ctx, g.entity.Owner, &req)
} }
if err != nil { if err != nil {
@ -482,7 +483,7 @@ func (g *githubClient) RateLimit(ctx context.Context) (*github.RateLimits, error
return limits, nil return limits, nil
} }
func (g *githubClient) GetEntity() params.GithubEntity { func (g *githubClient) GetEntity() params.ForgeEntity {
return g.entity return g.entity
} }
@ -514,8 +515,49 @@ func NewRateLimitClient(ctx context.Context, credentials params.GithubCredential
return cli, nil return cli, nil
} }
func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) { func withGiteaURLs(client *github.Client, apiBaseURL, uploadBaseURL string) (*github.Client, error) {
// func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) { if client == nil {
return nil, errors.New("client is nil")
}
if apiBaseURL == "" || uploadBaseURL == "" {
return nil, errors.New("invalid gitea URLs")
}
parsedBaseURL, err := url.ParseRequestURI(apiBaseURL)
if err != nil {
return nil, errors.Wrap(err, "parsing gitea base URL")
}
if !strings.HasSuffix(parsedBaseURL.Path, "/") {
parsedBaseURL.Path += "/"
}
if !strings.HasSuffix(parsedBaseURL.Path, "/api/v1/") {
parsedBaseURL.Path += "api/v1/"
}
parsedUploadURL, err := url.ParseRequestURI(uploadBaseURL)
if err != nil {
return nil, errors.Wrap(err, "parsing gitea upload URL")
}
if !strings.HasSuffix(parsedUploadURL.Path, "/") {
parsedUploadURL.Path += "/"
}
if !strings.HasSuffix(parsedUploadURL.Path, "/api/v1/") {
parsedUploadURL.Path += "api/v1/"
}
client.BaseURL = parsedBaseURL
client.UploadURL = parsedUploadURL
return client, nil
}
func Client(ctx context.Context, entity params.ForgeEntity) (common.GithubClient, error) {
// func GithubClient(ctx context.Context, entity params.ForgeEntity) (common.GithubClient, error) {
httpClient, err := entity.Credentials.GetHTTPClient(ctx) httpClient, err := entity.Credentials.GetHTTPClient(ctx)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching http client") return nil, errors.Wrap(err, "fetching http client")
@ -523,11 +565,17 @@ func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClien
slog.DebugContext( slog.DebugContext(
ctx, "creating client for entity", ctx, "creating client for entity",
"entity", entity.String(), "base_url", entity.Credentials.APIBaseURL, "entity", entity.String(), "base_url", entity.Credentials.APIBaseURL(),
"upload_url", entity.Credentials.UploadBaseURL) "upload_url", entity.Credentials.UploadBaseURL())
ghClient := github.NewClient(httpClient)
switch entity.Credentials.ForgeType {
case params.GithubEndpointType:
ghClient, err = ghClient.WithEnterpriseURLs(entity.Credentials.APIBaseURL(), entity.Credentials.UploadBaseURL())
case params.GiteaEndpointType:
ghClient, err = withGiteaURLs(ghClient, entity.Credentials.APIBaseURL(), entity.Credentials.UploadBaseURL())
}
ghClient, err := github.NewClient(httpClient).WithEnterpriseURLs(
entity.Credentials.APIBaseURL, entity.Credentials.UploadBaseURL)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "fetching github client") return nil, errors.Wrap(err, "fetching github client")
} }

View file

@ -36,7 +36,7 @@ func (s *ScaleSetClient) getActionServiceInfo(ctx context.Context) (params.Actio
entity := s.ghCli.GetEntity() entity := s.ghCli.GetEntity()
body := params.ActionsServiceAdminInfoRequest{ body := params.ActionsServiceAdminInfoRequest{
URL: entity.GithubURL(), URL: entity.ForgeURL(),
RunnerEvent: "register", RunnerEvent: "register",
} }

View file

@ -262,7 +262,7 @@ func (w *Worker) handleEntityEvent(entityGetter params.EntityGetter, op common.O
w.toolsWorkes[entity.ID] = worker w.toolsWorkes[entity.ID] = worker
} else if hasOld { } else if hasOld {
// probably an update operation // probably an update operation
if old.Credentials.ID != entity.Credentials.ID { if old.Credentials.GetID() != entity.Credentials.GetID() {
worker.Reset() worker.Reset()
} }
} }

View file

@ -16,7 +16,7 @@ import (
"github.com/cloudbase/garm/util/github" "github.com/cloudbase/garm/util/github"
) )
func newToolsUpdater(ctx context.Context, entity params.GithubEntity) *toolsUpdater { func newToolsUpdater(ctx context.Context, entity params.ForgeEntity) *toolsUpdater {
return &toolsUpdater{ return &toolsUpdater{
ctx: ctx, ctx: ctx,
entity: entity, entity: entity,
@ -27,7 +27,7 @@ func newToolsUpdater(ctx context.Context, entity params.GithubEntity) *toolsUpda
type toolsUpdater struct { type toolsUpdater struct {
ctx context.Context ctx context.Context
entity params.GithubEntity entity params.ForgeEntity
tools []commonParams.RunnerApplicationDownload tools []commonParams.RunnerApplicationDownload
lastUpdate time.Time lastUpdate time.Time

View file

@ -31,7 +31,7 @@ func composeControllerWatcherFilters() dbCommon.PayloadFilterFunc {
) )
} }
func composeWorkerWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFunc { func composeWorkerWatcherFilters(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return watcher.WithAny( return watcher.WithAny(
watcher.WithAll( watcher.WithAll(
watcher.WithEntityFilter(entity), watcher.WithEntityFilter(entity),
@ -39,7 +39,7 @@ func composeWorkerWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFil
), ),
// Watch for credentials updates. // Watch for credentials updates.
watcher.WithAll( watcher.WithAll(
watcher.WithGithubCredentialsFilter(entity.Credentials), watcher.WithForgeCredentialsFilter(entity.Credentials),
watcher.WithOperationTypeFilter(dbCommon.UpdateOperation), watcher.WithOperationTypeFilter(dbCommon.UpdateOperation),
), ),
) )

View file

@ -7,6 +7,8 @@ import (
"sync" "sync"
"time" "time"
"golang.org/x/sync/errgroup"
"github.com/cloudbase/garm/cache" "github.com/cloudbase/garm/cache"
dbCommon "github.com/cloudbase/garm/database/common" dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/database/watcher" "github.com/cloudbase/garm/database/watcher"
@ -16,10 +18,9 @@ import (
"github.com/cloudbase/garm/util/github" "github.com/cloudbase/garm/util/github"
"github.com/cloudbase/garm/util/github/scalesets" "github.com/cloudbase/garm/util/github/scalesets"
"github.com/cloudbase/garm/workers/scaleset" "github.com/cloudbase/garm/workers/scaleset"
"golang.org/x/sync/errgroup"
) )
func NewWorker(ctx context.Context, store dbCommon.Store, entity params.GithubEntity, providers map[string]common.Provider) (*Worker, error) { func NewWorker(ctx context.Context, store dbCommon.Store, entity params.ForgeEntity, providers map[string]common.Provider) (*Worker, error) {
consumerID := fmt.Sprintf("entity-worker-%s", entity.String()) consumerID := fmt.Sprintf("entity-worker-%s", entity.String())
ctx = garmUtil.WithSlogContext( ctx = garmUtil.WithSlogContext(
@ -43,7 +44,7 @@ type Worker struct {
store dbCommon.Store store dbCommon.Store
ghCli common.GithubClient ghCli common.GithubClient
Entity params.GithubEntity Entity params.ForgeEntity
providers map[string]common.Provider providers map[string]common.Provider
scaleSetController *scaleset.Controller scaleSetController *scaleset.Controller

View file

@ -44,7 +44,7 @@ func (w *Worker) handleEntityEventPayload(event dbCommon.ChangePayload) {
defer w.mux.Unlock() defer w.mux.Unlock()
credentials := entity.Credentials credentials := entity.Credentials
if w.Entity.Credentials.ID != credentials.ID { if w.Entity.Credentials.GetID() != credentials.GetID() {
// credentials were swapped on the entity. We need to recompose the watcher // credentials were swapped on the entity. We need to recompose the watcher
// filters. // filters.
w.consumer.SetFilters(composeWorkerWatcherFilters(entity)) w.consumer.SetFilters(composeWorkerWatcherFilters(entity))
@ -63,18 +63,29 @@ func (w *Worker) handleEntityEventPayload(event dbCommon.ChangePayload) {
} }
func (w *Worker) handleEntityCredentialsEventPayload(event dbCommon.ChangePayload) { func (w *Worker) handleEntityCredentialsEventPayload(event dbCommon.ChangePayload) {
credentials, ok := event.Payload.(params.GithubCredentials) var credsGetter params.ForgeCredentialsGetter
var ok bool
switch event.EntityType {
case dbCommon.GithubCredentialsEntityType:
credsGetter, ok = event.Payload.(params.GithubCredentials)
default:
slog.ErrorContext(w.ctx, "invalid entity type", "entity_type", event.EntityType)
return
}
if !ok { if !ok {
slog.ErrorContext(w.ctx, "invalid payload for entity type", "entity_type", event.EntityType, "payload", event.Payload) slog.ErrorContext(w.ctx, "invalid payload for entity type", "entity_type", event.EntityType, "payload", event.Payload)
return return
} }
credentials := credsGetter.GetForgeCredentials()
switch event.Operation { switch event.Operation {
case dbCommon.UpdateOperation: case dbCommon.UpdateOperation:
slog.DebugContext(w.ctx, "got delete operation") slog.DebugContext(w.ctx, "got delete operation")
w.mux.Lock() w.mux.Lock()
defer w.mux.Unlock() defer w.mux.Unlock()
if w.Entity.Credentials.ID != credentials.ID { if w.Entity.Credentials.GetID() != credentials.GetID() {
// The channel is buffered. We may get an old update. If credentials get updated // The channel is buffered. We may get an old update. If credentials get updated
// immediately after they are swapped on the entity, we may still get an update // immediately after they are swapped on the entity, we may still get an update
// pushed to the channel before the filters are swapped. We can ignore the update. // pushed to the channel before the filters are swapped. We can ignore the update.

View file

@ -1,3 +1 @@
package pools package pools

View file

@ -52,7 +52,7 @@ type instanceManager struct {
helper providerHelper helper providerHelper
scaleSet params.ScaleSet scaleSet params.ScaleSet
scaleSetEntity params.GithubEntity scaleSetEntity params.ForgeEntity
deleteBackoff time.Duration deleteBackoff time.Duration
@ -120,14 +120,14 @@ func (i *instanceManager) incrementBackOff() {
} }
} }
func (i *instanceManager) getEntity() (params.GithubEntity, error) { func (i *instanceManager) getEntity() (params.ForgeEntity, error) {
entity, err := i.scaleSet.GetEntity() entity, err := i.scaleSet.GetEntity()
if err != nil { if err != nil {
return params.GithubEntity{}, fmt.Errorf("getting entity: %w", err) return params.ForgeEntity{}, fmt.Errorf("getting entity: %w", err)
} }
ghEntity, err := i.helper.GetGithubEntity(entity) ghEntity, err := i.helper.GetGithubEntity(entity)
if err != nil { if err != nil {
return params.GithubEntity{}, fmt.Errorf("getting entity: %w", err) return params.ForgeEntity{}, fmt.Errorf("getting entity: %w", err)
} }
return ghEntity, nil return ghEntity, nil
} }
@ -156,7 +156,7 @@ func (i *instanceManager) handleCreateInstanceInProvider(instance params.Instanc
bootstrapArgs := commonParams.BootstrapInstance{ bootstrapArgs := commonParams.BootstrapInstance{
Name: instance.Name, Name: instance.Name,
Tools: tools, Tools: tools,
RepoURL: entity.GithubURL(), RepoURL: entity.ForgeURL(),
MetadataURL: instance.MetadataURL, MetadataURL: instance.MetadataURL,
CallbackURL: instance.CallbackURL, CallbackURL: instance.CallbackURL,
InstanceToken: token, InstanceToken: token,
@ -167,7 +167,7 @@ func (i *instanceManager) handleCreateInstanceInProvider(instance params.Instanc
ExtraSpecs: i.scaleSet.ExtraSpecs, ExtraSpecs: i.scaleSet.ExtraSpecs,
// This is temporary. We need to extend providers to know about scale sets. // This is temporary. We need to extend providers to know about scale sets.
PoolID: i.pseudoPoolID(), PoolID: i.pseudoPoolID(),
CACertBundle: entity.Credentials.CABundle, CACertBundle: entity.Credentials.CABundle(),
GitHubRunnerGroup: i.scaleSet.GitHubRunnerGroup, GitHubRunnerGroup: i.scaleSet.GitHubRunnerGroup,
JitConfigEnabled: true, JitConfigEnabled: true,
} }

View file

@ -14,7 +14,7 @@ type providerHelper interface {
InstanceTokenGetter() auth.InstanceTokenGetter InstanceTokenGetter() auth.InstanceTokenGetter
updateArgsFromProviderInstance(instanceName string, providerInstance commonParams.ProviderInstance) (params.Instance, error) updateArgsFromProviderInstance(instanceName string, providerInstance commonParams.ProviderInstance) (params.Instance, error)
GetControllerInfo() (params.ControllerInfo, error) GetControllerInfo() (params.ControllerInfo, error)
GetGithubEntity(entity params.GithubEntity) (params.GithubEntity, error) GetGithubEntity(entity params.ForgeEntity) (params.ForgeEntity, error)
} }
func (p *Provider) updateArgsFromProviderInstance(instanceName string, providerInstance commonParams.ProviderInstance) (params.Instance, error) { func (p *Provider) updateArgsFromProviderInstance(instanceName string, providerInstance commonParams.ProviderInstance) (params.Instance, error) {
@ -71,10 +71,10 @@ func (p *Provider) InstanceTokenGetter() auth.InstanceTokenGetter {
return p.tokenGetter return p.tokenGetter
} }
func (p *Provider) GetGithubEntity(entity params.GithubEntity) (params.GithubEntity, error) { func (p *Provider) GetGithubEntity(entity params.ForgeEntity) (params.ForgeEntity, error) {
ghEntity, err := p.store.GetGithubEntity(p.ctx, entity.EntityType, entity.ID) ghEntity, err := p.store.GetForgeEntity(p.ctx, entity.EntityType, entity.ID)
if err != nil { if err != nil {
return params.GithubEntity{}, fmt.Errorf("getting github entity: %w", err) return params.ForgeEntity{}, fmt.Errorf("getting github entity: %w", err)
} }
return ghEntity, nil return ghEntity, nil

View file

@ -15,7 +15,7 @@ import (
garmUtil "github.com/cloudbase/garm/util" garmUtil "github.com/cloudbase/garm/util"
) )
func NewController(ctx context.Context, store dbCommon.Store, entity params.GithubEntity, providers map[string]common.Provider) (*Controller, error) { func NewController(ctx context.Context, store dbCommon.Store, entity params.ForgeEntity, providers map[string]common.Provider) (*Controller, error) {
consumerID := fmt.Sprintf("scaleset-controller-%s", entity.String()) consumerID := fmt.Sprintf("scaleset-controller-%s", entity.String())
ctx = garmUtil.WithSlogContext( ctx = garmUtil.WithSlogContext(
@ -57,7 +57,7 @@ type Controller struct {
ScaleSets map[uint]*scaleSet ScaleSets map[uint]*scaleSet
Entity params.GithubEntity Entity params.ForgeEntity
consumer dbCommon.Consumer consumer dbCommon.Consumer
store dbCommon.Store store dbCommon.Store

View file

@ -127,11 +127,11 @@ func (c *Controller) handleEntityEvent(event dbCommon.ChangePayload) {
var entityGetter params.EntityGetter var entityGetter params.EntityGetter
var ok bool var ok bool
switch c.Entity.EntityType { switch c.Entity.EntityType {
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
entityGetter, ok = event.Payload.(params.Repository) entityGetter, ok = event.Payload.(params.Repository)
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
entityGetter, ok = event.Payload.(params.Organization) entityGetter, ok = event.Payload.(params.Organization)
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
entityGetter, ok = event.Payload.(params.Enterprise) entityGetter, ok = event.Payload.(params.Enterprise)
} }
if !ok { if !ok {

View file

@ -60,11 +60,11 @@ func (w *Worker) recordOrUpdateJob(job params.ScaleSetJobMessage) error {
jobParams.RunnerGroupName = w.scaleSet.GitHubRunnerGroup jobParams.RunnerGroupName = w.scaleSet.GitHubRunnerGroup
switch entity.EntityType { switch entity.EntityType {
case params.GithubEntityTypeEnterprise: case params.ForgeEntityTypeEnterprise:
jobParams.EnterpriseID = &asUUID jobParams.EnterpriseID = &asUUID
case params.GithubEntityTypeRepository: case params.ForgeEntityTypeRepository:
jobParams.RepoID = &asUUID jobParams.RepoID = &asUUID
case params.GithubEntityTypeOrganization: case params.ForgeEntityTypeOrganization:
jobParams.OrgID = &asUUID jobParams.OrgID = &asUUID
default: default:
return fmt.Errorf("unknown entity type: %s", entity.EntityType) return fmt.Errorf("unknown entity type: %s", entity.EntityType)

View file

@ -6,7 +6,7 @@ import (
"github.com/cloudbase/garm/params" "github.com/cloudbase/garm/params"
) )
func composeControllerWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFilterFunc { func composeControllerWatcherFilters(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return watcher.WithAny( return watcher.WithAny(
watcher.WithAll( watcher.WithAll(
watcher.WithEntityScaleSetFilter(entity), watcher.WithEntityScaleSetFilter(entity),