Merge pull request #124 from gabriel-samfira/fix-entity-update
Fix entity update
This commit is contained in:
commit
3fe5d510fe
18 changed files with 445 additions and 102 deletions
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -28,6 +28,20 @@ func (_m *Store) AddInstanceEvent(ctx context.Context, instanceID string, event
|
|||
return r0
|
||||
}
|
||||
|
||||
// BreakLockJobIsQueued provides a mock function with given fields: ctx, jobID
|
||||
func (_m *Store) BreakLockJobIsQueued(ctx context.Context, jobID int64) error {
|
||||
ret := _m.Called(ctx, jobID)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
|
||||
r0 = rf(ctx, jobID)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// ControllerInfo provides a mock function with given fields:
|
||||
func (_m *Store) ControllerInfo() (params.ControllerInfo, error) {
|
||||
ret := _m.Called()
|
||||
|
|
@ -124,6 +138,30 @@ func (_m *Store) CreateInstance(ctx context.Context, poolID string, param params
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateOrUpdateJob provides a mock function with given fields: ctx, job
|
||||
func (_m *Store) CreateOrUpdateJob(ctx context.Context, job params.Job) (params.Job, error) {
|
||||
ret := _m.Called(ctx, job)
|
||||
|
||||
var r0 params.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Job) (params.Job, error)); ok {
|
||||
return rf(ctx, job)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Job) params.Job); ok {
|
||||
r0 = rf(ctx, job)
|
||||
} else {
|
||||
r0 = ret.Get(0).(params.Job)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.Job) error); ok {
|
||||
r1 = rf(ctx, job)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// CreateOrganization provides a mock function with given fields: ctx, name, credentialsName, webhookSecret
|
||||
func (_m *Store) CreateOrganization(ctx context.Context, name string, credentialsName string, webhookSecret string) (params.Organization, error) {
|
||||
ret := _m.Called(ctx, name, credentialsName, webhookSecret)
|
||||
|
|
@ -244,6 +282,20 @@ func (_m *Store) CreateUser(ctx context.Context, user params.NewUserParams) (par
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// DeleteCompletedJobs provides a mock function with given fields: ctx
|
||||
func (_m *Store) DeleteCompletedJobs(ctx context.Context) error {
|
||||
ret := _m.Called(ctx)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context) error); ok {
|
||||
r0 = rf(ctx)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// DeleteEnterprise provides a mock function with given fields: ctx, enterpriseID
|
||||
func (_m *Store) DeleteEnterprise(ctx context.Context, enterpriseID string) error {
|
||||
ret := _m.Called(ctx, enterpriseID)
|
||||
|
|
@ -286,6 +338,20 @@ func (_m *Store) DeleteInstance(ctx context.Context, poolID string, instanceName
|
|||
return r0
|
||||
}
|
||||
|
||||
// DeleteJob provides a mock function with given fields: ctx, jobID
|
||||
func (_m *Store) DeleteJob(ctx context.Context, jobID int64) error {
|
||||
ret := _m.Called(ctx, jobID)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) error); ok {
|
||||
r0 = rf(ctx, jobID)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// DeleteOrganization provides a mock function with given fields: ctx, orgID
|
||||
func (_m *Store) DeleteOrganization(ctx context.Context, orgID string) error {
|
||||
ret := _m.Called(ctx, orgID)
|
||||
|
|
@ -404,6 +470,32 @@ func (_m *Store) FindOrganizationPoolByTags(ctx context.Context, orgID string, t
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// FindPoolsMatchingAllTags provides a mock function with given fields: ctx, entityType, entityID, tags
|
||||
func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params.PoolType, entityID string, tags []string) ([]params.Pool, error) {
|
||||
ret := _m.Called(ctx, entityType, entityID, tags)
|
||||
|
||||
var r0 []params.Pool
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.PoolType, string, []string) ([]params.Pool, error)); ok {
|
||||
return rf(ctx, entityType, entityID, tags)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.PoolType, string, []string) []params.Pool); ok {
|
||||
r0 = rf(ctx, entityType, entityID, tags)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]params.Pool)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.PoolType, string, []string) error); ok {
|
||||
r1 = rf(ctx, entityType, entityID, tags)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// FindRepositoryPoolByTags provides a mock function with given fields: ctx, repoID, tags
|
||||
func (_m *Store) FindRepositoryPoolByTags(ctx context.Context, repoID string, tags []string) (params.Pool, error) {
|
||||
ret := _m.Called(ctx, repoID, tags)
|
||||
|
|
@ -524,6 +616,30 @@ func (_m *Store) GetInstanceByName(ctx context.Context, instanceName string) (pa
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// GetJobByID provides a mock function with given fields: ctx, jobID
|
||||
func (_m *Store) GetJobByID(ctx context.Context, jobID int64) (params.Job, error) {
|
||||
ret := _m.Called(ctx, jobID)
|
||||
|
||||
var r0 params.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) (params.Job, error)); ok {
|
||||
return rf(ctx, jobID)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64) params.Job); ok {
|
||||
r0 = rf(ctx, jobID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(params.Job)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
|
||||
r1 = rf(ctx, jobID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetOrganization provides a mock function with given fields: ctx, name
|
||||
func (_m *Store) GetOrganization(ctx context.Context, name string) (params.Organization, error) {
|
||||
ret := _m.Called(ctx, name)
|
||||
|
|
@ -828,6 +944,32 @@ func (_m *Store) ListAllInstances(ctx context.Context) ([]params.Instance, error
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllJobs provides a mock function with given fields: ctx
|
||||
func (_m *Store) ListAllJobs(ctx context.Context) ([]params.Job, error) {
|
||||
ret := _m.Called(ctx)
|
||||
|
||||
var r0 []params.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context) ([]params.Job, error)); ok {
|
||||
return rf(ctx)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context) []params.Job); ok {
|
||||
r0 = rf(ctx)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]params.Job)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
|
||||
r1 = rf(ctx)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ListAllPools provides a mock function with given fields: ctx
|
||||
func (_m *Store) ListAllPools(ctx context.Context) ([]params.Pool, error) {
|
||||
ret := _m.Called(ctx)
|
||||
|
|
@ -932,6 +1074,32 @@ func (_m *Store) ListEnterprises(ctx context.Context) ([]params.Enterprise, erro
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// ListEntityJobsByStatus provides a mock function with given fields: ctx, entityType, entityID, status
|
||||
func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.PoolType, entityID string, status params.JobStatus) ([]params.Job, error) {
|
||||
ret := _m.Called(ctx, entityType, entityID, status)
|
||||
|
||||
var r0 []params.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.PoolType, string, params.JobStatus) ([]params.Job, error)); ok {
|
||||
return rf(ctx, entityType, entityID, status)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.PoolType, string, params.JobStatus) []params.Job); ok {
|
||||
r0 = rf(ctx, entityType, entityID, status)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]params.Job)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.PoolType, string, params.JobStatus) error); ok {
|
||||
r1 = rf(ctx, entityType, entityID, status)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ListInstanceEvents provides a mock function with given fields: ctx, instanceID, eventType, eventLevel
|
||||
func (_m *Store) ListInstanceEvents(ctx context.Context, instanceID string, eventType params.EventType, eventLevel params.EventLevel) ([]params.StatusMessage, error) {
|
||||
ret := _m.Called(ctx, instanceID, eventType, eventLevel)
|
||||
|
|
@ -958,6 +1126,32 @@ func (_m *Store) ListInstanceEvents(ctx context.Context, instanceID string, even
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// ListJobsByStatus provides a mock function with given fields: ctx, status
|
||||
func (_m *Store) ListJobsByStatus(ctx context.Context, status params.JobStatus) ([]params.Job, error) {
|
||||
ret := _m.Called(ctx, status)
|
||||
|
||||
var r0 []params.Job
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.JobStatus) ([]params.Job, error)); ok {
|
||||
return rf(ctx, status)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.JobStatus) []params.Job); ok {
|
||||
r0 = rf(ctx, status)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]params.Job)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.JobStatus) error); ok {
|
||||
r1 = rf(ctx, status)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// ListOrgInstances provides a mock function with given fields: ctx, orgID
|
||||
func (_m *Store) ListOrgInstances(ctx context.Context, orgID string) ([]params.Instance, error) {
|
||||
ret := _m.Called(ctx, orgID)
|
||||
|
|
@ -1140,6 +1334,20 @@ func (_m *Store) ListRepositories(ctx context.Context) ([]params.Repository, err
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// LockJob provides a mock function with given fields: ctx, jobID, entityID
|
||||
func (_m *Store) LockJob(ctx context.Context, jobID int64, entityID string) error {
|
||||
ret := _m.Called(ctx, jobID, entityID)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok {
|
||||
r0 = rf(ctx, jobID, entityID)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// PoolInstanceCount provides a mock function with given fields: ctx, poolID
|
||||
func (_m *Store) PoolInstanceCount(ctx context.Context, poolID string) (int64, error) {
|
||||
ret := _m.Called(ctx, poolID)
|
||||
|
|
@ -1164,6 +1372,20 @@ func (_m *Store) PoolInstanceCount(ctx context.Context, poolID string) (int64, e
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// UnlockJob provides a mock function with given fields: ctx, jobID, entityID
|
||||
func (_m *Store) UnlockJob(ctx context.Context, jobID int64, entityID string) error {
|
||||
ret := _m.Called(ctx, jobID, entityID)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, int64, string) error); ok {
|
||||
r0 = rf(ctx, jobID, entityID)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// UpdateEnterprise provides a mock function with given fields: ctx, enterpriseID, param
|
||||
func (_m *Store) UpdateEnterprise(ctx context.Context, enterpriseID string, param params.UpdateEntityParams) (params.Enterprise, error) {
|
||||
ret := _m.Called(ctx, enterpriseID, param)
|
||||
|
|
@ -1356,13 +1578,12 @@ func (_m *Store) UpdateUser(ctx context.Context, user string, param params.Updat
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewStore interface {
|
||||
// NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewStore(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewStore creates a new instance of Store. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewStore(t mockConstructorTestingTNewStore) *Store {
|
||||
}) *Store {
|
||||
mock := &Store{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -402,7 +402,8 @@ type Provider struct {
|
|||
}
|
||||
|
||||
type UpdatePoolStateParams struct {
|
||||
WebhookSecret string
|
||||
WebhookSecret string
|
||||
InternalConfig *Internal
|
||||
}
|
||||
|
||||
type PoolManagerStatus struct {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -311,13 +311,12 @@ func (_m *GithubClient) RemoveRunner(ctx context.Context, owner string, repo str
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewGithubClient interface {
|
||||
// NewGithubClient creates a new instance of GithubClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewGithubClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewGithubClient creates a new instance of GithubClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewGithubClient(t mockConstructorTestingTNewGithubClient) *GithubClient {
|
||||
}) *GithubClient {
|
||||
mock := &GithubClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -145,13 +145,12 @@ func (_m *GithubEnterpriseClient) RemoveRunner(ctx context.Context, enterprise s
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewGithubEnterpriseClient interface {
|
||||
// NewGithubEnterpriseClient creates a new instance of GithubEnterpriseClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewGithubEnterpriseClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewGithubEnterpriseClient creates a new instance of GithubEnterpriseClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewGithubEnterpriseClient(t mockConstructorTestingTNewGithubEnterpriseClient) *GithubEnterpriseClient {
|
||||
}) *GithubEnterpriseClient {
|
||||
mock := &GithubEnterpriseClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -162,13 +162,12 @@ func (_m *PoolManager) WebhookSecret() string {
|
|||
return r0
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewPoolManager interface {
|
||||
// NewPoolManager creates a new instance of PoolManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewPoolManager(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewPoolManager creates a new instance of PoolManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewPoolManager(t mockConstructorTestingTNewPoolManager) *PoolManager {
|
||||
}) *PoolManager {
|
||||
mock := &PoolManager{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -158,13 +158,12 @@ func (_m *Provider) Stop(ctx context.Context, instance string, force bool) error
|
|||
return r0
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewProvider interface {
|
||||
// NewProvider creates a new instance of Provider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewProvider(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewProvider creates a new instance of Provider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewProvider(t mockConstructorTestingTNewProvider) *Provider {
|
||||
}) *Provider {
|
||||
mock := &Provider{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -169,21 +169,12 @@ func (r *Runner) UpdateEnterprise(ctx context.Context, enterpriseID string, para
|
|||
return params.Enterprise{}, errors.Wrap(err, "updating enterprise")
|
||||
}
|
||||
|
||||
poolMgr, err := r.poolManagerCtrl.GetEnterprisePoolManager(enterprise)
|
||||
poolMgr, err := r.poolManagerCtrl.UpdateEnterprisePoolManager(r.ctx, enterprise)
|
||||
if err != nil {
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: enterprise.WebhookSecret,
|
||||
}
|
||||
// stop the pool mgr
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return params.Enterprise{}, errors.Wrap(err, "updating enterprise pool manager")
|
||||
}
|
||||
} else {
|
||||
if _, err := r.poolManagerCtrl.CreateEnterprisePoolManager(r.ctx, enterprise, r.providers, r.store); err != nil {
|
||||
return params.Enterprise{}, errors.Wrap(err, "creating enterprise pool manager")
|
||||
}
|
||||
return params.Enterprise{}, fmt.Errorf("failed to update enterprise pool manager: %w", err)
|
||||
}
|
||||
|
||||
enterprise.PoolManagerStatus = poolMgr.Status()
|
||||
return enterprise, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolMgrFailed() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestUpdateEnterprise() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetEnterprisePoolManager", mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateEnterprisePoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Enterprise"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateEnterprisePoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrMock.On("Status").Return(params.PoolManagerStatus{IsRunning: true}, nil)
|
||||
|
||||
org, err := s.Runner.UpdateEnterprise(s.Fixtures.AdminContext, s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
|
|
@ -317,25 +317,21 @@ func (s *EnterpriseTestSuite) TestUpdateEnterpriseInvalidCreds() {
|
|||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetEnterprisePoolManager", mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrMock.On("RefreshState", s.Fixtures.UpdatePoolStateParams).Return(s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateEnterprisePoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateEnterprise(s.Fixtures.AdminContext, s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("updating enterprise pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
s.Require().Equal(fmt.Sprintf("failed to update enterprise pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestUpdateEnterpriseCreateEnterprisePoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetEnterprisePoolManager", mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateEnterprisePoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Enterprise"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateEnterprisePoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Enterprise")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateEnterprise(s.Fixtures.AdminContext, s.Fixtures.StoreEnterprises["test-enterprise-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("creating enterprise pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
s.Require().Equal(fmt.Sprintf("failed to update enterprise pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *EnterpriseTestSuite) TestCreateEnterprisePool() {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
|
||||
type RepoPoolManager interface {
|
||||
CreateRepoPoolManager(ctx context.Context, repo params.Repository, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error)
|
||||
UpdateRepoPoolManager(ctx context.Context, repo params.Repository) (common.PoolManager, error)
|
||||
GetRepoPoolManager(repo params.Repository) (common.PoolManager, error)
|
||||
DeleteRepoPoolManager(repo params.Repository) error
|
||||
GetRepoPoolManagers() (map[string]common.PoolManager, error)
|
||||
|
|
@ -31,6 +32,7 @@ type RepoPoolManager interface {
|
|||
|
||||
type OrgPoolManager interface {
|
||||
CreateOrgPoolManager(ctx context.Context, org params.Organization, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error)
|
||||
UpdateOrgPoolManager(ctx context.Context, org params.Organization) (common.PoolManager, error)
|
||||
GetOrgPoolManager(org params.Organization) (common.PoolManager, error)
|
||||
DeleteOrgPoolManager(org params.Organization) error
|
||||
GetOrgPoolManagers() (map[string]common.PoolManager, error)
|
||||
|
|
@ -38,6 +40,7 @@ type OrgPoolManager interface {
|
|||
|
||||
type EnterprisePoolManager interface {
|
||||
CreateEnterprisePoolManager(ctx context.Context, enterprise params.Enterprise, providers map[string]common.Provider, store dbCommon.Store) (common.PoolManager, error)
|
||||
UpdateEnterprisePoolManager(ctx context.Context, enterprise params.Enterprise) (common.PoolManager, error)
|
||||
GetEnterprisePoolManager(enterprise params.Enterprise) (common.PoolManager, error)
|
||||
DeleteEnterprisePoolManager(enterprise params.Enterprise) error
|
||||
GetEnterprisePoolManagers() (map[string]common.PoolManager, error)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v2.22.1. DO NOT EDIT.
|
||||
// Code generated by mockery v0.0.0-dev. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
|
|
@ -295,13 +295,90 @@ func (_m *PoolManagerController) GetRepoPoolManagers() (map[string]common.PoolMa
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
type mockConstructorTestingTNewPoolManagerController interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
// UpdateEnterprisePoolManager provides a mock function with given fields: ctx, enterprise
|
||||
func (_m *PoolManagerController) UpdateEnterprisePoolManager(ctx context.Context, enterprise params.Enterprise) (common.PoolManager, error) {
|
||||
ret := _m.Called(ctx, enterprise)
|
||||
|
||||
var r0 common.PoolManager
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Enterprise) (common.PoolManager, error)); ok {
|
||||
return rf(ctx, enterprise)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Enterprise) common.PoolManager); ok {
|
||||
r0 = rf(ctx, enterprise)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(common.PoolManager)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.Enterprise) error); ok {
|
||||
r1 = rf(ctx, enterprise)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// UpdateOrgPoolManager provides a mock function with given fields: ctx, org
|
||||
func (_m *PoolManagerController) UpdateOrgPoolManager(ctx context.Context, org params.Organization) (common.PoolManager, error) {
|
||||
ret := _m.Called(ctx, org)
|
||||
|
||||
var r0 common.PoolManager
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Organization) (common.PoolManager, error)); ok {
|
||||
return rf(ctx, org)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Organization) common.PoolManager); ok {
|
||||
r0 = rf(ctx, org)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(common.PoolManager)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.Organization) error); ok {
|
||||
r1 = rf(ctx, org)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// UpdateRepoPoolManager provides a mock function with given fields: ctx, repo
|
||||
func (_m *PoolManagerController) UpdateRepoPoolManager(ctx context.Context, repo params.Repository) (common.PoolManager, error) {
|
||||
ret := _m.Called(ctx, repo)
|
||||
|
||||
var r0 common.PoolManager
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Repository) (common.PoolManager, error)); ok {
|
||||
return rf(ctx, repo)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, params.Repository) common.PoolManager); ok {
|
||||
r0 = rf(ctx, repo)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(common.PoolManager)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, params.Repository) error); ok {
|
||||
r1 = rf(ctx, repo)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// NewPoolManagerController creates a new instance of PoolManagerController. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewPoolManagerController(t mockConstructorTestingTNewPoolManagerController) *PoolManagerController {
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewPoolManagerController(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *PoolManagerController {
|
||||
mock := &PoolManagerController{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -183,21 +183,12 @@ func (r *Runner) UpdateOrganization(ctx context.Context, orgID string, param par
|
|||
return params.Organization{}, errors.Wrap(err, "updating org")
|
||||
}
|
||||
|
||||
poolMgr, err := r.poolManagerCtrl.GetOrgPoolManager(org)
|
||||
poolMgr, err := r.poolManagerCtrl.UpdateOrgPoolManager(r.ctx, org)
|
||||
if err != nil {
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: org.WebhookSecret,
|
||||
}
|
||||
// stop the pool mgr
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return params.Organization{}, errors.Wrap(err, "updating org pool manager")
|
||||
}
|
||||
} else {
|
||||
if _, err := r.poolManagerCtrl.CreateOrgPoolManager(r.ctx, org, r.providers, r.store); err != nil {
|
||||
return params.Organization{}, errors.Wrap(err, "creating org pool manager")
|
||||
}
|
||||
return params.Organization{}, fmt.Errorf("updating org pool manager: %w", err)
|
||||
}
|
||||
|
||||
org.PoolManagerStatus = poolMgr.Status()
|
||||
return org, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ func (s *OrgTestSuite) TestDeleteOrganizationPoolMgrFailed() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestUpdateOrganization() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetOrgPoolManager", mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateOrgPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Organization"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateOrgPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrMock.On("Status").Return(params.PoolManagerStatus{IsRunning: true}, nil)
|
||||
|
||||
org, err := s.Runner.UpdateOrganization(s.Fixtures.AdminContext, s.Fixtures.StoreOrgs["test-org-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
|
|
@ -317,25 +317,21 @@ func (s *OrgTestSuite) TestUpdateOrganizationInvalidCreds() {
|
|||
}
|
||||
|
||||
func (s *OrgTestSuite) TestUpdateOrganizationPoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetOrgPoolManager", mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrMock.On("RefreshState", s.Fixtures.UpdatePoolStateParams).Return(s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateOrgPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateOrganization(s.Fixtures.AdminContext, s.Fixtures.StoreOrgs["test-org-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("updating org pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestUpdateOrganizationCreateOrgPoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetOrgPoolManager", mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateOrgPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Organization"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateOrgPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Organization")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateOrganization(s.Fixtures.AdminContext, s.Fixtures.StoreOrgs["test-org-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("creating org pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
s.Require().Equal(fmt.Sprintf("updating org pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *OrgTestSuite) TestCreateOrgPool() {
|
||||
|
|
|
|||
|
|
@ -99,6 +99,9 @@ func (r *enterprise) UpdateState(param params.UpdatePoolStateParams) error {
|
|||
defer r.mux.Unlock()
|
||||
|
||||
r.cfg.WebhookSecret = param.WebhookSecret
|
||||
if param.InternalConfig != nil {
|
||||
r.cfgInternal = *param.InternalConfig
|
||||
}
|
||||
|
||||
ghc, ghcEnterprise, err := util.GithubClient(r.ctx, r.GetGithubToken(), r.cfgInternal.GithubCredentialsDetails)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,9 @@ func (r *organization) UpdateState(param params.UpdatePoolStateParams) error {
|
|||
defer r.mux.Unlock()
|
||||
|
||||
r.cfg.WebhookSecret = param.WebhookSecret
|
||||
if param.InternalConfig != nil {
|
||||
r.cfgInternal = *param.InternalConfig
|
||||
}
|
||||
|
||||
ghc, _, err := util.GithubClient(r.ctx, r.GetGithubToken(), r.cfgInternal.GithubCredentialsDetails)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -113,6 +113,9 @@ func (r *repository) UpdateState(param params.UpdatePoolStateParams) error {
|
|||
defer r.mux.Unlock()
|
||||
|
||||
r.cfg.WebhookSecret = param.WebhookSecret
|
||||
if param.InternalConfig != nil {
|
||||
r.cfgInternal = *param.InternalConfig
|
||||
}
|
||||
|
||||
ghc, _, err := util.GithubClient(r.ctx, r.GetGithubToken(), r.cfgInternal.GithubCredentialsDetails)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -182,21 +182,12 @@ func (r *Runner) UpdateRepository(ctx context.Context, repoID string, param para
|
|||
return params.Repository{}, errors.Wrap(err, "updating repo")
|
||||
}
|
||||
|
||||
poolMgr, err := r.poolManagerCtrl.GetRepoPoolManager(repo)
|
||||
poolMgr, err := r.poolManagerCtrl.UpdateRepoPoolManager(r.ctx, repo)
|
||||
if err != nil {
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: repo.WebhookSecret,
|
||||
}
|
||||
// stop the pool mgr
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return params.Repository{}, errors.Wrap(err, "updating repo pool manager")
|
||||
}
|
||||
} else {
|
||||
if _, err := r.poolManagerCtrl.CreateRepoPoolManager(r.ctx, repo, r.providers, r.store); err != nil {
|
||||
return params.Repository{}, errors.Wrap(err, "creating repo pool manager")
|
||||
}
|
||||
return params.Repository{}, fmt.Errorf("failed to update pool manager: %w", err)
|
||||
}
|
||||
|
||||
repo.PoolManagerStatus = poolMgr.Status()
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -293,13 +293,13 @@ func (s *RepoTestSuite) TestDeleteRepositoryPoolMgrFailed() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestUpdateRepository() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetRepoPoolManager", mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrMock.On("Status").Return(params.PoolManagerStatus{IsRunning: true}, nil)
|
||||
|
||||
repo, err := s.Runner.UpdateRepository(s.Fixtures.AdminContext, s.Fixtures.StoreRepos["test-repo-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Require().Nil(err)
|
||||
s.Require().Equal(s.Fixtures.UpdateRepoParams.CredentialsName, repo.CredentialsName)
|
||||
s.Require().Equal(s.Fixtures.UpdateRepoParams.WebhookSecret, repo.WebhookSecret)
|
||||
|
|
@ -320,25 +320,21 @@ func (s *RepoTestSuite) TestUpdateRepositoryInvalidCreds() {
|
|||
}
|
||||
|
||||
func (s *RepoTestSuite) TestUpdateRepositoryPoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetRepoPoolManager", mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrMock.On("RefreshState", s.Fixtures.UpdatePoolStateParams).Return(s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateRepository(s.Fixtures.AdminContext, s.Fixtures.StoreRepos["test-repo-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("updating repo pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
s.Require().Equal(fmt.Sprintf("failed to update pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestUpdateRepositoryCreateRepoPoolMgrFailed() {
|
||||
s.Fixtures.PoolMgrCtrlMock.On("GetRepoPoolManager", mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, nil)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("CreateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository"), s.Fixtures.Providers, s.Fixtures.Store).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
s.Fixtures.PoolMgrCtrlMock.On("UpdateRepoPoolManager", s.Fixtures.AdminContext, mock.AnythingOfType("params.Repository")).Return(s.Fixtures.PoolMgrMock, s.Fixtures.ErrMock)
|
||||
|
||||
_, err := s.Runner.UpdateRepository(s.Fixtures.AdminContext, s.Fixtures.StoreRepos["test-repo-1"].ID, s.Fixtures.UpdateRepoParams)
|
||||
|
||||
s.Fixtures.PoolMgrMock.AssertExpectations(s.T())
|
||||
s.Fixtures.PoolMgrCtrlMock.AssertExpectations(s.T())
|
||||
s.Require().Equal(fmt.Sprintf("creating repo pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
s.Require().Equal(fmt.Sprintf("failed to update pool manager: %s", s.Fixtures.ErrMock.Error()), err.Error())
|
||||
}
|
||||
|
||||
func (s *RepoTestSuite) TestCreateRepoPool() {
|
||||
|
|
|
|||
|
|
@ -117,6 +117,31 @@ func (p *poolManagerCtrl) CreateRepoPoolManager(ctx context.Context, repo params
|
|||
return poolManager, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) UpdateRepoPoolManager(ctx context.Context, repo params.Repository) (common.PoolManager, error) {
|
||||
p.mux.Lock()
|
||||
defer p.mux.Unlock()
|
||||
|
||||
poolMgr, ok := p.repositories[repo.ID]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(runnerErrors.ErrNotFound, "repository %s/%s pool manager not loaded", repo.Owner, repo.Name)
|
||||
}
|
||||
|
||||
internalCfg, err := p.getInternalConfig(repo.CredentialsName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetching internal config")
|
||||
}
|
||||
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: repo.WebhookSecret,
|
||||
InternalConfig: &internalCfg,
|
||||
}
|
||||
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return nil, errors.Wrap(err, "updating repo pool manager")
|
||||
}
|
||||
return poolMgr, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) GetRepoPoolManager(repo params.Repository) (common.PoolManager, error) {
|
||||
if repoPoolMgr, ok := p.repositories[repo.ID]; ok {
|
||||
return repoPoolMgr, nil
|
||||
|
|
@ -158,6 +183,31 @@ func (p *poolManagerCtrl) CreateOrgPoolManager(ctx context.Context, org params.O
|
|||
return poolManager, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) UpdateOrgPoolManager(ctx context.Context, org params.Organization) (common.PoolManager, error) {
|
||||
p.mux.Lock()
|
||||
defer p.mux.Unlock()
|
||||
|
||||
poolMgr, ok := p.organizations[org.ID]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(runnerErrors.ErrNotFound, "org %s pool manager not loaded", org.Name)
|
||||
}
|
||||
|
||||
internalCfg, err := p.getInternalConfig(org.CredentialsName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetching internal config")
|
||||
}
|
||||
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: org.WebhookSecret,
|
||||
InternalConfig: &internalCfg,
|
||||
}
|
||||
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return nil, errors.Wrap(err, "updating repo pool manager")
|
||||
}
|
||||
return poolMgr, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) GetOrgPoolManager(org params.Organization) (common.PoolManager, error) {
|
||||
if orgPoolMgr, ok := p.organizations[org.ID]; ok {
|
||||
return orgPoolMgr, nil
|
||||
|
|
@ -199,6 +249,31 @@ func (p *poolManagerCtrl) CreateEnterprisePoolManager(ctx context.Context, enter
|
|||
return poolManager, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) UpdateEnterprisePoolManager(ctx context.Context, enterprise params.Enterprise) (common.PoolManager, error) {
|
||||
p.mux.Lock()
|
||||
defer p.mux.Unlock()
|
||||
|
||||
poolMgr, ok := p.enterprises[enterprise.ID]
|
||||
if !ok {
|
||||
return nil, errors.Wrapf(runnerErrors.ErrNotFound, "enterprise %s pool manager not loaded", enterprise.Name)
|
||||
}
|
||||
|
||||
internalCfg, err := p.getInternalConfig(enterprise.CredentialsName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fetching internal config")
|
||||
}
|
||||
|
||||
newState := params.UpdatePoolStateParams{
|
||||
WebhookSecret: enterprise.WebhookSecret,
|
||||
InternalConfig: &internalCfg,
|
||||
}
|
||||
|
||||
if err := poolMgr.RefreshState(newState); err != nil {
|
||||
return nil, errors.Wrap(err, "updating repo pool manager")
|
||||
}
|
||||
return poolMgr, nil
|
||||
}
|
||||
|
||||
func (p *poolManagerCtrl) GetEnterprisePoolManager(enterprise params.Enterprise) (common.PoolManager, error) {
|
||||
if enterprisePoolMgr, ok := p.enterprises[enterprise.ID]; ok {
|
||||
return enterprisePoolMgr, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue