Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve credentials null check #168

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading