Skip to content

Commit

Permalink
improve credentials null check
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Sep 23, 2024
1 parent 81b66b7 commit b3b8225
Show file tree
Hide file tree
Showing 14 changed files with 615 additions and 3 deletions.
64 changes: 64 additions & 0 deletions csharp/core/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ public Dictionary<string, object> DoRPCRequest(string action, string version, st
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = this._credential.GetCredential();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -536,6 +544,14 @@ public async Task<Dictionary<string, object>> DoRPCRequestAsync(string action, s
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = await this._credential.GetCredentialAsync();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -791,6 +807,14 @@ public Dictionary<string, object> DoROARequest(string action, string version, st
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = this._credential.GetCredential();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -1043,6 +1067,14 @@ public async Task<Dictionary<string, object>> DoROARequestAsync(string action, s
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = await this._credential.GetCredentialAsync();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -1296,6 +1328,14 @@ public Dictionary<string, object> DoROARequestWithForm(string action, string ver
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = this._credential.GetCredential();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -1547,6 +1587,14 @@ public async Task<Dictionary<string, object>> DoROARequestWithFormAsync(string a
}
if (!AlibabaCloud.TeaUtil.Common.EqualString(authType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = await this._credential.GetCredentialAsync();
string credentialType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(credentialType, "bearer"))
Expand Down Expand Up @@ -1833,6 +1881,14 @@ public Dictionary<string, object> DoRequest(Params params_, OpenApiRequest reque
request_.Headers["x-acs-content-sha256"] = hashedRequestPayload;
if (!AlibabaCloud.TeaUtil.Common.EqualString(params_.AuthType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = this._credential.GetCredential();
string authType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(authType, "bearer"))
Expand Down Expand Up @@ -2130,6 +2186,14 @@ public async Task<Dictionary<string, object>> DoRequestAsync(Params params_, Ope
request_.Headers["x-acs-content-sha256"] = hashedRequestPayload;
if (!AlibabaCloud.TeaUtil.Common.EqualString(params_.AuthType, "Anonymous"))
{
if (AlibabaCloud.TeaUtil.Common.IsUnset(_credential))
{
throw new TeaException(new Dictionary<string, string>
{
{"code", "InvalidCredentials"},
{"message", "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details."},
});
}
Aliyun.Credentials.Models.CredentialModel credentialModel = await this._credential.GetCredentialAsync();
string authType = credentialModel.Type;
if (AlibabaCloud.TeaUtil.Common.EqualString(authType, "bearer"))
Expand Down
4 changes: 2 additions & 2 deletions csharp/core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly : AssemblyVersion("0.1.11.0")]
[assembly : AssemblyFileVersion("0.1.11.0")]
[assembly : AssemblyVersion("0.1.12.0")]
[assembly : AssemblyFileVersion("0.1.12.0")]
32 changes: 32 additions & 0 deletions golang/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ func (client *Client) DoRPCRequest(action *string, version *string, protocol *st
}

if !tea.BoolValue(util.EqualString(authType, tea.String("Anonymous"))) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_err = tea.NewSDKError(map[string]interface{}{
"code": "InvalidCredentials",
"message": "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.",
})
return _result, _err
}

credentialModel, _err := client.Credential.GetCredential()
if _err != nil {
return _result, _err
Expand Down Expand Up @@ -1004,6 +1012,14 @@ func (client *Client) DoROARequest(action *string, version *string, protocol *st
}

if !tea.BoolValue(util.EqualString(authType, tea.String("Anonymous"))) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_err = tea.NewSDKError(map[string]interface{}{
"code": "InvalidCredentials",
"message": "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.",
})
return _result, _err
}

credentialModel, _err := client.Credential.GetCredential()
if _err != nil {
return _result, _err
Expand Down Expand Up @@ -1277,6 +1293,14 @@ func (client *Client) DoROARequestWithForm(action *string, version *string, prot
}

if !tea.BoolValue(util.EqualString(authType, tea.String("Anonymous"))) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_err = tea.NewSDKError(map[string]interface{}{
"code": "InvalidCredentials",
"message": "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.",
})
return _result, _err
}

credentialModel, _err := client.Credential.GetCredential()
if _err != nil {
return _result, _err
Expand Down Expand Up @@ -1591,6 +1615,14 @@ 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"))) {
if tea.BoolValue(util.IsUnset(client.Credential)) {
_err = tea.NewSDKError(map[string]interface{}{
"code": "InvalidCredentials",
"message": "Please set up the credentials correctly. If you are setting them through environment variables, please ensure that ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set correctly. See https://help.aliyun.com/zh/sdk/developer-reference/configure-the-alibaba-cloud-accesskey-environment-variable-on-linux-macos-and-windows-systems for more details.",
})
return _result, _err
}

credentialModel, _err := client.Credential.GetCredential()
if _err != nil {
return _result, _err
Expand Down
Loading

0 comments on commit b3b8225

Please sign in to comment.