Skip to content

Commit 8e0c276

Browse files
committed
update .gitignore
1 parent ec1e4d1 commit 8e0c276

16 files changed

+303
-47
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ vendor
55
# test.php
66
# test*.php
77
tests/config/test.yaml
8-
tmp
8+
tmp
9+
tests/reports

phpunit.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
<phpunit bootstrap="tests/config/TestConfig.php">
2+
<filter>
3+
<whitelist processUncoveredFilesFromWhitelist="true">
4+
<!--可以定义多个 对./app下的业务代码做覆盖率统计-->
5+
<directory suffix=".php">src</directory>
6+
</whitelist>
7+
</filter>
8+
<logging>
9+
<!--覆盖率报告生成类型和输出目录 lowUpperBound低覆盖率阈值 highLowerBound高覆盖率阈值-->
10+
<log type="coverage-html" target="tests/reports" lowUpperBound="35" highLowerBound="70"/>
11+
</logging>
212
</phpunit>

src/BaseClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ public function httpPatch($path, $data = [])
169169
return $this->arrayToObject($result);
170170
}
171171

172+
public function httpPut($path, $data = [])
173+
{
174+
$result = $this->send($this->host . $path, $data, 'PUT');
175+
return $this->arrayToObject($result);
176+
}
177+
172178
/**
173179
* @param $path string
174180
* @return object
@@ -285,6 +291,10 @@ private function send($url, $data = '', $method = 'POST', $time = 30000)
285291
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? json_encode($data) : $data);
286292
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
287293
break;
294+
case "PUT":
295+
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? json_encode($data) : $data);
296+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
297+
break;
288298
case "DELETE":
289299
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? json_encode($data) : $data);
290300
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");

src/Mgmt/AclManagementClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Authing\Mgmt;
3+
namespace Authing\Mgmt\Acl;
44

55
use Authing\Types\AllowParam;
66
use Authing\Types\AuthorizedResourcesParam;

src/Mgmt/GroupsManagementClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33

4-
namespace Authing\Mgmt;
4+
namespace Authing\Mgmt\Groups;
55

66

77
use Authing\Types\AddUserToGroupParam;

src/Mgmt/ManagementClient.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,27 @@ public function orgs() {
156156
return new OrgManagementClient($this);
157157
}
158158

159+
/**
160+
* @return NamespaceManagementClient
161+
*/
162+
public function namespaces() {
163+
return new NamespaceManagementClient($this);
164+
}
165+
166+
/**
167+
* @return UserActionManagementClient
168+
*/
169+
public function userActions() {
170+
return new UserActionManagementClient($this);
171+
}
172+
173+
/**
174+
* @return StatisticsManagementClient
175+
*/
176+
public function statistics() {
177+
return new StatisticsManagementClient($this);
178+
}
179+
159180

160181
public function sendEmail(string $email, string $scene)
161182
{
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Authing\Mgmt;
4+
use Authing\Mgmt\ManagementClient;
5+
6+
class NamespaceManagementClient {
7+
private array $options;
8+
9+
/**
10+
* @var ManagementClient
11+
*/
12+
private ManagementClient $client;
13+
14+
public function __construct(ManagementClient $client)
15+
{
16+
$this->client = $client;
17+
$this->options = $client->options;
18+
}
19+
20+
public function list(array $params = [])
21+
{
22+
$userPoolId = $this->options->userPoolId;
23+
$page = $params['page'] ?? 1;
24+
$limit = $params['limit'] ?? 10;
25+
$data = $this->client->httpGet("/api/v2/resource-namespace/$userPoolId/?page=$page&limit=$limit");
26+
return $data;
27+
}
28+
29+
30+
public function create(string $code, string $name, string $description = "")
31+
{
32+
$res = $this->client->httpPost("/api/v2/resource-namespace/{$this->options->userPoolId}", (object)[
33+
'name' => $name,
34+
'code' => $code,
35+
'description' => $description
36+
]);
37+
return $res;
38+
}
39+
40+
public function delete(string $code)
41+
{
42+
$this->client->httpDelete("/api/v2/resource-namespace/{$this->options->userPoolId}/code/$code");
43+
return true;
44+
}
45+
46+
public function update(string $code, array $updates)
47+
{
48+
$data = $this->client->httpPut("/api/v2/resource-namespace/{$this->options->userPoolId}/code/{$code}", (object)$updates);
49+
return $data;
50+
}
51+
}
52+

src/Mgmt/OrgManagementClient.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,4 @@ public function listAuthorizedResourcesByNodeCode(string $orgId, string $code, s
284284
$_->totalCount = $totalCount;
285285
return $_;
286286
}
287-
288-
289287
}

src/Mgmt/RolesManagementClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Authing\Mgmt;
3+
namespace Authing\Mgmt\Roles;
44

55
use Authing\Types\AddPolicyAssignmentsParam;
66
use Authing\Types\AssignRoleParam;

src/Mgmt/StatisticsManagementClient.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,27 @@ public function listUserActions(array $options = [])
3636
$requestParam->operator_arn = $options->userIds;
3737
}
3838

39-
$requestParam->page = $options['page'] ?? 1;
40-
$requestParam->limit = $options['limit'] ?? 10;
39+
$requestParam->page = $options->page ?? 1;
40+
$requestParam->limit = $options->limit ?? 10;
4141
$params = http_build_query($requestParam);
4242
$data = $this->client->httpGet("/api/v2/analysis/user-action?$params");
43-
['list' => $list, 'totalCount' => $totalCount] = $data;
43+
['list' => $list, 'totalCount' => $totalCount] = (array)$data->data;
4444
array_map(function ($item) {
4545
return (object) [
4646
'userpoolId' => $item->userpool_id,
47-
'userId' => $item->user && $item->user->id,
48-
'username' => $item->user && $item->user->displayName,
49-
'cityName' => $item->geoip && $item->geoip->city_name,
50-
'regionName' => $item->geoip && $item->geoip->region_name,
51-
'clientIp' => $item->geoip && $item->geoip->ip,
47+
'userId' => ($item->user ?? null) && $item->user->id,
48+
'username' => ($item->user ?? null) && $item->user->displayName,
49+
'cityName' => ($item->geoip ?? null) && $item->geoip->city_name,
50+
'regionName' => ($item->geoip ?? null) && $item->geoip->region_name,
51+
'clientIp' => ($item->geoip ?? null) && $item->geoip->ip,
5252
'operationDesc' => $item->operation_desc,
5353
'operationName' => $item->operation_name,
5454
'timestamp' => $item->timestamp,
5555
'appId' => $item->app_id,
56-
'appName' => $item->appName,
56+
'appName' => $item->appName ?? null,
5757
];
5858
}, $list);
59-
return [
59+
return (object)[
6060
'list' => $list,
6161
'totalCount' => $totalCount,
6262
];
@@ -76,28 +76,29 @@ public function listAuditLogs(array $options = [])
7676
$requestParam->operator_arn = $options->operatorArns;
7777
}
7878

