feat(region): allow to update account with provider vmware

This commit is contained in:
rainzm
2021-04-12 15:55:15 +08:00
parent 7f7745bb55
commit be1f33c601
3 changed files with 32 additions and 1 deletions
+11
View File
@@ -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
+3 -1
View File
@@ -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)
}
+18
View File
@@ -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)