代码同步
This commit is contained in:
@@ -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
|
||||
@@ -29,7 +32,7 @@ class AccessKeyCredential implements CredentialsInterface
|
||||
{
|
||||
Filter::accessKey($access_key_id, $access_key_secret);
|
||||
|
||||
$this->accessKeyId = $access_key_id;
|
||||
$this->accessKeyId = $access_key_id;
|
||||
$this->accessKeySecret = $access_key_secret;
|
||||
}
|
||||
|
||||
@@ -69,4 +72,15 @@ class AccessKeyCredential implements CredentialsInterface
|
||||
{
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $this->accessKeyId,
|
||||
'accessKeySecret' => $this->accessKeySecret,
|
||||
'type' => 'access_key',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Signature\BearerTokenSignature;
|
||||
|
||||
/**
|
||||
@@ -18,13 +20,13 @@ class BearerTokenCredential implements CredentialsInterface
|
||||
/**
|
||||
* BearerTokenCredential constructor.
|
||||
*
|
||||
* @param $bearerToken
|
||||
* @param $bearer_token
|
||||
*/
|
||||
public function __construct($bearerToken)
|
||||
public function __construct($bearer_token)
|
||||
{
|
||||
Filter::bearerToken($bearerToken);
|
||||
Filter::bearerToken($bearer_token);
|
||||
|
||||
$this->bearerToken = $bearerToken;
|
||||
$this->bearerToken = $bearer_token;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,4 +52,16 @@ class BearerTokenCredential implements CredentialsInterface
|
||||
{
|
||||
return new BearerTokenSignature();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
return new CredentialModel([
|
||||
'bearerToken' => $this->bearerToken,
|
||||
'type' => 'bearer',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,153 +3,188 @@
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Credential\Config;
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Providers\DefaultCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\EcsRamRoleCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\OIDCRoleArnCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\RamRoleArnCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\RsaKeyPairCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\StaticAKCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\StaticSTSCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Providers\URLCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionParameter;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class Credential
|
||||
*
|
||||
* @package AlibabaCloud\Credentials
|
||||
*
|
||||
* @mixin AccessKeyCredential
|
||||
* @mixin BearerTokenCredential
|
||||
* @mixin EcsRamRoleCredential
|
||||
* @mixin RamRoleArnCredential
|
||||
* @mixin RsaKeyPairCredential
|
||||
*/
|
||||
class Credential
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* Version of the Client
|
||||
*/
|
||||
protected $types = [
|
||||
'access_key' => AccessKeyCredential::class,
|
||||
'sts' => StsCredential::class,
|
||||
'ecs_ram_role' => EcsRamRoleCredential::class,
|
||||
'ram_role_arn' => RamRoleArnCredential::class,
|
||||
'rsa_key_pair' => RsaKeyPairCredential::class,
|
||||
];
|
||||
const VERSION = '1.1.5';
|
||||
|
||||
/**
|
||||
* @var AccessKeyCredential|BearerTokenCredential|EcsRamRoleCredential|RamRoleArnCredential|RsaKeyPairCredential
|
||||
* @var Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var CredentialsInterface
|
||||
*/
|
||||
protected $credential;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Credential constructor.
|
||||
*
|
||||
* @param array|Config $config
|
||||
*
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if ($config instanceof Config) {
|
||||
$config = $this->parse($config);
|
||||
}
|
||||
if ($config !== []) {
|
||||
$this->config = array_change_key_case($config);
|
||||
$this->parseConfig();
|
||||
if (\is_array($config)) {
|
||||
if (empty($config)) {
|
||||
$this->config = null;
|
||||
} else {
|
||||
$this->config = new Config($this->parseConfig($config));
|
||||
}
|
||||
} else {
|
||||
$this->credential = Credentials::get()->getCredential();
|
||||
$this->config = $config;
|
||||
}
|
||||
$this->credential = $this->getCredentials($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param array $config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function parse($config)
|
||||
private function parseConfig($config)
|
||||
{
|
||||
$config = get_object_vars($config);
|
||||
$res = [];
|
||||
foreach ($config as $key => $value) {
|
||||
$res[$this->toUnderScore($key)] = $value;
|
||||
$res = [];
|
||||
foreach (\array_change_key_case($config) as $key => $value) {
|
||||
$res[Helper::snakeToCamelCase($key)] = $value;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function toUnderScore($str)
|
||||
{
|
||||
$dstr = preg_replace_callback('/([A-Z]+)/', function ($matchs) {
|
||||
return '_' . strtolower($matchs[0]);
|
||||
}, $str);
|
||||
return trim(preg_replace('/_{2,}/', '_', $dstr), '_');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
private function parseConfig()
|
||||
{
|
||||
if (!isset($this->config['type'])) {
|
||||
throw new InvalidArgumentException('Missing required type option');
|
||||
}
|
||||
|
||||
$this->type = $this->config['type'];
|
||||
if (!isset($this->types[$this->type])) {
|
||||
throw new InvalidArgumentException(
|
||||
'Invalid type option, support: ' .
|
||||
implode(', ', array_keys($this->types))
|
||||
);
|
||||
}
|
||||
|
||||
$class = new ReflectionClass($this->types[$this->type]);
|
||||
$parameters = [];
|
||||
/**
|
||||
* @var $parameter ReflectionParameter
|
||||
*/
|
||||
foreach ($class->getConstructor()->getParameters() as $parameter) {
|
||||
$parameters[] = $this->getValue($parameter);
|
||||
}
|
||||
|
||||
$this->credential = $class->newInstance(...$parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionParameter $parameter
|
||||
* Credentials getter.
|
||||
*
|
||||
* @param Config $config
|
||||
* @return CredentialsInterface
|
||||
*
|
||||
* @return string|array
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
protected function getValue(ReflectionParameter $parameter)
|
||||
private function getCredentials($config)
|
||||
{
|
||||
if ($parameter->name === 'config' || $parameter->name === 'credential') {
|
||||
return $this->config;
|
||||
if (is_null($config)) {
|
||||
return new CredentialsProviderWrap('default', new DefaultCredentialsProvider());
|
||||
}
|
||||
|
||||
foreach ($this->config as $key => $value) {
|
||||
if (strtolower($parameter->name) === $key) {
|
||||
return $value;
|
||||
}
|
||||
switch ($config->type) {
|
||||
case 'access_key':
|
||||
$provider = new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => $config->accessKeyId,
|
||||
'accessKeySecret' => $config->accessKeySecret,
|
||||
]);
|
||||
return new CredentialsProviderWrap('access_key', $provider);
|
||||
case 'sts':
|
||||
$provider = new StaticSTSCredentialsProvider([
|
||||
'accessKeyId' => $config->accessKeyId,
|
||||
'accessKeySecret' => $config->accessKeySecret,
|
||||
'securityToken' => $config->securityToken,
|
||||
]);
|
||||
return new CredentialsProviderWrap('sts', $provider);
|
||||
case 'bearer':
|
||||
return new BearerTokenCredential($config->bearerToken);
|
||||
case 'ram_role_arn':
|
||||
if (!is_null($config->securityToken) && $config->securityToken !== '') {
|
||||
$innerProvider = new StaticSTSCredentialsProvider([
|
||||
'accessKeyId' => $config->accessKeyId,
|
||||
'accessKeySecret' => $config->accessKeySecret,
|
||||
'securityToken' => $config->securityToken,
|
||||
]);
|
||||
} else {
|
||||
$innerProvider = new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => $config->accessKeyId,
|
||||
'accessKeySecret' => $config->accessKeySecret,
|
||||
]);
|
||||
}
|
||||
$provider = new RamRoleArnCredentialsProvider([
|
||||
'credentialsProvider' => $innerProvider,
|
||||
'roleArn' => $config->roleArn,
|
||||
'roleSessionName' => $config->roleSessionName,
|
||||
'policy' => $config->policy,
|
||||
'durationSeconds' => $config->roleSessionExpiration,
|
||||
'externalId' => $config->externalId,
|
||||
'stsEndpoint' => $config->STSEndpoint,
|
||||
], [
|
||||
'connectTimeout' => $config->connectTimeout,
|
||||
'readTimeout' => $config->readTimeout,
|
||||
]);
|
||||
return new CredentialsProviderWrap('ram_role_arn', $provider);
|
||||
case 'rsa_key_pair':
|
||||
$provider = new RsaKeyPairCredentialsProvider([
|
||||
'publicKeyId' => $config->publicKeyId,
|
||||
'privateKeyFile' => $config->privateKeyFile,
|
||||
'durationSeconds' => $config->roleSessionExpiration,
|
||||
'stsEndpoint' => $config->STSEndpoint,
|
||||
], [
|
||||
'connectTimeout' => $config->connectTimeout,
|
||||
'readTimeout' => $config->readTimeout,
|
||||
]);
|
||||
return new CredentialsProviderWrap('rsa_key_pair', $provider);
|
||||
case 'ecs_ram_role':
|
||||
$provider = new EcsRamRoleCredentialsProvider([
|
||||
'roleName' => $config->roleName,
|
||||
'disableIMDSv1' => $config->disableIMDSv1,
|
||||
], [
|
||||
'connectTimeout' => $config->connectTimeout,
|
||||
'readTimeout' => $config->readTimeout,
|
||||
]);
|
||||
return new CredentialsProviderWrap('ecs_ram_role', $provider);
|
||||
case 'oidc_role_arn':
|
||||
$provider = new OIDCRoleArnCredentialsProvider([
|
||||
'roleArn' => $config->roleArn,
|
||||
'oidcProviderArn' => $config->oidcProviderArn,
|
||||
'oidcTokenFilePath' => $config->oidcTokenFilePath,
|
||||
'roleSessionName' => $config->roleSessionName,
|
||||
'policy' => $config->policy,
|
||||
'durationSeconds' => $config->roleSessionExpiration,
|
||||
'stsEndpoint' => $config->STSEndpoint,
|
||||
], [
|
||||
'connectTimeout' => $config->connectTimeout,
|
||||
'readTimeout' => $config->readTimeout,
|
||||
]);
|
||||
return new CredentialsProviderWrap('oidc_role_arn', $provider);
|
||||
case "credentials_uri":
|
||||
$provider = new URLCredentialsProvider([
|
||||
'credentialsURI' => $config->credentialsURI,
|
||||
], [
|
||||
'connectTimeout' => $config->connectTimeout,
|
||||
'readTimeout' => $config->readTimeout,
|
||||
]);
|
||||
return new CredentialsProviderWrap('credentials_uri', $provider);
|
||||
default:
|
||||
throw new InvalidArgumentException('Unsupported credential type option: ' . $config->type . ', support: access_key, sts, bearer, ecs_ram_role, ram_role_arn, rsa_key_pair, oidc_role_arn, credentials_uri');
|
||||
}
|
||||
|
||||
if ($parameter->isDefaultValueAvailable()) {
|
||||
return $parameter->getDefaultValue();
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException("Missing required {$parameter->name} option in config for {$this->type}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccessKeyCredential|BearerTokenCredential|EcsRamRoleCredential|RamRoleArnCredential|RsaKeyPairCredential
|
||||
* @return CredentialModel
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
return $this->credential;
|
||||
return $this->credential->getCredential();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,17 +192,68 @@ class Credential
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
return $this->config->toMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getCredential() instead
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
return $this->credential->getCredential()->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getCredential() instead
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->credential->getCredential()->getAccessKeyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getCredential() instead
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->credential->getCredential()->getAccessKeySecret();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getCredential() instead
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getSecurityToken()
|
||||
{
|
||||
return $this->credential->getCredential()->getSecurityToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getCredential() instead
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function getBearerToken()
|
||||
{
|
||||
return $this->credential->getCredential()->getBearerToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
|
||||
@@ -2,49 +2,269 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials\Credential;
|
||||
|
||||
class Config
|
||||
use AlibabaCloud\Tea\Model;
|
||||
|
||||
class Config extends Model
|
||||
{
|
||||
public function validate()
|
||||
{
|
||||
}
|
||||
public function toMap()
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->accessKeyId) {
|
||||
$res['accessKeyId'] = $this->accessKeyId;
|
||||
}
|
||||
if (null !== $this->accessKeySecret) {
|
||||
$res['accessKeySecret'] = $this->accessKeySecret;
|
||||
}
|
||||
if (null !== $this->securityToken) {
|
||||
$res['securityToken'] = $this->securityToken;
|
||||
}
|
||||
if (null !== $this->bearerToken) {
|
||||
$res['bearerToken'] = $this->bearerToken;
|
||||
}
|
||||
if (null !== $this->durationSeconds) {
|
||||
$res['durationSeconds'] = $this->durationSeconds;
|
||||
}
|
||||
if (null !== $this->roleArn) {
|
||||
$res['roleArn'] = $this->roleArn;
|
||||
}
|
||||
if (null !== $this->policy) {
|
||||
$res['policy'] = $this->policy;
|
||||
}
|
||||
if (null !== $this->roleSessionExpiration) {
|
||||
$res['roleSessionExpiration'] = $this->roleSessionExpiration;
|
||||
}
|
||||
if (null !== $this->roleSessionName) {
|
||||
$res['roleSessionName'] = $this->roleSessionName;
|
||||
}
|
||||
if (null !== $this->publicKeyId) {
|
||||
$res['publicKeyId'] = $this->publicKeyId;
|
||||
}
|
||||
if (null !== $this->privateKeyFile) {
|
||||
$res['privateKeyFile'] = $this->privateKeyFile;
|
||||
}
|
||||
if (null !== $this->roleName) {
|
||||
$res['roleName'] = $this->roleName;
|
||||
}
|
||||
if (null !== $this->credentialsURI) {
|
||||
$res['credentialsURI'] = $this->credentialsURI;
|
||||
}
|
||||
if (null !== $this->type) {
|
||||
$res['type'] = $this->type;
|
||||
}
|
||||
if (null !== $this->STSEndpoint) {
|
||||
$res['STSEndpoint'] = $this->STSEndpoint;
|
||||
}
|
||||
if (null !== $this->externalId) {
|
||||
$res['externalId'] = $this->externalId;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @param array $map
|
||||
* @return Config
|
||||
*/
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['accessKeyId'])) {
|
||||
$model->accessKeyId = $map['accessKeyId'];
|
||||
}
|
||||
if (isset($map['accessKeySecret'])) {
|
||||
$model->accessKeySecret = $map['accessKeySecret'];
|
||||
}
|
||||
if (isset($map['securityToken'])) {
|
||||
$model->securityToken = $map['securityToken'];
|
||||
}
|
||||
if (isset($map['bearerToken'])) {
|
||||
$model->bearerToken = $map['bearerToken'];
|
||||
}
|
||||
if (isset($map['durationSeconds'])) {
|
||||
$model->durationSeconds = $map['durationSeconds'];
|
||||
}
|
||||
if (isset($map['roleArn'])) {
|
||||
$model->roleArn = $map['roleArn'];
|
||||
}
|
||||
if (isset($map['policy'])) {
|
||||
$model->policy = $map['policy'];
|
||||
}
|
||||
if (isset($map['roleSessionExpiration'])) {
|
||||
$model->roleSessionExpiration = $map['roleSessionExpiration'];
|
||||
}
|
||||
if (isset($map['roleSessionName'])) {
|
||||
$model->roleSessionName = $map['roleSessionName'];
|
||||
}
|
||||
if (isset($map['publicKeyId'])) {
|
||||
$model->publicKeyId = $map['publicKeyId'];
|
||||
}
|
||||
if (isset($map['privateKeyFile'])) {
|
||||
$model->privateKeyFile = $map['privateKeyFile'];
|
||||
}
|
||||
if (isset($map['roleName'])) {
|
||||
$model->roleName = $map['roleName'];
|
||||
}
|
||||
if (isset($map['credentialsURI'])) {
|
||||
$model->credentialsURI = $map['credentialsURI'];
|
||||
}
|
||||
if (isset($map['type'])) {
|
||||
$model->type = $map['type'];
|
||||
}
|
||||
if (isset($map['STSEndpoint'])) {
|
||||
$model->STSEndpoint = $map['STSEndpoint'];
|
||||
}
|
||||
if (isset($map['externalId'])) {
|
||||
$model->externalId = $map['externalId'];
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* @description credential type
|
||||
* @example access_key
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'default';
|
||||
|
||||
public $accessKeyId = "";
|
||||
/**
|
||||
* @description accesskey id
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeyId;
|
||||
|
||||
public $accessKeySecret = "";
|
||||
/**
|
||||
* @description accesskey secret
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeySecret;
|
||||
|
||||
public $securityToken = "";
|
||||
/**
|
||||
* @description security token
|
||||
* @var string
|
||||
*/
|
||||
public $securityToken;
|
||||
|
||||
public $bearerToken = "";
|
||||
/**
|
||||
* @description bearer token
|
||||
* @var string
|
||||
*/
|
||||
public $bearerToken;
|
||||
|
||||
public $roleName = "";
|
||||
/**
|
||||
* @description role name
|
||||
* @var string
|
||||
*/
|
||||
public $roleName;
|
||||
|
||||
public $roleArn = "";
|
||||
/**
|
||||
* @description role arn
|
||||
* @var string
|
||||
*/
|
||||
public $roleArn;
|
||||
|
||||
public $roleSessionName = "";
|
||||
/**
|
||||
* @description oidc provider arn
|
||||
* @var string
|
||||
*/
|
||||
public $oidcProviderArn;
|
||||
|
||||
public $host = "";
|
||||
/**
|
||||
* @description oidc token file path
|
||||
* @var string
|
||||
*/
|
||||
public $oidcTokenFilePath;
|
||||
|
||||
public $publicKeyId = "";
|
||||
/**
|
||||
* @description role session expiration
|
||||
* @example 3600
|
||||
* @var int
|
||||
*/
|
||||
public $roleSessionExpiration;
|
||||
|
||||
public $privateKeyFile = "";
|
||||
/**
|
||||
* @description role session name
|
||||
* @var string
|
||||
*/
|
||||
public $roleSessionName;
|
||||
|
||||
public $readTimeout = 0;
|
||||
/**
|
||||
* @description role arn policy
|
||||
* @var string
|
||||
*/
|
||||
public $policy;
|
||||
|
||||
public $connectTimeout = 0;
|
||||
/**
|
||||
* @description external id for ram role arn
|
||||
* @var string
|
||||
*/
|
||||
public $externalId;
|
||||
|
||||
/**
|
||||
* @description sts endpoint
|
||||
* @var string
|
||||
*/
|
||||
public $STSEndpoint;
|
||||
|
||||
public $publicKeyId;
|
||||
|
||||
public $privateKeyFile;
|
||||
|
||||
/**
|
||||
* @description read timeout
|
||||
* @var int
|
||||
*/
|
||||
public $readTimeout;
|
||||
|
||||
/**
|
||||
* @description connection timeout
|
||||
* @var int
|
||||
*/
|
||||
public $connectTimeout;
|
||||
|
||||
/**
|
||||
* @description disable IMDS v1
|
||||
* @var bool
|
||||
*/
|
||||
public $disableIMDSv1;
|
||||
|
||||
/**
|
||||
* @description credentials URI
|
||||
* @var string
|
||||
*/
|
||||
public $credentialsURI;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $metadataTokenDuration;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $durationSeconds;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $host;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $expiration;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $certFile = "";
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public $certPassword = "";
|
||||
|
||||
public $proxy = "";
|
||||
|
||||
public $expiration = 0;
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
foreach ($config as $k => $v) {
|
||||
$this->{$k} = $v;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public $proxy;
|
||||
}
|
||||
|
||||
143
Server/vendor/alibabacloud/credentials/src/Credential/CredentialModel.php
vendored
Normal file
143
Server/vendor/alibabacloud/credentials/src/Credential/CredentialModel.php
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
// This file is auto-generated, don't edit it. Thanks.
|
||||
namespace AlibabaCloud\Credentials\Credential;
|
||||
|
||||
use AlibabaCloud\Tea\Model;
|
||||
|
||||
class CredentialModel extends Model
|
||||
{
|
||||
public function validate()
|
||||
{
|
||||
}
|
||||
public function toMap()
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->accessKeyId) {
|
||||
$res['accessKeyId'] = $this->accessKeyId;
|
||||
}
|
||||
if (null !== $this->accessKeySecret) {
|
||||
$res['accessKeySecret'] = $this->accessKeySecret;
|
||||
}
|
||||
if (null !== $this->securityToken) {
|
||||
$res['securityToken'] = $this->securityToken;
|
||||
}
|
||||
if (null !== $this->bearerToken) {
|
||||
$res['bearerToken'] = $this->bearerToken;
|
||||
}
|
||||
if (null !== $this->type) {
|
||||
$res['type'] = $this->type;
|
||||
}
|
||||
if (null !== $this->providerName) {
|
||||
$res['providerName'] = $this->providerName;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @param array $map
|
||||
* @return CredentialModel
|
||||
*/
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['accessKeyId'])) {
|
||||
$model->accessKeyId = $map['accessKeyId'];
|
||||
}
|
||||
if (isset($map['accessKeySecret'])) {
|
||||
$model->accessKeySecret = $map['accessKeySecret'];
|
||||
}
|
||||
if (isset($map['securityToken'])) {
|
||||
$model->securityToken = $map['securityToken'];
|
||||
}
|
||||
if (isset($map['bearerToken'])) {
|
||||
$model->bearerToken = $map['bearerToken'];
|
||||
}
|
||||
if (isset($map['type'])) {
|
||||
$model->type = $map['type'];
|
||||
}
|
||||
if(isset($map['providerName'])){
|
||||
$model->providerName = $map['providerName'];
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* @description accesskey id
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeyId;
|
||||
|
||||
/**
|
||||
* @description accesskey secret
|
||||
* @var string
|
||||
*/
|
||||
public $accessKeySecret;
|
||||
|
||||
/**
|
||||
* @description security token
|
||||
* @var string
|
||||
*/
|
||||
public $securityToken;
|
||||
|
||||
/**
|
||||
* @description bearer token
|
||||
* @var string
|
||||
*/
|
||||
public $bearerToken;
|
||||
|
||||
/**
|
||||
* @description type
|
||||
* @example access_key
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* @description provider name
|
||||
* @example cli_profile/static_ak
|
||||
* @var string
|
||||
*/
|
||||
public $providerName;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecurityToken()
|
||||
{
|
||||
return $this->securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBearerToken()
|
||||
{
|
||||
return $this->bearerToken;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getProviderName()
|
||||
{
|
||||
return $this->providerName;
|
||||
}
|
||||
|
||||
}
|
||||
99
Server/vendor/alibabacloud/credentials/src/Credential/RefreshResult.php
vendored
Normal file
99
Server/vendor/alibabacloud/credentials/src/Credential/RefreshResult.php
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Credential;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\Credentials;
|
||||
|
||||
use function PHPUnit\Framework\isNull;
|
||||
|
||||
class RefreshResult
|
||||
{
|
||||
|
||||
/**
|
||||
* RefreshResult constructor.
|
||||
* @param Credentials $params
|
||||
* @param int $staleTime
|
||||
* @param int $prefetchTime
|
||||
*/
|
||||
public function __construct($credentials = null, $staleTime = PHP_INT_MAX, $prefetchTime = PHP_INT_MAX)
|
||||
{
|
||||
$this->credentials = $credentials;
|
||||
$this->staleTime = $staleTime;
|
||||
$this->prefetchTime = $prefetchTime;
|
||||
}
|
||||
public function validate() {}
|
||||
public function toMap()
|
||||
{
|
||||
$res = [];
|
||||
if (null !== $this->staleTime) {
|
||||
$res['staleTime'] = $this->staleTime;
|
||||
}
|
||||
if (null !== $this->prefetchTime) {
|
||||
$res['prefetchTime'] = $this->prefetchTime;
|
||||
}
|
||||
if (null !== $this->credentials) {
|
||||
$res['credentials'] = $this->credentials;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @param array $map
|
||||
* @return RefreshResult
|
||||
*/
|
||||
public static function fromMap($map = [])
|
||||
{
|
||||
$model = new self();
|
||||
if (isset($map['staleTime'])) {
|
||||
$model->staleTime = $map['staleTime'];
|
||||
}
|
||||
if (isset($map['prefetchTime'])) {
|
||||
$model->staleTime = $map['prefetchTime'];
|
||||
}
|
||||
if (isset($map['credentials'])) {
|
||||
$model->staleTime = $map['credentials'];
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* @description staleTime
|
||||
* @var int
|
||||
*/
|
||||
public $staleTime;
|
||||
|
||||
/**
|
||||
* @description prefetchTime
|
||||
* @var int
|
||||
*/
|
||||
public $prefetchTime;
|
||||
|
||||
/**
|
||||
* @description credentials
|
||||
* @var Credentials
|
||||
*/
|
||||
public $credentials;
|
||||
|
||||
|
||||
/**
|
||||
* @return Credentials
|
||||
*/
|
||||
public function credentials()
|
||||
{
|
||||
return $this->credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public function staleTime()
|
||||
{
|
||||
return $this->staleTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public function prefetchTime()
|
||||
{
|
||||
return $this->prefetchTime;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\ChainProvider;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Utils\MockTrait;
|
||||
use ReflectionException;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -99,4 +101,4 @@ class Credentials
|
||||
|
||||
self::$credentials[\strtolower($name)] = \array_change_key_case($credential);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Signature\SignatureInterface;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Interface CredentialsInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
@@ -12,12 +14,19 @@ use AlibabaCloud\Credentials\Signature\SignatureInterface;
|
||||
interface CredentialsInterface
|
||||
{
|
||||
/**
|
||||
* @deprecated
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return SignatureInterface
|
||||
*/
|
||||
public function getSignature();
|
||||
|
||||
/**
|
||||
* @return CredentialModel
|
||||
*/
|
||||
public function getCredential();
|
||||
}
|
||||
|
||||
76
Server/vendor/alibabacloud/credentials/src/CredentialsProviderWrap.php
vendored
Normal file
76
Server/vendor/alibabacloud/credentials/src/CredentialsProviderWrap.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Providers\CredentialsProvider;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class CredentialsProviderWrap
|
||||
*
|
||||
* @package AlibabaCloud\Credentials
|
||||
*/
|
||||
class CredentialsProviderWrap implements CredentialsInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $typeName;
|
||||
|
||||
/**
|
||||
* @var CredentialsProvider
|
||||
*/
|
||||
private $credentialsProvider;
|
||||
|
||||
/**
|
||||
* CLIProfileCredentialsProvider constructor.
|
||||
*
|
||||
* @param string $typeName
|
||||
* @param CredentialsProvider $credentialsProvider
|
||||
*/
|
||||
public function __construct($typeName, $credentialsProvider)
|
||||
{
|
||||
$this->typeName = $typeName;
|
||||
$this->credentialsProvider = $credentialsProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
$credentials = $this->credentialsProvider->getCredentials();
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'type' => $this->typeName,
|
||||
'providerName' => $credentials->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return $this->credentialsProvider->$name($arguments);
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return "credentialsProviderWrap#$this->typeName";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ShaHmac1Signature
|
||||
*/
|
||||
public function getSignature()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,18 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\EcsRamRoleProvider;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use AlibabaCloud\Credentials\Providers\EcsRamRoleCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Use the RAM role of an ECS instance to complete the authentication.
|
||||
*/
|
||||
class EcsRamRoleCredential implements CredentialsInterface
|
||||
@@ -21,16 +24,33 @@ class EcsRamRoleCredential implements CredentialsInterface
|
||||
*/
|
||||
private $roleName;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $disableIMDSv1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $metadataTokenDuration;
|
||||
|
||||
|
||||
/**
|
||||
* EcsRamRoleCredential constructor.
|
||||
*
|
||||
* @param $role_name
|
||||
*/
|
||||
public function __construct($role_name = null)
|
||||
public function __construct($role_name = null, $disable_imdsv1 = false, $metadata_token_duration = 21600)
|
||||
{
|
||||
Filter::roleName($role_name);
|
||||
|
||||
$this->roleName = $role_name;
|
||||
|
||||
Filter::disableIMDSv1($disable_imdsv1);
|
||||
|
||||
$this->disableIMDSv1 = $disable_imdsv1;
|
||||
|
||||
$this->metadataTokenDuration = $metadata_token_duration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +76,8 @@ class EcsRamRoleCredential implements CredentialsInterface
|
||||
public function getRoleNameFromMeta()
|
||||
{
|
||||
$options = [
|
||||
'http_errors' => false,
|
||||
'timeout' => 1,
|
||||
'http_errors' => false,
|
||||
'timeout' => 1,
|
||||
'connect_timeout' => 1,
|
||||
];
|
||||
|
||||
@@ -75,7 +95,7 @@ class EcsRamRoleCredential implements CredentialsInterface
|
||||
throw new RuntimeException('Error retrieving credentials from result: ' . $result->getBody());
|
||||
}
|
||||
|
||||
$role_name = (string)$result;
|
||||
$role_name = (string) $result;
|
||||
if (!$role_name) {
|
||||
throw new RuntimeException('Error retrieving credentials from result is empty');
|
||||
}
|
||||
@@ -110,13 +130,18 @@ class EcsRamRoleCredential implements CredentialsInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StsCredential
|
||||
* @return AlibabaCloud\Credentials\Providers\Credentials
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function getSessionCredential()
|
||||
{
|
||||
return (new EcsRamRoleProvider($this))->get();
|
||||
$params = [
|
||||
"roleName" => $this->roleName,
|
||||
'disableIMDSv1' => $this->disableIMDSv1,
|
||||
'metadataTokenDuration' => $this->metadataTokenDuration,
|
||||
];
|
||||
return (new EcsRamRoleCredentialsProvider($params))->getCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,4 +173,27 @@ class EcsRamRoleCredential implements CredentialsInterface
|
||||
{
|
||||
return $this->getSessionCredential()->getExpiration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisableIMDSv1()
|
||||
{
|
||||
return $this->disableIMDSv1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
$credentials = $this->getSessionCredential();
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'type' => 'ecs_ram_role',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function credentialName($name)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
throw new InvalidArgumentException('Name must be a string');
|
||||
}
|
||||
|
||||
if ($name === '') {
|
||||
throw new InvalidArgumentException('Name cannot be empty');
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bearerToken
|
||||
*
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function bearerToken($bearerToken)
|
||||
{
|
||||
if (!is_string($bearerToken)) {
|
||||
throw new InvalidArgumentException('Bearer Token must be a string');
|
||||
}
|
||||
|
||||
if ($bearerToken === '') {
|
||||
throw new InvalidArgumentException('Bearer Token cannot be empty');
|
||||
}
|
||||
|
||||
return $bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $publicKeyId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function publicKeyId($publicKeyId)
|
||||
{
|
||||
if (!is_string($publicKeyId)) {
|
||||
throw new InvalidArgumentException('public_key_id must be a string');
|
||||
}
|
||||
|
||||
if ($publicKeyId === '') {
|
||||
throw new InvalidArgumentException('public_key_id cannot be empty');
|
||||
}
|
||||
|
||||
return $publicKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $privateKeyFile
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function privateKeyFile($privateKeyFile)
|
||||
{
|
||||
if (!is_string($privateKeyFile)) {
|
||||
throw new InvalidArgumentException('private_key_file must be a string');
|
||||
}
|
||||
|
||||
if ($privateKeyFile === '') {
|
||||
throw new InvalidArgumentException('private_key_file cannot be empty');
|
||||
}
|
||||
|
||||
return $privateKeyFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $role_name
|
||||
*/
|
||||
public static function roleName($role_name)
|
||||
{
|
||||
if ($role_name === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($role_name)) {
|
||||
throw new InvalidArgumentException('role_name must be a string');
|
||||
}
|
||||
|
||||
if ($role_name === '') {
|
||||
throw new InvalidArgumentException('role_name cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
*/
|
||||
public static function accessKey($accessKeyId, $accessKeySecret)
|
||||
{
|
||||
if (!is_string($accessKeyId)) {
|
||||
throw new InvalidArgumentException('access_key_id must be a string');
|
||||
}
|
||||
|
||||
if ($accessKeyId === '') {
|
||||
throw new InvalidArgumentException('access_key_id cannot be empty');
|
||||
}
|
||||
|
||||
if (!is_string($accessKeySecret)) {
|
||||
throw new InvalidArgumentException('access_key_secret must be a string');
|
||||
}
|
||||
|
||||
if ($accessKeySecret === '') {
|
||||
throw new InvalidArgumentException('access_key_secret cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $expiration
|
||||
*/
|
||||
public static function expiration($expiration)
|
||||
{
|
||||
if (!is_int($expiration)) {
|
||||
throw new InvalidArgumentException('expiration must be a int');
|
||||
}
|
||||
}
|
||||
}
|
||||
187
Server/vendor/alibabacloud/credentials/src/Providers/CLIProfileCredentialsProvider.php
vendored
Normal file
187
Server/vendor/alibabacloud/credentials/src/Providers/CLIProfileCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class CLIProfileCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class CLIProfileCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $profileName;
|
||||
|
||||
/**
|
||||
* @var CredentialsProvider
|
||||
*/
|
||||
private $credentialsProvider;
|
||||
|
||||
|
||||
/**
|
||||
* CLIProfileCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
$this->filterProfileName($params);
|
||||
}
|
||||
|
||||
private function filterProfileName(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_PROFILE')) {
|
||||
$this->profileName = Helper::env('ALIBABA_CLOUD_PROFILE');
|
||||
}
|
||||
|
||||
if (isset($params['profileName'])) {
|
||||
$this->profileName = $params['profileName'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldReloadCredentialsProvider()
|
||||
{
|
||||
if (is_null($this->credentialsProvider)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CredentialsProvider
|
||||
*/
|
||||
protected function reloadCredentialsProvider($profileFile, $profileName)
|
||||
{
|
||||
if (!Helper::inOpenBasedir($profileFile)) {
|
||||
throw new RuntimeException('Unable to open credentials file: ' . $profileFile);
|
||||
}
|
||||
|
||||
if (!\is_readable($profileFile) || !\is_file($profileFile)) {
|
||||
throw new RuntimeException('Credentials file is not readable: ' . $profileFile);
|
||||
}
|
||||
|
||||
$jsonContent = \file_get_contents($profileFile);
|
||||
$fileArray = json_decode($jsonContent, true);
|
||||
|
||||
if (\is_array($fileArray) && !empty($fileArray)) {
|
||||
if (is_null($profileName) || $profileName === '') {
|
||||
$profileName = $fileArray['current'];
|
||||
}
|
||||
if (isset($fileArray['profiles'])) {
|
||||
foreach ($fileArray['profiles'] as $profile) {
|
||||
if (Helper::unsetReturnNull($profile, 'name') === $profileName) {
|
||||
switch (Helper::unsetReturnNull($profile, 'mode')) {
|
||||
case 'AK':
|
||||
return new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => Helper::unsetReturnNull($profile, 'access_key_id'),
|
||||
'accessKeySecret' => Helper::unsetReturnNull($profile, 'access_key_secret'),
|
||||
]);
|
||||
case 'RamRoleArn':
|
||||
$innerProvider = new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => Helper::unsetReturnNull($profile, 'access_key_id'),
|
||||
'accessKeySecret' => Helper::unsetReturnNull($profile, 'access_key_secret'),
|
||||
]);
|
||||
return new RamRoleArnCredentialsProvider([
|
||||
'credentialsProvider' => $innerProvider,
|
||||
'roleArn' => Helper::unsetReturnNull($profile, 'ram_role_arn'),
|
||||
'roleSessionName' => Helper::unsetReturnNull($profile, 'ram_session_name'),
|
||||
'durationSeconds' => Helper::unsetReturnNull($profile, 'expired_seconds'),
|
||||
'policy' => Helper::unsetReturnNull($profile, 'policy'),
|
||||
'externalId' => Helper::unsetReturnNull($profile, 'external_id'),
|
||||
'stsRegionId' => Helper::unsetReturnNull($profile, 'sts_region'),
|
||||
'enableVpc' => Helper::unsetReturnNull($profile, 'enable_vpc'),
|
||||
]);
|
||||
case 'EcsRamRole':
|
||||
return new EcsRamRoleCredentialsProvider([
|
||||
'roleName' => Helper::unsetReturnNull($profile, 'ram_role_name'),
|
||||
]);
|
||||
case 'OIDC':
|
||||
return new OIDCRoleArnCredentialsProvider([
|
||||
'roleArn' => Helper::unsetReturnNull($profile, 'ram_role_arn'),
|
||||
'oidcProviderArn' => Helper::unsetReturnNull($profile, 'oidc_provider_arn'),
|
||||
'oidcTokenFilePath' => Helper::unsetReturnNull($profile, 'oidc_token_file'),
|
||||
'roleSessionName' => Helper::unsetReturnNull($profile, 'ram_session_name'),
|
||||
'durationSeconds' => Helper::unsetReturnNull($profile, 'expired_seconds'),
|
||||
'policy' => Helper::unsetReturnNull($profile, 'policy'),
|
||||
'stsRegionId' => Helper::unsetReturnNull($profile, 'sts_region'),
|
||||
'enableVpc' => Helper::unsetReturnNull($profile, 'enable_vpc'),
|
||||
]);
|
||||
case 'ChainableRamRoleArn':
|
||||
$previousProvider = $this->reloadCredentialsProvider($profileFile, Helper::unsetReturnNull($profile, 'source_profile'));
|
||||
return new RamRoleArnCredentialsProvider([
|
||||
'credentialsProvider' => $previousProvider,
|
||||
'roleArn' => Helper::unsetReturnNull($profile, 'ram_role_arn'),
|
||||
'roleSessionName' => Helper::unsetReturnNull($profile, 'ram_session_name'),
|
||||
'durationSeconds' => Helper::unsetReturnNull($profile, 'expired_seconds'),
|
||||
'policy' => Helper::unsetReturnNull($profile, 'policy'),
|
||||
'externalId' => Helper::unsetReturnNull($profile, 'external_id'),
|
||||
'stsRegionId' => Helper::unsetReturnNull($profile, 'sts_region'),
|
||||
'enableVpc' => Helper::unsetReturnNull($profile, 'enable_vpc'),
|
||||
]);
|
||||
default:
|
||||
throw new RuntimeException('Unsupported credential mode from CLI credentials file: ' . Helper::unsetReturnNull($profile, 'mode'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('Failed to get credential from CLI credentials file: ' . $profileFile);
|
||||
}
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_CLI_PROFILE_DISABLED') && Helper::env('ALIBABA_CLOUD_CLI_PROFILE_DISABLED') === true) {
|
||||
throw new RuntimeException('CLI credentials file is disabled');
|
||||
}
|
||||
$cliProfileFile = self::getDefaultFile();
|
||||
if ($this->shouldReloadCredentialsProvider()) {
|
||||
$this->credentialsProvider = $this->reloadCredentialsProvider($cliProfileFile, $this->profileName);
|
||||
}
|
||||
|
||||
$credentials = $this->credentialsProvider->getCredentials();
|
||||
return new Credentials([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'providerName' => $this->getProviderName() . '/' . $this->credentialsProvider->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default credential file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDefaultFile()
|
||||
{
|
||||
return Helper::getHomeDirectory() .
|
||||
DIRECTORY_SEPARATOR .
|
||||
'.aliyun' .
|
||||
DIRECTORY_SEPARATOR .
|
||||
'config.json';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'cli_profile';
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Credentials;
|
||||
use AlibabaCloud\Credentials\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use Closure;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Class ChainProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
@@ -184,4 +185,4 @@ class ChainProvider
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Server/vendor/alibabacloud/credentials/src/Providers/Credentials.php
vendored
Normal file
87
Server/vendor/alibabacloud/credentials/src/Providers/Credentials.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class Credentials
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class Credentials
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $securityToken;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $expiration;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $providerName;
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (!empty($config)) {
|
||||
foreach ($config as $k => $v) {
|
||||
$this->{$k} = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeyId()
|
||||
{
|
||||
return $this->accessKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessKeySecret()
|
||||
{
|
||||
return $this->accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecurityToken()
|
||||
{
|
||||
return $this->securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getExpiration()
|
||||
{
|
||||
return $this->expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return $this->providerName;
|
||||
}
|
||||
}
|
||||
24
Server/vendor/alibabacloud/credentials/src/Providers/CredentialsProvider.php
vendored
Normal file
24
Server/vendor/alibabacloud/credentials/src/Providers/CredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Interface CredentialsInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
interface CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @return Credentials
|
||||
*/
|
||||
public function getCredentials();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName();
|
||||
}
|
||||
175
Server/vendor/alibabacloud/credentials/src/Providers/DefaultCredentialsProvider.php
vendored
Normal file
175
Server/vendor/alibabacloud/credentials/src/Providers/DefaultCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class DefaultCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class DefaultCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $defaultProviders = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $reuseLastProviderEnabled;
|
||||
|
||||
/**
|
||||
* @var CredentialsProvider
|
||||
*/
|
||||
private $lastUsedCredentialsProvider;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $customChain = [];
|
||||
|
||||
/**
|
||||
* DefaultCredentialsProvider constructor.
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
$this->filterReuseLastProviderEnabled($params);
|
||||
$this->createDefaultChain();
|
||||
Filter::reuseLastProviderEnabled($this->reuseLastProviderEnabled);
|
||||
}
|
||||
|
||||
private function filterReuseLastProviderEnabled(array $params)
|
||||
{
|
||||
$this->reuseLastProviderEnabled = true;
|
||||
if (isset($params['reuseLastProviderEnabled'])) {
|
||||
$this->reuseLastProviderEnabled = $params['reuseLastProviderEnabled'];
|
||||
}
|
||||
}
|
||||
|
||||
private function createDefaultChain()
|
||||
{
|
||||
self::$defaultProviders = [
|
||||
new EnvironmentVariableCredentialsProvider(),
|
||||
];
|
||||
if (
|
||||
Helper::envNotEmpty('ALIBABA_CLOUD_ROLE_ARN')
|
||||
&& Helper::envNotEmpty('ALIBABA_CLOUD_OIDC_PROVIDER_ARN')
|
||||
&& Helper::envNotEmpty('ALIBABA_CLOUD_OIDC_TOKEN_FILE')
|
||||
) {
|
||||
array_push(
|
||||
self::$defaultProviders,
|
||||
new OIDCRoleArnCredentialsProvider()
|
||||
);
|
||||
}
|
||||
array_push(
|
||||
self::$defaultProviders,
|
||||
new CLIProfileCredentialsProvider()
|
||||
);
|
||||
array_push(
|
||||
self::$defaultProviders,
|
||||
new ProfileCredentialsProvider()
|
||||
);
|
||||
array_push(
|
||||
self::$defaultProviders,
|
||||
new EcsRamRoleCredentialsProvider()
|
||||
);
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_CREDENTIALS_URI')) {
|
||||
array_push(
|
||||
self::$defaultProviders,
|
||||
new URLCredentialsProvider()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CredentialsProvider ...$providers
|
||||
*/
|
||||
public static function set(...$providers)
|
||||
{
|
||||
if (empty($providers)) {
|
||||
throw new InvalidArgumentException('No providers in chain');
|
||||
}
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
if (!$provider instanceof CredentialsProvider) {
|
||||
throw new InvalidArgumentException('Providers must all be CredentialsProvider');
|
||||
}
|
||||
}
|
||||
|
||||
self::$customChain = $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasCustomChain()
|
||||
{
|
||||
return (bool) self::$customChain;
|
||||
}
|
||||
|
||||
public static function flush()
|
||||
{
|
||||
self::$customChain = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
if ($this->reuseLastProviderEnabled && !is_null($this->lastUsedCredentialsProvider)) {
|
||||
$credentials = $this->lastUsedCredentialsProvider->getCredentials();
|
||||
return new Credentials([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'providerName' => $this->getProviderName() . '/' . $this->lastUsedCredentialsProvider->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
$providerChain = array_merge(
|
||||
self::$customChain,
|
||||
self::$defaultProviders
|
||||
);
|
||||
|
||||
$exceptionMessages = [];
|
||||
|
||||
foreach ($providerChain as $provider) {
|
||||
try {
|
||||
$credentials = $provider->getCredentials();
|
||||
$this->lastUsedCredentialsProvider = $provider;
|
||||
return new Credentials([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'providerName' => $this->getProviderName() . '/' . $provider->getProviderName(),
|
||||
]);
|
||||
} catch (Exception $exception) {
|
||||
array_push($exceptionMessages, basename(str_replace('\\', '/', get_class($provider))) . ': ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('Unable to load credentials from any of the providers in the chain: ' . implode(', ', $exceptionMessages));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
276
Server/vendor/alibabacloud/credentials/src/Providers/EcsRamRoleCredentialsProvider.php
vendored
Normal file
276
Server/vendor/alibabacloud/credentials/src/Providers/EcsRamRoleCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class EcsRamRoleCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class EcsRamRoleCredentialsProvider extends SessionCredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $metadataHost = 'http://100.100.100.200';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $ecsUri = '/latest/meta-data/ram/security-credentials/';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $metadataTokenUri = '/latest/api/token';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleName;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $disableIMDSv1 = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $metadataTokenDuration = 21600;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $connectTimeout = 1;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readTimeout = 1;
|
||||
|
||||
|
||||
/**
|
||||
* EcsRamRoleCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $params = [], array $options = [])
|
||||
{
|
||||
$this->filterOptions($options);
|
||||
$this->filterRoleName($params);
|
||||
$this->filterDisableECSIMDSv1($params);
|
||||
Filter::roleName($this->roleName);
|
||||
Filter::disableIMDSv1($this->disableIMDSv1);
|
||||
}
|
||||
|
||||
private function filterOptions(array $options)
|
||||
{
|
||||
if (isset($options['connectTimeout'])) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($options['readTimeout'])) {
|
||||
$this->readTimeout = $options['readTimeout'];
|
||||
}
|
||||
|
||||
Filter::timeout($this->connectTimeout, $this->readTimeout);
|
||||
}
|
||||
|
||||
private function filterRoleName(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ECS_METADATA')) {
|
||||
$this->roleName = Helper::env('ALIBABA_CLOUD_ECS_METADATA');
|
||||
}
|
||||
|
||||
if (isset($params['roleName'])) {
|
||||
$this->roleName = $params['roleName'];
|
||||
}
|
||||
}
|
||||
|
||||
private function filterDisableECSIMDSv1($params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_IMDSV1_DISABLED')) {
|
||||
$this->disableIMDSv1 = Helper::env('ALIBABA_CLOUD_IMDSV1_DISABLED') === true ? true : false;
|
||||
}
|
||||
|
||||
if (isset($params['disableIMDSv1'])) {
|
||||
$this->disableIMDSv1 = $params['disableIMDSv1'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return RefreshResult
|
||||
* @throws InvalidArgumentException
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function refreshCredentials()
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ECS_METADATA_DISABLED') && Helper::env('ALIBABA_CLOUD_ECS_METADATA_DISABLED') === true) {
|
||||
throw new RuntimeException('IMDS credentials is disabled');
|
||||
}
|
||||
|
||||
if (is_null($this->roleName) || $this->roleName === '') {
|
||||
$this->roleName = $this->getRoleNameFromMeta();
|
||||
}
|
||||
|
||||
$url = $this->metadataHost . $this->ecsUri . $this->roleName;
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$metadataToken = $this->getMetadataToken();
|
||||
if (!is_null($metadataToken)) {
|
||||
$options['headers']['X-aliyun-ecs-metadata-token'] = $metadataToken;
|
||||
}
|
||||
|
||||
$result = Request::createClient()->request('GET', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() === 404) {
|
||||
throw new InvalidArgumentException('The role was not found in the instance' . (string) $result);
|
||||
}
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error refreshing credentials from IMDS, statusCode: ' . $result->getStatusCode() . ', result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$credentials = $result->toArray();
|
||||
|
||||
if (!isset($credentials['AccessKeyId']) || !isset($credentials['AccessKeySecret']) || !isset($credentials['SecurityToken'])) {
|
||||
throw new RuntimeException('Error retrieving credentials from IMDS result:' . $result->toJson());
|
||||
}
|
||||
|
||||
if (!isset($credentials['Code']) || $credentials['Code'] !== 'Success') {
|
||||
throw new RuntimeException('Error retrieving credentials from IMDS result, Code is not Success:' . $result->toJson());
|
||||
}
|
||||
|
||||
return new RefreshResult(new Credentials([
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
'expiration' => \strtotime($credentials['Expiration']),
|
||||
'providerName' => $this->getProviderName(),
|
||||
]), $this->getStaleTime(strtotime($credentials["Expiration"])), $this->getPrefetchTime(strtotime($credentials["Expiration"])));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws InvalidArgumentException
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
private function getRoleNameFromMeta()
|
||||
{
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$metadataToken = $this->getMetadataToken();
|
||||
if (!is_null($metadataToken)) {
|
||||
$options['headers']['X-aliyun-ecs-metadata-token'] = $metadataToken;
|
||||
}
|
||||
|
||||
$result = Request::createClient()->request(
|
||||
'GET',
|
||||
'http://100.100.100.200/latest/meta-data/ram/security-credentials/',
|
||||
$options
|
||||
);
|
||||
|
||||
if ($result->getStatusCode() === 404) {
|
||||
throw new InvalidArgumentException('The role name was not found in the instance' . (string) $result);
|
||||
}
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error retrieving role name from result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$role_name = (string) $result;
|
||||
if (!$role_name) {
|
||||
throw new RuntimeException('Error retrieving role name from result is empty');
|
||||
}
|
||||
|
||||
return $role_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata token by request.
|
||||
*
|
||||
* @return string
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
private function getMetadataToken()
|
||||
{
|
||||
$url = $this->metadataHost . $this->metadataTokenUri;
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
$options['headers']['X-aliyun-ecs-metadata-token-ttl-seconds'] = $this->metadataTokenDuration;
|
||||
|
||||
$result = Request::createClient()->request('PUT', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() != 200) {
|
||||
if ($this->disableIMDSv1) {
|
||||
throw new RuntimeException('Failed to get token from ECS Metadata Service. HttpCode= ' . $result->getStatusCode());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return (string) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public function getPrefetchTime($expiration)
|
||||
{
|
||||
return $expiration <= 0 ?
|
||||
time() + (5 * 60) :
|
||||
time() + (60 * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return 'ecs_ram_role#roleName#' . $this->roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'ecs_ram_role';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleName()
|
||||
{
|
||||
return $this->roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisableIMDSv1()
|
||||
{
|
||||
return $this->disableIMDSv1;
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use AlibabaCloud\Credentials\StsCredential;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use AlibabaCloud\Tea\Response;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class EcsRamRoleProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class EcsRamRoleProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Expiration time slot for temporary security credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expirationSlot = 10;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $uri = 'http://100.100.100.200/latest/meta-data/ram/security-credentials/';
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$result = $this->getCredentialsInCache();
|
||||
|
||||
if ($result === null) {
|
||||
$result = $this->request();
|
||||
|
||||
if (!isset($result['AccessKeyId'], $result['AccessKeySecret'], $result['SecurityToken'])) {
|
||||
throw new RuntimeException($this->error);
|
||||
}
|
||||
|
||||
$this->cache($result->toArray());
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$result['AccessKeyId'],
|
||||
$result['AccessKeySecret'],
|
||||
strtotime($result['Expiration']),
|
||||
$result['SecurityToken']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
$credential = $this->credential;
|
||||
$url = $this->uri . $credential->getRoleName();
|
||||
|
||||
$options = [
|
||||
'http_errors' => false,
|
||||
'timeout' => 1,
|
||||
'connect_timeout' => 1,
|
||||
];
|
||||
|
||||
$result = Request::createClient()->request('GET', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() === 404) {
|
||||
$message = 'The role was not found in the instance';
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error retrieving credentials from result: ' . $result->toJson());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
65
Server/vendor/alibabacloud/credentials/src/Providers/EnvironmentVariableCredentialsProvider.php
vendored
Normal file
65
Server/vendor/alibabacloud/credentials/src/Providers/EnvironmentVariableCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class EnvironmentVariableCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class EnvironmentVariableCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
/**
|
||||
* EnvironmentVariableCredentialsProvider constructor.
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_ID')) {
|
||||
$accessKeyId = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_ID');
|
||||
} else {
|
||||
throw new InvalidArgumentException('Access key ID must be specified via environment variable (ALIBABA_CLOUD_ACCESS_KEY_ID)');
|
||||
}
|
||||
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_SECRET')) {
|
||||
$accessKeySecret = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
|
||||
} else {
|
||||
throw new InvalidArgumentException('Access key Secret must be specified via environment variable (ALIBABA_CLOUD_ACCESS_KEY_SECRET)');
|
||||
}
|
||||
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_SECURITY_TOKEN')) {
|
||||
$securityToken = Helper::env('ALIBABA_CLOUD_SECURITY_TOKEN');
|
||||
return new Credentials([
|
||||
'accessKeyId' => $accessKeyId,
|
||||
'accessKeySecret' => $accessKeySecret,
|
||||
'securityToken' => $securityToken,
|
||||
'providerName' => $this->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
return new Credentials([
|
||||
'accessKeyId' => $accessKeyId,
|
||||
'accessKeySecret' => $accessKeySecret,
|
||||
'providerName' => $this->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return "env";
|
||||
}
|
||||
}
|
||||
264
Server/vendor/alibabacloud/credentials/src/Providers/OIDCRoleArnCredentialsProvider.php
vendored
Normal file
264
Server/vendor/alibabacloud/credentials/src/Providers/OIDCRoleArnCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Exception;
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class OIDCRoleArnCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class OIDCRoleArnCredentialsProvider extends SessionCredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleArn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $oidcProviderArn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $oidcTokenFilePath;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleSessionName;
|
||||
|
||||
/**
|
||||
* @description role session expiration
|
||||
* @example 3600
|
||||
* @var int
|
||||
*/
|
||||
private $durationSeconds = 3600;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $policy;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $stsEndpoint;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $connectTimeout = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readTimeout = 5;
|
||||
|
||||
/**
|
||||
* OIDCRoleArnCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $params = [], array $options = [])
|
||||
{
|
||||
$this->filterOptions($options);
|
||||
$this->filterRoleArn($params);
|
||||
$this->filterOIDCProviderArn($params);
|
||||
$this->filterOIDCTokenFilePath($params);
|
||||
$this->filterRoleSessionName($params);
|
||||
$this->filterDurationSeconds($params);
|
||||
$this->filterPolicy($params);
|
||||
$this->filterSTSEndpoint($params);
|
||||
}
|
||||
|
||||
private function filterRoleArn(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ROLE_ARN')) {
|
||||
$this->roleArn = Helper::env('ALIBABA_CLOUD_ROLE_ARN');
|
||||
}
|
||||
|
||||
if (isset($params['roleArn'])) {
|
||||
$this->roleArn = $params['roleArn'];
|
||||
}
|
||||
|
||||
Filter::roleArn($this->roleArn);
|
||||
}
|
||||
|
||||
private function filterOIDCProviderArn(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_OIDC_PROVIDER_ARN')) {
|
||||
$this->oidcProviderArn = Helper::env('ALIBABA_CLOUD_OIDC_PROVIDER_ARN');
|
||||
}
|
||||
|
||||
if (isset($params['oidcProviderArn'])) {
|
||||
$this->oidcProviderArn = $params['oidcProviderArn'];
|
||||
}
|
||||
|
||||
Filter::oidcProviderArn($this->oidcProviderArn);
|
||||
}
|
||||
|
||||
private function filterOIDCTokenFilePath(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_OIDC_TOKEN_FILE')) {
|
||||
$this->oidcTokenFilePath = Helper::env('ALIBABA_CLOUD_OIDC_TOKEN_FILE');
|
||||
}
|
||||
|
||||
if (isset($params['oidcTokenFilePath'])) {
|
||||
$this->oidcTokenFilePath = $params['oidcTokenFilePath'];
|
||||
}
|
||||
|
||||
Filter::oidcTokenFilePath($this->oidcTokenFilePath);
|
||||
}
|
||||
|
||||
private function filterRoleSessionName(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ROLE_SESSION_NAME')) {
|
||||
$this->roleSessionName = Helper::env('ALIBABA_CLOUD_ROLE_SESSION_NAME');
|
||||
}
|
||||
|
||||
if (isset($params['roleSessionName'])) {
|
||||
$this->roleSessionName = $params['roleSessionName'];
|
||||
}
|
||||
|
||||
if (is_null($this->roleSessionName) || $this->roleSessionName === '') {
|
||||
$this->roleSessionName = 'phpSdkRoleSessionName';
|
||||
}
|
||||
}
|
||||
|
||||
private function filterDurationSeconds(array $params)
|
||||
{
|
||||
if (isset($params['durationSeconds'])) {
|
||||
if (is_int($params['durationSeconds'])) {
|
||||
$this->durationSeconds = $params['durationSeconds'];
|
||||
}
|
||||
}
|
||||
if ($this->durationSeconds < 900) {
|
||||
throw new InvalidArgumentException('Role session expiration should be in the range of 900s - max session duration');
|
||||
}
|
||||
}
|
||||
|
||||
private function filterPolicy(array $params)
|
||||
{
|
||||
if (isset($params['policy'])) {
|
||||
if (is_string($params['policy'])) {
|
||||
$this->policy = $params['policy'];
|
||||
}
|
||||
|
||||
if (is_array($params['policy'])) {
|
||||
$this->policy = json_encode($params['policy']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function filterSTSEndpoint(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_STS_REGION')) {
|
||||
$this->stsEndpoint = 'sts' . Helper::env('ALIBABA_CLOUD_STS_REGION') . '.aliyuncs.com';
|
||||
}
|
||||
|
||||
if (isset($params['stsRegionId'])) {
|
||||
$this->stsEndpoint = 'sts' . $params['stsRegionId'] . '.aliyuncs.com';
|
||||
}
|
||||
|
||||
if (isset($params['stsEndpoint'])) {
|
||||
$this->stsEndpoint = $params['stsEndpoint'];
|
||||
}
|
||||
|
||||
if (is_null($this->stsEndpoint) || $this->stsEndpoint === '') {
|
||||
$this->stsEndpoint = 'sts.aliyuncs.com';
|
||||
}
|
||||
}
|
||||
|
||||
private function filterOptions(array $options)
|
||||
{
|
||||
if (isset($options['connectTimeout'])) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($options['readTimeout'])) {
|
||||
$this->readTimeout = $options['readTimeout'];
|
||||
}
|
||||
|
||||
Filter::timeout($this->connectTimeout, $this->readTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return RefreshResult
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function refreshCredentials()
|
||||
{
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$options['query']['Action'] = 'AssumeRoleWithOIDC';
|
||||
$options['query']['Version'] = '2015-04-01';
|
||||
$options['query']['Format'] = 'JSON';
|
||||
$options['query']['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$options['query']['RoleArn'] = $this->roleArn;
|
||||
$options['query']['OIDCProviderArn'] = $this->oidcProviderArn;
|
||||
try {
|
||||
$oidcToken = file_get_contents($this->oidcTokenFilePath);
|
||||
$options['query']['OIDCToken'] = $oidcToken;
|
||||
} catch (Exception $exception) {
|
||||
throw new InvalidArgumentException($exception->getMessage());
|
||||
}
|
||||
$options['query']['RoleSessionName'] = $this->roleSessionName;
|
||||
$options['query']['DurationSeconds'] = (string) $this->durationSeconds;
|
||||
if (!is_null($this->policy)) {
|
||||
$options['query']['Policy'] = $this->policy;
|
||||
}
|
||||
|
||||
$url = (new Uri())->withScheme('https')->withHost($this->stsEndpoint);
|
||||
|
||||
$result = Request::createClient()->request('POST', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error refreshing credentials from OIDC, statusCode: ' . $result->getStatusCode() . ', result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$json = $result->toArray();
|
||||
$credentials = $json['Credentials'];
|
||||
|
||||
if (!isset($credentials['AccessKeyId']) || !isset($credentials['AccessKeySecret']) || !isset($credentials['SecurityToken'])) {
|
||||
throw new RuntimeException('Error retrieving credentials from OIDC result:' . $result->toJson());
|
||||
}
|
||||
|
||||
return new RefreshResult(new Credentials([
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
'expiration' => \strtotime($credentials['Expiration']),
|
||||
'providerName' => $this->getProviderName(),
|
||||
]), $this->getStaleTime(strtotime($credentials['Expiration'])) );
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return 'oidc_role_arn#roleArn#' . $this->roleArn . '#oidcProviderArn#' . $this->oidcProviderArn . '#roleSessionName#' . $this->roleSessionName;
|
||||
}
|
||||
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'oidc_role_arn';
|
||||
}
|
||||
}
|
||||
188
Server/vendor/alibabacloud/credentials/src/Providers/ProfileCredentialsProvider.php
vendored
Normal file
188
Server/vendor/alibabacloud/credentials/src/Providers/ProfileCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class ProfileCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class ProfileCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $profileName;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $profileFile;
|
||||
|
||||
/**
|
||||
* @var CredentialsProvider
|
||||
*/
|
||||
private $credentialsProvider;
|
||||
|
||||
|
||||
/**
|
||||
* ProfileCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
$this->filterProfileName($params);
|
||||
$this->filterProfileFile();
|
||||
}
|
||||
|
||||
private function filterProfileName(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_PROFILE')) {
|
||||
$this->profileName = Helper::env('ALIBABA_CLOUD_PROFILE');
|
||||
}
|
||||
|
||||
if (isset($params['profileName'])) {
|
||||
$this->profileName = $params['profileName'];
|
||||
}
|
||||
|
||||
if (is_null($this->profileName) || $this->profileName === '') {
|
||||
$this->profileName = 'default';
|
||||
}
|
||||
}
|
||||
|
||||
private function filterProfileFile()
|
||||
{
|
||||
$this->profileFile = Helper::envNotEmpty('ALIBABA_CLOUD_CREDENTIALS_FILE');
|
||||
|
||||
if (!$this->profileFile) {
|
||||
$this->profileFile = self::getDefaultFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldReloadCredentialsProvider()
|
||||
{
|
||||
if (is_null($this->credentialsProvider)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CredentialsProvider
|
||||
*/
|
||||
private function reloadCredentialsProvider($profileFile, $profileName)
|
||||
{
|
||||
if (!Helper::inOpenBasedir($profileFile)) {
|
||||
throw new RuntimeException('Unable to open credentials file: ' . $profileFile);
|
||||
}
|
||||
|
||||
if (!\is_readable($profileFile) || !\is_file($profileFile)) {
|
||||
throw new RuntimeException('Credentials file is not readable: ' . $profileFile);
|
||||
}
|
||||
|
||||
$fileArray = \parse_ini_file($profileFile, true);
|
||||
|
||||
if (\is_array($fileArray) && !empty($fileArray)) {
|
||||
$credentialsConfigures = [];
|
||||
foreach (\array_change_key_case($fileArray) as $name => $configures) {
|
||||
if ($name === $profileName) {
|
||||
$credentialsConfigures = $configures;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (\is_array($credentialsConfigures) && !empty($credentialsConfigures)) {
|
||||
switch (Helper::unsetReturnNull($credentialsConfigures, 'type')) {
|
||||
case 'access_key':
|
||||
return new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => Helper::unsetReturnNull($credentialsConfigures, 'access_key_id'),
|
||||
'accessKeySecret' => Helper::unsetReturnNull($credentialsConfigures, 'access_key_secret'),
|
||||
]);
|
||||
case 'ram_role_arn':
|
||||
$innerProvider = new StaticAKCredentialsProvider([
|
||||
'accessKeyId' => Helper::unsetReturnNull($credentialsConfigures, 'access_key_id'),
|
||||
'accessKeySecret' => Helper::unsetReturnNull($credentialsConfigures, 'access_key_secret'),
|
||||
]);
|
||||
return new RamRoleArnCredentialsProvider([
|
||||
'credentialsProvider' => $innerProvider,
|
||||
'roleArn' => Helper::unsetReturnNull($credentialsConfigures, 'role_arn'),
|
||||
'roleSessionName' => Helper::unsetReturnNull($credentialsConfigures, 'role_session_name'),
|
||||
'policy' => Helper::unsetReturnNull($credentialsConfigures, 'policy'),
|
||||
]);
|
||||
case 'ecs_ram_role':
|
||||
return new EcsRamRoleCredentialsProvider([
|
||||
'roleName' => Helper::unsetReturnNull($credentialsConfigures, 'role_name'),
|
||||
]);
|
||||
case 'oidc_role_arn':
|
||||
return new OIDCRoleArnCredentialsProvider([
|
||||
'roleArn' => Helper::unsetReturnNull($credentialsConfigures, 'role_arn'),
|
||||
'oidcProviderArn' => Helper::unsetReturnNull($credentialsConfigures, 'oidc_provider_arn'),
|
||||
'oidcTokenFilePath' => Helper::unsetReturnNull($credentialsConfigures, 'oidc_token_file_path'),
|
||||
'roleSessionName' => Helper::unsetReturnNull($credentialsConfigures, 'role_session_name'),
|
||||
'policy' => Helper::unsetReturnNull($credentialsConfigures, 'policy'),
|
||||
]);
|
||||
case 'rsa_key_pair':
|
||||
return new RsaKeyPairCredentialsProvider([
|
||||
'publicKeyId' => Helper::unsetReturnNull($credentialsConfigures, 'public_key_id'),
|
||||
'privateKeyFile' => Helper::unsetReturnNull($credentialsConfigures, 'private_key_file'),
|
||||
]);
|
||||
default:
|
||||
throw new RuntimeException('Unsupported credential type from credentials file: ' . Helper::unsetReturnNull($credentialsConfigures, 'type'));
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('Failed to get credential from credentials file: ' . $profileFile);
|
||||
}
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
if ($this->shouldReloadCredentialsProvider()) {
|
||||
$this->credentialsProvider = $this->reloadCredentialsProvider($this->profileFile, $this->profileName);
|
||||
}
|
||||
|
||||
$credentials = $this->credentialsProvider->getCredentials();
|
||||
return new Credentials([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'providerName' => $this->getProviderName() . '/' . $this->credentialsProvider->getProviderName(),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default credential file.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getDefaultFile()
|
||||
{
|
||||
return Helper::getHomeDirectory() .
|
||||
DIRECTORY_SEPARATOR .
|
||||
'.alibabacloud' .
|
||||
DIRECTORY_SEPARATOR .
|
||||
'credentials';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'profile';
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\CredentialsInterface;
|
||||
use AlibabaCloud\Credentials\EcsRamRoleCredential;
|
||||
use AlibabaCloud\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Credentials\RsaKeyPairCredential;
|
||||
|
||||
abstract class Provider
|
||||
{
|
||||
/**
|
||||
* For TSC Duration Seconds
|
||||
*/
|
||||
const DURATION_SECONDS = 3600;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $credentialsCache = [];
|
||||
|
||||
/**
|
||||
* Expiration time slot for temporary security credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expirationSlot = 180;
|
||||
|
||||
/**
|
||||
* @var RamRoleArnCredential|RsaKeyPairCredential|EcsRamRoleCredential
|
||||
*/
|
||||
protected $credential;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'Result contains no credentials';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* CredentialTrait constructor.
|
||||
*
|
||||
* @param CredentialsInterface $credential
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(CredentialsInterface $credential, $config = [])
|
||||
{
|
||||
$this->credential = $credential;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the credentials from the cache in the validity period.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getCredentialsInCache()
|
||||
{
|
||||
if (isset(self::$credentialsCache[(string)$this->credential])) {
|
||||
$result = self::$credentialsCache[(string)$this->credential];
|
||||
if (\strtotime($result['Expiration']) - \time() >= $this->expirationSlot) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache credentials.
|
||||
*
|
||||
* @param array $credential
|
||||
*/
|
||||
protected function cache(array $credential)
|
||||
{
|
||||
self::$credentialsCache[(string)$this->credential] = $credential;
|
||||
}
|
||||
}
|
||||
317
Server/vendor/alibabacloud/credentials/src/Providers/RamRoleArnCredentialsProvider.php
vendored
Normal file
317
Server/vendor/alibabacloud/credentials/src/Providers/RamRoleArnCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class RamRoleArnCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class RamRoleArnCredentialsProvider extends SessionCredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CredentialsProvider
|
||||
*/
|
||||
private $credentialsProvider;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleArn;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $roleSessionName;
|
||||
|
||||
/**
|
||||
* @description role session expiration
|
||||
* @example 3600
|
||||
* @var int
|
||||
*/
|
||||
private $durationSeconds = 3600;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $externalId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $policy;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $stsEndpoint;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $connectTimeout = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readTimeout = 5;
|
||||
|
||||
/**
|
||||
* RamRoleArnCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $params = [], array $options = [])
|
||||
{
|
||||
$this->filterOptions($options);
|
||||
$this->filterCredentials($params);
|
||||
$this->filterRoleArn($params);
|
||||
$this->filterRoleSessionName($params);
|
||||
$this->filterDurationSeconds($params);
|
||||
$this->filterPolicy($params);
|
||||
$this->filterExternalId($params);
|
||||
$this->filterSTSEndpoint($params);
|
||||
}
|
||||
|
||||
private function filterRoleArn(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ROLE_ARN')) {
|
||||
$this->roleArn = Helper::env('ALIBABA_CLOUD_ROLE_ARN');
|
||||
}
|
||||
|
||||
if (isset($params['roleArn'])) {
|
||||
$this->roleArn = $params['roleArn'];
|
||||
}
|
||||
|
||||
Filter::roleArn($this->roleArn);
|
||||
}
|
||||
|
||||
private function filterRoleSessionName(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ROLE_SESSION_NAME')) {
|
||||
$this->roleSessionName = Helper::env('ALIBABA_CLOUD_ROLE_SESSION_NAME');
|
||||
}
|
||||
|
||||
if (isset($params['roleSessionName'])) {
|
||||
$this->roleSessionName = $params['roleSessionName'];
|
||||
}
|
||||
|
||||
if (is_null($this->roleSessionName) || $this->roleSessionName === '') {
|
||||
$this->roleSessionName = 'phpSdkRoleSessionName';
|
||||
}
|
||||
}
|
||||
|
||||
private function filterDurationSeconds(array $params)
|
||||
{
|
||||
if (isset($params['durationSeconds'])) {
|
||||
if (is_int($params['durationSeconds'])) {
|
||||
$this->durationSeconds = $params['durationSeconds'];
|
||||
}
|
||||
}
|
||||
if ($this->durationSeconds < 900) {
|
||||
throw new InvalidArgumentException('Role session expiration should be in the range of 900s - max session duration');
|
||||
}
|
||||
}
|
||||
|
||||
private function filterPolicy(array $params)
|
||||
{
|
||||
if (isset($params['policy'])) {
|
||||
if (is_string($params['policy'])) {
|
||||
$this->policy = $params['policy'];
|
||||
}
|
||||
|
||||
if (is_array($params['policy'])) {
|
||||
$this->policy = json_encode($params['policy']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function filterExternalId(array $params)
|
||||
{
|
||||
if (isset($params['externalId'])) {
|
||||
if (is_string($params['externalId'])) {
|
||||
$this->externalId = $params['externalId'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function filterSTSEndpoint(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_STS_REGION')) {
|
||||
$this->stsEndpoint = 'sts.' . Helper::env('ALIBABA_CLOUD_STS_REGION') . '.aliyuncs.com';
|
||||
}
|
||||
|
||||
if (isset($params['stsRegionId'])) {
|
||||
$this->stsEndpoint = 'sts.' . $params['stsRegionId'] . '.aliyuncs.com';
|
||||
}
|
||||
|
||||
if (isset($params['stsEndpoint'])) {
|
||||
$this->stsEndpoint = $params['stsEndpoint'];
|
||||
}
|
||||
|
||||
if (is_null($this->stsEndpoint) || $this->stsEndpoint === '') {
|
||||
$this->stsEndpoint = 'sts.aliyuncs.com';
|
||||
}
|
||||
}
|
||||
|
||||
private function filterCredentials(array $params)
|
||||
{
|
||||
if (isset($params['credentialsProvider'])) {
|
||||
if (!($params['credentialsProvider'] instanceof CredentialsProvider)) {
|
||||
throw new InvalidArgumentException('Invalid credentialsProvider option for ram_role_arn');
|
||||
}
|
||||
$this->credentialsProvider = $params['credentialsProvider'];
|
||||
} else if (isset($params['accessKeyId']) && isset($params['accessKeySecret']) && isset($params['securityToken'])) {
|
||||
Filter::accessKey($params['accessKeyId'], $params['accessKeySecret']);
|
||||
Filter::securityToken($params['securityToken']);
|
||||
$this->credentialsProvider = new StaticSTSCredentialsProvider($params);
|
||||
} else if (isset($params['accessKeyId']) && isset($params['accessKeySecret'])) {
|
||||
Filter::accessKey($params['accessKeyId'], $params['accessKeySecret']);
|
||||
$this->credentialsProvider = new StaticAKCredentialsProvider($params);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Missing required credentials option for ram_role_arn');
|
||||
}
|
||||
}
|
||||
|
||||
private function filterOptions(array $options)
|
||||
{
|
||||
if (isset($options['connectTimeout'])) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($options['readTimeout'])) {
|
||||
$this->readTimeout = $options['readTimeout'];
|
||||
}
|
||||
|
||||
Filter::timeout($this->connectTimeout, $this->readTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return RefreshResult
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function refreshCredentials()
|
||||
{
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$options['query']['Action'] = 'AssumeRole';
|
||||
$options['query']['Version'] = '2015-04-01';
|
||||
$options['query']['Format'] = 'JSON';
|
||||
$options['query']['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$options['query']['SignatureMethod'] = 'HMAC-SHA1';
|
||||
$options['query']['SignatureVersion'] = '1.0';
|
||||
$options['query']['SignatureNonce'] = Request::uuid(json_encode($options['query']));
|
||||
$options['query']['RoleArn'] = $this->roleArn;
|
||||
$options['query']['RoleSessionName'] = $this->roleSessionName;
|
||||
$options['query']['DurationSeconds'] = (string) $this->durationSeconds;
|
||||
if (!is_null($this->policy) && $this->policy !== '') {
|
||||
$options['query']['Policy'] = $this->policy;
|
||||
}
|
||||
if (!is_null($this->externalId) && $this->externalId !== '') {
|
||||
$options['query']['ExternalId'] = $this->externalId;
|
||||
}
|
||||
|
||||
$sessionCredentials = $this->credentialsProvider->getCredentials();
|
||||
$options['query']['AccessKeyId'] = $sessionCredentials->getAccessKeyId();
|
||||
if (!is_null($sessionCredentials->getSecurityToken())) {
|
||||
$options['query']['SecurityToken'] = $sessionCredentials->getSecurityToken();
|
||||
}
|
||||
$options['query']['Signature'] = Request::shaHmac1sign(
|
||||
Request::signString('GET', $options['query']),
|
||||
$sessionCredentials->getAccessKeySecret() . '&'
|
||||
);
|
||||
|
||||
$url = (new Uri())->withScheme('https')->withHost($this->stsEndpoint);
|
||||
|
||||
$result = Request::createClient()->request('GET', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error refreshing credentials from RamRoleArn, statusCode: ' . $result->getStatusCode() . ', result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$json = $result->toArray();
|
||||
$credentials = $json['Credentials'];
|
||||
|
||||
if (!isset($credentials['AccessKeyId']) || !isset($credentials['AccessKeySecret']) || !isset($credentials['SecurityToken'])) {
|
||||
throw new RuntimeException('Error retrieving credentials from RamRoleArn result:' . $result->toJson());
|
||||
}
|
||||
|
||||
return new RefreshResult(new Credentials([
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
'expiration' => \strtotime($credentials['Expiration']),
|
||||
'providerName' => $this->getProviderName(),
|
||||
]), $this->getStaleTime(strtotime($credentials['Expiration'])));
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
$credentials = $this->credentialsProvider->getCredentials();
|
||||
return 'ram_role_arn#credential#' . $credentials->getAccessKeyId() . '#roleArn#' . $this->roleArn . '#roleSessionName#' . $this->roleSessionName;
|
||||
}
|
||||
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'ram_role_arn/' . $this->credentialsProvider->getProviderName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleArn()
|
||||
{
|
||||
return $this->roleArn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleSessionName()
|
||||
{
|
||||
return $this->roleSessionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPolicy()
|
||||
{
|
||||
return $this->policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return string
|
||||
*/
|
||||
public function getOriginalAccessKeyId()
|
||||
{
|
||||
return $this->credentialsProvider->getCredentials()->getAccessKeyId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return string
|
||||
*/
|
||||
public function getOriginalAccessKeySecret()
|
||||
{
|
||||
return $this->credentialsProvider->getCredentials()->getAccessKeySecret();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Request\AssumeRole;
|
||||
use AlibabaCloud\Credentials\StsCredential;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use RuntimeException;
|
||||
|
||||
class RamRoleArnProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$credential = $this->getCredentialsInCache();
|
||||
|
||||
if (null === $credential) {
|
||||
$result = (new AssumeRole($this->credential))->request();
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException(isset($result['Message']) ? $result['Message'] : (string)$result->getBody());
|
||||
}
|
||||
|
||||
if (!isset($result['Credentials']['AccessKeyId'],
|
||||
$result['Credentials']['AccessKeySecret'],
|
||||
$result['Credentials']['SecurityToken'])) {
|
||||
throw new RuntimeException($this->error);
|
||||
}
|
||||
|
||||
$credential = $result['Credentials'];
|
||||
$this->cache($credential);
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$credential['AccessKeyId'],
|
||||
$credential['AccessKeySecret'],
|
||||
strtotime($credential['Expiration']),
|
||||
$credential['SecurityToken']
|
||||
);
|
||||
}
|
||||
}
|
||||
200
Server/vendor/alibabacloud/credentials/src/Providers/RsaKeyPairCredentialsProvider.php
vendored
Normal file
200
Server/vendor/alibabacloud/credentials/src/Providers/RsaKeyPairCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class RsaKeyPairCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class RsaKeyPairCredentialsProvider extends SessionCredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $privateKey;
|
||||
|
||||
/**
|
||||
* @description role session expiration
|
||||
* @example 3600
|
||||
* @var int
|
||||
*/
|
||||
private $durationSeconds = 3600;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $stsEndpoint;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $connectTimeout = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readTimeout = 5;
|
||||
|
||||
/**
|
||||
* RsaKeyPairCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $params = [], array $options = [])
|
||||
{
|
||||
$this->filterOptions($options);
|
||||
$this->filterDurationSeconds($params);
|
||||
$this->filterSTSEndpoint($params);
|
||||
$this->publicKeyId = isset($params['publicKeyId']) ? $params['publicKeyId'] : null;
|
||||
$privateKeyFile = isset($params['privateKeyFile']) ? $params['privateKeyFile'] : null;
|
||||
Filter::publicKeyId($this->publicKeyId);
|
||||
Filter::privateKeyFile($privateKeyFile);
|
||||
|
||||
try {
|
||||
$this->privateKey = file_get_contents($privateKeyFile);
|
||||
} catch (Exception $exception) {
|
||||
throw new InvalidArgumentException($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function filterOptions(array $options)
|
||||
{
|
||||
if (isset($options['connectTimeout'])) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($options['readTimeout'])) {
|
||||
$this->readTimeout = $options['readTimeout'];
|
||||
}
|
||||
|
||||
Filter::timeout($this->connectTimeout, $this->readTimeout);
|
||||
}
|
||||
|
||||
private function filterDurationSeconds(array $params)
|
||||
{
|
||||
if (isset($params['durationSeconds'])) {
|
||||
if (is_int($params['durationSeconds'])) {
|
||||
$this->durationSeconds = $params['durationSeconds'];
|
||||
}
|
||||
}
|
||||
if ($this->durationSeconds < 900) {
|
||||
throw new InvalidArgumentException('Role session expiration should be in the range of 900s - max session duration');
|
||||
}
|
||||
}
|
||||
|
||||
private function filterSTSEndpoint(array $params)
|
||||
{
|
||||
if (isset($params['stsEndpoint'])) {
|
||||
$this->stsEndpoint = $params['stsEndpoint'];
|
||||
}
|
||||
|
||||
if (is_null($this->stsEndpoint) || $this->stsEndpoint === '') {
|
||||
$this->stsEndpoint = 'sts.ap-northeast-1.aliyuncs.com';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return RefreshResult
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function refreshCredentials()
|
||||
{
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$options['query']['Action'] = 'GenerateSessionAccessKey';
|
||||
$options['query']['Version'] = '2015-04-01';
|
||||
$options['query']['Format'] = 'JSON';
|
||||
$options['query']['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$options['query']['SignatureMethod'] = 'SHA256withRSA';
|
||||
$options['query']['SignatureType'] = 'PRIVATEKEY';
|
||||
$options['query']['SignatureVersion'] = '1.0';
|
||||
$options['query']['SignatureNonce'] = Request::uuid(json_encode($options['query']));
|
||||
$options['query']['DurationSeconds'] = (string) $this->durationSeconds;
|
||||
$options['query']['AccessKeyId'] = $this->publicKeyId;
|
||||
$options['query']['Signature'] = Request::shaHmac256WithRsasign(
|
||||
Request::signString('GET', $options['query']),
|
||||
$this->privateKey
|
||||
);
|
||||
|
||||
$url = (new Uri())->withScheme('https')->withHost($this->stsEndpoint);
|
||||
|
||||
$result = Request::createClient()->request('GET', $url, $options);
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error refreshing credentials from RsaKeyPair, statusCode: ' . $result->getStatusCode() . ', result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$json = $result->toArray();
|
||||
|
||||
if (!isset($json['SessionAccessKey']['SessionAccessKeyId']) || !isset($json['SessionAccessKey']['SessionAccessKeySecret'])) {
|
||||
throw new RuntimeException('Error retrieving credentials from RsaKeyPair result:' . $result->toJson());
|
||||
}
|
||||
|
||||
$credentials = [];
|
||||
$credentials['AccessKeyId'] = $json['SessionAccessKey']['SessionAccessKeyId'];
|
||||
$credentials['AccessKeySecret'] = $json['SessionAccessKey']['SessionAccessKeySecret'];
|
||||
$credentials['Expiration'] = $json['SessionAccessKey']['Expiration'];
|
||||
$credentials['SecurityToken'] = null;
|
||||
|
||||
|
||||
return new RefreshResult(new Credentials([
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
'expiration' => \strtotime($credentials['Expiration']),
|
||||
'providerName' => $this->getProviderName(),
|
||||
]), $this->getStaleTime(strtotime($credentials['Expiration'])));
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return 'rsa_key_pair#publicKeyId#' . $this->publicKeyId;
|
||||
}
|
||||
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'rsa_key_pair';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicKeyId()
|
||||
{
|
||||
return $this->publicKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPrivateKey()
|
||||
{
|
||||
return $this->privateKey;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Request\GenerateSessionAccessKey;
|
||||
use AlibabaCloud\Credentials\StsCredential;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class RsaKeyPairProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class RsaKeyPairProvider extends Provider
|
||||
{
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
*
|
||||
* @return StsCredential
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
$credential = $this->getCredentialsInCache();
|
||||
|
||||
if ($credential === null) {
|
||||
$result = (new GenerateSessionAccessKey($this->credential))->request();
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException(isset($result['Message']) ? $result['Message'] : (string)$result->getBody());
|
||||
}
|
||||
|
||||
if (!isset($result['SessionAccessKey']['SessionAccessKeyId'],
|
||||
$result['SessionAccessKey']['SessionAccessKeySecret'])) {
|
||||
throw new RuntimeException($this->error);
|
||||
}
|
||||
|
||||
$credential = $result['SessionAccessKey'];
|
||||
$this->cache($credential);
|
||||
}
|
||||
|
||||
return new StsCredential(
|
||||
$credential['SessionAccessKeyId'],
|
||||
$credential['SessionAccessKeySecret'],
|
||||
strtotime($credential['Expiration'])
|
||||
);
|
||||
}
|
||||
}
|
||||
161
Server/vendor/alibabacloud/credentials/src/Providers/SessionCredentialsProvider.php
vendored
Normal file
161
Server/vendor/alibabacloud/credentials/src/Providers/SessionCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
abstract class SessionCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $credentialsCache = [];
|
||||
|
||||
/**
|
||||
* Expiration time slot for temporary security credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $expirationSlot = 180;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $error = 'Result contains no credentials';
|
||||
|
||||
/**
|
||||
* Get the credentials from the cache in the validity period.
|
||||
*
|
||||
* @return RefreshResult|null
|
||||
*/
|
||||
protected function getCredentialsInCache()
|
||||
{
|
||||
if (isset(self::$credentialsCache[$this->key()])) {
|
||||
$result = self::$credentialsCache[$this->key()];
|
||||
return $result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache credentials.
|
||||
*
|
||||
* @param RefreshResult $credential
|
||||
*/
|
||||
protected function cache(RefreshResult $credential)
|
||||
{
|
||||
self::$credentialsCache[$this->key()] = $credential;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
if ($this->cacheIsStale() || $this->shouldInitiateCachePrefetch()) {
|
||||
$result = $this->refreshCache();
|
||||
$this->cache($result);
|
||||
}
|
||||
|
||||
$result = $this->getCredentialsInCache();
|
||||
|
||||
return $result->credentials();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RefreshResult
|
||||
*/
|
||||
protected function refreshCache()
|
||||
{
|
||||
try {
|
||||
return $this->handleFetchedSuccess($this->refreshCredentials());
|
||||
} catch (\Exception $e) {
|
||||
return $this->handleFetchedFailure($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RefreshResult
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function handleFetchedFailure(\Exception $e)
|
||||
{
|
||||
$currentCachedValue = $this->getCredentialsInCache();
|
||||
if (is_null($currentCachedValue)) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if (time() < $currentCachedValue->staleTime()) {
|
||||
return $currentCachedValue;
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
/**
|
||||
* @return RefreshResult
|
||||
*/
|
||||
protected function handleFetchedSuccess(RefreshResult $value)
|
||||
{
|
||||
$now = time();
|
||||
// 过期时间大于15分钟,不用管
|
||||
if ($now < $value->staleTime()) {
|
||||
return $value;
|
||||
}
|
||||
// 不足或等于15分钟,但未过期,下次会再次刷新
|
||||
if ($now < $value->staleTime() + 15 * 60) {
|
||||
$value->staleTime = $now;
|
||||
return $value;
|
||||
}
|
||||
// 已过期,看缓存,缓存若大于15分钟,返回缓存,若小于15分钟,则稍后重试
|
||||
if (is_null($this->getCredentialsInCache())) {
|
||||
throw new \Exception("The fetched credentials have expired and no cache is available.");
|
||||
} else if ($now < $this->getCredentialsInCache()->staleTime()) {
|
||||
return $this->getCredentialsInCache();
|
||||
} else {
|
||||
// 返回成功,延长有效期 1 分钟
|
||||
$expectation = mt_rand(50, 70);
|
||||
$value->staleTime = time() + $expectation;
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function cacheIsStale()
|
||||
{
|
||||
return is_null($this->getCredentialsInCache()) || time() >= $this->getCredentialsInCache()->staleTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function shouldInitiateCachePrefetch()
|
||||
{
|
||||
return is_null($this->getCredentialsInCache()) || time() >= $this->getCredentialsInCache()->prefetchTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStaleTime($expiration)
|
||||
{
|
||||
return $expiration <= 0 ?
|
||||
time() + (60 * 60) :
|
||||
$expiration - (15 * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RefreshResult
|
||||
*/
|
||||
abstract function refreshCredentials();
|
||||
|
||||
/**
|
||||
* Get the toString of the credentials provider as the key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract function key();
|
||||
}
|
||||
78
Server/vendor/alibabacloud/credentials/src/Providers/StaticAKCredentialsProvider.php
vendored
Normal file
78
Server/vendor/alibabacloud/credentials/src/Providers/StaticAKCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class StaticAKCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class StaticAKCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* StaticAKCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
$this->filterAK($params);
|
||||
}
|
||||
|
||||
private function filterAK(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_ID')) {
|
||||
$this->accessKeyId = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_ID');
|
||||
}
|
||||
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_SECRET')) {
|
||||
$this->accessKeySecret = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
|
||||
}
|
||||
|
||||
if (isset($params['accessKeyId'])) {
|
||||
$this->accessKeyId = $params['accessKeyId'];
|
||||
}
|
||||
if (isset($params['accessKeySecret'])) {
|
||||
$this->accessKeySecret = $params['accessKeySecret'];
|
||||
}
|
||||
|
||||
Filter::accessKey($this->accessKeyId, $this->accessKeySecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
return new Credentials([
|
||||
'accessKeyId' => $this->accessKeyId,
|
||||
'accessKeySecret' => $this->accessKeySecret,
|
||||
'providerName' => $this->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return "static_ak";
|
||||
}
|
||||
}
|
||||
92
Server/vendor/alibabacloud/credentials/src/Providers/StaticSTSCredentialsProvider.php
vendored
Normal file
92
Server/vendor/alibabacloud/credentials/src/Providers/StaticSTSCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class StaticSTSCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class StaticSTSCredentialsProvider implements CredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $accessKeySecret;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $securityToken;
|
||||
|
||||
/**
|
||||
* StaticSTSCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct(array $params = [])
|
||||
{
|
||||
$this->filterSTS($params);
|
||||
}
|
||||
|
||||
private function filterSTS(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_ID')) {
|
||||
$this->accessKeyId = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_ID');
|
||||
}
|
||||
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_ACCESS_KEY_SECRET')) {
|
||||
$this->accessKeySecret = Helper::env('ALIBABA_CLOUD_ACCESS_KEY_SECRET');
|
||||
}
|
||||
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_SECURITY_TOKEN')) {
|
||||
$this->securityToken = Helper::env('ALIBABA_CLOUD_SECURITY_TOKEN');
|
||||
}
|
||||
|
||||
if (isset($params['accessKeyId'])) {
|
||||
$this->accessKeyId = $params['accessKeyId'];
|
||||
}
|
||||
if (isset($params['accessKeySecret'])) {
|
||||
$this->accessKeySecret = $params['accessKeySecret'];
|
||||
}
|
||||
if (isset($params['securityToken'])) {
|
||||
$this->securityToken = $params['securityToken'];
|
||||
}
|
||||
|
||||
Filter::accessKey($this->accessKeyId, $this->accessKeySecret);
|
||||
Filter::securityToken($this->securityToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credential.
|
||||
*
|
||||
* @return Credentials
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
return new Credentials([
|
||||
'accessKeyId' => $this->accessKeyId,
|
||||
'accessKeySecret' => $this->accessKeySecret,
|
||||
'securityToken' => $this->securityToken,
|
||||
'providerName' => $this->getProviderName(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return "static_sts";
|
||||
}
|
||||
}
|
||||
126
Server/vendor/alibabacloud/credentials/src/Providers/URLCredentialsProvider.php
vendored
Normal file
126
Server/vendor/alibabacloud/credentials/src/Providers/URLCredentialsProvider.php
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Providers;
|
||||
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use AlibabaCloud\Credentials\Request\Request;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use AlibabaCloud\Credentials\Credential\RefreshResult;
|
||||
|
||||
/**
|
||||
* @internal This class is intended for internal use within the package.
|
||||
* Class URLCredentialsProvider
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Providers
|
||||
*/
|
||||
class URLCredentialsProvider extends SessionCredentialsProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $credentialsURI;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $connectTimeout = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $readTimeout = 5;
|
||||
|
||||
/**
|
||||
* URLCredentialsProvider constructor.
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $params = [], array $options = [])
|
||||
{
|
||||
$this->filterOptions($options);
|
||||
$this->filterCredentialsURI($params);
|
||||
}
|
||||
|
||||
private function filterOptions(array $options)
|
||||
{
|
||||
if (isset($options['connectTimeout'])) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
}
|
||||
|
||||
if (isset($options['readTimeout'])) {
|
||||
$this->readTimeout = $options['readTimeout'];
|
||||
}
|
||||
|
||||
Filter::timeout($this->connectTimeout, $this->readTimeout);
|
||||
}
|
||||
|
||||
private function filterCredentialsURI(array $params)
|
||||
{
|
||||
if (Helper::envNotEmpty('ALIBABA_CLOUD_CREDENTIALS_URI')) {
|
||||
$this->credentialsURI = Helper::env('ALIBABA_CLOUD_CREDENTIALS_URI');
|
||||
}
|
||||
|
||||
if (isset($params['credentialsURI'])) {
|
||||
$this->credentialsURI = $params['credentialsURI'];
|
||||
}
|
||||
|
||||
Filter::credentialsURI($this->credentialsURI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credentials by request.
|
||||
*
|
||||
* @return RefreshResult
|
||||
* @throws InvalidArgumentException
|
||||
* @throws RuntimeException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function refreshCredentials()
|
||||
{
|
||||
$options = Request::commonOptions();
|
||||
$options['read_timeout'] = $this->readTimeout;
|
||||
$options['connect_timeout'] = $this->connectTimeout;
|
||||
|
||||
$result = Request::createClient()->request('GET', $this->credentialsURI, $options);
|
||||
|
||||
if ($result->getStatusCode() !== 200) {
|
||||
throw new RuntimeException('Error refreshing credentials from credentialsURI, statusCode: ' . $result->getStatusCode() . ', result: ' . (string) $result);
|
||||
}
|
||||
|
||||
$credentials = $result->toArray();
|
||||
|
||||
if (!isset($credentials['AccessKeyId']) || !isset($credentials['AccessKeySecret']) || !isset($credentials['SecurityToken']) || !isset($credentials['Expiration'])) {
|
||||
throw new RuntimeException('Error retrieving credentials from credentialsURI result:' . $result->toJson());
|
||||
}
|
||||
|
||||
return new RefreshResult(new Credentials([
|
||||
'accessKeyId' => $credentials['AccessKeyId'],
|
||||
'accessKeySecret' => $credentials['AccessKeySecret'],
|
||||
'securityToken' => $credentials['SecurityToken'],
|
||||
'expiration' => \strtotime($credentials['Expiration']),
|
||||
'providerName' => $this->getProviderName(),
|
||||
]), $this->getStaleTime(strtotime($credentials['Expiration'])));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return 'credential_uri#' . $this->credentialsURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProviderName()
|
||||
{
|
||||
return 'credential_uri';
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\RamRoleArnProvider;
|
||||
use AlibabaCloud\Credentials\Providers\RamRoleArnCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Use the AssumeRole of the RAM account to complete the authentication.
|
||||
*/
|
||||
class RamRoleArnCredential implements CredentialsInterface
|
||||
@@ -57,10 +60,10 @@ class RamRoleArnCredential implements CredentialsInterface
|
||||
|
||||
Filter::accessKey($credential['access_key_id'], $credential['access_key_secret']);
|
||||
|
||||
$this->config = $config;
|
||||
$this->accessKeyId = $credential['access_key_id'];
|
||||
$this->config = $config;
|
||||
$this->accessKeyId = $credential['access_key_id'];
|
||||
$this->accessKeySecret = $credential['access_key_secret'];
|
||||
$this->roleArn = $credential['role_arn'];
|
||||
$this->roleArn = $credential['role_arn'];
|
||||
$this->roleSessionName = $credential['role_session_name'];
|
||||
}
|
||||
|
||||
@@ -177,13 +180,20 @@ class RamRoleArnCredential implements CredentialsInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StsCredential
|
||||
* @return AlibabaCloud\Credentials\Providers\Credentials
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function getSessionCredential()
|
||||
{
|
||||
return (new RamRoleArnProvider($this))->get();
|
||||
$params = [
|
||||
'accessKeyId' => $this->accessKeyId,
|
||||
'accessKeySecret' => $this->accessKeyId,
|
||||
'roleArn' => $this->roleArn,
|
||||
'roleSessionName' => $this->roleSessionName,
|
||||
'policy' => $this->policy,
|
||||
];
|
||||
return (new RamRoleArnCredentialsProvider($params))->getCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,4 +225,18 @@ class RamRoleArnCredential implements CredentialsInterface
|
||||
{
|
||||
return $this->getSessionCredential()->getExpiration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
$credentials = $this->getSessionCredential();
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'type' => 'ram_role_arn',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\Provider;
|
||||
use AlibabaCloud\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
|
||||
/**
|
||||
* Retrieving assume role credentials.
|
||||
*/
|
||||
class AssumeRole extends Request
|
||||
{
|
||||
/**
|
||||
* AssumeRole constructor.
|
||||
*
|
||||
* @param RamRoleArnCredential $arnCredential
|
||||
*/
|
||||
public function __construct(RamRoleArnCredential $arnCredential)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->signature = new ShaHmac1Signature();
|
||||
$this->credential = $arnCredential;
|
||||
$this->uri = $this->uri->withHost('sts.aliyuncs.com');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['RoleArn'] = $arnCredential->getRoleArn();
|
||||
$this->options['query']['RoleSessionName'] = $arnCredential->getRoleSessionName();
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
$this->options['query']['AccessKeyId'] = $this->credential->getOriginalAccessKeyId();
|
||||
$this->options['query']['Version'] = '2015-04-01';
|
||||
$this->options['query']['Action'] = 'AssumeRole';
|
||||
$this->options['query']['RegionId'] = 'cn-hangzhou';
|
||||
if ($arnCredential->getPolicy()) {
|
||||
$this->options['query']['Policy'] = $arnCredential->getPolicy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\Provider;
|
||||
use AlibabaCloud\Credentials\RsaKeyPairCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac256WithRsaSignature;
|
||||
|
||||
/**
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*/
|
||||
class GenerateSessionAccessKey extends Request
|
||||
{
|
||||
/**
|
||||
* GenerateSessionAccessKey constructor.
|
||||
*
|
||||
* @param RsaKeyPairCredential $credential
|
||||
*/
|
||||
public function __construct(RsaKeyPairCredential $credential)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->signature = new ShaHmac256WithRsaSignature();
|
||||
$this->credential = $credential;
|
||||
$this->uri = $this->uri->withHost('sts.ap-northeast-1.aliyuncs.com');
|
||||
$this->options['verify'] = false;
|
||||
$this->options['query']['Version'] = '2015-04-01';
|
||||
$this->options['query']['Action'] = 'GenerateSessionAccessKey';
|
||||
$this->options['query']['RegionId'] = 'cn-hangzhou';
|
||||
$this->options['query']['AccessKeyId'] = $credential->getPublicKeyId();
|
||||
$this->options['query']['PublicKeyId'] = $credential->getPublicKeyId();
|
||||
$this->options['query']['DurationSeconds'] = Provider::DURATION_SECONDS;
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,16 @@
|
||||
namespace AlibabaCloud\Credentials\Request;
|
||||
|
||||
use AlibabaCloud\Credentials\Credentials;
|
||||
use AlibabaCloud\Credentials\EcsRamRoleCredential;
|
||||
use AlibabaCloud\Credentials\Helper;
|
||||
use AlibabaCloud\Credentials\RamRoleArnCredential;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac256WithRsaSignature;
|
||||
use Exception;
|
||||
use AlibabaCloud\Credentials\Utils\Helper;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use AlibabaCloud\Tea\Response;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* RESTful RPC Request.
|
||||
*/
|
||||
@@ -28,67 +25,33 @@ class Request
|
||||
const CONNECT_TIMEOUT = 5;
|
||||
|
||||
/**
|
||||
* Request Timeout
|
||||
* Request Read Timeout
|
||||
*/
|
||||
const TIMEOUT = 10;
|
||||
const READ_TIMEOUT = 5;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $config = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $options = [];
|
||||
|
||||
/**
|
||||
* @var Uri
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public $uri;
|
||||
|
||||
/**
|
||||
* @var EcsRamRoleCredential|RamRoleArnCredential
|
||||
*/
|
||||
protected $credential;
|
||||
|
||||
/**
|
||||
* @var ShaHmac256WithRsaSignature|ShaHmac1Signature
|
||||
*/
|
||||
protected $signature;
|
||||
|
||||
/**
|
||||
* Request constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
public static function commonOptions()
|
||||
{
|
||||
$this->uri = (new Uri())->withScheme('https');
|
||||
$this->options['http_errors'] = false;
|
||||
$this->options['connect_timeout'] = self::CONNECT_TIMEOUT;
|
||||
$this->options['timeout'] = self::TIMEOUT;
|
||||
$options = [];
|
||||
$options['http_errors'] = false;
|
||||
$options['connect_timeout'] = self::CONNECT_TIMEOUT;
|
||||
$options['read_timeout'] = self::READ_TIMEOUT;
|
||||
$options['headers']['User-Agent'] = Helper::getUserAgent();
|
||||
|
||||
// Turn on debug mode based on environment variable.
|
||||
if (strtolower(Helper::env('DEBUG')) === 'sdk') {
|
||||
$this->options['debug'] = true;
|
||||
$options['debug'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function request()
|
||||
{
|
||||
$this->options['query']['Format'] = 'JSON';
|
||||
$this->options['query']['SignatureMethod'] = $this->signature->getMethod();
|
||||
$this->options['query']['SignatureVersion'] = $this->signature->getVersion();
|
||||
$this->options['query']['SignatureNonce'] = self::uuid(json_encode($this->options['query']));
|
||||
$this->options['query']['Timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
|
||||
$this->options['query']['Signature'] = $this->signature->sign(
|
||||
self::signString('GET', $this->options['query']),
|
||||
$this->credential->getOriginalAccessKeySecret() . '&'
|
||||
);
|
||||
return self::createClient()->request('GET', (string)$this->uri, $this->options);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +81,53 @@ class Request
|
||||
return $method . '&%2F&' . self::percentEncode(substr($canonicalized, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $accessKeySecret
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function shaHmac1sign($string, $accessKeySecret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha1', $string, $accessKeySecret, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $accessKeySecret
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function shaHmac256sign($string, $accessKeySecret)
|
||||
{
|
||||
return base64_encode(hash_hmac('sha256', $string, $accessKeySecret, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @param string $privateKey
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function shaHmac256WithRsasign($string, $privateKey)
|
||||
{
|
||||
$binarySignature = '';
|
||||
try {
|
||||
openssl_sign(
|
||||
$string,
|
||||
$binarySignature,
|
||||
$privateKey,
|
||||
\OPENSSL_ALGO_SHA256
|
||||
);
|
||||
} catch (Exception $exception) {
|
||||
throw new InvalidArgumentException(
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
return base64_encode($binarySignature);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
@@ -140,6 +150,8 @@ class Request
|
||||
{
|
||||
if (Credentials::hasMock()) {
|
||||
$stack = HandlerStack::create(Credentials::getMock());
|
||||
$history = Credentials::getHandlerHistory();
|
||||
$stack->push($history);
|
||||
} else {
|
||||
$stack = HandlerStack::create();
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
|
||||
use AlibabaCloud\Credentials\Providers\RsaKeyPairProvider;
|
||||
use AlibabaCloud\Credentials\Providers\RsaKeyPairCredentialsProvider;
|
||||
use AlibabaCloud\Credentials\Credential\CredentialModel;
|
||||
use AlibabaCloud\Credentials\Signature\ShaHmac1Signature;
|
||||
use AlibabaCloud\Credentials\Utils\Filter;
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Use the RSA key pair to complete the authentication (supported only on Japanese site)
|
||||
*/
|
||||
class RsaKeyPairCredential implements CredentialsInterface
|
||||
@@ -19,6 +22,11 @@ class RsaKeyPairCredential implements CredentialsInterface
|
||||
*/
|
||||
private $publicKeyId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $privateKeyFile;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -42,7 +50,8 @@ class RsaKeyPairCredential implements CredentialsInterface
|
||||
Filter::privateKeyFile($private_key_file);
|
||||
|
||||
$this->publicKeyId = $public_key_id;
|
||||
$this->config = $config;
|
||||
$this->privateKeyFile = $private_key_file;
|
||||
$this->config = $config;
|
||||
try {
|
||||
$this->privateKey = file_get_contents($private_key_file);
|
||||
} catch (Exception $exception) {
|
||||
@@ -117,13 +126,17 @@ class RsaKeyPairCredential implements CredentialsInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StsCredential
|
||||
* @return AlibabaCloud\Credentials\Providers\Credentials
|
||||
* @throws Exception
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
protected function getSessionCredential()
|
||||
{
|
||||
return (new RsaKeyPairProvider($this))->get();
|
||||
$params = [
|
||||
'publicKeyId' => $this->publicKeyId,
|
||||
'privateKeyFile' => $this->privateKeyFile,
|
||||
];
|
||||
return (new RsaKeyPairCredentialsProvider($params))->getCredentials();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,4 +168,18 @@ class RsaKeyPairCredential implements CredentialsInterface
|
||||
{
|
||||
return $this->getSessionCredential()->getExpiration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
$credentials = $this->getSessionCredential();
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $credentials->getAccessKeyId(),
|
||||
'accessKeySecret' => $credentials->getAccessKeySecret(),
|
||||
'securityToken' => $credentials->getSecurityToken(),
|
||||
'type' => 'rsa_key_pair',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 STS Token to complete the authentication.
|
||||
*/
|
||||
class StsCredential implements CredentialsInterface
|
||||
@@ -42,10 +45,10 @@ class StsCredential implements CredentialsInterface
|
||||
{
|
||||
Filter::accessKey($access_key_id, $access_key_secret);
|
||||
Filter::expiration($expiration);
|
||||
$this->accessKeyId = $access_key_id;
|
||||
$this->accessKeyId = $access_key_id;
|
||||
$this->accessKeySecret = $access_key_secret;
|
||||
$this->expiration = $expiration;
|
||||
$this->securityToken = $security_token;
|
||||
$this->expiration = $expiration;
|
||||
$this->securityToken = $security_token;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,4 +98,18 @@ class StsCredential implements CredentialsInterface
|
||||
{
|
||||
return new ShaHmac1Signature();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCredential()
|
||||
{
|
||||
return new CredentialModel([
|
||||
'accessKeyId' => $this->accessKeyId,
|
||||
'accessKeySecret' => $this->accessKeySecret,
|
||||
'securityToken' => $this->securityToken,
|
||||
'type' => 'sts',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
233
Server/vendor/alibabacloud/credentials/src/Utils/Filter.php
vendored
Normal file
233
Server/vendor/alibabacloud/credentials/src/Utils/Filter.php
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials\Utils;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Class Filter
|
||||
*
|
||||
* @package AlibabaCloud\Credentials\Utils
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return string
|
||||
*/
|
||||
public static function credentialName($name)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
throw new InvalidArgumentException('Name must be a string');
|
||||
}
|
||||
|
||||
if ($name === '') {
|
||||
throw new InvalidArgumentException('Name cannot be empty');
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bearerToken
|
||||
*
|
||||
* @return mixed
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function bearerToken($bearerToken)
|
||||
{
|
||||
if (!is_string($bearerToken)) {
|
||||
throw new InvalidArgumentException('bearerToken must be a string');
|
||||
}
|
||||
|
||||
if ($bearerToken === '') {
|
||||
throw new InvalidArgumentException('bearerToken cannot be empty');
|
||||
}
|
||||
|
||||
return $bearerToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $publicKeyId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function publicKeyId($publicKeyId)
|
||||
{
|
||||
if (!is_string($publicKeyId)) {
|
||||
throw new InvalidArgumentException('publicKeyId must be a string');
|
||||
}
|
||||
|
||||
if ($publicKeyId === '') {
|
||||
throw new InvalidArgumentException('publicKeyId cannot be empty');
|
||||
}
|
||||
|
||||
return $publicKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $privateKeyFile
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function privateKeyFile($privateKeyFile)
|
||||
{
|
||||
if (!is_string($privateKeyFile)) {
|
||||
throw new InvalidArgumentException('privateKeyFile must be a string');
|
||||
}
|
||||
|
||||
if ($privateKeyFile === '') {
|
||||
throw new InvalidArgumentException('privateKeyFile cannot be empty');
|
||||
}
|
||||
|
||||
return $privateKeyFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $roleName
|
||||
*/
|
||||
public static function roleName($roleName)
|
||||
{
|
||||
if ($roleName === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($roleName)) {
|
||||
throw new InvalidArgumentException('roleName must be a string');
|
||||
}
|
||||
|
||||
if ($roleName === '') {
|
||||
throw new InvalidArgumentException('roleName cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean|null $disableIMDSv1
|
||||
*/
|
||||
public static function disableIMDSv1($disableIMDSv1)
|
||||
{
|
||||
if (!is_bool($disableIMDSv1)) {
|
||||
throw new InvalidArgumentException('disableIMDSv1 must be a boolean');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string|null $roleArn
|
||||
*/
|
||||
public static function roleArn($roleArn)
|
||||
{
|
||||
if (is_null($roleArn) || $roleArn === '') {
|
||||
throw new InvalidArgumentException('roleArn cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $roleArn
|
||||
*/
|
||||
public static function oidcProviderArn($oidcProviderArn)
|
||||
{
|
||||
if (is_null($oidcProviderArn) || $oidcProviderArn === '') {
|
||||
throw new InvalidArgumentException('oidcProviderArn cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $roleArn
|
||||
*/
|
||||
public static function oidcTokenFilePath($oidcTokenFilePath)
|
||||
{
|
||||
if (is_null($oidcTokenFilePath) || $oidcTokenFilePath === '') {
|
||||
throw new InvalidArgumentException('oidcTokenFilePath cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $accessKeyId
|
||||
* @param string $accessKeySecret
|
||||
*/
|
||||
public static function accessKey($accessKeyId, $accessKeySecret)
|
||||
{
|
||||
if (!is_string($accessKeyId)) {
|
||||
throw new InvalidArgumentException('accessKeyId must be a string');
|
||||
}
|
||||
|
||||
if ($accessKeyId === '') {
|
||||
throw new InvalidArgumentException('accessKeyId cannot be empty');
|
||||
}
|
||||
|
||||
if (!is_string($accessKeySecret)) {
|
||||
throw new InvalidArgumentException('accessKeySecret must be a string');
|
||||
}
|
||||
|
||||
if ($accessKeySecret === '') {
|
||||
throw new InvalidArgumentException('accessKeySecret cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $securityToken
|
||||
*/
|
||||
public static function securityToken($securityToken)
|
||||
{
|
||||
if (!is_string($securityToken)) {
|
||||
throw new InvalidArgumentException('securityToken must be a string');
|
||||
}
|
||||
|
||||
if ($securityToken === '') {
|
||||
throw new InvalidArgumentException('securityToken cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $expiration
|
||||
*/
|
||||
public static function expiration($expiration)
|
||||
{
|
||||
if (!is_int($expiration)) {
|
||||
throw new InvalidArgumentException('expiration must be a int');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $connectTimeout
|
||||
* @param int $readTimeout
|
||||
*/
|
||||
public static function timeout($connectTimeout, $readTimeout)
|
||||
{
|
||||
if (!is_int($connectTimeout)) {
|
||||
throw new InvalidArgumentException('connectTimeout must be a int');
|
||||
}
|
||||
|
||||
if (!is_int($readTimeout)) {
|
||||
throw new InvalidArgumentException('readTimeout must be a int');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $credentialsURI
|
||||
*/
|
||||
public static function credentialsURI($credentialsURI)
|
||||
{
|
||||
if (!is_string($credentialsURI)) {
|
||||
throw new InvalidArgumentException('credentialsURI must be a string');
|
||||
}
|
||||
|
||||
if ($credentialsURI === '') {
|
||||
throw new InvalidArgumentException('credentialsURI cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean|null $reuseLastProviderEnabled
|
||||
*/
|
||||
public static function reuseLastProviderEnabled($reuseLastProviderEnabled)
|
||||
{
|
||||
if (!is_bool($reuseLastProviderEnabled)) {
|
||||
throw new InvalidArgumentException('reuseLastProviderEnabled must be a boolean');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
namespace AlibabaCloud\Credentials\Utils;
|
||||
|
||||
use AlibabaCloud\Credentials\Credential;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* Class Helper
|
||||
*
|
||||
* @package AlibabaCloud\Credentials
|
||||
* @package AlibabaCloud\Credentials\Utils
|
||||
*/
|
||||
class Helper
|
||||
{
|
||||
@@ -51,6 +53,10 @@ class Helper
|
||||
if (!$open_basedir) {
|
||||
return true;
|
||||
}
|
||||
if (0 === strpos($filename, vfsStream::SCHEME)) {
|
||||
// 虚拟文件忽略
|
||||
return true;
|
||||
}
|
||||
|
||||
$dirs = explode(PATH_SEPARATOR, $open_basedir);
|
||||
|
||||
@@ -199,4 +205,47 @@ class Helper
|
||||
dump(...$parameters);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snake to camel case.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function snakeToCamelCase($str)
|
||||
{
|
||||
$components = explode('_', $str);
|
||||
$camelCaseStr = $components[0];
|
||||
for ($i = 1; $i < count($components); $i++) {
|
||||
$camelCaseStr .= ucfirst($components[$i]);
|
||||
}
|
||||
return $camelCaseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user agent.
|
||||
*
|
||||
* @param string $userAgent
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getUserAgent()
|
||||
{
|
||||
return sprintf('AlibabaCloud (%s; %s) PHP/%s Credentials/%s TeaDSL/1', PHP_OS, \PHP_SAPI, PHP_VERSION, Credential::VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arrays
|
||||
* @param string $key
|
||||
*
|
||||
* @return mix
|
||||
*/
|
||||
public static function unsetReturnNull(array $arrays, $key)
|
||||
{
|
||||
if(isset($arrays[$key])) {
|
||||
return $arrays[$key];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace AlibabaCloud\Credentials;
|
||||
namespace AlibabaCloud\Credentials\Utils;
|
||||
|
||||
use Exception;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Middleware;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Trait MockTrait
|
||||
*
|
||||
* @package AlibabaCloud\Credentials
|
||||
* @package AlibabaCloud\Credentials\Utils
|
||||
*/
|
||||
trait MockTrait
|
||||
{
|
||||
@@ -21,6 +22,11 @@ trait MockTrait
|
||||
*/
|
||||
private static $mockQueue = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $history = [];
|
||||
|
||||
/**
|
||||
* @var MockHandler
|
||||
*/
|
||||
@@ -46,6 +52,14 @@ trait MockTrait
|
||||
self::$mock = new MockHandler(self::$mockQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MockHandler
|
||||
*/
|
||||
public static function getHandlerHistory()
|
||||
{
|
||||
return Middleware::history(self::$history);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param RequestInterface $request
|
||||
@@ -95,4 +109,12 @@ trait MockTrait
|
||||
{
|
||||
return self::$mock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getHistroy()
|
||||
{
|
||||
return self::$history;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user