Merge pull request #10757 from rainzm/ecloud/validate_fix

Validate creating cloud account data about ecloud
This commit is contained in:
Zexi Li
2021-04-16 10:06:15 +08:00
committed by GitHub
2 changed files with 16 additions and 4 deletions
+12
View File
@@ -103,6 +103,18 @@ func (ec *SEcloudClient) fetchRegions() {
return
}
func (ec *SEcloudClient) TryConnect() error {
iregions := ec.GetIRegions()
if len(iregions) == 0 {
return fmt.Errorf("no invalid region for ecloud")
}
_, err := iregions[0].GetIZones()
if err != nil {
return errors.Wrap(err, "try to connect failed")
}
return nil
}
func (ec *SEcloudClient) GetIRegions() []cloudprovider.ICloudRegion {
if ec.iregions == nil {
ec.fetchRegions()
+4 -4
View File
@@ -52,12 +52,8 @@ func (f *SEcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Cont
if len(input.AccessKeySecret) == 0 {
return output, errors.Wrap(httperrors.ErrMissingParameter, "access_key_secret")
}
if len(input.Environment) == 0 {
return output, errors.Wrap(httperrors.ErrMissingParameter, "environment")
}
output.Account = input.AccessKeyId
output.Secret = input.AccessKeySecret
output.AccessUrl = input.Environment
return output, nil
}
@@ -91,6 +87,10 @@ func (f *SEcloudProviderFactory) GetProvider(cfg cloudprovider.ProviderConfig) (
if err != nil {
return nil, err
}
err = client.TryConnect()
if err != nil {
return nil, err
}
return &SEcloudProvider{
SBaseProvider: cloudprovider.NewBaseProvider(f),
client: client,