From dc87c9a81479185208ce3bc78c80797e056ba5fc Mon Sep 17 00:00:00 2001 From: Jackson Tian Date: Mon, 23 Sep 2024 15:01:58 +0800 Subject: [PATCH] improve credentials null check --- main.tea | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/main.tea b/main.tea index 986275c..b6243c4 100644 --- a/main.tea +++ b/main.tea @@ -227,6 +227,12 @@ api doRPCRequest(action: string, version: string, protocol: string, method: stri } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + 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.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) { @@ -405,6 +411,12 @@ api doROARequest(action: string, version: string, protocol: string, method: stri } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + 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.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) { @@ -584,6 +596,12 @@ api doROARequestWithForm(action: string, version: string, protocol: string, meth } if (!Util.equalString(authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + 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.` + } + } var credentialModel = @credential.getCredential(); var credentialType = credentialModel.type; if (Util.equalString(credentialType, 'bearer')) { @@ -816,6 +834,12 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti __request.headers.x-acs-content-sha256 = hashedRequestPayload; if (!Util.equalString(params.authType, 'Anonymous')) { + if (Util.isUnset(@credential)) { + throw { + 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.` + } + } var credentialModel = @credential.getCredential(); var authType = credentialModel.type; if (Util.equalString(authType, 'bearer')) {