Skip to content

Commit

Permalink
release 3.0.2-beta source code for php
Browse files Browse the repository at this point in the history
  • Loading branch information
Huaweicloud-SDK committed Dec 7, 2020
1 parent 718859a commit 49040a0
Show file tree
Hide file tree
Showing 71 changed files with 9,851 additions and 636 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# __3.0.1-beta__ __20200-10-19__
# 3.0.2-beta 2020-12-04

## HuaweiCloud SDK Core

- ### Features

- None

- ### Bug Fix

- Fix the problem that the Credentials type is incorrect because the HUAWEICLOUD_SDK_TYPE variable is not set when credentials are obtained from environment variables.

- ### Change

- A listener is added to obtain the original encrypted HTTP request and return information.

# __3.0.1-beta__ __2020-10-19__
## First Release
- ### Supported Services
- Identity and Access Management(IAM)
16 changes: 16 additions & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 3.0.2-beta 2020-12-04

## HuaweiCloud SDK Core

- ### 新增特性

-

- ### 解决问题

- 解决从环境变量获取Credentials 时 HUAWEICLOUD_SDK_TYPE 变量没设置导致的 Credentials 类型错误问题。

- ### 特性变更

- 增加侦听器功能来获取原始的为加密的Http请求和返回信息。

# 3.0.1-beta 2020-10-19
## 首次发布
- ### 已支持服务
Expand Down
3 changes: 2 additions & 1 deletion Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"api",
"core"
],
"version": "3.0.1-beta",
"version": "3.0.2-beta",
"type": "library",
"license": "Apache-2.0",
"authors": [
Expand All @@ -18,6 +18,7 @@
"homepage": "https://sdkcenter.developer.huaweicloud.com/?language=PHP"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.6.0",
"guzzlehttp/guzzle": "6.3.0",
Expand Down
72 changes: 50 additions & 22 deletions Core/src/Auth/BasicCredentials.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
<?php
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache LICENSE, Version 2.0 (the
* "LICENSE"); you may not use this file except in compliance
* with the LICENSE. You may obtain a copy of the LICENSE at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the LICENSE is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the LICENSE for the
* specific language governing permissions and limitations
* under the LICENSE.
*/

namespace HuaweiCloud\SDK\Core\Auth;

use HuaweiCloud\SDK\Core\SdkRequest;

class BasicCredentials extends Credentials
{
private $ak;
private $sk;
private $securityToken;
private $projectId;

/**
* BasicCredentials constructor.
*
* @param $ak
* @param $sk
* @param $securityToken
Expand All @@ -22,48 +39,57 @@ public function __construct($ak = null,
$projectId = null,
$securityToken = null
) {
$this->ak = $ak;
$this->sk = $sk;
$this->projectId = $projectId;
$this->securityToken = $securityToken;
$this->ak = isset($ak) ? $ak : null;
$this->sk = isset($sk) ? $sk : null;
$this->projectId = isset($projectId) ? $projectId : null;
$this->securityToken = isset($securityToken) ? $securityToken : null;
}

public function withAk($ak)
{
$this->setSk($ak);
$this->setAk($ak);

return $this;
}

public function withSk($sk)
{
$this->setSk($sk);

return $this;
}

public function withProjectId($projectId)
{
$this->setSk($projectId);
$this->setProjectId($projectId);

return $this;
}

/**
* @param $securityToken
*
* @return BasicCredentials
*/
public function withSecurityToken($securityToken)
{
$this->setSk($securityToken);
$this->setSecurityToken($securityToken);

return $this;
}

protected static $setters = [
'ak' => 'setAk',
'sk' => 'setSk',
'securityToken' => 'setSecurityToken',
'projectId' => 'setProjectId'
'projectId' => 'setProjectId',
];

protected static $getters = [
'ak' => 'getAk',
'sk' => 'getSk',
'securityToken' => 'getSecurityToken',
'projectId' => 'getProjectId'
'projectId' => 'getProjectId',
];

public static function setters()
Expand Down Expand Up @@ -145,10 +171,11 @@ public function setProjectId($projectId)
*/
public function getUpdatePathParams()
{
$pathParams = Array();
if ($this->projectId){
$pathParams = [];
if ($this->projectId) {
$pathParams['project_id'] = $this->projectId;
}

return $pathParams;
}

Expand All @@ -157,19 +184,20 @@ public function processAuthRequest(SdkRequest $request)
return $this->signRequest($request);
}

public function signRequest(SdkRequest $request)
private function signRequest(SdkRequest $request)
{
$request->headerParams["X-Project-Id"] = $this->projectId;
if ($this->securityToken != null) {
$request->headerParams["X-Security-Token"] = $this->securityToken;
$request->headerParams['X-Project-Id'] = $this->projectId;
if (null != $this->securityToken) {
$request->headerParams['X-Security-Token'] = $this->securityToken;
}
if (isset($request->headerParams['Content-Type']) and
strpos($request->headerParams['Content-Type'],
"application/json")===0) {
$request->headerParams["X-Sdk-Content-Sha256"] = "UNSIGNED-PAYLOAD";
0 === strpos($request->headerParams['Content-Type'],
'application/json')) {
$request->headerParams['X-Sdk-Content-Sha256'] = 'UNSIGNED-PAYLOAD';
}

$signer = new Signer($this);

return $signer->sign($request);
}
}
}
60 changes: 41 additions & 19 deletions Core/src/Auth/Credentials.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
<?php
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache LICENSE, Version 2.0 (the
* "LICENSE"); you may not use this file except in compliance
* with the LICENSE. You may obtain a copy of the LICENSE at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the LICENSE is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the LICENSE for the
* specific language governing permissions and limitations
* under the LICENSE.
*/

namespace HuaweiCloud\SDK\Core\Auth;

use HuaweiCloud\SDK\Core\SdkRequest;
use HuaweiCloud\SDK\Core\Exceptions\SdkException;
use HuaweiCloud\SDK\Core\SdkRequest;

class Credentials implements ICredentials
{
public function getUpdatePathParams()
{
}
protected $ak;
protected $sk;
protected $securityToken;

public function processAuthRequest(SdkRequest $request)
{
}

private static function getCredentialsClass($iamClient, $credentialType)
private static function getCredentialsClass($clientType, $credentialType)
{
$credentialPath = "HuaweiCloud\SDK\Core\Auth\\" . $credentialType;
if (class_exists($credentialPath)) {
return new $credentialPath;
return new $credentialPath();
} else {
try {
$class = new \ReflectionClass($iamClient);
$class = new \ReflectionClass($clientType);
} catch (ReflectionException $e) {
throw new SdkException($e->getMessage());
}
$credentialPath = $class->getNamespaceName() . '\\' .
$credentialPath = $class->getNamespaceName().'\\'.
$credentialType;
if (class_exists($credentialPath)) {
return new $credentialPath;
return new $credentialPath();
} else {
throw new SdkException('Class ' . $credentialPath . " not find");
throw new SdkException('Class '.$credentialPath.' not find');
}
}
}
Expand All @@ -48,9 +62,10 @@ private static function initializeCredentials($credentials)
if (!isset($propertySetter)) {
continue;
}
$credentials->$propertySetter(getenv( 'HUAWEICLOUD_SDK_' .
$credentials->$propertySetter(getenv('HUAWEICLOUD_SDK_'.
strtoupper(Credentials::camelToUnderscore($key))));
}

return $credentials;
}

Expand All @@ -63,23 +78,30 @@ public static function getCredentialFromEnvironment($clientType,
$defaultCredentials)
{
$credentialsTypeDef = getenv('HUAWEICLOUD_SDK_TYPE');
if (!isset($credentialsTypeDef)) {
if (! $credentialsTypeDef) {
$credentialsTypeDef = $defaultCredentials;
}
$credentialsType = Credentials::getCredentialsClass($clientType,
$credentialsTypeDef);
$credentials = Credentials::initializeCredentials($credentialsType);
$credentials = Credentials::loadOptionalParams($credentials);

return $credentials;
}

public static function setters()
{
// TODO: Implement setters() method.
}

public static function getters()
{
// TODO: Implement getters() method.
}
}

public function getUpdatePathParams()
{
}

public function processAuthRequest(SdkRequest $request)
{
}
}
Loading

0 comments on commit 49040a0

Please sign in to comment.