mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-10-29 17:58:36 +08:00
Merge pull request #6006 from swordqiu/hotfix/qj-gcp-account-project-id-name-conflict
Hotfix/qj gcp account project id name conflict
This commit is contained in:
@@ -26,6 +26,28 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
)
|
||||
|
||||
func parseGcpCredential(filename string) (jsonutils.JSONObject, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
authParams, err := jsonutils.Parse(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := jsonutils.NewDict()
|
||||
for _, k := range []string{
|
||||
"client_email",
|
||||
"project_id",
|
||||
"private_key_id",
|
||||
"private_key",
|
||||
} {
|
||||
v, _ := authParams.Get(k)
|
||||
ret.Add(v, fmt.Sprintf("gcp_%s", k))
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
type CloudaccountListOptions struct {
|
||||
@@ -149,11 +171,7 @@ func init() {
|
||||
R(&options.SGoogleCloudAccountCreateOptions{}, "cloud-account-create-google", "Create a Google cloud account", func(s *mcclient.ClientSession, args *options.SGoogleCloudAccountCreateOptions) error {
|
||||
params := jsonutils.Marshal(args)
|
||||
params.(*jsonutils.JSONDict).Add(jsonutils.NewString("Google"), "provider")
|
||||
data, err := ioutil.ReadFile(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
authParams, err := jsonutils.Parse(data)
|
||||
authParams, err := parseGcpCredential(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -699,11 +717,7 @@ func init() {
|
||||
})
|
||||
|
||||
R(&options.SGoogleCloudAccountUpdateCredentialOptions{}, "cloud-account-update-credential-google", "Update credential of a Google cloud account", func(s *mcclient.ClientSession, args *options.SGoogleCloudAccountUpdateCredentialOptions) error {
|
||||
data, err := ioutil.ReadFile(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params, err := jsonutils.Parse(data)
|
||||
params, err := parseGcpCredential(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -826,11 +840,7 @@ func init() {
|
||||
})
|
||||
|
||||
R(&options.SGoogleCloudAccountUpdateCredentialOptions{}, "cloud-account-test-connectivity-google", "Update credential of a Google cloud account", func(s *mcclient.ClientSession, args *options.SGoogleCloudAccountUpdateCredentialOptions) error {
|
||||
data, err := ioutil.ReadFile(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params, err := jsonutils.Parse(data)
|
||||
params, err := parseGcpCredential(args.GoogleJsonFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -33,66 +33,66 @@ const (
|
||||
)
|
||||
|
||||
type SCloudaccountCredential struct {
|
||||
// 账号所在的项目
|
||||
// 账号所在的项目 (openstack)
|
||||
ProjectName string `json:"project_name"`
|
||||
|
||||
// 账号所在的域
|
||||
// 账号所在的域 (openstack)
|
||||
// default: Default
|
||||
DomainName string `json:"domain_name"`
|
||||
|
||||
// 用户名
|
||||
// 用户名 (openstack, zstack, esxi)
|
||||
Username string `json:"username"`
|
||||
|
||||
// 密码
|
||||
// 密码 (openstack, zstack, esxi)
|
||||
Password string `json:"password"`
|
||||
|
||||
// 认证地址
|
||||
// 认证地址 (openstack,zstack)
|
||||
AuthUrl string `json:"auto_url"`
|
||||
|
||||
// 秘钥id
|
||||
// 秘钥id (Aliyun, Aws, huawei, ucloud, ctyun, zstack, s3)
|
||||
AccessKeyId string `json:"access_key_id"`
|
||||
|
||||
// 秘钥key
|
||||
// 秘钥key (Aliyun, Aws, huawei, ucloud, ctyun, zstack, s3)
|
||||
AccessKeySecret string `json:"access_key_secret"`
|
||||
|
||||
// 环境
|
||||
// 环境 (Azure, Aws, huawei, ctyun)
|
||||
Environment string `json:"environment"`
|
||||
|
||||
// 目录ID
|
||||
// 目录ID (Azure)
|
||||
DirectoryId string `json:"directory_id"`
|
||||
|
||||
// 客户端ID
|
||||
// 客户端ID (Azure)
|
||||
ClientId string `json:"client_id"`
|
||||
|
||||
// 客户端秘钥
|
||||
// 客户端秘钥 (Azure)
|
||||
ClientSecret string `json:"client_secret"`
|
||||
|
||||
// 主机IP
|
||||
// 主机IP (esxi)
|
||||
Host string `json:"host"`
|
||||
|
||||
// 主机端口
|
||||
// 主机端口 (esxi)
|
||||
Port int `json:"port"`
|
||||
|
||||
// 端点
|
||||
// 端点 (s3)
|
||||
Endpoint string `json:"endpoint"`
|
||||
|
||||
// app id
|
||||
// app id (Qcloud)
|
||||
AppId string `json:"app_id"`
|
||||
|
||||
//秘钥ID
|
||||
//秘钥ID (Qcloud)
|
||||
SecretId string `json:"secret_id"`
|
||||
|
||||
//秘钥key
|
||||
//秘钥key (Qcloud)
|
||||
SecretKey string `json:"secret_key"`
|
||||
|
||||
// Google服务账号email
|
||||
ClientEmail string `json:"client_email"`
|
||||
// Google服务账号project id
|
||||
ProjectId string `json:"project_id"`
|
||||
// Google服务账号秘钥id
|
||||
PrivateKeyId string `json:"private_key_id"`
|
||||
// Google服务账号秘钥
|
||||
PrivateKey string `json:"private_key"`
|
||||
// Google服务账号email (gcp)
|
||||
GCPClientEmail string `json:"gcp_client_email"`
|
||||
// Google服务账号project id (gcp)
|
||||
GCPProjectId string `json:"gcp_project_id"`
|
||||
// Google服务账号秘钥id (gcp)
|
||||
GCPPrivateKeyId string `json:"gcp_private_key_id"`
|
||||
// Google服务账号秘钥 (gcp)
|
||||
GCPPrivateKey string `json:"gcp_private_key"`
|
||||
}
|
||||
|
||||
type SCloudaccount struct {
|
||||
|
||||
@@ -56,17 +56,17 @@ func (self *SGoogleProviderFactory) NeedSyncSkuFromCloud() bool {
|
||||
func (self *SGoogleProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input cloudprovider.SCloudaccountCredential) (cloudprovider.SCloudaccount, error) {
|
||||
output := cloudprovider.SCloudaccount{}
|
||||
for key, value := range map[string]string{
|
||||
"client_email": input.ClientEmail,
|
||||
"project_id": input.ProjectId,
|
||||
"private_key_id": input.PrivateKeyId,
|
||||
"private_key": input.PrivateKey,
|
||||
"client_email": input.GCPClientEmail,
|
||||
"project_id": input.GCPProjectId,
|
||||
"private_key_id": input.GCPPrivateKeyId,
|
||||
"private_key": input.GCPPrivateKey,
|
||||
} {
|
||||
if len(value) == 0 {
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, key)
|
||||
}
|
||||
}
|
||||
output.Account = fmt.Sprintf("%s/%s", input.ProjectId, input.ClientEmail)
|
||||
output.Secret = fmt.Sprintf("%s/%s", input.PrivateKeyId, input.PrivateKey)
|
||||
output.Account = fmt.Sprintf("%s/%s", input.GCPProjectId, input.GCPClientEmail)
|
||||
output.Secret = fmt.Sprintf("%s/%s", input.GCPPrivateKeyId, input.GCPPrivateKey)
|
||||
return output, nil
|
||||
}
|
||||
|
||||
@@ -79,24 +79,24 @@ func (self *SGoogleProviderFactory) ValidateUpdateCloudaccountCredential(ctx con
|
||||
}
|
||||
|
||||
for key, value := range map[string]string{
|
||||
"private_key_id": input.PrivateKeyId,
|
||||
"private_key": input.PrivateKey,
|
||||
"private_key_id": input.GCPPrivateKeyId,
|
||||
"private_key": input.GCPPrivateKey,
|
||||
} {
|
||||
if len(value) == 0 {
|
||||
return output, errors.Wrap(httperrors.ErrMissingParameter, key)
|
||||
}
|
||||
}
|
||||
if len(input.ClientEmail) == 0 {
|
||||
input.ClientEmail = clientEmail
|
||||
if len(input.GCPClientEmail) == 0 {
|
||||
input.GCPClientEmail = clientEmail
|
||||
}
|
||||
|
||||
if len(input.ProjectId) == 0 {
|
||||
input.ProjectId = projectID
|
||||
if len(input.GCPProjectId) == 0 {
|
||||
input.GCPProjectId = projectID
|
||||
}
|
||||
|
||||
output = cloudprovider.SCloudaccount{
|
||||
Account: fmt.Sprintf("%s/%s", input.ProjectId, input.ClientEmail),
|
||||
Secret: fmt.Sprintf("%s/%s", input.PrivateKeyId, input.PrivateKey),
|
||||
Account: fmt.Sprintf("%s/%s", input.GCPProjectId, input.GCPClientEmail),
|
||||
Secret: fmt.Sprintf("%s/%s", input.GCPPrivateKeyId, input.GCPPrivateKey),
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user