Skip to content

Commit

Permalink
refactor: improve all credentials providers
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Oct 14, 2024
1 parent 8750d18 commit 69e0ee8
Show file tree
Hide file tree
Showing 73 changed files with 4,492 additions and 1,714 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
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
11 changes: 3 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@
<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/Credential/Config.php</file>
<file>./src/Credential/CredentialModel.php</file>
<file>./src/Providers/CredentialsProvider.php</file>
<file>./src/Credentials/CredentialsInterface.php</file>
</exclude>
</whitelist>
Expand Down
25 changes: 15 additions & 10 deletions src/AccessKeyCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace AlibabaCloud\Credentials;

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

/**
* @deprecated
* Use the AccessKey to complete the authentication.
*/
class AccessKeyCredential implements CredentialsInterface
Expand All @@ -29,7 +31,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 @@ -57,16 +59,19 @@ public function __toString()
return "$this->accessKeyId#$this->accessKeySecret";
}

/**
* @return ShaHmac1Signature
*/
public function getSignature()
{
return new ShaHmac1Signature();
}

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

namespace AlibabaCloud\Credentials;

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

/**
* Class BearerTokenCredential
Expand Down Expand Up @@ -44,10 +45,14 @@ public function __toString()
}

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

}
Loading

0 comments on commit 69e0ee8

Please sign in to comment.