Skip to content

Commit

Permalink
feat: codegen php with credentials consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Oct 25, 2024
1 parent 85c113f commit dfe777a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"require": {
"php": ">5.5",
"alibabacloud/tea-utils": "^0.2.21",
"alibabacloud/credentials": "^1.1",
"alibabacloud/credentials": "^1.2",
"alibabacloud/openapi-util": "^0.1.10|^0.2.1",
"alibabacloud/gateway-spi": "^1",
"alibabacloud/tea-xml": "^0.2"
Expand Down
62 changes: 33 additions & 29 deletions php/src/OpenApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,16 @@ public function doRPCRequest($action, $version, $protocol, $method, $authType, $
"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."
]);
}
$credentialType = $this->getType();
$credentialModel = $this->_credential->getCredential();
$credentialType = $credentialModel->type;
if (Utils::equalString($credentialType, "bearer")) {
$bearerToken = $this->getBearerToken();
$bearerToken = $credentialModel->bearerToken;
$_request->query["BearerToken"] = $bearerToken;
$_request->query["SignatureType"] = "BEARERTOKEN";
} else {
$accessKeyId = $this->getAccessKeyId();
$accessKeySecret = $this->getAccessKeySecret();
$securityToken = $this->getSecurityToken();
$accessKeyId = $credentialModel->accessKeyId;
$accessKeySecret = $credentialModel->accessKeySecret;
$securityToken = $credentialModel->securityToken;
if (!Utils::empty_($securityToken)) {
$_request->query["SecurityToken"] = $securityToken;
}
Expand Down Expand Up @@ -393,13 +394,13 @@ public function doROARequest($action, $version, $protocol, $method, $authType, $
"socks5NetWork" => Utils::defaultString($runtime->socks5NetWork, $this->_socks5NetWork),
"maxIdleConns" => Utils::defaultNumber($runtime->maxIdleConns, $this->_maxIdleConns),
"retry" => [
"retryable" => $runtime->autoretry,
"maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3)
],
"retryable" => $runtime->autoretry,
"maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3)
],
"backoff" => [
"policy" => Utils::defaultString($runtime->backoffPolicy, "no"),
"period" => Utils::defaultNumber($runtime->backoffPeriod, 1)
],
"policy" => Utils::defaultString($runtime->backoffPolicy, "no"),
"period" => Utils::defaultNumber($runtime->backoffPeriod, 1)
],
"ignoreSSL" => $runtime->ignoreSSL
];
$_lastRequest = null;
Expand Down Expand Up @@ -467,15 +468,16 @@ public function doROARequest($action, $version, $protocol, $method, $authType, $
"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."
]);
}
$credentialType = $this->getType();
$credentialModel = $this->_credential->getCredential();
$credentialType = $credentialModel->type;
if (Utils::equalString($credentialType, "bearer")) {
$bearerToken = $this->getBearerToken();
$bearerToken = $credentialModel->bearerToken;
$_request->headers["x-acs-bearer-token"] = $bearerToken;
$_request->headers["x-acs-signature-type"] = "BEARERTOKEN";
} else {
$accessKeyId = $this->getAccessKeyId();
$accessKeySecret = $this->getAccessKeySecret();
$securityToken = $this->getSecurityToken();
$accessKeyId = $credentialModel->accessKeyId;
$accessKeySecret = $credentialModel->accessKeySecret;
$securityToken = $credentialModel->securityToken;
if (!Utils::empty_($securityToken)) {
$_request->headers["x-acs-accesskey-id"] = $accessKeyId;
$_request->headers["x-acs-security-token"] = $securityToken;
Expand Down Expand Up @@ -599,9 +601,9 @@ public function doROARequestWithForm($action, $version, $protocol, $method, $aut
"maxAttempts" => Utils::defaultNumber($runtime->maxAttempts, 3)
],
"backoff" => [
"policy" => Utils::defaultString($runtime->backoffPolicy, "no"),
"period" => Utils::defaultNumber($runtime->backoffPeriod, 1)
],
"policy" => Utils::defaultString($runtime->backoffPolicy, "no"),
"period" => Utils::defaultNumber($runtime->backoffPeriod, 1)
],
"ignoreSSL" => $runtime->ignoreSSL
];
$_lastRequest = null;
Expand Down Expand Up @@ -670,15 +672,16 @@ public function doROARequestWithForm($action, $version, $protocol, $method, $aut
"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."
]);
}
$credentialType = $this->getType();
$credentialModel = $this->_credential->getCredential();
$credentialType = $credentialModel->type;
if (Utils::equalString($credentialType, "bearer")) {
$bearerToken = $this->getBearerToken();
$bearerToken = $credentialModel->bearerToken;
$_request->headers["x-acs-bearer-token"] = $bearerToken;
$_request->headers["x-acs-signature-type"] = "BEARERTOKEN";
} else {
$accessKeyId = $this->getAccessKeyId();
$accessKeySecret = $this->getAccessKeySecret();
$securityToken = $this->getSecurityToken();
$accessKeyId = $credentialModel->accessKeyId;
$accessKeySecret = $credentialModel->accessKeySecret;
$securityToken = $credentialModel->securityToken;
if (!Utils::empty_($securityToken)) {
$_request->headers["x-acs-accesskey-id"] = $accessKeyId;
$_request->headers["x-acs-security-token"] = $securityToken;
Expand Down Expand Up @@ -891,19 +894,20 @@ public function doRequest($params, $request, $runtime)
"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."
]);
}
$authType = $this->getType();
$credentialModel = $this->_credential->getCredential();
$authType = $credentialModel->type;
if (Utils::equalString($authType, "bearer")) {
$bearerToken = $this->getBearerToken();
$bearerToken = $credentialModel->bearerToken;
$_request->headers["x-acs-bearer-token"] = $bearerToken;
if (Utils::equalString($params->style, "RPC")) {
$_request->query["SignatureType"] = "BEARERTOKEN";
} else {
$_request->headers["x-acs-signature-type"] = "BEARERTOKEN";
}
} else {
$accessKeyId = $this->getAccessKeyId();
$accessKeySecret = $this->getAccessKeySecret();
$securityToken = $this->getSecurityToken();
$accessKeyId = $credentialModel->accessKeyId;
$accessKeySecret = $credentialModel->accessKeySecret;
$securityToken = $credentialModel->securityToken;
if (!Utils::empty_($securityToken)) {
$_request->headers["x-acs-accesskey-id"] = $accessKeyId;
$_request->headers["x-acs-security-token"] = $securityToken;
Expand Down
4 changes: 2 additions & 2 deletions ts/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ describe('$openapi', function () {
client = new OpenApi(config);
assert.strictEqual(await client.getAccessKeyId(), 'ak');
assert.strictEqual(await client.getAccessKeySecret(), 'secret');
assert.strictEqual(await client.getSecurityToken(), '');
assert.strictEqual(await client.getBearerToken(), '');
assert.strictEqual(await client.getSecurityToken(), undefined);
assert.strictEqual(await client.getBearerToken(), undefined);
assert.strictEqual(await client.getType(), 'access_key');

assert.strictEqual(client._spi, undefined);
Expand Down

0 comments on commit dfe777a

Please sign in to comment.