mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-28 19:45:07 +08:00
Merge pull request #3187 from ioito/hotfix/qx-cloud-account-tenant
fix: 创建云账号时指定tenant生效
This commit is contained in:
@@ -27,6 +27,7 @@ CloudaccountCreate:
|
||||
auto_create_project:
|
||||
type: boolean
|
||||
example: false
|
||||
default: false
|
||||
description: 自动在本地创建纳管云上的项目
|
||||
access_key_id:
|
||||
type: string
|
||||
@@ -92,6 +93,10 @@ CloudaccountCreate:
|
||||
type: string
|
||||
example: 123134442
|
||||
description: 腾讯云专有的app_id
|
||||
tenant:
|
||||
type: string
|
||||
example: system
|
||||
description: 项目ID或名称,指定此参数后子账号将归属于指定的项目,优先级高于auto_create_project参数
|
||||
|
||||
|
||||
CloudaccountResponse:
|
||||
@@ -284,4 +289,4 @@ CloudaccountEnableAutoSync:
|
||||
sync_interval_seconds:
|
||||
type: integer
|
||||
example: 3600
|
||||
description: 云账号自动同步间隔时间
|
||||
description: 云账号自动同步间隔时间
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2019 Yunion
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package compute
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
)
|
||||
|
||||
type CloudaccountCreateInput struct {
|
||||
apis.Meta
|
||||
|
||||
Provider string
|
||||
Brand string
|
||||
IsPublicCloud bool
|
||||
IsOnPremise bool
|
||||
Account string
|
||||
Secret string
|
||||
AccessUrl string
|
||||
TenantId string
|
||||
Name string
|
||||
Description string
|
||||
Enabled bool
|
||||
EnableAutoSync bool
|
||||
SyncIntervalSeconds int
|
||||
AutoCreateProject bool
|
||||
Options *jsonutils.JSONObject
|
||||
|
||||
ProjectName string //OpenStack
|
||||
DomainName string //OpenStack
|
||||
Username string //OpenStack Esxi ZStack
|
||||
Password string //OpenStack Esxi ZStack
|
||||
AuthUrl string //OpenStack ZStack
|
||||
|
||||
AccessKeyId string //Huawei Aliyun Ucloud Aws
|
||||
AccessKeySecret string //Huawei Aliyun Ucloud Aws
|
||||
Environment string //Huawei Azure Aws
|
||||
|
||||
DirectoryId string //Azure
|
||||
ClientId string //Azure
|
||||
ClientSecret string //Azure
|
||||
|
||||
Host string //Esxi
|
||||
Port int //Esxi
|
||||
|
||||
Endpoint string
|
||||
|
||||
AppId string //Qcloud
|
||||
SecretId string //Qcloud
|
||||
SecretKey string //Qcloud
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
@@ -44,7 +45,7 @@ type ICloudProviderFactory interface {
|
||||
GetName() string
|
||||
|
||||
ValidateChangeBandwidth(instanceId string, bandwidth int64) error
|
||||
ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error
|
||||
ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error
|
||||
ValidateUpdateCloudaccountCredential(ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject, cloudaccount string) (*SCloudaccount, error)
|
||||
GetSupportedBrands() []string
|
||||
|
||||
@@ -202,7 +203,7 @@ func (factory *baseProviderFactory) GetSupportedBrands() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (factory *baseProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
func (factory *baseProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
return httperrors.NewNotImplementedError("Not Implemented ValidateCreateCloudaccountData")
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/compute/options"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -76,6 +77,8 @@ type SCloudaccount struct {
|
||||
SSyncableBaseResource
|
||||
LastAutoSync time.Time `list:"domain"`
|
||||
|
||||
ProjectId string `name:"tenant_id" width:"128" charset:"ascii" list:"user" create:"domain_optional"`
|
||||
|
||||
AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"domain" update:"domain" create:"domain_optional"`
|
||||
|
||||
Account string `width:"128" charset:"ascii" nullable:"false" list:"domain" create:"domain_required"` // Column(VARCHAR(64, charset='ascii'), nullable=False)
|
||||
@@ -258,40 +261,46 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// check provider
|
||||
// name, _ := data.GetString("name")
|
||||
provider, _ := data.GetString("provider")
|
||||
if !cloudprovider.IsSupported(provider) {
|
||||
return nil, httperrors.NewInputParameterError("Unsupported provider %s", provider)
|
||||
}
|
||||
providerDriver, _ := cloudprovider.GetProviderFactory(provider)
|
||||
if err := providerDriver.ValidateCreateCloudaccountData(ctx, userCred, data); err != nil {
|
||||
|
||||
tenantV := validators.NewModelIdOrNameValidator("tenant", "tenant", ownerId)
|
||||
tenantV.Optional(true)
|
||||
err = tenantV.Validate(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
brand, _ := data.GetString("brand")
|
||||
if len(brand) > 0 && brand != providerDriver.GetName() {
|
||||
|
||||
input := &api.CloudaccountCreateInput{}
|
||||
err = data.Unmarshal(input)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("failed to unmarshal input params error: %v", err)
|
||||
}
|
||||
|
||||
if !cloudprovider.IsSupported(input.Provider) {
|
||||
return nil, httperrors.NewInputParameterError("Unsupported provider %s", input.Provider)
|
||||
}
|
||||
providerDriver, _ := cloudprovider.GetProviderFactory(input.Provider)
|
||||
err = providerDriver.ValidateCreateCloudaccountData(ctx, userCred, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(input.Brand) > 0 && input.Brand != providerDriver.GetName() {
|
||||
brands := providerDriver.GetSupportedBrands()
|
||||
if !utils.IsInStringArray(providerDriver.GetName(), brands) {
|
||||
brands = append(brands, providerDriver.GetName())
|
||||
}
|
||||
if !utils.IsInStringArray(brand, brands) {
|
||||
return nil, httperrors.NewUnsupportOperationError("Not support brand %s, only support %s", brand, brands)
|
||||
if !utils.IsInStringArray(input.Brand, brands) {
|
||||
return nil, httperrors.NewUnsupportOperationError("Not support brand %s, only support %s", input.Brand, brands)
|
||||
}
|
||||
}
|
||||
data.Set("is_public_cloud", jsonutils.NewBool(providerDriver.IsPublicCloud()))
|
||||
data.Set("is_on_premise", jsonutils.NewBool(providerDriver.IsOnPremise()))
|
||||
// check duplication
|
||||
// url, account, provider must be unique
|
||||
account, _ := data.GetString("account")
|
||||
secret, _ := data.GetString("secret")
|
||||
url, _ := data.GetString("access_url")
|
||||
input.IsPublicCloud = providerDriver.IsPublicCloud()
|
||||
input.IsOnPremise = providerDriver.IsOnPremise()
|
||||
|
||||
q := manager.Query().Equals("provider", provider)
|
||||
if len(account) > 0 {
|
||||
q = q.Equals("account", account)
|
||||
q := manager.Query().Equals("provider", input.Provider)
|
||||
if len(input.Account) > 0 {
|
||||
q = q.Equals("account", input.Account)
|
||||
}
|
||||
if len(url) > 0 {
|
||||
q = q.Equals("access_url", url)
|
||||
if len(input.AccessUrl) > 0 {
|
||||
q = q.Equals("access_url", input.AccessUrl)
|
||||
}
|
||||
|
||||
cnt, err := q.CountWithError()
|
||||
@@ -302,10 +311,10 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
return nil, httperrors.NewConflictError("The account has been registered")
|
||||
}
|
||||
|
||||
accountId, err := cloudprovider.IsValidCloudAccount(url, account, secret, provider)
|
||||
accountId, err := cloudprovider.IsValidCloudAccount(input.AccessUrl, input.Account, input.Secret, input.Provider)
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNoSuchProvder {
|
||||
return nil, httperrors.NewResourceNotFoundError("no such provider %s", provider)
|
||||
return nil, httperrors.NewResourceNotFoundError("no such provider %s", input.Provider)
|
||||
}
|
||||
//log.Debugf("ValidateCreateData %s", err.Error())
|
||||
return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error())
|
||||
@@ -323,15 +332,13 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
data.Set("account_id", jsonutils.NewString(accountId))
|
||||
}
|
||||
|
||||
syncIntervalSecs, _ := data.Int("sync_interval_seconds")
|
||||
if syncIntervalSecs == 0 {
|
||||
syncIntervalSecs = int64(options.Options.DefaultSyncIntervalSeconds)
|
||||
} else if syncIntervalSecs < int64(options.Options.MinimalSyncIntervalSeconds) {
|
||||
syncIntervalSecs = int64(options.Options.MinimalSyncIntervalSeconds)
|
||||
if input.SyncIntervalSeconds == 0 {
|
||||
input.SyncIntervalSeconds = options.Options.DefaultSyncIntervalSeconds
|
||||
} else if input.SyncIntervalSeconds < options.Options.MinimalSyncIntervalSeconds {
|
||||
input.SyncIntervalSeconds = options.Options.MinimalSyncIntervalSeconds
|
||||
}
|
||||
data.Set("sync_interval_seconds", jsonutils.NewInt(syncIntervalSecs))
|
||||
|
||||
if !jsonutils.QueryBoolean(query, "auto_create_project", false) {
|
||||
if !input.AutoCreateProject {
|
||||
if userCred.GetProjectDomainId() != ownerId.GetProjectDomainId() {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
params := jsonutils.Marshal(map[string]string{"domain_id": ownerId.GetProjectDomainId()})
|
||||
@@ -345,7 +352,12 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
}
|
||||
}
|
||||
|
||||
return manager.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, data)
|
||||
data, err = manager.SEnabledStatusStandaloneResourceBaseManager.ValidateCreateData(ctx, userCred, ownerId, query, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return input.JSON(input), nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) error {
|
||||
@@ -655,9 +667,19 @@ func (self *SCloudaccount) importSubAccount(ctx context.Context, userCred mcclie
|
||||
newCloudprovider.Status = api.CLOUD_PROVIDER_CONNECTED
|
||||
newCloudprovider.HealthStatus = self.HealthStatus
|
||||
newCloudprovider.Name = newName
|
||||
if !self.AutoCreateProject {
|
||||
if !self.AutoCreateProject || len(self.ProjectId) > 0 {
|
||||
ownerId := self.GetOwnerId()
|
||||
if ownerId == nil || ownerId.GetProjectDomainId() == userCred.GetProjectDomainId() {
|
||||
if len(self.ProjectId) > 0 {
|
||||
t, err := db.TenantCacheManager.FetchTenantById(ctx, self.ProjectId)
|
||||
if err != nil {
|
||||
log.Errorf("cannot find tenant %s for domain %s", self.ProjectId, ownerId.GetProjectDomainId())
|
||||
return nil, err
|
||||
}
|
||||
ownerId = &db.SOwnerId{
|
||||
DomainId: t.DomainId,
|
||||
ProjectId: t.Id,
|
||||
}
|
||||
} else if ownerId == nil || ownerId.GetProjectDomainId() == userCred.GetProjectDomainId() {
|
||||
ownerId = userCred
|
||||
} else {
|
||||
// find default project of domain
|
||||
@@ -698,7 +720,7 @@ func (self *SCloudaccount) importSubAccount(ctx context.Context, userCred mcclie
|
||||
|
||||
newCloudprovider.savePassword(passwd)
|
||||
|
||||
if self.AutoCreateProject {
|
||||
if self.AutoCreateProject && len(self.ProjectId) == 0 {
|
||||
err = newCloudprovider.syncProject(ctx, userCred)
|
||||
if err != nil {
|
||||
log.Errorf("syncproject fail %s", err)
|
||||
|
||||
@@ -38,17 +38,15 @@ func (self *SAliyunProviderFactory) GetName() string {
|
||||
return aliyun.CLOUD_PROVIDER_ALIYUN_CN
|
||||
}
|
||||
|
||||
func (self *SAliyunProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
func (self *SAliyunProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AccessKeyId) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
input.Account = input.AccessKeyId
|
||||
input.Secret = input.AccessKeySecret
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -42,22 +42,19 @@ func (self *SAwsProviderFactory) IsSupportPrepaidResources() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SAwsProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
func (self *SAwsProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AccessKeyId) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
environment, _ := data.GetString("environment")
|
||||
if len(environment) == 0 {
|
||||
if len(input.Environment) == 0 {
|
||||
return httperrors.NewMissingParameterError("environment")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
data.Set("access_url", jsonutils.NewString(environment))
|
||||
input.Account = input.AccessKeyId
|
||||
input.Secret = input.AccessKeySecret
|
||||
input.AccessUrl = input.Environment
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -49,26 +49,22 @@ func (self *SAzureProviderFactory) IsSupportPrepaidResources() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SAzureProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
directoryID, _ := data.GetString("directory_id")
|
||||
if len(directoryID) == 0 {
|
||||
func (self *SAzureProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.DirectoryId) == 0 {
|
||||
return httperrors.NewMissingParameterError("directory_id")
|
||||
}
|
||||
clientID, _ := data.GetString("client_id")
|
||||
if len(clientID) == 0 {
|
||||
if len(input.ClientId) == 0 {
|
||||
return httperrors.NewMissingParameterError("client_id")
|
||||
}
|
||||
clientSecret, _ := data.GetString("client_secret")
|
||||
if len(clientSecret) == 0 {
|
||||
if len(input.ClientSecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("client_secret")
|
||||
}
|
||||
environment, _ := data.GetString("environment")
|
||||
if len(environment) == 0 {
|
||||
if len(input.Environment) == 0 {
|
||||
return httperrors.NewMissingParameterError("environment")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(directoryID))
|
||||
data.Set("secret", jsonutils.NewString(fmt.Sprintf("%s/%s", clientID, clientSecret)))
|
||||
data.Set("access_url", jsonutils.NewString(environment))
|
||||
input.Account = input.DirectoryId
|
||||
input.Secret = fmt.Sprintf("%s/%s", input.ClientId, input.ClientSecret)
|
||||
input.AccessUrl = input.Environment
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -47,27 +47,22 @@ func (self *SESXiProviderFactory) ValidateChangeBandwidth(instanceId string, ban
|
||||
return fmt.Errorf("Changing %s bandwidth is not supported", esxi.CLOUD_PROVIDER_VMWARE)
|
||||
}
|
||||
|
||||
func (self *SESXiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
username, _ := data.GetString("username")
|
||||
if len(username) == 0 {
|
||||
func (self *SESXiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.Username) == 0 {
|
||||
return httperrors.NewMissingParameterError("username")
|
||||
}
|
||||
password, _ := data.GetString("password")
|
||||
if len(password) == 0 {
|
||||
if len(input.Password) == 0 {
|
||||
return httperrors.NewMissingParameterError("password")
|
||||
}
|
||||
host, _ := data.GetString("host")
|
||||
if len(host) == 0 {
|
||||
if len(input.Host) == 0 {
|
||||
return httperrors.NewMissingParameterError("host")
|
||||
}
|
||||
port, _ := data.Int("port")
|
||||
accessURL := fmt.Sprintf("https://%s:%d/sdk", host, port)
|
||||
if port == 0 || port == 443 {
|
||||
accessURL = fmt.Sprintf("https://%s/sdk", host)
|
||||
input.AccessUrl = fmt.Sprintf("https://%s:%d/sdk", input.Host, input.Port)
|
||||
if input.Port == 0 || input.Port == 443 {
|
||||
input.AccessUrl = fmt.Sprintf("https://%s/sdk", input.Host)
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(username))
|
||||
data.Set("secret", jsonutils.NewString(password))
|
||||
data.Set("access_url", jsonutils.NewString(accessURL))
|
||||
input.Account = input.Username
|
||||
input.Secret = input.Password
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -39,22 +39,21 @@ func (self *SHuaweiProviderFactory) GetName() string {
|
||||
return huawei.CLOUD_PROVIDER_HUAWEI_CN
|
||||
}
|
||||
|
||||
func (self *SHuaweiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
func (self *SHuaweiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AccessKeyId) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
environment, _ := data.GetString("environment")
|
||||
if len(environment) == 0 {
|
||||
if len(input.Environment) == 0 {
|
||||
return httperrors.NewMissingParameterError("environment")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
data.Set("access_url", jsonutils.NewString(environment))
|
||||
|
||||
input.Account = input.AccessKeyId
|
||||
input.Secret = input.AccessKeySecret
|
||||
input.AccessUrl = input.Environment
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -42,22 +42,19 @@ func (factory *SObjectStoreProviderFactory) IsSupportObjectStorage() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (self *SObjectStoreProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
func (self *SObjectStoreProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AccessKeyId) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
endpointURL, _ := data.GetString("endpoint")
|
||||
if len(endpointURL) == 0 {
|
||||
if len(input.Endpoint) == 0 {
|
||||
return httperrors.NewMissingParameterError("endpoint")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
data.Set("access_url", jsonutils.NewString(endpointURL))
|
||||
input.Account = input.AccessKeyId
|
||||
input.Secret = input.AccessKeySecret
|
||||
input.AccessUrl = input.Endpoint
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -42,31 +42,27 @@ func (self *SOpenStackProviderFactory) GetName() string {
|
||||
return openstack.CLOUD_PROVIDER_OPENSTACK
|
||||
}
|
||||
|
||||
func (self *SOpenStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
projectName, _ := data.GetString("project_name")
|
||||
if len(projectName) == 0 {
|
||||
func (self *SOpenStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.ProjectName) == 0 {
|
||||
return httperrors.NewMissingParameterError("project_name")
|
||||
}
|
||||
username, _ := data.GetString("username")
|
||||
if len(username) == 0 {
|
||||
if len(input.Username) == 0 {
|
||||
return httperrors.NewMissingParameterError("username")
|
||||
}
|
||||
password, _ := data.GetString("password")
|
||||
if len(password) == 0 {
|
||||
if len(input.Password) == 0 {
|
||||
return httperrors.NewMissingParameterError("password")
|
||||
}
|
||||
authURL, _ := data.GetString("auth_url")
|
||||
if len(authURL) == 0 {
|
||||
if len(input.AuthUrl) == 0 {
|
||||
return httperrors.NewMissingParameterError("auth_url")
|
||||
}
|
||||
account := fmt.Sprintf("%s/%s", projectName, username)
|
||||
if domainName, _ := data.GetString("domain_name"); len(domainName) > 0 {
|
||||
account = fmt.Sprintf("%s/%s", account, domainName)
|
||||
|
||||
input.Account = fmt.Sprintf("%s/%s", input.ProjectName, input.Username)
|
||||
if len(input.DomainName) > 0 {
|
||||
input.Account = fmt.Sprintf("%s/%s", input.Account, input.DomainName)
|
||||
}
|
||||
|
||||
data.Set("account", jsonutils.NewString(account))
|
||||
data.Set("secret", jsonutils.NewString(password))
|
||||
data.Set("access_url", jsonutils.NewString(authURL))
|
||||
input.Secret = input.Password
|
||||
input.AccessUrl = input.AuthUrl
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -47,21 +47,18 @@ func (self *SQcloudProviderFactory) ValidateChangeBandwidth(instanceId string, b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
appID, _ := data.GetString("app_id")
|
||||
if len(appID) == 0 {
|
||||
func (self *SQcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AppId) == 0 {
|
||||
return httperrors.NewMissingParameterError("app_id")
|
||||
}
|
||||
secretID, _ := data.GetString("secret_id")
|
||||
if len(secretID) == 0 {
|
||||
if len(input.SecretId) == 0 {
|
||||
return httperrors.NewMissingParameterError("secret_id")
|
||||
}
|
||||
secretKey, _ := data.GetString("secret_key")
|
||||
if len(secretKey) == 0 {
|
||||
if len(input.SecretKey) == 0 {
|
||||
return httperrors.NewMissingParameterError("secret_key")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(fmt.Sprintf("%s/%s", secretID, appID)))
|
||||
data.Set("secret", jsonutils.NewString(secretKey))
|
||||
input.Account = fmt.Sprintf("%s/%s", input.SecretId, input.AppId)
|
||||
input.Secret = input.SecretKey
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -40,17 +40,15 @@ func (self *SUcloudProviderFactory) GetName() string {
|
||||
return ucloud.CLOUD_PROVIDER_UCLOUD_CN
|
||||
}
|
||||
|
||||
func (self *SUcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
func (self *SUcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.AccessKeyId) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
if len(input.AccessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
input.Account = input.AccessKeyId
|
||||
input.Secret = input.AccessKeySecret
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -43,22 +43,19 @@ func (self *SZStackProviderFactory) GetSupportedBrands() []string {
|
||||
return []string{api.ZSTACK_BRAND_DSTACK}
|
||||
}
|
||||
|
||||
func (self *SZStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
username, _ := data.GetString("username")
|
||||
if len(username) == 0 {
|
||||
func (self *SZStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, input *api.CloudaccountCreateInput) error {
|
||||
if len(input.Username) == 0 {
|
||||
return httperrors.NewMissingParameterError("username")
|
||||
}
|
||||
password, _ := data.GetString("password")
|
||||
if len(password) == 0 {
|
||||
if len(input.Password) == 0 {
|
||||
return httperrors.NewMissingParameterError("password")
|
||||
}
|
||||
authURL, _ := data.GetString("auth_url")
|
||||
if len(authURL) == 0 {
|
||||
if len(input.AuthUrl) == 0 {
|
||||
return httperrors.NewMissingParameterError("auth_url")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(username))
|
||||
data.Set("secret", jsonutils.NewString(password))
|
||||
data.Set("access_url", jsonutils.NewString(authURL))
|
||||
input.Account = input.Username
|
||||
input.Secret = input.Password
|
||||
input.AccessUrl = input.AuthUrl
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user