mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user