37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
provider.go 3.24 KB
一键复制 编辑 原始数据 按行查看 历史
phli 提交于 2018-09-19 16:48 . add bitbucket support in pipeline
package bitbucketcloud
import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/rancher/norman/store/subtype"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/pipeline/providers/common"
"github.com/rancher/rancher/pkg/pipeline/remote/model"
"github.com/rancher/types/apis/project.cattle.io/v3"
"github.com/rancher/types/apis/project.cattle.io/v3/schema"
"github.com/rancher/types/client/project/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type BcProvider struct {
common.BaseProvider
}
func (b *BcProvider) CustomizeSchemas(schemas *types.Schemas) {
scpConfigBaseSchema := schemas.Schema(&schema.Version, client.SourceCodeProviderConfigType)
configSchema := schemas.Schema(&schema.Version, client.BitbucketCloudPipelineConfigType)
configSchema.ActionHandler = b.ActionHandler
configSchema.Formatter = b.Formatter
configSchema.Store = subtype.NewSubTypeStore(client.BitbucketCloudPipelineConfigType, scpConfigBaseSchema.Store)
providerBaseSchema := schemas.Schema(&schema.Version, client.SourceCodeProviderType)
providerSchema := schemas.Schema(&schema.Version, client.BitbucketCloudProviderType)
providerSchema.Formatter = b.providerFormatter
providerSchema.ActionHandler = b.providerActionHandler
providerSchema.Store = subtype.NewSubTypeStore(client.BitbucketCloudProviderType, providerBaseSchema.Store)
}
func (b *BcProvider) GetName() string {
return model.BitbucketCloudType
}
func (b *BcProvider) TransformToSourceCodeProvider(config map[string]interface{}) map[string]interface{} {
m := b.BaseProvider.TransformToSourceCodeProvider(config, client.BitbucketCloudProviderType)
m[client.BitbucketCloudProviderFieldRedirectURL] = formBitbucketRedirectURLFromMap(config)
return m
}
func (b *BcProvider) GetProviderConfig(projectID string) (interface{}, error) {
scpConfigObj, err := b.SourceCodeProviderConfigs.ObjectClient().UnstructuredClient().GetNamespaced(projectID, model.BitbucketCloudType, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to retrieve BitbucketConfig, error: %v", err)
}
u, ok := scpConfigObj.(runtime.Unstructured)
if !ok {
return nil, fmt.Errorf("failed to retrieve BitbucketConfig, cannot read k8s Unstructured data")
}
storedBitbucketPipelineConfigMap := u.UnstructuredContent()
storedBitbucketPipelineConfig := &v3.BitbucketCloudPipelineConfig{}
if err := mapstructure.Decode(storedBitbucketPipelineConfigMap, storedBitbucketPipelineConfig); err != nil {
return nil, fmt.Errorf("failed to decode the config, error: %v", err)
}
metadataMap, ok := storedBitbucketPipelineConfigMap["metadata"].(map[string]interface{})
if !ok {
return nil, fmt.Errorf("failed to retrieve BitbucketConfig metadata, cannot read k8s Unstructured data")
}
typemeta := &metav1.ObjectMeta{}
//time.Time cannot decode directly
delete(metadataMap, "creationTimestamp")
if err := mapstructure.Decode(metadataMap, typemeta); err != nil {
return nil, fmt.Errorf("failed to decode the config, error: %v", err)
}
storedBitbucketPipelineConfig.ObjectMeta = *typemeta
storedBitbucketPipelineConfig.APIVersion = "project.cattle.io/v3"
storedBitbucketPipelineConfig.Kind = v3.SourceCodeProviderConfigGroupVersionKind.Kind
return storedBitbucketPipelineConfig, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.2-rc3

搜索帮助

0d507c66 1850385 C8b1a773 1850385