79-
$requestParam->page = $options['page'] ?? 1;
80-
$requestParam->limit = $options['limit'] ?? 10;
79+
$requestParam->page = $options->page ?? 1;
80+
$requestParam->limit = $options->limit ?? 10;
8181
$params = http_build_query($requestParam);
8282
$data = $this->client->httpGet("/api/v2/analysis/user-action?$params");
83-
['list' => $list, 'totalCount' => $totalCount] = $data;
83+
84+
['list' => $list, 'totalCount' => $totalCount] = (array)$data->data;
8485
array_map(function ($item) {
8586
return (object) [
8687
'userpoolId' => $item->userpool_id,
87-
'operatorType' => $item->operator_type,
88-
'userId' => $item->user && $item->user->id,
89-
'username' => $item->user && $item->user->displayName,
90-
'cityName' => $item->geoip && $item->geoip->city_name,
91-
'regionName' => $item->geoip && $item->geoip->region_name,
92-
'clientIp' => $item->geoip && $item->geoip->ip,
88+
'operatorType' => $item->operator_type ?? null,
89+
'userId' => ($item->user ?? null) && $item->user->id,
90+
'username' => ($item->user ?? null) && $item->user->displayName,
91+
'cityName' => ($item->geoip ?? null) && $item->geoip->city_name,
92+
'regionName' => ($item->geoip ?? null) && $item->geoip->region_name,
93+
'clientIp' => ($item->geoip ?? null) && $item->geoip->ip,
9394
'operationDesc' => $item->operation_desc,
9495
'operationName' => $item->operation_name,
9596
'timestamp' => $item->timestamp,
9697
'appId' => $item->app_id,
97-
'appName' => $item->appName,
98+
'appName' => $item->appName ?? null,
9899
];
99100
}, $list);
100-
return [
101+
return (object)[
101102
'list' => $list,
102103
'totalCount' => $totalCount,
103104
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Authing\Mgmt;
4+
use Authing\Mgmt\ManagementClient;
5+
6+
class UserActionManagementClient {
7+
private array $options;
8+
9+
/**
10+
* @var ManagementClient
11+
*/
12+
private ManagementClient $client;
13+
14+
public function __construct(ManagementClient $client)
15+
{
16+
$this->client = $client;
17+
$this->options = $client->options;
18+
}
19+
20+
public function list(array $params = [
21+
'page' => 1,
22+
'limit' => 10
23+
])
24+
{
25+
$userPoolId = $this->options->userPoolId;
26+
$page = $params['page'] ?? 1;
27+
$limit = $params['limit'] ?? 10;
28+
$att = [
29+
'page' => $page,
30+
'limit' => $limit,
31+
'clientip' => $clientIp,
32+
'operation_name' => $operationName,
33+
'operator_arn' => $operatoArn
34+
];
35+
$qstr = http_build_query($att);
36+
$data = $this->client->httpGet("/api/v2/analysis/user-action?$qstr");
37+
return $data;
38+
}
39+
}
40+

tests/Mgmt/OrgManagementClientTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,40 @@ public function testGetNodeById()
3939
parent::assertNotEmpty($node);
4040
parent::assertEquals($nodeId, $node->id);
4141
}
42+
43+
public function testExportByOrgId()
44+
{
45+
$orgId = $this->_testConfig->orgId;
46+
$data = $this->orgManagement->exportByOrgId($orgId);
47+
parent::assertNotEmpty($data);
48+
}
49+
50+
public function testExportAll()
51+
{
52+
$orgData = $this->orgManagement->exportAll();
53+
parent::assertNotEmpty($orgData);
54+
}
55+
56+
public function testListAuthorizedResourcesByNodeId()
57+
{
58+
$nodeId = $this->_testConfig->nodeId;
59+
$data = $this->orgManagement->listAuthorizedResourcesByNodeId($nodeId, 'default');
60+
parent::assertNotEmpty($data);
61+
}
62+
63+
public function testListAuthorizedResourcesByNodeCode()
64+
{
65+
$orgId = $this->_testConfig->orgId;
66+
$nodeCode = $this->_testConfig->nodeId;
67+
$data = $this->orgManagement->listAuthorizedResourcesByNodeCode($orgId, $nodeCode, 'default');
68+
parent::assertNotEmpty($data);
69+
}
70+
71+
public function testSetMainDepartment()
72+
{
73+
$userId = $this->_testConfig->userId;
74+
$departmentId = $this->_testConfig->nodeId;
75+
$data = $this->orgManagement->setMainDepartment($userId, $departmentId);
76+
parent::assertNotEmpty($data);
77+
}
4278
}

0 commit comments

Comments
 (0)