diff --git a/docs/schemas/cloudaccount.yaml b/docs/schemas/cloudaccount.yaml index 513044ce94..2a4b750d98 100644 --- a/docs/schemas/cloudaccount.yaml +++ b/docs/schemas/cloudaccount.yaml @@ -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: 云账号自动同步间隔时间 \ No newline at end of file + description: 云账号自动同步间隔时间 diff --git a/pkg/apis/compute/cloudaccount.go b/pkg/apis/compute/cloudaccount.go new file mode 100644 index 0000000000..193154f061 --- /dev/null +++ b/pkg/apis/compute/cloudaccount.go @@ -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 +} diff --git a/pkg/cloudprovider/cloudprovider.go b/pkg/cloudprovider/cloudprovider.go index c5c4a214e3..a73043ff9d 100644 --- a/pkg/cloudprovider/cloudprovider.go +++ b/pkg/cloudprovider/cloudprovider.go @@ -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") } diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 94d7a9fad3..172e2319ad 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -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) diff --git a/pkg/multicloud/aliyun/provider/provider.go b/pkg/multicloud/aliyun/provider/provider.go index 0623d68f19..5dc26e076c 100644 --- a/pkg/multicloud/aliyun/provider/provider.go +++ b/pkg/multicloud/aliyun/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/aws/provider/provider.go b/pkg/multicloud/aws/provider/provider.go index 5887cc9b61..37baeb78ff 100644 --- a/pkg/multicloud/aws/provider/provider.go +++ b/pkg/multicloud/aws/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/azure/provider/provider.go b/pkg/multicloud/azure/provider/provider.go index 3d37d930dc..625724ca7d 100644 --- a/pkg/multicloud/azure/provider/provider.go +++ b/pkg/multicloud/azure/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/esxi/provider/provider.go b/pkg/multicloud/esxi/provider/provider.go index b5fb02948d..c7bc1f2985 100644 --- a/pkg/multicloud/esxi/provider/provider.go +++ b/pkg/multicloud/esxi/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/huawei/provider/provider.go b/pkg/multicloud/huawei/provider/provider.go index 6b62cf21ad..1a68590cf0 100644 --- a/pkg/multicloud/huawei/provider/provider.go +++ b/pkg/multicloud/huawei/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/objectstore/provider/provider.go b/pkg/multicloud/objectstore/provider/provider.go index 9a452868dd..0c856c51ea 100644 --- a/pkg/multicloud/objectstore/provider/provider.go +++ b/pkg/multicloud/objectstore/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/openstack/provider/provider.go b/pkg/multicloud/openstack/provider/provider.go index f809674d79..802fa3a119 100644 --- a/pkg/multicloud/openstack/provider/provider.go +++ b/pkg/multicloud/openstack/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/qcloud/provider/provider.go b/pkg/multicloud/qcloud/provider/provider.go index a576365766..be7a2fc15d 100644 --- a/pkg/multicloud/qcloud/provider/provider.go +++ b/pkg/multicloud/qcloud/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/ucloud/provider/provider.go b/pkg/multicloud/ucloud/provider/provider.go index ea01d02ab6..0fb0038fb9 100644 --- a/pkg/multicloud/ucloud/provider/provider.go +++ b/pkg/multicloud/ucloud/provider/provider.go @@ -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 } diff --git a/pkg/multicloud/zstack/provider/provider.go b/pkg/multicloud/zstack/provider/provider.go index d810ec5013..c67c9f1b10 100644 --- a/pkg/multicloud/zstack/provider/provider.go +++ b/pkg/multicloud/zstack/provider/provider.go @@ -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 }