Skip to content

Commit 4519c9b

Browse files
authored
Merge pull request #451 from auth0/log-streams
Add Support for Log Streams Management APIs
2 parents 12a8d25 + 041f59d commit 4519c9b

File tree

3 files changed

+412
-0
lines changed

3 files changed

+412
-0
lines changed

src/API/Management.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Auth0\SDK\API\Management\Guardian;
1717
use Auth0\SDK\API\Management\Jobs;
1818
use Auth0\SDK\API\Management\Logs;
19+
use Auth0\SDK\API\Management\LogStreams;
1920
use Auth0\SDK\API\Management\ResourceServers;
2021
use Auth0\SDK\API\Management\Roles;
2122
use Auth0\SDK\API\Management\Rules;
@@ -118,6 +119,13 @@ class Management
118119
*/
119120
private $logs;
120121

122+
/**
123+
* Instance of Auth0\SDK\API\Management\LogStreams
124+
*
125+
* @var LogStreams
126+
*/
127+
private $logStreams;
128+
121129
/**
122130
* Instance of Auth0\SDK\API\Management\Roles
123131
*
@@ -359,6 +367,20 @@ public function logs() : Logs
359367
return $this->logs;
360368
}
361369

370+
/**
371+
* Return an instance of the LogStreams class.
372+
*
373+
* @return LogStreams
374+
*/
375+
public function logStreams() : LogStreams
376+
{
377+
if (! $this->logStreams instanceof LogStreams) {
378+
$this->logStreams = new LogStreams($this->apiClient);
379+
}
380+
381+
return $this->logStreams;
382+
}
383+
362384
/**
363385
* Return an instance of the Roles class.
364386
*

src/API/Management/LogStreams.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
namespace Auth0\SDK\API\Management;
4+
5+
use Auth0\SDK\Exception\EmptyOrInvalidParameterException;
6+
7+
/**
8+
* Class LogStreams.
9+
* Access to the v2 Management API Log Streams endpoint.
10+
*
11+
* @package Auth0\SDK\API\Management
12+
*/
13+
class LogStreams extends GenericResource {
14+
15+
private const LOG_STREAMS_PATH = 'log-streams';
16+
17+
/**
18+
* Get all Log Streams.
19+
* Required scope: "read:log_streams"
20+
*
21+
* @return mixed
22+
*
23+
* @throws \Exception Thrown by Guzzle for API errors.
24+
*
25+
* @link https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams
26+
*/
27+
public function getAll()
28+
{
29+
return $this->apiClient->method('get')
30+
->addPath(self::LOG_STREAMS_PATH)
31+
->call();
32+
}
33+
34+
/**
35+
* Get a single Log Stream.
36+
* Required scope: "read:log_streams"
37+
*
38+
* @param string $log_stream_id Log Stream ID to get.
39+
*
40+
* @return mixed
41+
*
42+
* @throws \Exception Thrown by Guzzle for API errors.
43+
*
44+
* @link https://auth0.com/docs/api/management/v2#!/Log_Streams/get_log_streams_by_id
45+
*/
46+
public function get($log_stream_id)
47+
{
48+
$this->checkEmptyOrInvalidString($log_stream_id, 'log_stream_id');
49+
50+
return $this->apiClient->method('get')
51+
->addPath(self::LOG_STREAMS_PATH, $log_stream_id)
52+
->call();
53+
}
54+
55+
/**
56+
* Create a new Log Stream.
57+
* Required scope: "create:log_streams"
58+
*
59+
* @param array $data Log Stream data to create:
60+
* - "name" if not specified, a name of the Log Stream will be assigned by the Log Stream endpoint.
61+
* - "type" field is required.
62+
* - "sink" field is required. It's value and requirements depends upon the type of Log Stream to create; see the linked documentation below.
63+
*
64+
* @return mixed
65+
*
66+
* @throws EmptyOrInvalidParameterException Thrown if any required parameters are empty or invalid.
67+
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
68+
*
69+
* @link https://auth0.com/docs/api/management/v2#!/Log_Streams/post_log_streams
70+
*/
71+
public function create(array $data)
72+
{
73+
if (empty($data)) {
74+
throw new EmptyOrInvalidParameterException('Missing required "data" parameter.');
75+
}
76+
77+
if (empty($data['type'])) {
78+
throw new EmptyOrInvalidParameterException('Missing required "type" field.');
79+
}
80+
81+
if (empty($data['sink'])) {
82+
throw new EmptyOrInvalidParameterException('Missing required "sink" field.');
83+
}
84+
85+
return $this->apiClient->method('post')
86+
->addPath(self::LOG_STREAMS_PATH)
87+
->withBody(json_encode($data))
88+
->call();
89+
}
90+
91+
/**
92+
* Updates an existing Log Stream.
93+
* Required scope: "update:log_streams"
94+
*
95+
* @param string $log_stream_id the ID of the Log Stream to update.
96+
* @param array $data Log Stream data to update. Only certain fields are update-able; see the documentation linked below.
97+
*
98+
* @return mixed
99+
*
100+
* @throws EmptyOrInvalidParameterException Thrown if the log_stream_id parameter is empty.
101+
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
102+
*
103+
* @link https://auth0.com/docs/api/management/v2#!/Log_Streams/patch_log_streams_by_id
104+
*/
105+
public function update($log_stream_id, array $data)
106+
{
107+
if (empty($log_stream_id)) {
108+
throw new EmptyOrInvalidParameterException('Missing required "log_stream_id" field');
109+
}
110+
111+
return $this->apiClient->method('patch')
112+
->addPath(self::LOG_STREAMS_PATH, $log_stream_id)
113+
->withBody(json_encode($data))
114+
->call();
115+
}
116+
117+
/**
118+
* Deletes a Log Stream.
119+
* Required scope: "delete:log_streams"
120+
*
121+
* @param string $log_stream_id the ID of the Log Stream to delete.
122+
*
123+
* @return mixed
124+
*
125+
* @throws EmptyOrInvalidParameterException Thrown if the log_stream_id parameter is empty.
126+
* @throws \Exception Thrown by the HTTP client when there is a problem with the API call.
127+
*
128+
* @link https://auth0.com/docs/api/management/v2#!/Log_Streams/delete_log_streams_by_id
129+
*/
130+
public function delete($log_stream_id)
131+
{
132+
if (empty($log_stream_id)) {
133+
throw new EmptyOrInvalidParameterException('Missing required "log_stream_id" field');
134+
}
135+
136+
return $this->apiClient->method('delete')
137+
->addPath(self::LOG_STREAMS_PATH, $log_stream_id)
138+
->call();
139+
}
140+
141+
}

0 commit comments

Comments
 (0)