mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): azure china user create
This commit is contained in:
@@ -83,7 +83,7 @@ require (
|
||||
k8s.io/client-go v0.19.3
|
||||
k8s.io/cluster-bootstrap v0.19.3
|
||||
moul.io/http2curl/v2 v2.3.0
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406105729-f8da6df0afdb
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406135917-db04e7cb9d6e
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656
|
||||
yunion.io/x/jsonutils v1.0.1-0.20220819091305-3bab322ab4fd
|
||||
yunion.io/x/log v1.0.0
|
||||
|
||||
@@ -1164,8 +1164,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406105729-f8da6df0afdb h1:GKybau2Ra065D8jAa1XiBi3inXxhPAfHvy94B4g30e0=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406105729-f8da6df0afdb/go.mod h1:VBAtfyGMDW11x5JmF0vUEmn/PmNpZ8CKBAQCiyz+cDY=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406135917-db04e7cb9d6e h1:+zRaNZcXOYv28+2MZNoRC5a5SOefYPwFRgNRKa8EV0M=
|
||||
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406135917-db04e7cb9d6e/go.mod h1:VBAtfyGMDW11x5JmF0vUEmn/PmNpZ8CKBAQCiyz+cDY=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656 h1:0zlZD5uhZoIHgLVAWCz2aHaYk2ZrNsACCYD7R6EIBII=
|
||||
yunion.io/x/executor v0.0.0-20211018100936-39a2cd966656/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
|
||||
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
|
||||
|
||||
Vendored
+1
-1
@@ -1442,7 +1442,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
|
||||
# sigs.k8s.io/yaml v1.2.0
|
||||
## explicit; go 1.12
|
||||
sigs.k8s.io/yaml
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406105729-f8da6df0afdb
|
||||
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20230406135917-db04e7cb9d6e
|
||||
## explicit; go 1.18
|
||||
yunion.io/x/cloudmux/pkg/apis
|
||||
yunion.io/x/cloudmux/pkg/apis/billing
|
||||
|
||||
+11
@@ -184,6 +184,10 @@ func (self *SAzureClient) getClient(resource TAzureResource) (*azureAuthClient,
|
||||
case GraphResource:
|
||||
ret.domain = env.GraphEndpoint
|
||||
conf.Resource = env.GraphEndpoint
|
||||
if self.envName == "AzureChinaCloud" {
|
||||
ret.domain = "https://graph.chinacloudapi.cn/"
|
||||
conf.Resource = "https://graph.chinacloudapi.cn/"
|
||||
}
|
||||
case LoganalyticsResource:
|
||||
ret.domain = env.ResourceIdentifiers.OperationalInsights
|
||||
conf.Resource = env.ResourceIdentifiers.OperationalInsights
|
||||
@@ -1107,12 +1111,19 @@ func (self *SAzureClient) msGraphClient() *http.Client {
|
||||
TokenURL: fmt.Sprintf("https://login.microsoftonline.com/%s/oauth2/v2.0/token", self.tenantId),
|
||||
Scopes: []string{"https://graph.microsoft.com/.default"},
|
||||
}
|
||||
if self.envName == "AzureChinaCloud" {
|
||||
conf.TokenURL = fmt.Sprintf("https://login.partner.microsoftonline.cn/%s/oauth2/v2.0/token", self.tenantId)
|
||||
conf.Scopes = []string{"https://microsoftgraph.chinacloudapi.cn/.default"}
|
||||
}
|
||||
return conf.Client(context.TODO())
|
||||
}
|
||||
|
||||
func (self *SAzureClient) msGraphRequest(method string, resource string, body jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
client := self.msGraphClient()
|
||||
url := fmt.Sprintf("https://graph.microsoft.com/v1.0/%s", resource)
|
||||
if self.envName == "AzureChinaCloud" {
|
||||
url = fmt.Sprintf("https://microsoftgraph.chinacloudapi.cn/v1.0/%s", resource)
|
||||
}
|
||||
req := httputils.NewJsonRequest(httputils.THttpMethod(method), url, body)
|
||||
ae := AzureResponseError{}
|
||||
cli := httputils.NewJsonClient(client)
|
||||
|
||||
+3
@@ -239,6 +239,9 @@ func (self *SAzureClient) AddGroupUser(id, userName string) error {
|
||||
params := map[string]string{
|
||||
"@odata.id": fmt.Sprintf("https://graph.microsoft.com/v1.0/directoryObjects/%s", user.Id),
|
||||
}
|
||||
if self.envName == "AzureChinaCloud" {
|
||||
params["@odata.id"] = fmt.Sprintf("https://microsoftgraph.chinacloudapi.cn/v1.0/directoryObjects/%s", user.Id)
|
||||
}
|
||||
err = self.gcreate(resource, jsonutils.Marshal(params), nil)
|
||||
if err != nil && !strings.Contains(err.Error(), "One or more added object references already exist for the following modified properties") {
|
||||
return err
|
||||
|
||||
+5
-6
@@ -17,7 +17,6 @@ package azure
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
@@ -277,6 +276,7 @@ func (self *SAzureClient) CreateIClouduser(conf *cloudprovider.SClouduserCreateC
|
||||
|
||||
type SDomain struct {
|
||||
Name string
|
||||
Id string
|
||||
AuthenticationType string
|
||||
AvailabilityStatus string
|
||||
IsAdminManaged bool
|
||||
@@ -301,14 +301,13 @@ func (self *SAzureClient) GetDomains() ([]SDomain, error) {
|
||||
}
|
||||
|
||||
func (self *SAzureClient) GetDefaultDomain() (string, error) {
|
||||
users, err := self.ListGraphUsers()
|
||||
domains, err := self.GetDomains()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "ListGraphUsers")
|
||||
}
|
||||
for i := range users {
|
||||
idx := strings.Index(users[i].UserPrincipalName, "@")
|
||||
if idx > -1 {
|
||||
return users[i].UserPrincipalName[idx+1:], nil
|
||||
for i := range domains {
|
||||
if domains[i].IsDefault && domains[i].IsVerified && domains[i].IsRoot {
|
||||
return domains[i].Id, nil
|
||||
}
|
||||
}
|
||||
return "", cloudprovider.ErrNotFound
|
||||
|
||||
Reference in New Issue
Block a user