diff --git a/go.mod b/go.mod index 81e5c70c0..77f692602 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/kubernetes-sigs/alibaba-cloud-csi-driver go 1.22.9 require ( - github.com/alibabacloud-go/darabonba-openapi v0.1.16 + github.com/alibabacloud-go/darabonba-openapi v0.2.1 github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6 github.com/alibabacloud-go/ens-20171110/v3 v3.0.2 github.com/alibabacloud-go/nas-20170626/v3 v3.2.0 diff --git a/go.sum b/go.sum index a20c2dcf9..c6713ba02 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,9 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJnOkZsene9olVspKmkX5A2YBEo= github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc= -github.com/alibabacloud-go/darabonba-openapi v0.1.16 h1:f6ZspWKTBurQzyLpZKMVxO51HAePY8aedicwuX3+E20= github.com/alibabacloud-go/darabonba-openapi v0.1.16/go.mod h1:ZjyqRbbZOaUBSh7keeH8VQN/BzCPvxCQwMuJGDdbmXQ= +github.com/alibabacloud-go/darabonba-openapi v0.2.1 h1:WyzxxKvhdVDlwpAMOHgAiCJ+NXa6g5ZWPFEzaK/ewwY= +github.com/alibabacloud-go/darabonba-openapi v0.2.1/go.mod h1:zXOqLbpIqq543oioL9IuuZYOQgHQ5B8/n5OPrnko8aY= github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6 h1:y1K+zKhpWcxso8zqI03CcYuwgyZPFwQdwAQOXAeuOVM= github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI= github.com/alibabacloud-go/darabonba-string v1.0.0/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA= @@ -74,6 +75,7 @@ github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeG github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= github.com/alibabacloud-go/tea v1.1.11/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= +github.com/alibabacloud-go/tea v1.1.19/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= github.com/alibabacloud-go/tea v1.2.1 h1:rFF1LnrAdhaiPmKwH5xwYOKlMh66CqRwPUTzIK74ask= github.com/alibabacloud-go/tea v1.2.1/go.mod h1:qbzof29bM/IFhLMtJPrgTGK3eauV5J2wSyEUo4OEmnA= github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE= @@ -81,6 +83,7 @@ github.com/alibabacloud-go/tea-utils v1.4.3 h1:8SzwmmRrOnQ09Hf5a9GyfJc0d7Sjv6fms github.com/alibabacloud-go/tea-utils v1.4.3/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw= github.com/alibabacloud-go/tea-utils/v2 v2.0.5 h1:EUakYEUAwr6L3wLT0vejIw2rc0IA1RSXDwLnIb3f2vU= github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4= +github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= github.com/alibabacloud-go/tea-xml v1.1.3 h1:7LYnm+JbOq2B+T/B0fHC4Ies4/FofC4zHzYtqw7dgt0= github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= github.com/aliyun/alibaba-cloud-sdk-go v1.62.719 h1:ZYBHflrrLzobuUZ7RE1MZYskFFVx0JtpkIURmOJFCG8= diff --git a/vendor/github.com/alibabacloud-go/darabonba-openapi/client/client.go b/vendor/github.com/alibabacloud-go/darabonba-openapi/client/client.go index d5d1cce5d..e014c11ff 100644 --- a/vendor/github.com/alibabacloud-go/darabonba-openapi/client/client.go +++ b/vendor/github.com/alibabacloud-go/darabonba-openapi/client/client.go @@ -10,10 +10,34 @@ import ( spi "github.com/alibabacloud-go/alibabacloud-gateway-spi/client" openapiutil "github.com/alibabacloud-go/openapi-util/service" util "github.com/alibabacloud-go/tea-utils/service" + xml "github.com/alibabacloud-go/tea-xml/service" "github.com/alibabacloud-go/tea/tea" credential "github.com/aliyun/credentials-go/credentials" ) +type GlobalParameters struct { + Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` + Queries map[string]*string `json:"queries,omitempty" xml:"queries,omitempty"` +} + +func (s GlobalParameters) String() string { + return tea.Prettify(s) +} + +func (s GlobalParameters) GoString() string { + return s.String() +} + +func (s *GlobalParameters) SetHeaders(v map[string]*string) *GlobalParameters { + s.Headers = v + return s +} + +func (s *GlobalParameters) SetQueries(v map[string]*string) *GlobalParameters { + s.Queries = v + return s +} + /** * Model for initing client */ @@ -67,6 +91,8 @@ type Config struct { SignatureVersion *string `json:"signatureVersion,omitempty" xml:"signatureVersion,omitempty"` // Signature Algorithm SignatureAlgorithm *string `json:"signatureAlgorithm,omitempty" xml:"signatureAlgorithm,omitempty"` + // Global Parameters + GlobalParameters *GlobalParameters `json:"globalParameters,omitempty" xml:"globalParameters,omitempty"` } func (s Config) String() string { @@ -197,12 +223,18 @@ func (s *Config) SetSignatureAlgorithm(v string) *Config { return s } +func (s *Config) SetGlobalParameters(v *GlobalParameters) *Config { + s.GlobalParameters = v + return s +} + type OpenApiRequest struct { - Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` - Query map[string]*string `json:"query,omitempty" xml:"query,omitempty"` - Body interface{} `json:"body,omitempty" xml:"body,omitempty"` - Stream io.Reader `json:"stream,omitempty" xml:"stream,omitempty"` - HostMap map[string]*string `json:"hostMap,omitempty" xml:"hostMap,omitempty"` + Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` + Query map[string]*string `json:"query,omitempty" xml:"query,omitempty"` + Body interface{} `json:"body,omitempty" xml:"body,omitempty"` + Stream io.Reader `json:"stream,omitempty" xml:"stream,omitempty"` + HostMap map[string]*string `json:"hostMap,omitempty" xml:"hostMap,omitempty"` + EndpointOverride *string `json:"endpointOverride,omitempty" xml:"endpointOverride,omitempty"` } func (s OpenApiRequest) String() string { @@ -238,6 +270,11 @@ func (s *OpenApiRequest) SetHostMap(v map[string]*string) *OpenApiRequest { return s } +func (s *OpenApiRequest) SetEndpointOverride(v string) *OpenApiRequest { + s.EndpointOverride = &v + return s +} + type Params struct { Action *string `json:"action,omitempty" xml:"action,omitempty" require:"true"` Version *string `json:"version,omitempty" xml:"version,omitempty" require:"true"` @@ -329,6 +366,7 @@ type Client struct { SignatureAlgorithm *string Headers map[string]*string Spi spi.ClientInterface + GlobalParameters *GlobalParameters } /** @@ -390,6 +428,7 @@ func (client *Client) Init(config *Config) (_err error) { client.MaxIdleConns = config.MaxIdleConns client.SignatureVersion = config.SignatureVersion client.SignatureAlgorithm = config.SignatureAlgorithm + client.GlobalParameters = config.GlobalParameters return nil } @@ -1078,7 +1117,22 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime request_.Protocol = util.DefaultString(client.Protocol, params.Protocol) request_.Method = params.Method request_.Pathname = params.Pathname - request_.Query = request.Query + globalQueries := make(map[string]*string) + globalHeaders := make(map[string]*string) + if !tea.BoolValue(util.IsUnset(tea.ToMap(client.GlobalParameters))) { + globalParams := client.GlobalParameters + if !tea.BoolValue(util.IsUnset(globalParams.Queries)) { + globalQueries = globalParams.Queries + } + + if !tea.BoolValue(util.IsUnset(globalParams.Headers)) { + globalHeaders = globalParams.Headers + } + + } + + request_.Query = tea.Merge(globalQueries, + request.Query) // endpoint is setted in product client request_.Headers = tea.Merge(map[string]*string{ "host": client.Endpoint, @@ -1088,7 +1142,8 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime "x-acs-date": openapiutil.GetTimestamp(), "x-acs-signature-nonce": util.GetNonce(), "accept": tea.String("application/json"), - }, request.Headers) + }, globalHeaders, + request.Headers) if tea.BoolValue(util.EqualString(params.Style, tea.String("RPC"))) { headers, _err := client.GetRpcHeaders() if _err != nil { @@ -1134,27 +1189,42 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime request_.Headers["x-acs-content-sha256"] = hashedRequestPayload if !tea.BoolValue(util.EqualString(params.AuthType, tea.String("Anonymous"))) { - accessKeyId, _err := client.GetAccessKeyId() + authType, _err := client.GetType() if _err != nil { return _result, _err } - accessKeySecret, _err := client.GetAccessKeySecret() - if _err != nil { - return _result, _err - } + if tea.BoolValue(util.EqualString(authType, tea.String("bearer"))) { + bearerToken, _err := client.GetBearerToken() + if _err != nil { + return _result, _err + } - securityToken, _err := client.GetSecurityToken() - if _err != nil { - return _result, _err - } + request_.Headers["x-acs-bearer-token"] = bearerToken + } else { + accessKeyId, _err := client.GetAccessKeyId() + if _err != nil { + return _result, _err + } - if !tea.BoolValue(util.Empty(securityToken)) { - request_.Headers["x-acs-accesskey-id"] = accessKeyId - request_.Headers["x-acs-security-token"] = securityToken + accessKeySecret, _err := client.GetAccessKeySecret() + if _err != nil { + return _result, _err + } + + securityToken, _err := client.GetSecurityToken() + if _err != nil { + return _result, _err + } + + if !tea.BoolValue(util.Empty(securityToken)) { + request_.Headers["x-acs-accesskey-id"] = accessKeyId + request_.Headers["x-acs-security-token"] = securityToken + } + + request_.Headers["Authorization"] = openapiutil.GetAuthorization(request_, signatureAlgorithm, hashedRequestPayload, accessKeyId, accessKeySecret) } - request_.Headers["Authorization"] = openapiutil.GetAuthorization(request_, signatureAlgorithm, hashedRequestPayload, accessKeyId, accessKeySecret) } response_, _err := tea.DoRequest(request_, _runtime) @@ -1162,12 +1232,25 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime return _result, _err } if tea.BoolValue(util.Is4xx(response_.StatusCode)) || tea.BoolValue(util.Is5xx(response_.StatusCode)) { - _res, _err := util.ReadAsJSON(response_.Body) - if _err != nil { - return _result, _err + err := map[string]interface{}{} + if !tea.BoolValue(util.IsUnset(response_.Headers["content-type"])) && tea.BoolValue(util.EqualString(response_.Headers["content-type"], tea.String("text/xml;charset=utf-8"))) { + _str, _err := util.ReadAsString(response_.Body) + if _err != nil { + return _result, _err + } + + respMap := xml.ParseXml(_str, nil) + err = util.AssertAsMap(respMap["Error"]) + } else { + _res, _err := util.ReadAsJSON(response_.Body) + if _err != nil { + return _result, _err + } + + err = util.AssertAsMap(_res) } - err := util.AssertAsMap(_res) + err["statusCode"] = response_.StatusCode _err = tea.NewSDKError(map[string]interface{}{ "code": tea.ToString(DefaultAny(err["Code"], err["code"])), "message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(DefaultAny(err["RequestId"], err["requestId"])), @@ -1178,8 +1261,9 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime if tea.BoolValue(util.EqualString(params.BodyType, tea.String("binary"))) { resp := map[string]interface{}{ - "body": response_.Body, - "headers": response_.Headers, + "body": response_.Body, + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), } _result = resp return _result, _err @@ -1191,8 +1275,9 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ - "body": byt, - "headers": response_.Headers, + "body": byt, + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), }, &_result) return _result, _err } else if tea.BoolValue(util.EqualString(params.BodyType, tea.String("string"))) { @@ -1203,8 +1288,9 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ - "body": tea.StringValue(str), - "headers": response_.Headers, + "body": tea.StringValue(str), + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), }, &_result) return _result, _err } else if tea.BoolValue(util.EqualString(params.BodyType, tea.String("json"))) { @@ -1216,8 +1302,9 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime res := util.AssertAsMap(obj) _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ - "body": res, - "headers": response_.Headers, + "body": res, + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), }, &_result) return _result, _err } else if tea.BoolValue(util.EqualString(params.BodyType, tea.String("array"))) { @@ -1228,14 +1315,16 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ - "body": arr, - "headers": response_.Headers, + "body": arr, + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), }, &_result) return _result, _err } else { _result = make(map[string]interface{}) - _err = tea.Convert(map[string]map[string]*string{ - "headers": response_.Headers, + _err = tea.Convert(map[string]interface{}{ + "headers": response_.Headers, + "statusCode": tea.IntValue(response_.StatusCode), }, &_result) return _result, _err } @@ -1312,10 +1401,26 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * return _result, _err } + globalQueries := make(map[string]*string) + globalHeaders := make(map[string]*string) + if !tea.BoolValue(util.IsUnset(tea.ToMap(client.GlobalParameters))) { + globalParams := client.GlobalParameters + if !tea.BoolValue(util.IsUnset(globalParams.Queries)) { + globalQueries = globalParams.Queries + } + + if !tea.BoolValue(util.IsUnset(globalParams.Headers)) { + globalHeaders = globalParams.Headers + } + + } + requestContext := &spi.InterceptorContextRequest{ - Headers: tea.Merge(request.Headers, + Headers: tea.Merge(globalHeaders, + request.Headers, headers), - Query: request.Query, + Query: tea.Merge(globalQueries, + request.Query), Body: request.Body, Stream: request.Stream, HostMap: request.HostMap, @@ -1336,7 +1441,7 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * } configurationContext := &spi.InterceptorContextConfiguration{ RegionId: client.RegionId, - Endpoint: client.Endpoint, + Endpoint: util.DefaultString(request.EndpointOverride, client.Endpoint), EndpointRule: client.EndpointRule, EndpointMap: client.EndpointMap, EndpointType: client.EndpointType, @@ -1381,8 +1486,9 @@ func (client *Client) Execute(params *Params, request *OpenApiRequest, runtime * } _result = make(map[string]interface{}) _err = tea.Convert(map[string]interface{}{ - "headers": interceptorContext.Response.Headers, - "body": interceptorContext.Response.DeserializedBody, + "headers": interceptorContext.Response.Headers, + "statusCode": tea.IntValue(interceptorContext.Response.StatusCode), + "body": interceptorContext.Response.DeserializedBody, }, &_result) return _result, _err }() @@ -1506,6 +1612,36 @@ func (client *Client) GetSecurityToken() (_result *string, _err error) { return _result, _err } +/** + * Get bearer token by credential + * @return bearer token + */ +func (client *Client) GetBearerToken() (_result *string, _err error) { + if tea.BoolValue(util.IsUnset(client.Credential)) { + _result = tea.String("") + return _result, _err + } + + token := client.Credential.GetBearerToken() + _result = token + return _result, _err +} + +/** + * Get credential type by credential + * @return credential type e.g. access_key + */ +func (client *Client) GetType() (_result *string, _err error) { + if tea.BoolValue(util.IsUnset(client.Credential)) { + _result = tea.String("") + return _result, _err + } + + authType := client.Credential.GetType() + _result = authType + return _result, _err +} + /** * If inputValue is not null, return it or return defaultValue * @param inputValue users input value diff --git a/vendor/modules.txt b/vendor/modules.txt index d080c36e9..e6568c8ca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ # github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 ## explicit; go 1.14 github.com/alibabacloud-go/alibabacloud-gateway-spi/client -# github.com/alibabacloud-go/darabonba-openapi v0.1.16 +# github.com/alibabacloud-go/darabonba-openapi v0.2.1 ## explicit; go 1.14 github.com/alibabacloud-go/darabonba-openapi/client # github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6