Use database for github creds
Add database models that deal with github credentials. This change adds models for github endpoints (github.com, GHES, etc). This change also adds code to migrate config credntials to the DB. Tests need to be fixed and new tests need to be written. This will come in a later commit. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
834c3bb798
commit
90870c11be
22 changed files with 1312 additions and 77 deletions
|
|
@ -89,35 +89,56 @@ type Pool struct {
|
|||
type Repository struct {
|
||||
Base
|
||||
|
||||
CredentialsName string
|
||||
CredentialsName string
|
||||
|
||||
CredentialsID *uint `gorm:"index"`
|
||||
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
||||
|
||||
Owner string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
||||
Name string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
||||
WebhookSecret []byte
|
||||
Pools []Pool `gorm:"foreignKey:RepoID"`
|
||||
Jobs []WorkflowJob `gorm:"foreignKey:RepoID;constraint:OnDelete:SET NULL"`
|
||||
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
||||
|
||||
EndpointName *string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
|
||||
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
Base
|
||||
|
||||
CredentialsName string
|
||||
CredentialsName string
|
||||
|
||||
CredentialsID *uint `gorm:"index"`
|
||||
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
||||
|
||||
Name string `gorm:"index:idx_org_name_nocase,collate:nocase"`
|
||||
WebhookSecret []byte
|
||||
Pools []Pool `gorm:"foreignKey:OrgID"`
|
||||
Jobs []WorkflowJob `gorm:"foreignKey:OrgID;constraint:OnDelete:SET NULL"`
|
||||
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
||||
|
||||
EndpointName *string `gorm:"index"`
|
||||
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
||||
}
|
||||
|
||||
type Enterprise struct {
|
||||
Base
|
||||
|
||||
CredentialsName string
|
||||
CredentialsName string
|
||||
|
||||
CredentialsID *uint `gorm:"index"`
|
||||
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
|
||||
|
||||
Name string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
|
||||
WebhookSecret []byte
|
||||
Pools []Pool `gorm:"foreignKey:EnterpriseID"`
|
||||
Jobs []WorkflowJob `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:SET NULL"`
|
||||
PoolBalancerType params.PoolBalancerType `gorm:"type:varchar(64)"`
|
||||
|
||||
EndpointName *string `gorm:"index"`
|
||||
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
|
||||
}
|
||||
|
||||
type Address struct {
|
||||
|
|
@ -246,3 +267,35 @@ type WorkflowJob struct {
|
|||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
}
|
||||
|
||||
type GithubEndpoint struct {
|
||||
Name string `gorm:"type:varchar(64) collate nocase;primary_key;"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
|
||||
Description string `gorm:"type:text"`
|
||||
APIBaseURL string `gorm:"type:text collate nocase"`
|
||||
UploadBaseURL string `gorm:"type:text collate nocase"`
|
||||
BaseURL string `gorm:"type:text collate nocase"`
|
||||
CACertBundle []byte `gorm:"type:longblob"`
|
||||
}
|
||||
|
||||
type GithubCredentials struct {
|
||||
gorm.Model
|
||||
|
||||
Name string `gorm:"index:idx_github_credentials,unique;type:varchar(64) collate nocase"`
|
||||
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"`
|
||||
|
||||
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
|
||||
EndpointName *string `gorm:"index"`
|
||||
|
||||
Repositories []Repository `gorm:"foreignKey:CredentialsID"`
|
||||
Organizations []Organization `gorm:"foreignKey:CredentialsID"`
|
||||
Enterprises []Enterprise `gorm:"foreignKey:CredentialsID"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue