Skip to content

Commit

Permalink
feat: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jendahieu942 committed May 18, 2023
2 parents 7a79e36 + 566b67e commit 16611d2
Show file tree
Hide file tree
Showing 122 changed files with 4,025 additions and 57 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
file/
private/
tests/security_file.json
/vendor/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### 2023-05-17
- Done kms client php.

### 2023-05-18
- Change encode param url
864 changes: 807 additions & 57 deletions README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "vcc/kms-client",
"description": "KMS is a key management system for data encryption, decryption, signing and verification",
"type": "library",
"license": "proprietary",
"autoload": {
"psr-4": {
"": "src/"
}
},
"authors": [
{
"name": "cuongpm",
"email": "cuongphammanh@tech.admicro.vn"
}
],
"minimum-stability": "dev",
"require": {}
}
34 changes: 34 additions & 0 deletions src/vcc_kms_client/ChangeStateKMSKeyRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once 'HandlerResponseHttp.php';
require_once 'constants/Constants.php';
class ChangeStateKMSKeyRepository extends HandlerResponseHttp
{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}


public function change_state_kms_key($change_state_dto)
{
$result = $this->http_caller->post(
Constants::CHANGE_STATE_KEY_API,
json_encode($change_state_dto),
['Content-type: application/json'],
null,
10
);
$response_body = json_decode($result);
return $this->handler_response($response_body);
}

public function handler_response_success($result)
{
return empty($result->data) ? null : $result->data[0];
}
}
34 changes: 34 additions & 0 deletions src/vcc_kms_client/CreateKMSKeyRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
require_once 'HandlerResponseHttp.php';
require_once 'constants/Constants.php';
class CreateKMSKeyRepository extends HandlerResponseHttp
{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}


public function create_kms_key($kms_key_dto)
{
$result = $this->http_caller->post(
Constants::CREATE_KEY_API,
json_encode($kms_key_dto),
['Content-type: application/json'],
null,
10
);
$response_body = json_decode($result);
return $this->handler_response($response_body);
}

public function handler_response_success($result)
{
return empty($result->data) ? null : $result->data[0];
}
}
27 changes: 27 additions & 0 deletions src/vcc_kms_client/CreateKMSKeyService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once 'dtos/KMSKeyDto.php';
require_once 'models/KeyState.php';
require_once 'CreateKMSKeyRepository.php';
require_once 'models/CreateKMSKeyResult.php';
class CreateKMSKeyService
{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}

public function create_kms_key($request)
{
$kms_key_dto = new KMSKeyDto(null, $request->description, $request->alias, KeyState::ENABLED, $request->algorithm);
$create_kms_key_repository = new CreateKMSKeyRepository($this->http_caller);
$kms_key_dto = $create_kms_key_repository->create_kms_key($kms_key_dto);
return new CreateKMSKeyResult($kms_key_dto->id, $kms_key_dto->alias, $kms_key_dto->algorithm, $kms_key_dto->state, $kms_key_dto->description);
}


}
60 changes: 60 additions & 0 deletions src/vcc_kms_client/DecryptRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
require_once 'HandlerResponseHttp.php';
require_once 'constants/Constants.php';
class DecryptRepository extends HandlerResponseHttp{

private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}


public function decrypt($decrypt_dto)
{
$result = $this->http_caller->post(
Constants::DECRYPT_API,
json_encode($decrypt_dto),
['Content-type: application/json'],
null,
10
);
$response_body = json_decode($result);
return $this->handler_response($response_body);
}

public function decrypt_with_data_key($decrypt_dto)
{
$result = $this->http_caller->post(
Constants::DECRYPT_WITH_DATA_KEY_API,
json_encode($decrypt_dto),
['Content-type: application/json'],
null,
10
);
$response_body = json_decode($result);
return $this->handler_response($response_body);
}

public function decrypt_with_data_key_pair($decrypt_dto)
{
$result = $this->http_caller->post(
Constants::DECRYPT_WITH_DATA_KEY_PAIR_API,
json_encode($decrypt_dto),
['Content-type: application/json'],
null,
10
);
$response_body = json_decode($result);
return $this->handler_response($response_body);
}

public function handler_response_success($result)
{
return empty($result->data) ? null : $result->data[0];
}
}
45 changes: 45 additions & 0 deletions src/vcc_kms_client/DecryptService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
require_once 'dtos/DecryptDto.php';
require_once 'models/ContentType.php';
require_once 'models/Action.php';
require_once 'DecryptRepository.php';
require_once 'models/DecryptResult.php';
class DecryptService{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}

public function decrypt($request){
$decrypt_dto = new DecryptDto(
$request->key_id,
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null,
Action::DECRYPT,
$request->content_type
);

$decrypt_repository = new DecryptRepository($this->http_caller);
$decrypt_dto = $decrypt_repository->decrypt($decrypt_dto);

$output = null;
if($request->content_type == ContentType::SINGLE_STRING){
$output = $decrypt_dto->text;
}
if($request->content_type == ContentType::LIST_STRING){
$output = $decrypt_dto->texts;
}
if($request->content_type == ContentType::LIST_JSON_OBJECT){
$output = $decrypt_dto->jsons;
}

return new DecryptResult($decrypt_dto->keyId, $output);
}

}
45 changes: 45 additions & 0 deletions src/vcc_kms_client/DecryptWithDataKeyPairService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
require_once 'dtos/DecryptDto.php';
require_once 'models/ContentType.php';
require_once 'models/Action.php';
require_once 'DecryptRepository.php';
require_once 'models/DecryptWithDataKeyPairResult.php';
class DecryptWithDataKeyPairService{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}

public function decrypt_with_data_key_pair($request){
$decrypt_dto = new DecryptDto(
$request->key_id,
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null,
Action::DECRYPT_WITH_DATA_KEY_PAIR,
$request->content_type
);

$decrypt_repository = new DecryptRepository($this->http_caller);
$decrypt_dto = $decrypt_repository->decrypt_with_data_key_pair($decrypt_dto);

$output = null;
if($request->content_type == ContentType::SINGLE_STRING){
$output = $decrypt_dto->text;
}
if($request->content_type == ContentType::LIST_STRING){
$output = $decrypt_dto->texts;
}
if($request->content_type == ContentType::LIST_JSON_OBJECT){
$output = $decrypt_dto->jsons;
}

return new DecryptWithDataKeyPairResult($decrypt_dto->keyId, $output);
}

}
45 changes: 45 additions & 0 deletions src/vcc_kms_client/DecryptWithDataKeyService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
require_once 'dtos/DecryptDto.php';
require_once 'models/ContentType.php';
require_once 'models/Action.php';
require_once 'DecryptRepository.php';
require_once 'models/DecryptWithDataKeyResult.php';
class DecryptWithDataKeyService{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}

public function decrypt_with_data_key($request){
$decrypt_dto = new DecryptDto(
$request->key_id,
$request->content_type == ContentType::SINGLE_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_STRING ? $request->input : null,
$request->content_type == ContentType::LIST_JSON_OBJECT ? $request->input : null,
Action::DECRYPT_WITH_DATA_KEY,
$request->content_type
);

$decrypt_repository = new DecryptRepository($this->http_caller);
$decrypt_dto = $decrypt_repository->decrypt_with_data_key($decrypt_dto);

$output = null;
if($request->content_type == ContentType::SINGLE_STRING){
$output = $decrypt_dto->text;
}
if($request->content_type == ContentType::LIST_STRING){
$output = $decrypt_dto->texts;
}
if($request->content_type == ContentType::LIST_JSON_OBJECT){
$output = $decrypt_dto->jsons;
}

return new DecryptWithDataKeyResult($decrypt_dto->keyId, $output);
}

}
23 changes: 23 additions & 0 deletions src/vcc_kms_client/DeleteAliasKeyService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once 'dtos/AliasKeyDto.php';
require_once 'ManageAliasKeyRepository.php';
require_once 'models/DeleteAliasKeyResult.php';
require_once 'models/Action.php';
class DeleteAliasKeyService{
private $http_caller;

/**
* @param $http_caller
*/
public function __construct($http_caller)
{
$this->http_caller = $http_caller;
}

public function delete_alias_key($request){
$alias_key_dto = new AliasKeyDto($request->key_id, null, Action::DELETE_ALIAS);
$manage_alias_key_repository = new ManageAliasKeyRepository($this->http_caller);
$alias_key_dto = $manage_alias_key_repository->delete_alias($alias_key_dto);
return new DeleteAliasKeyResult($alias_key_dto->keyId);
}
}
Loading

0 comments on commit 16611d2

Please sign in to comment.