Add EndpointType

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2025-05-12 17:32:37 +00:00
parent ef676488b7
commit 4890eb4732
6 changed files with 48 additions and 11 deletions

View file

@ -103,6 +103,7 @@ func (a *APIController) handleWorkflowJobEvent(ctx context.Context, w http.Respo
handleError(ctx, w, gErrors.NewBadRequestError("invalid post body: %s", err)) handleError(ctx, w, gErrors.NewBadRequestError("invalid post body: %s", err))
return return
} }
slog.Debug("received workflow job event", "body", string(body))
signature := r.Header.Get("X-Hub-Signature-256") signature := r.Header.Get("X-Hub-Signature-256")
hookType := r.Header.Get("X-Github-Hook-Installation-Target-Type") hookType := r.Header.Get("X-Github-Hook-Installation-Target-Type")
@ -154,6 +155,9 @@ func (a *APIController) WebhookHandler(w http.ResponseWriter, r *http.Request) {
} }
headers := r.Header.Clone() headers := r.Header.Clone()
for k, v := range headers {
slog.Debug("header", "key", k, "value", v)
}
event := runnerParams.Event(headers.Get("X-Github-Event")) event := runnerParams.Event(headers.Get("X-Github-Event"))
switch event { switch event {

View file

@ -97,6 +97,7 @@ func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.Githu
UploadBaseURL: ep.UploadBaseURL, UploadBaseURL: ep.UploadBaseURL,
CACertBundle: ep.CACertBundle, CACertBundle: ep.CACertBundle,
CreatedAt: ep.CreatedAt, CreatedAt: ep.CreatedAt,
EndpointType: ep.EndpointType,
UpdatedAt: ep.UpdatedAt, UpdatedAt: ep.UpdatedAt,
}, nil }, nil
} }

View file

@ -381,6 +381,8 @@ type GithubEndpoint struct {
UpdatedAt time.Time UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"` DeletedAt gorm.DeletedAt `gorm:"index"`
EndpointType params.EndpointType
Description string `gorm:"type:text"` Description string `gorm:"type:text"`
APIBaseURL string `gorm:"type:text collate nocase"` APIBaseURL string `gorm:"type:text collate nocase"`
UploadBaseURL string `gorm:"type:text collate nocase"` UploadBaseURL string `gorm:"type:text collate nocase"`

View file

@ -409,6 +409,17 @@ func (s *sqlDatabase) migrateDB() error {
} }
} }
if s.conn.Migrator().HasTable(&GithubEndpoint{}) {
if !s.conn.Migrator().HasColumn(&GithubEndpoint{}, "endpoint_type") {
if err := s.conn.Migrator().AutoMigrate(&GithubEndpoint{}); err != nil {
return errors.Wrap(err, "migrating github endpoints")
}
if err := s.conn.Exec("update github_endpoints set endpoint_type = 'github' where endpoint_type is null").Error; err != nil {
return errors.Wrap(err, "updating github endpoints")
}
}
}
var needsCredentialMigration bool var needsCredentialMigration bool
if !s.conn.Migrator().HasTable(&GithubCredentials{}) || !s.conn.Migrator().HasTable(&GithubEndpoint{}) { if !s.conn.Migrator().HasTable(&GithubCredentials{}) || !s.conn.Migrator().HasTable(&GithubEndpoint{}) {
needsCredentialMigration = true needsCredentialMigration = true

View file

@ -44,6 +44,7 @@ type (
RunnerStatus string RunnerStatus string
WebhookEndpointType string WebhookEndpointType string
GithubAuthType string GithubAuthType string
EndpointType string
PoolBalancerType string PoolBalancerType string
ScaleSetState string ScaleSetState string
ScaleSetMessageType string ScaleSetMessageType string
@ -76,6 +77,11 @@ const (
PoolBalancerTypeNone PoolBalancerType = "" PoolBalancerTypeNone PoolBalancerType = ""
) )
const (
GithubEndpointType EndpointType = "github"
GiteaEndpointType EndpointType = "gitea"
)
const ( const (
// LXDProvider represents the LXD provider. // LXDProvider represents the LXD provider.
LXDProvider ProviderType = "lxd" LXDProvider ProviderType = "lxd"
@ -1138,5 +1144,7 @@ type GithubEndpoint struct {
CreatedAt time.Time `json:"created_at,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"`
EndpointType EndpointType `json:"endpoint_type,omitempty"`
Credentials []GithubCredentials `json:"credentials,omitempty"` Credentials []GithubCredentials `json:"credentials,omitempty"`
} }

View file

@ -281,6 +281,7 @@ type CreateGithubEndpointParams struct {
APIBaseURL string `json:"api_base_url,omitempty"` APIBaseURL string `json:"api_base_url,omitempty"`
UploadBaseURL string `json:"upload_base_url,omitempty"` UploadBaseURL string `json:"upload_base_url,omitempty"`
BaseURL string `json:"base_url,omitempty"` BaseURL string `json:"base_url,omitempty"`
EndpointType string `json:"endpoint_type,omitempty"`
CACertBundle []byte `json:"ca_cert_bundle,omitempty"` CACertBundle []byte `json:"ca_cert_bundle,omitempty"`
} }
@ -289,6 +290,14 @@ func (c CreateGithubEndpointParams) Validate() error {
return runnerErrors.NewBadRequestError("missing api_base_url") return runnerErrors.NewBadRequestError("missing api_base_url")
} }
if c.EndpointType != "" {
switch c.EndpointType {
case string(GithubEndpointType), string(GiteaEndpointType):
default:
return runnerErrors.NewBadRequestError("invalid endpoint_type: %s", c.EndpointType)
}
}
url, err := url.Parse(c.APIBaseURL) url, err := url.Parse(c.APIBaseURL)
if err != nil || url.Scheme == "" || url.Host == "" { if err != nil || url.Scheme == "" || url.Host == "" {
return runnerErrors.NewBadRequestError("invalid api_base_url") return runnerErrors.NewBadRequestError("invalid api_base_url")
@ -299,19 +308,21 @@ func (c CreateGithubEndpointParams) Validate() error {
return runnerErrors.NewBadRequestError("invalid api_base_url") return runnerErrors.NewBadRequestError("invalid api_base_url")
} }
if c.UploadBaseURL == "" { if c.EndpointType == string(GithubEndpointType) {
return runnerErrors.NewBadRequestError("missing upload_base_url") if c.UploadBaseURL == "" {
} return runnerErrors.NewBadRequestError("missing upload_base_url")
}
url, err = url.Parse(c.UploadBaseURL) url, err = url.Parse(c.UploadBaseURL)
if err != nil || url.Scheme == "" || url.Host == "" { if err != nil || url.Scheme == "" || url.Host == "" {
return runnerErrors.NewBadRequestError("invalid upload_base_url") return runnerErrors.NewBadRequestError("invalid upload_base_url")
} }
switch url.Scheme { switch url.Scheme {
case httpsScheme, httpScheme: case httpsScheme, httpScheme:
default: default:
return runnerErrors.NewBadRequestError("invalid api_base_url") return runnerErrors.NewBadRequestError("invalid api_base_url")
}
} }
if c.BaseURL == "" { if c.BaseURL == "" {