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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ type InstanceJWTClaims struct {
Name string `json:"name"`
PoolID string `json:"provider_id"`
// Scope is either repository or organization
Scope params.GithubEntityType `json:"scope"`
Scope params.ForgeEntityType `json:"scope"`
// Entity is the repo or org name
Entity string `json:"entity"`
CreateAttempt int `json:"create_attempt"`
@ -60,7 +60,7 @@ type instanceToken struct {
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
// 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.

View file

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

View file

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

View file

@ -19,7 +19,7 @@ func init() {
type GithubEntityTools struct {
updatedAt time.Time
entity params.GithubEntity
entity params.ForgeEntity
tools []commonParams.RunnerApplicationDownload
}
@ -44,7 +44,7 @@ func (g *GithubToolsCache) Get(entityID string) ([]commonParams.RunnerApplicatio
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()
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)
}

View file

@ -54,7 +54,7 @@ CreateGithubEndpointOK describes a response with status code 200, with default h
GithubEndpoint
*/
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
@ -97,7 +97,7 @@ func (o *CreateGithubEndpointOK) String() string {
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
}

View file

@ -54,7 +54,7 @@ GetGithubEndpointOK describes a response with status code 200, with default head
GithubEndpoint
*/
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
@ -97,7 +97,7 @@ func (o *GetGithubEndpointOK) String() string {
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
}

View file

@ -54,7 +54,7 @@ ListGithubEndpointsOK describes a response with status code 200, with default he
GithubEndpoints
*/
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
@ -97,7 +97,7 @@ func (o *ListGithubEndpointsOK) String() string {
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
}

View file

@ -54,7 +54,7 @@ UpdateGithubEndpointOK describes a response with status code 200, with default h
GithubEndpoint
*/
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
@ -97,7 +97,7 @@ func (o *UpdateGithubEndpointOK) String() string {
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
}

View file

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

View file

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

View file

@ -15,7 +15,7 @@ type Store struct {
}
// 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)
if len(ret) == 0 {
@ -23,7 +23,7 @@ func (_m *Store) AddEntityEvent(ctx context.Context, entity params.GithubEntity,
}
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)
} else {
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
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)
if len(ret) == 0 {
@ -134,16 +134,16 @@ func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -162,16 +162,16 @@ func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
panic("no return value specified for CreateGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
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)
}
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)
} 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 {
@ -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
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)
if len(ret) == 0 {
@ -449,7 +449,7 @@ func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntit
}
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)
} else {
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
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)
if len(ret) == 0 {
@ -630,10 +630,10 @@ func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params
var r0 []params.Pool
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -744,16 +744,16 @@ func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity,
var r0 params.Pool
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
panic("no return value specified for GetGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
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)
}
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)
} 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 {
@ -846,26 +846,26 @@ func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.Git
return r0, r1
}
// GetGithubEntity 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) {
// GetForgeEntity provides a mock function with given fields: _a0, entityType, entityID
func (_m *Store) GetForgeEntity(_a0 context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error) {
ret := _m.Called(_a0, entityType, entityID)
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
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)
}
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)
} 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)
} else {
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
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)
if len(ret) == 0 {
@ -1388,10 +1388,10 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
var r0 []params.Instance
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -1418,10 +1418,10 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
var r0 []params.Job
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -1448,10 +1448,10 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
var r0 []params.Pool
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -1478,10 +1478,10 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
var r0 []params.ScaleSet
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)
}
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)
} else {
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)
} else {
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
func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) {
func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for ListGithubEndpoints")
}
var r0 []params.GithubEndpoint
var r0 []params.ForgeEndpoint
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)
}
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)
} else {
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
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)
if len(ret) == 0 {
@ -1874,16 +1874,16 @@ func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
@ -1902,16 +1902,16 @@ func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet
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)
}
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)
} else {
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)
} else {
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
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)
if len(ret) == 0 {
panic("no return value specified for UpdateGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
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)
}
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)
} 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 {

View file

@ -21,10 +21,10 @@ import (
)
type GithubEndpointStore interface {
CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error)
GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error)
ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error)
UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error)
CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error)
GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error)
ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error)
UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error)
DeleteGithubEndpoint(ctx context.Context, name string) error
}
@ -76,7 +76,7 @@ type PoolStore interface {
PoolInstanceCount(ctx context.Context, poolID string) (int64, 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 {
@ -107,7 +107,7 @@ type InstanceStore interface {
type JobsStore interface {
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)
ListAllJobs(ctx context.Context) ([]params.Job, error)
@ -121,13 +121,13 @@ type JobsStore interface {
}
type EntityPoolStore interface {
CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error)
GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error)
DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error
UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error)
CreateEntityPool(ctx context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (params.Pool, error)
GetEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error)
DeleteEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) 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)
ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error)
ListEntityPools(ctx context.Context, entity params.ForgeEntity) ([]params.Pool, error)
ListEntityInstances(ctx context.Context, entity params.ForgeEntity) ([]params.Instance, error)
}
type ControllerStore interface {
@ -138,9 +138,9 @@ type ControllerStore interface {
type ScaleSetsStore interface {
ListAllScaleSets(ctx context.Context) ([]params.ScaleSet, error)
CreateEntityScaleSet(_ context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error)
ListEntityScaleSets(_ context.Context, entity params.GithubEntity) ([]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)
CreateEntityScaleSet(_ context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error)
ListEntityScaleSets(_ context.Context, entity params.ForgeEntity) ([]params.ScaleSet, 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)
DeleteScaleSetByID(ctx context.Context, scaleSetID uint) (err error)
SetScaleSetLastMessageID(ctx context.Context, scaleSetID uint, lastMessageID int64) error
@ -170,6 +170,6 @@ type Store interface {
ControllerInfo() (params.ControllerInfo, error)
InitController() (params.ControllerInfo, error)
GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error)
AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error
GetForgeEntity(_ context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, 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
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *EnterpriseTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -490,9 +490,9 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolMissingTags() {
}
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -637,9 +637,9 @@ func (s *EnterpriseTestSuite) TestListEnterprisePools() {
}
func (s *EnterpriseTestSuite) TestListEnterprisePoolsInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -662,9 +662,9 @@ func (s *EnterpriseTestSuite) TestGetEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestGetEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -688,9 +688,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +743,9 @@ func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
}
func (s *EnterpriseTestSuite) TestListEnterpriseInstancesInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -771,9 +771,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, 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
}
func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.GithubEndpoint, error) {
return params.GithubEndpoint{
func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.ForgeEndpoint, error) {
return params.ForgeEndpoint{
Name: ep.Name,
Description: ep.Description,
APIBaseURL: ep.APIBaseURL,
@ -115,7 +115,7 @@ func getUIDFromContext(ctx context.Context) (uuid.UUID, error) {
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() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.CreateOperation, ghEndpoint)
@ -141,23 +141,23 @@ func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.Creat
return 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)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
}
return ghEndpoint, nil
}
func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEndpoint, error) {
func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.ForgeEndpoint, error) {
var endpoints []GithubEndpoint
err := s.conn.Find(&endpoints).Error
if err != nil {
return nil, errors.Wrap(err, "fetching github endpoints")
}
var ret []params.GithubEndpoint
var ret []params.ForgeEndpoint
for _, ep := range endpoints {
commonEp, err := s.sqlToCommonGithubEndpoint(ep)
if err != nil {
@ -168,9 +168,9 @@ func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEnd
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 {
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() {
@ -213,24 +213,24 @@ func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param
return 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)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
}
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
err := s.conn.Where("name = ?", name).First(&endpoint).Error
if err != nil {
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)
@ -243,7 +243,7 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
defer func() {
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 {
@ -329,9 +329,9 @@ func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.
var data []byte
var err error
switch param.AuthType {
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
data, err = s.marshalAndSeal(param.PAT)
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
data, err = s.marshalAndSeal(param.App)
default:
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 err error
switch creds.AuthType {
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
if param.PAT != nil {
data, err = s.marshalAndSeal(param.PAT)
}
@ -503,7 +503,7 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
if param.App != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot update app credentials for PAT")
}
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
if param.App != nil {
data, err = s.marshalAndSeal(param.App)
}

View file

@ -266,7 +266,7 @@ func (s *GithubTestSuite) TestCreateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -290,7 +290,7 @@ func (s *GithubTestSuite) TestCreateCredentialsFailsOnDuplicateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -320,7 +320,7 @@ func (s *GithubTestSuite) TestNormalUsersCanOnlySeeTheirOwnCredentialsAdminCanSe
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -376,7 +376,7 @@ func (s *GithubTestSuite) TestGetGithubCredentialsByNameReturnsOnlyCurrentUserCr
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -421,7 +421,7 @@ func (s *GithubTestSuite) TestGetGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -451,7 +451,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -478,7 +478,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentialsByNonAdminUser() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds4",
},
@ -523,7 +523,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -581,7 +581,7 @@ func (s *GithubTestSuite) TestUpdateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -616,7 +616,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -643,7 +643,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: "test-credsApp",
Description: "test credsApp",
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypeApp,
AuthType: params.ForgeAuthTypeApp,
App: params.GithubApp{
AppID: 1,
InstallationID: 2,
@ -688,7 +688,7 @@ func (s *GithubTestSuite) TestUpdateCredentialsFailsIfCredentialsAreOwnedByNonAd
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
@ -717,7 +717,7 @@ func (s *GithubTestSuite) TestAdminUserCanUpdateAnyGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
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)
}
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)
}
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)
}
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.
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)
if err != nil {
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)
switch entityType {
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
query = query.Where("org_id = ?", u)
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
query = query.Where("repo_id = ?", u)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
query = query.Where("enterprise_id = ?", u)
}

View file

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

View file

@ -55,7 +55,7 @@ type OrgTestSuite struct {
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *OrgTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -492,9 +492,9 @@ func (s *OrgTestSuite) TestCreateOrganizationPoolMissingTags() {
}
func (s *OrgTestSuite) TestCreateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -640,9 +640,9 @@ func (s *OrgTestSuite) TestListOrgPools() {
}
func (s *OrgTestSuite) TestListOrgPoolsInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -665,9 +665,9 @@ func (s *OrgTestSuite) TestGetOrganizationPool() {
}
func (s *OrgTestSuite) TestGetOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -691,9 +691,9 @@ func (s *OrgTestSuite) TestDeleteOrganizationPool() {
}
func (s *OrgTestSuite) TestDeleteOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -748,9 +748,9 @@ func (s *OrgTestSuite) TestListOrgInstances() {
}
func (s *OrgTestSuite) TestListOrgInstancesInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -776,9 +776,9 @@ func (s *OrgTestSuite) TestUpdateOrganizationPool() {
}
func (s *OrgTestSuite) TestUpdateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, 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
}
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 == "" {
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 entityField string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
entityField = repositoryFieldName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
entityField = organizationFieldName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
entityField = enterpriseFieldName
default:
@ -135,7 +135,7 @@ func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityT
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 {
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 fieldName string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
preloadEntity = "Repository"
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
preloadEntity = "Organization"
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
preloadEntity = "Enterprise"
default:
@ -184,7 +184,7 @@ func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntit
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 {
return nil, runnerErrors.NewBadRequestError("missing tags")
}
@ -195,11 +195,11 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
var fieldName string
switch poolType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
default:
return nil, fmt.Errorf("invalid poolType: %v", poolType)
@ -238,7 +238,7 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
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 {
return nil, runnerErrors.NewBadRequestError("missing tags")
}
@ -254,7 +254,7 @@ func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType par
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 {
return params.Pool{}, runnerErrors.NewBadRequestError("no tags specified")
}
@ -289,11 +289,11 @@ func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEn
}
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
newPool.RepoID = &entityID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
newPool.OrgID = &entityID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
newPool.EnterpriseID = &entityID
}
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)
}
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")
if err != nil {
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)
}
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)
if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
@ -363,11 +363,11 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
}
var fieldName string
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
default:
return fmt.Errorf("invalid entityType: %v", entity.EntityType)
@ -379,7 +379,7 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
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() {
if err == nil {
s.sendNotify(common.PoolEntityType, common.UpdateOperation, updatedPool)
@ -403,7 +403,7 @@ func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEn
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")
if err != nil {
return nil, errors.Wrap(err, "fetching pools")
@ -420,7 +420,7 @@ func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEnt
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")
if err != nil {
return nil, errors.Wrap(err, "fetching entity")

View file

@ -60,7 +60,7 @@ type RepoTestSuite struct {
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *RepoTestSuite) equalReposByName(expected, actual []params.Repository) {
@ -541,9 +541,9 @@ func (s *RepoTestSuite) TestCreateRepositoryPoolMissingTags() {
}
func (s *RepoTestSuite) TestCreateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -692,9 +692,9 @@ func (s *RepoTestSuite) TestListRepoPools() {
}
func (s *RepoTestSuite) TestListRepoPoolsInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -717,9 +717,9 @@ func (s *RepoTestSuite) TestGetRepositoryPool() {
}
func (s *RepoTestSuite) TestGetRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +743,9 @@ func (s *RepoTestSuite) TestDeleteRepositoryPool() {
}
func (s *RepoTestSuite) TestDeleteRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -799,9 +799,9 @@ func (s *RepoTestSuite) TestListRepoInstances() {
}
func (s *RepoTestSuite) TestListRepoInstancesInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -827,9 +827,9 @@ func (s *RepoTestSuite) TestUpdateRepositoryPool() {
}
func (s *RepoTestSuite) TestUpdateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, 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
}
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 {
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
newScaleSet.RepoID = &entityID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
newScaleSet.OrgID = &entityID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
newScaleSet.EnterpriseID = &entityID
}
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)
}
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 {
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 fieldName string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
preloadEntity = repositoryFieldName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
preloadEntity = organizationFieldName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
preloadEntity = enterpriseFieldName
default:
@ -173,7 +173,7 @@ func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubE
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)
if err != nil {
return nil, errors.Wrap(err, "fetching scale sets")
@ -190,7 +190,7 @@ func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.Githu
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() {
if err == nil {
s.sendNotify(common.ScaleSetEntityType, common.UpdateOperation, updatedScaleSet)
@ -225,7 +225,7 @@ func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.Gith
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 == "" {
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 entityField string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
entityField = "Repository"
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
entityField = "Organization"
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
entityField = "Enterprise"
default:

View file

@ -25,9 +25,9 @@ type ScaleSetsTestSuite struct {
repo params.Repository
enterprise params.Enterprise
orgEntity params.GithubEntity
repoEntity params.GithubEntity
enterpriseEntity params.GithubEntity
orgEntity params.ForgeEntity
repoEntity params.ForgeEntity
enterpriseEntity params.ForgeEntity
}
func (s *ScaleSetsTestSuite) SetupTest() {
@ -298,7 +298,7 @@ func (s *ScaleSetsTestSuite) TestScaleSetOperations() {
})
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().Contains(err.Error(), "missing entity id")
})

View file

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

View file

@ -546,18 +546,18 @@ func (s *sqlDatabase) getScaleSetByID(tx *gorm.DB, scaleSetID uint, preload ...s
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)
if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
}
var q *gorm.DB
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
q = tx.Model(&Repository{}).Where("id = ?", u)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
q = tx.Model(&Organization{}).Where("id = ?", u)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
q = tx.Model(&Enterprise{}).Where("id = ?", u)
default:
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)
}
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 err error
switch entityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ghEntity, err = s.GetEnterpriseByID(s.ctx, entityID)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
ghEntity, err = s.GetOrganizationByID(s.ctx, entityID)
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
ghEntity, err = s.GetRepositoryByID(s.ctx, entityID)
default:
return params.GithubEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
return params.ForgeEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
}
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()
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
}
@ -747,17 +747,17 @@ func (s *sqlDatabase) addEnterpriseEvent(ctx context.Context, entID string, even
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 {
return errors.Wrap(runnerErrors.ErrBadRequest, "max events cannot be 0")
}
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return s.addEnterpriseEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
default:
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
// supplied Github entity. This is useful when an entity worker wants to watch for changes
// 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 {
switch payload.EntityType {
case dbCommon.PoolEntityType:
@ -72,11 +72,11 @@ func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFu
return false
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
return pool.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
return pool.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return pool.EnterpriseID == ghEntity.ID
default:
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
// supplied Github entity. This is useful when an entity worker wants to watch for changes
// 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 {
switch payload.EntityType {
case dbCommon.ScaleSetEntityType:
@ -99,11 +99,11 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
return false
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
return scaleSet.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
return scaleSet.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return scaleSet.EnterpriseID == ghEntity.ID
default:
return false
@ -116,26 +116,26 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
// WithEntityFilter returns a filter function that filters payloads by entity.
// 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 {
if params.GithubEntityType(payload.EntityType) != entity.EntityType {
if params.ForgeEntityType(payload.EntityType) != entity.EntityType {
return false
}
var ent IDGetter
var ok bool
switch payload.EntityType {
case dbCommon.RepositoryEntityType:
if entity.EntityType != params.GithubEntityTypeRepository {
if entity.EntityType != params.ForgeEntityTypeRepository {
return false
}
ent, ok = payload.Payload.(params.Repository)
case dbCommon.OrganizationEntityType:
if entity.EntityType != params.GithubEntityTypeOrganization {
if entity.EntityType != params.ForgeEntityTypeOrganization {
return false
}
ent, ok = payload.Payload.(params.Organization)
case dbCommon.EnterpriseEntityType:
if entity.EntityType != params.GithubEntityTypeEnterprise {
if entity.EntityType != params.ForgeEntityTypeEnterprise {
return false
}
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 {
switch payload.EntityType {
case dbCommon.JobEntityType:
@ -159,15 +159,15 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
if job.RepoID != nil && job.RepoID.String() != ghEntity.ID {
return false
}
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
if job.OrgID != nil && job.OrgID.String() != ghEntity.ID {
return false
}
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
if job.EnterpriseID != nil && job.EnterpriseID.String() != ghEntity.ID {
return false
}
@ -183,16 +183,20 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
}
// 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 {
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
}
credsPayload, ok := payload.Payload.(params.GithubCredentials)
if !ok {
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",
Description: "test credentials",
Endpoint: "github.com",
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "bogus",
},
@ -971,7 +971,7 @@ func (s *WatcherStoreTestSuite) TestGithubEndpointWatcher() {
EntityType: common.GithubEndpointEntityType,
Operation: common.DeleteOperation,
// We only get the name of the deleted entity
Payload: params.GithubEndpoint{Name: ghEp.Name},
Payload: params.ForgeEndpoint{Name: ghEp.Name},
}, event)
case <-time.After(1 * time.Second):
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
}
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{
Name: "github.com",
Description: "github endpoint",
@ -110,11 +110,11 @@ func CreateDefaultGithubEndpoint(ctx context.Context, db common.Store, s *testin
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{
Name: credsName,
Description: "Test creds",
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
Endpoint: endpoint.Name,
PAT: params.GithubPAT{
OAuth2Token: "test-token",

View file

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

View file

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

View file

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

View file

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

View file

@ -10,30 +10,30 @@ import (
"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) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
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)
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
}
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) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
endpoint, err := r.store.GetGithubEndpoint(ctx, name)
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
@ -52,23 +52,23 @@ func (r *Runner) DeleteGithubEndpoint(ctx context.Context, name string) error {
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) {
return params.GithubEndpoint{}, runnerErrors.ErrUnauthorized
return params.ForgeEndpoint{}, runnerErrors.ErrUnauthorized
}
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)
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
}
func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) {
func (r *Runner) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
if !auth.IsAdmin(ctx) {
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")
return "", runnerErrors.ErrUnauthorized
}
var entity params.GithubEntity
var entity params.ForgeEntity
switch {
case instance.PoolID != "":
@ -96,11 +96,11 @@ func (r *Runner) GetRunnerServiceName(ctx context.Context) (string, error) {
tpl := "actions.runner.%s.%s"
var serviceName string
switch entity.EntityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
serviceName = fmt.Sprintf(tpl, entity.Owner, instance.Name)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
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)
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
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) {
return []params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil {
@ -320,9 +320,9 @@ func (r *Runner) UpdateOrgPool(ctx context.Context, orgID, poolID string, param
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: orgID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
instances, err := r.store.ListEntityInstances(ctx, entity)

View file

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

View file

@ -67,7 +67,7 @@ const (
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))
ghc, err := ghClient.Client(ctx, entity)
if err != nil {
@ -83,7 +83,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
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)
consumer, err := watcher.RegisterConsumer(
ctx, consumerID,
@ -120,7 +120,7 @@ func NewEntityPoolManager(ctx context.Context, entity params.GithubEntity, insta
type basePoolManager struct {
ctx context.Context
consumerID string
entity params.GithubEntity
entity params.ForgeEntity
ghcli common.GithubClient
controllerInfo params.ControllerInfo
instanceTokenGetter auth.InstanceTokenGetter
@ -877,7 +877,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
bootstrapArgs := commonParams.BootstrapInstance{
Name: instance.Name,
Tools: r.tools,
RepoURL: r.entity.GithubURL(),
RepoURL: r.entity.ForgeURL(),
MetadataURL: instance.MetadataURL,
CallbackURL: instance.CallbackURL,
InstanceToken: jwtToken,
@ -887,7 +887,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error
Image: pool.Image,
ExtraSpecs: pool.ExtraSpecs,
PoolID: instance.PoolID,
CACertBundle: r.entity.Credentials.CABundle,
CACertBundle: r.entity.Credentials.CABundle(),
GitHubRunnerGroup: instance.GitHubRunnerGroup,
JitConfigEnabled: hasJITConfig,
}
@ -981,11 +981,11 @@ func (r *basePoolManager) paramsWorkflowJobToParamsJob(job params.WorkflowJob) (
}
switch r.entity.EntityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
jobParams.EnterpriseID = &asUUID
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
jobParams.RepoID = &asUUID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
jobParams.OrgID = &asUUID
default:
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 {
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) {
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) {
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) {
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
}
func (s *stubGithubClient) GetEntity() params.GithubEntity {
return params.GithubEntity{}
func (s *stubGithubClient) GetEntity() params.ForgeEntity {
return params.ForgeEntity{}
}
func (s *stubGithubClient) GithubBaseURL() *url.URL {

View file

@ -119,7 +119,7 @@ func isManagedRunner(labels []string, controllerID string) bool {
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
// entity itself.
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.
watcher.WithEntityFilter(entity),
// 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)
type entityGetter interface {
GetEntity() (params.GithubEntity, error)
GetEntity() (params.ForgeEntity, error)
}
func (r *basePoolManager) handleControllerUpdateEvent(controllerInfo params.ControllerInfo) {
@ -38,7 +38,7 @@ func (r *basePoolManager) getClientOrStub() runnerCommon.GithubClient {
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)
if r.entity.ID != 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
}
credentialsUpdate := r.entity.Credentials.ID != entity.Credentials.ID
credentialsUpdate := r.entity.Credentials.GetID() != entity.Credentials.GetID()
defer func() {
slog.DebugContext(r.ctx, "deferred tools update", "credentials_update", credentialsUpdate)
if !credentialsUpdate {
@ -85,7 +85,7 @@ func (r *basePoolManager) handleEntityUpdate(entity params.GithubEntity, operati
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
// 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
@ -97,12 +97,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
// 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
// handleEntityUpdate.
shouldUpdateTools := r.entity.Credentials.ID == credentials.ID
shouldUpdateTools := r.entity.Credentials.GetID() == credentials.GetID()
defer func() {
if !shouldUpdateTools {
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 {
slog.ErrorContext(r.ctx, "failed to update tools", "error", err)
}
@ -110,12 +110,12 @@ func (r *basePoolManager) handleCredentialsUpdate(credentials params.GithubCrede
r.mux.Lock()
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()
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.ghcli = r.getClientOrStub()
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")
return
}
r.handleCredentialsUpdate(credentials)
r.handleCredentialsUpdate(credentials.GetForgeCredentials())
case common.ControllerEntityType:
controllerInfo, ok := event.Payload.(params.ControllerInfo)
if !ok {

View file

@ -49,7 +49,7 @@ type PoolTestSuite struct {
adminCtx context.Context
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
githubEndpoint params.ForgeEndpoint
}
func (s *PoolTestSuite) SetupTest() {
@ -75,9 +75,9 @@ func (s *PoolTestSuite) SetupTest() {
}
// create some pool objects in the database, for testing purposes
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: org.ID,
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
orgPools := []params.Pool{}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
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
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -300,9 +300,9 @@ func (r *Runner) ListRepoPools(ctx context.Context, repoID string) ([]params.Poo
if !auth.IsAdmin(ctx) {
return []params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pools, err := r.store.ListEntityPools(ctx, entity)
if err != nil {
@ -328,9 +328,9 @@ func (r *Runner) UpdateRepoPool(ctx context.Context, repoID, poolID string, para
return params.Pool{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
pool, err := r.store.GetEntityPool(ctx, entity, poolID)
if err != nil {
@ -362,9 +362,9 @@ func (r *Runner) ListRepoInstances(ctx context.Context, repoID string) ([]params
if !auth.IsAdmin(ctx) {
return nil, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: repoID,
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
instances, err := r.store.ListEntityInstances(ctx, entity)
if err != nil {

View file

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

View file

@ -602,10 +602,10 @@ func (r *Runner) validateHookBody(signature, secret string, body []byte) error {
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)
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)
@ -616,7 +616,7 @@ func (r *Runner) findEndpointForJob(job params.WorkflowJob) (params.GithubEndpoi
// that much about the performance of this function.
endpoints, err := r.store.ListGithubEndpoints(r.ctx)
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 {
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 {
@ -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.
entity, err = r.store.GetGithubEntity(ctx, entity.EntityType, entity.ID)
entity, err = r.store.GetForgeEntity(ctx, entity.EntityType, entity.ID)
if err != nil {
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")
}
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID)
entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil {
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")
}
entity, err := r.store.GetGithubEntity(ctx, paramEntity.EntityType, paramEntity.ID)
entity, err := r.store.GetForgeEntity(ctx, paramEntity.EntityType, paramEntity.ID)
if err != nil {
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
}
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) {
return params.ScaleSet{}, runnerErrors.ErrUnauthorized
}
@ -211,7 +211,7 @@ func (r *Runner) CreateEntityScaleSet(ctx context.Context, entityType params.Git
param.GitHubRunnerGroup = "Default"
}
entity, err := r.store.GetGithubEntity(ctx, entityType, entityID)
entity, err := r.store.GetForgeEntity(ctx, entityType, entityID)
if err != nil {
return params.ScaleSet{}, errors.Wrap(err, "getting entity")
}
@ -287,11 +287,11 @@ func (r *Runner) ListScaleSetInstances(ctx context.Context, scalesetID uint) ([]
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) {
return []params.ScaleSet{}, runnerErrors.ErrUnauthorized
}
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: entityID,
EntityType: entityType,
}

View file

@ -77,7 +77,7 @@ func updateGithubCredentials(apiCli *client.GarmAPI, apiAuthToken runtime.Client
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(
clientEndpoints.NewCreateGithubEndpointParams().WithBody(endpointParams),
apiAuthToken)
@ -87,7 +87,7 @@ func createGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAut
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(
clientEndpoints.NewListGithubEndpointsParams(),
apiAuthToken)
@ -97,7 +97,7 @@ func listGithubEndpoints(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAuth
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(
clientEndpoints.NewGetGithubEndpointParams().WithName(endpointName),
apiAuthToken)
@ -113,7 +113,7 @@ func deleteGithubEndpoint(apiCli *client.GarmAPI, apiAuthToken runtime.ClientAut
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(
clientEndpoints.NewUpdateGithubEndpointParams().WithName(endpointName).WithBody(endpointParams),
apiAuthToken)

View file

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

View file

@ -8,7 +8,7 @@ import (
"github.com/cloudbase/garm/params"
)
func checkEndpointParamsAreEqual(a, b params.GithubEndpoint) error {
func checkEndpointParamsAreEqual(a, b params.ForgeEndpoint) error {
if a.Name != b.Name {
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")
}
func (suite *GarmSuite) GetGithubEndpoint(name string) *params.GithubEndpoint {
func (suite *GarmSuite) GetGithubEndpoint(name string) *params.ForgeEndpoint {
t := suite.T()
t.Log("Get GitHub endpoint")
endpoint, err := getGithubEndpoint(suite.cli, suite.authToken, name)
@ -172,7 +172,7 @@ func (suite *GarmSuite) GetGithubEndpoint(name string) *params.GithubEndpoint {
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.Log("Create GitHub endpoint")
endpoint, err := createGithubEndpoint(suite.cli, suite.authToken, params)
@ -190,7 +190,7 @@ func (suite *GarmSuite) DeleteGithubEndpoint(name string) error {
return nil
}
func (suite *GarmSuite) ListGithubEndpoints() params.GithubEndpoints {
func (suite *GarmSuite) ListGithubEndpoints() params.ForgeEndpoints {
t := suite.T()
t.Log("List GitHub endpoints")
endpoints, err := listGithubEndpoints(suite.cli, suite.authToken)
@ -199,7 +199,7 @@ func (suite *GarmSuite) ListGithubEndpoints() params.GithubEndpoints {
return endpoints
}
func (suite *GarmSuite) createDummyEndpoint(name string) (*params.GithubEndpoint, error) {
func (suite *GarmSuite) createDummyEndpoint(name string) (*params.ForgeEndpoint, error) {
endpointParams := params.CreateGithubEndpointParams{
Name: name,
Description: "Dummy endpoint",

View file

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

View file

@ -22,6 +22,7 @@ import (
"log/slog"
"net/http"
"net/url"
"strings"
"github.com/google/go-github/v71/github"
"github.com/pkg/errors"
@ -39,7 +40,7 @@ type githubClient struct {
enterprise *github.EnterpriseService
rateLimit *github.RateLimitService
entity params.GithubEntity
entity params.ForgeEntity
cli *github.Client
}
@ -57,9 +58,9 @@ func (g *githubClient) ListEntityHooks(ctx context.Context, opts *github.ListOpt
}
}()
switch g.entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.ListRunners(ctx, g.entity.Owner, opts)
default:
return nil, nil, errors.New("invalid entity type")
@ -214,11 +215,11 @@ func (g *githubClient) ListEntityRunnerApplicationDownloads(ctx context.Context)
}()
switch g.entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.ListRunnerApplicationDownloads(ctx, g.entity.Owner)
default:
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 {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
response, err = g.enterprise.RemoveRunner(ctx, g.entity.Owner, runnerID)
default:
return errors.New("invalid entity type")
@ -313,11 +314,11 @@ func (g *githubClient) CreateEntityRegistrationToken(ctx context.Context) (*gith
}()
switch g.entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.CreateRegistrationToken(ctx, g.entity.Owner)
default:
return nil, nil, errors.New("invalid entity type")
@ -326,7 +327,7 @@ func (g *githubClient) CreateEntityRegistrationToken(ctx context.Context) (*gith
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{
ListOptions: github.ListOptions{
PerPage: 100,
@ -362,7 +363,7 @@ func (g *githubClient) getOrganizationRunnerGroupIDByName(ctx context.Context, e
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{
ListOptions: github.ListOptions{
PerPage: 100,
@ -405,9 +406,9 @@ func (g *githubClient) GetEntityJITConfig(ctx context.Context, instance string,
if pool.GitHubRunnerGroup != "" {
switch g.entity.EntityType {
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
rgID, err = g.getOrganizationRunnerGroupIDByName(ctx, g.entity, pool.GitHubRunnerGroup)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
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
switch g.entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
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)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ret, response, err = g.enterprise.GenerateEnterpriseJITConfig(ctx, g.entity.Owner, &req)
}
if err != nil {
@ -482,7 +483,7 @@ func (g *githubClient) RateLimit(ctx context.Context) (*github.RateLimits, error
return limits, nil
}
func (g *githubClient) GetEntity() params.GithubEntity {
func (g *githubClient) GetEntity() params.ForgeEntity {
return g.entity
}
@ -514,8 +515,49 @@ func NewRateLimitClient(ctx context.Context, credentials params.GithubCredential
return cli, nil
}
func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
// func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
func withGiteaURLs(client *github.Client, apiBaseURL, uploadBaseURL string) (*github.Client, 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)
if err != nil {
return nil, errors.Wrap(err, "fetching http client")
@ -523,11 +565,17 @@ func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClien
slog.DebugContext(
ctx, "creating client for entity",
"entity", entity.String(), "base_url", entity.Credentials.APIBaseURL,
"upload_url", entity.Credentials.UploadBaseURL)
"entity", entity.String(), "base_url", entity.Credentials.APIBaseURL(),
"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 {
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()
body := params.ActionsServiceAdminInfoRequest{
URL: entity.GithubURL(),
URL: entity.ForgeURL(),
RunnerEvent: "register",
}

View file

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

View file

@ -16,7 +16,7 @@ import (
"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{
ctx: ctx,
entity: entity,
@ -27,7 +27,7 @@ func newToolsUpdater(ctx context.Context, entity params.GithubEntity) *toolsUpda
type toolsUpdater struct {
ctx context.Context
entity params.GithubEntity
entity params.ForgeEntity
tools []commonParams.RunnerApplicationDownload
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(
watcher.WithAll(
watcher.WithEntityFilter(entity),
@ -39,7 +39,7 @@ func composeWorkerWatcherFilters(entity params.GithubEntity) dbCommon.PayloadFil
),
// Watch for credentials updates.
watcher.WithAll(
watcher.WithGithubCredentialsFilter(entity.Credentials),
watcher.WithForgeCredentialsFilter(entity.Credentials),
watcher.WithOperationTypeFilter(dbCommon.UpdateOperation),
),
)

View file

@ -7,6 +7,8 @@ import (
"sync"
"time"
"golang.org/x/sync/errgroup"
"github.com/cloudbase/garm/cache"
dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/database/watcher"
@ -16,10 +18,9 @@ import (
"github.com/cloudbase/garm/util/github"
"github.com/cloudbase/garm/util/github/scalesets"
"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())
ctx = garmUtil.WithSlogContext(
@ -43,7 +44,7 @@ type Worker struct {
store dbCommon.Store
ghCli common.GithubClient
Entity params.GithubEntity
Entity params.ForgeEntity
providers map[string]common.Provider
scaleSetController *scaleset.Controller

View file

@ -44,7 +44,7 @@ func (w *Worker) handleEntityEventPayload(event dbCommon.ChangePayload) {
defer w.mux.Unlock()
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
// filters.
w.consumer.SetFilters(composeWorkerWatcherFilters(entity))
@ -63,18 +63,29 @@ func (w *Worker) handleEntityEventPayload(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 {
slog.ErrorContext(w.ctx, "invalid payload for entity type", "entity_type", event.EntityType, "payload", event.Payload)
return
}
credentials := credsGetter.GetForgeCredentials()
switch event.Operation {
case dbCommon.UpdateOperation:
slog.DebugContext(w.ctx, "got delete operation")
w.mux.Lock()
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
// 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.

View file

@ -1,3 +1 @@
package pools

View file

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

View file

@ -14,7 +14,7 @@ type providerHelper interface {
InstanceTokenGetter() auth.InstanceTokenGetter
updateArgsFromProviderInstance(instanceName string, providerInstance commonParams.ProviderInstance) (params.Instance, 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) {
@ -71,10 +71,10 @@ func (p *Provider) InstanceTokenGetter() auth.InstanceTokenGetter {
return p.tokenGetter
}
func (p *Provider) GetGithubEntity(entity params.GithubEntity) (params.GithubEntity, error) {
ghEntity, err := p.store.GetGithubEntity(p.ctx, entity.EntityType, entity.ID)
func (p *Provider) GetGithubEntity(entity params.ForgeEntity) (params.ForgeEntity, error) {
ghEntity, err := p.store.GetForgeEntity(p.ctx, entity.EntityType, entity.ID)
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

View file

@ -15,7 +15,7 @@ import (
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())
ctx = garmUtil.WithSlogContext(
@ -57,7 +57,7 @@ type Controller struct {
ScaleSets map[uint]*scaleSet
Entity params.GithubEntity
Entity params.ForgeEntity
consumer dbCommon.Consumer
store dbCommon.Store

View file

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

View file

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

View file

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