Make the default github.com endpoint mutable
The k8s operator seems to want to define its own endpoint. This change allows the removal of the default gh endpoint if no credentials are tied to it. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
1e0cb72aa3
commit
750446acec
92 changed files with 2568 additions and 1159 deletions
|
|
@ -28,10 +28,6 @@ import (
|
|||
"github.com/cloudbase/garm/params"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultGithubEndpoint string = "github.com"
|
||||
)
|
||||
|
||||
func (s *sqlDatabase) sqlToCommonGithubCredentials(creds GithubCredentials) (params.GithubCredentials, error) {
|
||||
if len(creds.Payload) == 0 {
|
||||
return params.GithubCredentials{}, errors.New("empty credentials payload")
|
||||
|
|
@ -168,10 +164,6 @@ func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEnd
|
|||
}
|
||||
|
||||
func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.GithubEndpoint, err error) {
|
||||
if name == defaultGithubEndpoint {
|
||||
return params.GithubEndpoint{}, errors.Wrap(runnerErrors.ErrBadRequest, "cannot update default github endpoint")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
s.sendNotify(common.GithubEndpointEntityType, common.UpdateOperation, ghEndpoint)
|
||||
|
|
@ -185,6 +177,16 @@ func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param
|
|||
}
|
||||
return errors.Wrap(err, "fetching github endpoint")
|
||||
}
|
||||
|
||||
var credsCount int64
|
||||
if err := tx.Model(&GithubCredentials{}).Where("endpoint_name = ?", endpoint.Name).Count(&credsCount).Error; err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return errors.Wrap(err, "fetching github credentials")
|
||||
}
|
||||
}
|
||||
if credsCount > 0 && (param.APIBaseURL != nil || param.BaseURL != nil || param.UploadBaseURL != nil) {
|
||||
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot update endpoint URLs with existing credentials")
|
||||
}
|
||||
if param.APIBaseURL != nil {
|
||||
endpoint.APIBaseURL = *param.APIBaseURL
|
||||
}
|
||||
|
|
@ -236,10 +238,6 @@ func (s *sqlDatabase) GetGithubEndpoint(_ context.Context, name string) (params.
|
|||
}
|
||||
|
||||
func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err error) {
|
||||
if name == defaultGithubEndpoint {
|
||||
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot delete default github endpoint")
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err == nil {
|
||||
s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.GithubEndpoint{Name: name})
|
||||
|
|
@ -283,7 +281,7 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
|
|||
}
|
||||
|
||||
if credsCount > 0 || repoCnt > 0 || orgCnt > 0 || entCnt > 0 {
|
||||
return errors.New("cannot delete endpoint with associated entities")
|
||||
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot delete endpoint with associated entities")
|
||||
}
|
||||
|
||||
if err := tx.Unscoped().Delete(&endpoint).Error; err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue