1
0
mirror of https://github.com/rancher/types.git synced 2025-08-27 08:18:24 +00:00

add bitbucket support

This commit is contained in:
gitlawr 2018-09-19 15:33:36 +08:00 committed by Alena Prokharchyk
parent 10dc7ca40f
commit a0165b14ba
2 changed files with 124 additions and 35 deletions

View File

@ -22,7 +22,7 @@ type SourceCodeProvider struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
ProjectName string `json:"projectName" norman:"type=reference[project]"`
Type string `json:"type" norman:"options=github|gitlab"`
Type string `json:"type" norman:"options=github|gitlab|bitbucketcloud|bitbucketserver"`
}
type OauthProvider struct {
@ -41,6 +41,14 @@ type GitlabProvider struct {
OauthProvider `json:",inline"`
}
type BitbucketCloudProvider struct {
OauthProvider `json:",inline"`
}
type BitbucketServerProvider struct {
OauthProvider `json:",inline"`
}
type SourceCodeProviderConfig struct {
types.Namespaced
@ -48,7 +56,7 @@ type SourceCodeProviderConfig struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
ProjectName string `json:"projectName" norman:"required,type=reference[project]"`
Type string `json:"type" norman:"noupdate,options=github|gitlab"`
Type string `json:"type" norman:"noupdate,options=github|gitlab|bitbucketcloud|bitbucketserver"`
Enabled bool `json:"enabled,omitempty"`
}
@ -76,6 +84,29 @@ type GitlabPipelineConfig struct {
RedirectURL string `json:"redirectUrl,omitempty" norman:"noupdate"`
}
type BitbucketCloudPipelineConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
SourceCodeProviderConfig `json:",inline" mapstructure:",squash"`
ClientID string `json:"clientId,omitempty" norman:"noupdate"`
ClientSecret string `json:"clientSecret,omitempty" norman:"noupdate,type=password"`
RedirectURL string `json:"redirectUrl,omitempty" norman:"noupdate"`
}
type BitbucketServerPipelineConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
SourceCodeProviderConfig `json:",inline" mapstructure:",squash"`
Hostname string `json:"hostname,omitempty"`
TLS bool `json:"tls,omitempty"`
ConsumerKey string `json:"consumerKey,omitempty"`
PublicKey string `json:"publicKey,omitempty"`
PrivateKey string `json:"privateKey,omitempty" norman:"type=password"`
RedirectURL string `json:"redirectUrl,omitempty"`
}
type Pipeline struct {
types.Namespaced
@ -270,14 +301,17 @@ type StepStatus struct {
type SourceCodeCredentialSpec struct {
ProjectName string `json:"projectName" norman:"type=reference[project]"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"required,options=github|gitlab"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"required,options=github|gitlab|bitbucketcloud|bitbucketserver"`
UserName string `json:"userName" norman:"required,type=reference[user]"`
DisplayName string `json:"displayName,omitempty" norman:"required"`
AvatarURL string `json:"avatarUrl,omitempty"`
HTMLURL string `json:"htmlUrl,omitempty"`
LoginName string `json:"loginName,omitempty"`
GitLoginName string `json:"gitLoginName,omitempty"`
GitCloneToken string `json:"gitCloneToken,omitempty" norman:"writeOnly,noupdate"`
AccessToken string `json:"accessToken,omitempty" norman:"writeOnly,noupdate"`
RefreshToken string `json:"refreshToken,omitempty" norman:"writeOnly,noupdate"`
Expiry string `json:"expiry,omitempty"`
}
type SourceCodeCredentialStatus struct {
@ -286,7 +320,7 @@ type SourceCodeCredentialStatus struct {
type SourceCodeRepositorySpec struct {
ProjectName string `json:"projectName" norman:"type=reference[project]"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"required,options=github|gitlab"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"required,options=github|gitlab|bitbucketcloud|bitbucketserver"`
UserName string `json:"userName" norman:"required,type=reference[user]"`
SourceCodeCredentialName string `json:"sourceCodeCredentialName,omitempty" norman:"required,type=reference[sourceCodeCredential]"`
URL string `json:"url,omitempty"`
@ -310,7 +344,7 @@ type RunPipelineInput struct {
type AuthAppInput struct {
InheritGlobal bool `json:"inheritGlobal,omitempty"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"type=string,required,options=github|gitlab"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"type=string,required,options=github|gitlab|bitbucketcloud|bitbucketserver"`
RedirectURL string `json:"redirectUrl,omitempty" norman:"type=string"`
TLS bool `json:"tls,omitempty"`
Host string `json:"host,omitempty"`
@ -320,7 +354,7 @@ type AuthAppInput struct {
}
type AuthUserInput struct {
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"type=string,required,options=github|gitlab"`
SourceCodeType string `json:"sourceCodeType,omitempty" norman:"type=string,required,options=github|gitlab|bitbucketcloud|bitbucketserver"`
RedirectURL string `json:"redirectUrl,omitempty" norman:"type=string"`
Code string `json:"code,omitempty" norman:"type=string,required"`
}
@ -340,23 +374,44 @@ type PipelineSystemImages struct {
KubeApply string `json:"kubeApply,omitempty"`
}
type GithubPipelineConfigApplyInput struct {
InheritAuth bool `json:"inheritAuth,omitempty"`
GithubConfig GithubPipelineConfig `json:"githubConfig,omitempty"`
Code string `json:"code,omitempty"`
type OauthApplyInput struct {
Hostname string `json:"hostname,omitempty"`
TLS bool `json:"tls,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
ClientID string `json:"clientId,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
Code string `json:"code,omitempty"`
}
type GithubLoginInput struct {
Code string `json:"code,omitempty" norman:"type=string,required"`
type GithubApplyInput struct {
OauthApplyInput
InheritAuth bool `json:"inheritAuth,omitempty"`
}
type GitlabPipelineConfigApplyInput struct {
GitlabConfig GitlabPipelineConfig `json:"gitlabConfig,omitempty"`
Code string `json:"code,omitempty"`
type GitlabApplyInput struct {
OauthApplyInput
}
type GitlabLoginInput struct {
Code string `json:"code,omitempty" norman:"type=string,required"`
type BitbucketCloudApplyInput struct {
OauthApplyInput
}
type BitbucketServerApplyInput struct {
OAuthToken string `json:"oauthToken,omitempty"`
OAuthVerifier string `json:"oauthVerifier,omitempty"`
Hostname string `json:"hostname,omitempty"`
TLS bool `json:"tls,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
}
type BitbucketServerRequestLoginInput struct {
Hostname string `json:"hostname,omitempty"`
TLS bool `json:"tls,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
}
type BitbucketServerRequestLoginOutput struct {
LoginURL string `json:"loginUrl"`
}
type EnvFrom struct {

View File

@ -782,6 +782,17 @@ func NewWorkloadTypeMapper() types.Mapper {
}
func pipelineTypes(schema *types.Schemas) *types.Schemas {
baseProviderCustomizeFunc := func(schema *types.Schema) {
schema.BaseType = "sourceCodeProvider"
schema.ResourceActions = map[string]types.Action{
"login": {
Input: "authUserInput",
Output: "sourceCodeCredential",
},
}
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{http.MethodGet}
}
return schema.
AddMapperForType(&Version, v3.SourceCodeProviderConfig{}).
AddMapperForType(&Version, v3.Pipeline{},
@ -796,29 +807,26 @@ func pipelineTypes(schema *types.Schemas) *types.Schemas {
MustImport(&Version, v3.AuthUserInput{}).
MustImport(&Version, v3.RunPipelineInput{}).
MustImport(&Version, v3.PushPipelineConfigInput{}).
MustImport(&Version, v3.GithubPipelineConfigApplyInput{}).
MustImport(&Version, v3.GithubLoginInput{}).
MustImport(&Version, v3.GitlabPipelineConfigApplyInput{}).
MustImport(&Version, v3.GitlabLoginInput{}).
MustImport(&Version, v3.GithubApplyInput{}).
MustImport(&Version, v3.GitlabApplyInput{}).
MustImport(&Version, v3.BitbucketCloudApplyInput{}).
MustImport(&Version, v3.BitbucketServerApplyInput{}).
MustImport(&Version, v3.BitbucketServerRequestLoginInput{}).
MustImport(&Version, v3.BitbucketServerRequestLoginOutput{}).
MustImportAndCustomize(&Version, v3.SourceCodeProvider{}, func(schema *types.Schema) {
schema.CollectionMethods = []string{http.MethodGet}
}).
MustImportAndCustomize(&Version, v3.GithubProvider{}, func(schema *types.Schema) {
MustImportAndCustomize(&Version, v3.GithubProvider{}, baseProviderCustomizeFunc).
MustImportAndCustomize(&Version, v3.GitlabProvider{}, baseProviderCustomizeFunc).
MustImportAndCustomize(&Version, v3.BitbucketCloudProvider{}, baseProviderCustomizeFunc).
MustImportAndCustomize(&Version, v3.BitbucketServerProvider{}, func(schema *types.Schema) {
schema.BaseType = "sourceCodeProvider"
schema.ResourceActions = map[string]types.Action{
"login": {
Input: "githubLoginInput",
Output: "sourceCodeCredential",
"requestLogin": {
Output: "bitbucketServerRequestLoginOutput",
},
}
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{http.MethodGet}
}).
MustImportAndCustomize(&Version, v3.GitlabProvider{}, func(schema *types.Schema) {
schema.BaseType = "sourceCodeProvider"
schema.ResourceActions = map[string]types.Action{
"login": {
Input: "gitlabLoginInput",
Input: "authUserInput",
Output: "sourceCodeCredential",
},
}
@ -834,7 +842,7 @@ func pipelineTypes(schema *types.Schemas) *types.Schemas {
schema.ResourceActions = map[string]types.Action{
"disable": {},
"testAndApply": {
Input: "githubPipelineConfigApplyInput",
Input: "githubApplyInput",
},
}
schema.CollectionMethods = []string{}
@ -845,12 +853,38 @@ func pipelineTypes(schema *types.Schemas) *types.Schemas {
schema.ResourceActions = map[string]types.Action{
"disable": {},
"testAndApply": {
Input: "gitlabPipelineConfigApplyInput",
Input: "gitlabApplyInput",
},
}
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{http.MethodGet, http.MethodPut}
}).
MustImportAndCustomize(&Version, v3.BitbucketCloudPipelineConfig{}, func(schema *types.Schema) {
schema.BaseType = "sourceCodeProviderConfig"
schema.ResourceActions = map[string]types.Action{
"disable": {},
"testAndApply": {
Input: "bitbucketCloudApplyInput",
},
}
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{http.MethodGet, http.MethodPut}
}).MustImportAndCustomize(&Version, v3.BitbucketServerPipelineConfig{}, func(schema *types.Schema) {
schema.BaseType = "sourceCodeProviderConfig"
schema.ResourceActions = map[string]types.Action{
"disable": {},
"generateKeys": {},
"requestLogin": {
Input: "bitbucketServerRequestLoginInput",
Output: "bitbucketServerRequestLoginOutput",
},
"testAndApply": {
Input: "bitbucketServerApplyInput",
},
}
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{http.MethodGet, http.MethodPut}
}).
MustImportAndCustomize(&Version, v3.Pipeline{}, func(schema *types.Schema) {
schema.ResourceActions = map[string]types.Action{
"activate": {},