cloudprovider: use ProviderConfig

This commit is contained in:
Yousong Zhou
2020-03-22 19:36:43 +08:00
parent 1e08ef5441
commit 944e57e572
19 changed files with 122 additions and 54 deletions
+28 -4
View File
@@ -149,6 +149,8 @@ type SCloudaccount struct {
IsPublic bool `default:"false" nullable:"false"`
// add share_mode field to indicate the share range of this account
ShareMode string `width:"32" charset:"ascii" nullable:"true" list:"domain"`
ProxySettingId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional" default:"default"`
}
func (self *SCloudaccount) GetCloudproviders() []SCloudprovider {
@@ -343,7 +345,12 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
return input, httperrors.NewConflictError("The account has been registered")
}
accountId, err := cloudprovider.IsValidCloudAccount(input.AccessUrl, input.Account, input.Secret, input.Provider)
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
Vendor: input.Provider,
URL: input.AccessUrl,
Account: input.Account,
Secret: input.Secret,
})
if err != nil {
if err == cloudprovider.ErrNoSuchProvder {
return input, httperrors.NewResourceNotFoundError("no such provider %s", input.Provider)
@@ -470,7 +477,12 @@ func (self *SCloudaccount) PerformTestConnectivity(ctx context.Context, userCred
return nil, err
}
_, err = cloudprovider.IsValidCloudAccount(self.AccessUrl, account.Account, account.Secret, self.Provider)
_, err = cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
URL: self.AccessUrl,
Vendor: self.Provider,
Account: account.Account,
Secret: account.Secret,
})
if err != nil {
return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error())
}
@@ -521,7 +533,12 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred
originSecret, _ := self.getPassword()
accountId, err := cloudprovider.IsValidCloudAccount(self.AccessUrl, account.Account, account.Secret, self.Provider)
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
Vendor: self.Provider,
URL: self.AccessUrl,
Account: account.Account,
Secret: account.Secret,
})
if err != nil {
return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error())
}
@@ -678,7 +695,14 @@ func (self *SCloudaccount) getProviderInternal() (cloudprovider.ICloudProvider,
if err != nil {
return nil, fmt.Errorf("Invalid password %s", err)
}
return cloudprovider.GetProvider(self.Id, self.Name, self.AccessUrl, self.Account, secret, self.Provider)
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
Id: self.Id,
Name: self.Name,
Vendor: self.Provider,
URL: self.AccessUrl,
Account: self.Account,
Secret: secret,
})
}
func (self *SCloudaccount) GetSubAccounts() ([]cloudprovider.SSubAccount, error) {
+8 -1
View File
@@ -754,7 +754,14 @@ func (self *SCloudprovider) GetProvider() (cloudprovider.ICloudProvider, error)
if err != nil {
return nil, err
}
return cloudprovider.GetProvider(self.Id, self.Name, accessUrl, self.Account, passwd, self.Provider)
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
Id: self.Id,
Name: self.Name,
Vendor: self.Provider,
URL: accessUrl,
Account: self.Account,
Secret: passwd,
})
}
func (self *SCloudprovider) savePassword(secret string) error {