From be1f33c60107148a5698c5fdee05f9b9d09941f8 Mon Sep 17 00:00:00 2001 From: rainzm Date: Mon, 12 Apr 2021 15:55:15 +0800 Subject: [PATCH] feat(region): allow to update account with provider vmware --- pkg/cloudprovider/cloudprovider.go | 11 +++++++++++ pkg/compute/models/cloudaccounts.go | 4 +++- pkg/multicloud/esxi/provider/provider.go | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/cloudprovider.go b/pkg/cloudprovider/cloudprovider.go index 952b3c2a85..c3918e95fd 100644 --- a/pkg/cloudprovider/cloudprovider.go +++ b/pkg/cloudprovider/cloudprovider.go @@ -225,6 +225,8 @@ type ICloudProviderFactory interface { GetTTLRange(zoneType TDnsZoneType, productType TDnsProductType) TTlRange IsSupportSAMLAuth() bool + + GetAccountIdEqualizer() func(origin, now string) bool } type ICloudProvider interface { @@ -711,6 +713,15 @@ func (factory *baseProviderFactory) GetTTLRange(zoneType TDnsZoneType, productTy return TTlRange{} } +func (factory *baseProviderFactory) GetAccountIdEqualizer() func(origin, now string) bool { + return func(origin, now string) bool { + if len(now) > 0 && now != origin { + return false + } + return true + } +} + type SDnsCapability struct { ZoneTypes []TDnsZoneType DnsTypes map[TDnsZoneType][]TDnsType diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index f2601fd7ef..49ed892f30 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -713,8 +713,10 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred if err != nil { return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error()) } + + isEqual := providerDriver.GetAccountIdEqualizer() // for backward compatibility - if len(self.AccountId) > 0 && accountId != self.AccountId { + if !isEqual(self.AccountId, accountId) { return nil, httperrors.NewConflictError("inconsistent account_id, previous '%s' and now '%s'", self.AccountId, accountId) } diff --git a/pkg/multicloud/esxi/provider/provider.go b/pkg/multicloud/esxi/provider/provider.go index cc80f82d31..836da9539a 100644 --- a/pkg/multicloud/esxi/provider/provider.go +++ b/pkg/multicloud/esxi/provider/provider.go @@ -143,6 +143,24 @@ func (self *SESXiProviderFactory) GetClientRC(info cloudprovider.SProviderInfo) }, nil } +func (self *SESXiProviderFactory) GetAccountIdEqualizer() func(origin, now string) bool { + return func(origin, now string) bool { + if len(now) == 0 { + return true + } + originUserName, nowUserName := origin, now + index1 := strings.Index(origin, "@") + index2 := strings.Index(now, "@") + if index1 != -1 { + originUserName = originUserName[:index1] + } + if index2 != -1 { + nowUserName = nowUserName[:index2] + } + return originUserName == nowUserName + } +} + func init() { factory := SESXiProviderFactory{} cloudprovider.RegisterFactory(&factory)