Merge pull request #11135 from ioito/automated-cherry-pick-of-#11134-upstream-release-3.7

Automated cherry pick of #11134: fix(cloudid): clouduser use default domain
This commit is contained in:
Zexi Li
2021-05-18 15:56:42 +08:00
committed by GitHub
+29 -7
View File
@@ -267,7 +267,19 @@ func (self *SAzureClient) CreateIClouduser(conf *cloudprovider.SClouduserCreateC
}
type SDomain struct {
Name string
Name string
AuthenticationType string
AvailabilityStatus string
IsAdminManaged bool
IsDefault bool
IsDefaultForCloudRedirections bool
IsInitial bool
IsRoot bool
IsVerified bool
ForceDeleteState string
State string
PasswordValidityPeriodInDays string
PasswordNotificationWindowInDays string
}
func (self *SAzureClient) GetDomains() ([]SDomain, error) {
@@ -279,6 +291,19 @@ func (self *SAzureClient) GetDomains() ([]SDomain, error) {
return domains, nil
}
func (self *SAzureClient) GetDefaultDomain() (*SDomain, error) {
domains, err := self.GetDomains()
if err != nil {
return nil, errors.Wrapf(err, "GetDomains")
}
for i := range domains {
if domains[i].IsDefault {
return &domains[i], nil
}
}
return nil, cloudprovider.ErrNotFound
}
func (self *SAzureClient) CreateClouduser(name, password string) (*SClouduser, error) {
passwordProfile := map[string]interface{}{
"password": "Lomo1824",
@@ -293,14 +318,11 @@ func (self *SAzureClient) CreateClouduser(name, password string) (*SClouduser, e
"passwordProfile": passwordProfile,
"userPrincipalName": name,
}
domains, err := self.GetDomains()
domain, err := self.GetDefaultDomain()
if err != nil {
return nil, errors.Wrap(err, "GetDomains")
return nil, errors.Wrap(err, "GetDefaultDomain")
}
if len(domains) == 0 {
return nil, errors.Wrap(err, "Missing domains")
}
params["userPrincipalName"] = fmt.Sprintf("%s@%s", name, domains[0].Name)
params["userPrincipalName"] = fmt.Sprintf("%s@%s", name, domain.Name)
user := SClouduser{client: self}
err = self.gcreate("users", jsonutils.Marshal(params), &user)
if err != nil {