Skip to content

refactor: improve all credentials providers #30

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

Merged
merged 1 commit into from
Oct 16, 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
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
defaults:
run:
shell: bash

permissions:
id-token: write

jobs:
build:

Expand Down Expand Up @@ -37,6 +41,19 @@ jobs:

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Setup OIDC
run: npm install @actions/core@1.6.0 @actions/http-client

- name: Get Id Token
uses: actions/github-script@v7
id: idtoken
with:
script: |
const coreDemo = require('@actions/core');
const idToken = await coreDemo.getIDToken('sts.aliyuncs.com');
const fsx = require('fs/promises');
await fsx.writeFile('/tmp/oidc_token', idToken);

- name: Run test case
run: composer test
Expand All @@ -46,7 +63,13 @@ jobs:
ROLE_ARN: ${{ secrets.ROLE_ARN }}
PUBLIC_KEY_ID: ${{ secrets.PUBLIC_KEY_ID }}
PRIVATE_KEY_LINE_1: ${{ secrets.PRIVATE_KEY_LINE_1 }}

# for OIDC
ALIBABA_CLOUD_OIDC_PROVIDER_ARN: ${{ secrets.ALIBABA_CLOUD_OIDC_PROVIDER_ARN }}
ALIBABA_CLOUD_OIDC_TOKEN_FILE: "/tmp/oidc_token"
ALIBABA_CLOUD_ROLE_ARN: ${{ secrets.OIDC_ROLE_ARN }}

- name: Upload Coverage Report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # required
token: ${{ secrets.CODECOV_TOKEN }} # required
1 change: 0 additions & 1 deletion README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ $bearerToken = new Credential([
'bearer_token' => '<bearer_token>',
]);
$bearerToken->getBearerToken();
$bearerToken->getSignature();
```

## 默认凭证提供程序链
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ $bearerToken = new Credential([
'bearer_token' => '<bearer_token>',
]);
$bearerToken->getBearerToken();
$bearerToken->getSignature();
```

## Default credential provider chain
Expand Down
14 changes: 5 additions & 9 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<file>./src/Profile/DefaultProfile.php</file>
<file>./src/DefaultAcsClient.php</file>
<file>./src/Release.php</file>
<file>./src/SDK.php</file>
<file>./src/Functions.php</file>
<file>./src/Constants/Business.php</file>
<file>./src/Constants/ErrorCode.php</file>
<file>./src/Signature/Signature.php</file>
<file>./src/Credentials/CredentialsInterface.php</file>
<file>./src/Credential/Config.php</file>
<file>./src/Credential/CredentialModel.php</file>
<file>./src/Providers/CredentialsProvider.php</file>
<file>./src/CredentialsInterface.php</file>
<file>./src/CredentialsProviderWrap.php</file>
</exclude>
</whitelist>
</filter>
Expand Down
16 changes: 15 additions & 1 deletion src/AccessKeyCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace AlibabaCloud\Credentials;

use AlibabaCloud\Credentials\Utils\Filter;
use AlibabaCloud\Credentials\Credential\CredentialModel;
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;

/**
* @deprecated
* Use the AccessKey to complete the authentication.
*/
class AccessKeyCredential implements CredentialsInterface
Expand All @@ -29,7 +32,7 @@ public function __construct($access_key_id, $access_key_secret)
{
Filter::accessKey($access_key_id, $access_key_secret);

$this->accessKeyId = $access_key_id;
$this->accessKeyId = $access_key_id;
$this->accessKeySecret = $access_key_secret;
}

Expand Down Expand Up @@ -69,4 +72,15 @@ public function getSecurityToken()
{
return '';
}
/**
* @inheritDoc
*/
public function getCredential()
{
return new CredentialModel([
'accessKeyId' => $this->accessKeyId,
'accessKeySecret' => $this->accessKeySecret,
'type' => 'access_key',
]);
}
}
14 changes: 14 additions & 0 deletions src/BearerTokenCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace AlibabaCloud\Credentials;

use AlibabaCloud\Credentials\Utils\Filter;
use AlibabaCloud\Credentials\Credential\CredentialModel;
use AlibabaCloud\Credentials\Signature\BearerTokenSignature;

/**
Expand Down Expand Up @@ -50,4 +52,16 @@ public function getSignature()
{
return new BearerTokenSignature();
}

/**
* @inheritDoc
*/
public function getCredential()
{
return new CredentialModel([
'bearerToken' => $this->bearerToken,
'type' => 'bearer',
]);
}

}
Loading