Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7873a17

Browse files
authored
Add new operation CloudWatchLogs::filterLogEvents (async-aws#1168)
* Add new operation CloudWatchLogs::filterLogEvents * psalm: Ignore Redundant cast to bool given docblock-provided type
1 parent dd548d2 commit 7873a17

13 files changed

Lines changed: 831 additions & 0 deletions

manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"methods": [
7070
"CreateLogGroup",
7171
"DescribeLogStreams",
72+
"FilterLogEvents",
7273
"PutLogEvents"
7374
]
7475
},

psalm.baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@
132132
<code>(bool) $v</code>
133133
</RedundantCastGivenDocblockType>
134134
</file>
135+
<file src="src/Service/CloudWatchLogs/src/Input/FilterLogEventsRequest.php">
136+
<RedundantCastGivenDocblockType occurrences="1">
137+
<code>(bool) $v</code>
138+
</RedundantCastGivenDocblockType>
139+
</file>
135140
<file src="src/Service/CodeDeploy/src/Input/CreateDeploymentInput.php">
136141
<RedundantCastGivenDocblockType occurrences="2">
137142
<code>(bool) $v</code>

src/Service/CloudWatchLogs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- AWS api-change: Added `us-iso-west-1` region
88
- AWS api-change: Use specific configuration for `us` regions
9+
- Added operation `filterLogEvents`
910

1011
## 1.2.0
1112

src/Service/CloudWatchLogs/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
],
1414
"require": {
1515
"php": "^7.2.5 || ^8.0",
16+
"ext-filter": "*",
1617
"ext-json": "*",
1718
"async-aws/core": "^1.9"
1819
},

src/Service/CloudWatchLogs/src/CloudWatchLogsClient.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
use AsyncAws\CloudWatchLogs\Exception\UnrecognizedClientException;
1515
use AsyncAws\CloudWatchLogs\Input\CreateLogGroupRequest;
1616
use AsyncAws\CloudWatchLogs\Input\DescribeLogStreamsRequest;
17+
use AsyncAws\CloudWatchLogs\Input\FilterLogEventsRequest;
1718
use AsyncAws\CloudWatchLogs\Input\PutLogEventsRequest;
1819
use AsyncAws\CloudWatchLogs\Result\DescribeLogStreamsResponse;
20+
use AsyncAws\CloudWatchLogs\Result\FilterLogEventsResponse;
1921
use AsyncAws\CloudWatchLogs\Result\PutLogEventsResponse;
2022
use AsyncAws\CloudWatchLogs\ValueObject\InputLogEvent;
2123
use AsyncAws\Core\AbstractApi;
@@ -93,6 +95,42 @@ public function describeLogStreams($input): DescribeLogStreamsResponse
9395
return new DescribeLogStreamsResponse($response, $this, $input);
9496
}
9597

98+
/**
99+
* Lists log events from the specified log group. You can list all the log events or filter the results using a filter
100+
* pattern, a time range, and the name of the log stream.
101+
*
102+
* @see https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_FilterLogEvents.html
103+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-logs-2014-03-28.html#filterlogevents
104+
*
105+
* @param array{
106+
* logGroupName: string,
107+
* logStreamNames?: string[],
108+
* logStreamNamePrefix?: string,
109+
* startTime?: string,
110+
* endTime?: string,
111+
* filterPattern?: string,
112+
* nextToken?: string,
113+
* limit?: int,
114+
* interleaved?: bool,
115+
* @region?: string,
116+
* }|FilterLogEventsRequest $input
117+
*
118+
* @throws InvalidParameterException
119+
* @throws ResourceNotFoundException
120+
* @throws ServiceUnavailableException
121+
*/
122+
public function filterLogEvents($input): FilterLogEventsResponse
123+
{
124+
$input = FilterLogEventsRequest::create($input);
125+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'FilterLogEvents', 'region' => $input->getRegion(), 'exceptionMapping' => [
126+
'InvalidParameterException' => InvalidParameterException::class,
127+
'ResourceNotFoundException' => ResourceNotFoundException::class,
128+
'ServiceUnavailableException' => ServiceUnavailableException::class,
129+
]]));
130+
131+
return new FilterLogEventsResponse($response, $this, $input);
132+
}
133+
96134
/**
97135
* Uploads a batch of log events to the specified log stream.
98136
*
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
<?php
2+
3+
namespace AsyncAws\CloudWatchLogs\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
final class FilterLogEventsRequest extends Input
11+
{
12+
/**
13+
* The name of the log group to search.
14+
*
15+
* @required
16+
*
17+
* @var string|null
18+
*/
19+
private $logGroupName;
20+
21+
/**
22+
* Filters the results to only logs from the log streams in this list.
23+
*
24+
* @var string[]|null
25+
*/
26+
private $logStreamNames;
27+
28+
/**
29+
* Filters the results to include only events from log streams that have names starting with this prefix.
30+
*
31+
* @var string|null
32+
*/
33+
private $logStreamNamePrefix;
34+
35+
/**
36+
* The start of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a
37+
* timestamp before this time are not returned.
38+
*
39+
* @var string|null
40+
*/
41+
private $startTime;
42+
43+
/**
44+
* The end of the time range, expressed as the number of milliseconds after Jan 1, 1970 00:00:00 UTC. Events with a
45+
* timestamp later than this time are not returned.
46+
*
47+
* @var string|null
48+
*/
49+
private $endTime;
50+
51+
/**
52+
* The filter pattern to use. For more information, see Filter and Pattern Syntax.
53+
*
54+
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
55+
*
56+
* @var string|null
57+
*/
58+
private $filterPattern;
59+
60+
/**
61+
* The token for the next set of events to return. (You received this token from a previous call.).
62+
*
63+
* @var string|null
64+
*/
65+
private $nextToken;
66+
67+
/**
68+
* The maximum number of events to return. The default is 10,000 events.
69+
*
70+
* @var int|null
71+
*/
72+
private $limit;
73+
74+
/**
75+
* If the value is true, the operation makes a best effort to provide responses that contain events from multiple log
76+
* streams within the log group, interleaved in a single response. If the value is false, all the matched log events in
77+
* the first log stream are searched first, then those in the next log stream, and so on. The default is false.
78+
*
79+
* @var bool|null
80+
*/
81+
private $interleaved;
82+
83+
/**
84+
* @param array{
85+
* logGroupName?: string,
86+
* logStreamNames?: string[],
87+
* logStreamNamePrefix?: string,
88+
* startTime?: string,
89+
* endTime?: string,
90+
* filterPattern?: string,
91+
* nextToken?: string,
92+
* limit?: int,
93+
* interleaved?: bool,
94+
* @region?: string,
95+
* } $input
96+
*/
97+
public function __construct(array $input = [])
98+
{
99+
$this->logGroupName = $input['logGroupName'] ?? null;
100+
$this->logStreamNames = $input['logStreamNames'] ?? null;
101+
$this->logStreamNamePrefix = $input['logStreamNamePrefix'] ?? null;
102+
$this->startTime = $input['startTime'] ?? null;
103+
$this->endTime = $input['endTime'] ?? null;
104+
$this->filterPattern = $input['filterPattern'] ?? null;
105+
$this->nextToken = $input['nextToken'] ?? null;
106+
$this->limit = $input['limit'] ?? null;
107+
$this->interleaved = $input['interleaved'] ?? null;
108+
parent::__construct($input);
109+
}
110+
111+
public static function create($input): self
112+
{
113+
return $input instanceof self ? $input : new self($input);
114+
}
115+
116+
public function getEndTime(): ?string
117+
{
118+
return $this->endTime;
119+
}
120+
121+
public function getFilterPattern(): ?string
122+
{
123+
return $this->filterPattern;
124+
}
125+
126+
/**
127+
* @deprecated
128+
*/
129+
public function getInterleaved(): ?bool
130+
{
131+
@trigger_error(sprintf('The property "interleaved" of "%s" is deprecated by AWS.', __CLASS__), \E_USER_DEPRECATED);
132+
133+
return $this->interleaved;
134+
}
135+
136+
public function getLimit(): ?int
137+
{
138+
return $this->limit;
139+
}
140+
141+
public function getLogGroupName(): ?string
142+
{
143+
return $this->logGroupName;
144+
}
145+
146+
public function getLogStreamNamePrefix(): ?string
147+
{
148+
return $this->logStreamNamePrefix;
149+
}
150+
151+
/**
152+
* @return string[]
153+
*/
154+
public function getLogStreamNames(): array
155+
{
156+
return $this->logStreamNames ?? [];
157+
}
158+
159+
public function getNextToken(): ?string
160+
{
161+
return $this->nextToken;
162+
}
163+
164+
public function getStartTime(): ?string
165+
{
166+
return $this->startTime;
167+
}
168+
169+
/**
170+
* @internal
171+
*/
172+
public function request(): Request
173+
{
174+
// Prepare headers
175+
$headers = [
176+
'Content-Type' => 'application/x-amz-json-1.1',
177+
'X-Amz-Target' => 'Logs_20140328.FilterLogEvents',
178+
];
179+
180+
// Prepare query
181+
$query = [];
182+
183+
// Prepare URI
184+
$uriString = '/';
185+
186+
// Prepare Body
187+
$bodyPayload = $this->requestBody();
188+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
189+
190+
// Return the Request
191+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
192+
}
193+
194+
public function setEndTime(?string $value): self
195+
{
196+
$this->endTime = $value;
197+
198+
return $this;
199+
}
200+
201+
public function setFilterPattern(?string $value): self
202+
{
203+
$this->filterPattern = $value;
204+
205+
return $this;
206+
}
207+
208+
/**
209+
* @deprecated
210+
*/
211+
public function setInterleaved(?bool $value): self
212+
{
213+
@trigger_error(sprintf('The property "interleaved" of "%s" is deprecated by AWS.', __CLASS__), \E_USER_DEPRECATED);
214+
$this->interleaved = $value;
215+
216+
return $this;
217+
}
218+
219+
public function setLimit(?int $value): self
220+
{
221+
$this->limit = $value;
222+
223+
return $this;
224+
}
225+
226+
public function setLogGroupName(?string $value): self
227+
{
228+
$this->logGroupName = $value;
229+
230+
return $this;
231+
}
232+
233+
public function setLogStreamNamePrefix(?string $value): self
234+
{
235+
$this->logStreamNamePrefix = $value;
236+
237+
return $this;
238+
}
239+
240+
/**
241+
* @param string[] $value
242+
*/
243+
public function setLogStreamNames(array $value): self
244+
{
245+
$this->logStreamNames = $value;
246+
247+
return $this;
248+
}
249+
250+
public function setNextToken(?string $value): self
251+
{
252+
$this->nextToken = $value;
253+
254+
return $this;
255+
}
256+
257+
public function setStartTime(?string $value): self
258+
{
259+
$this->startTime = $value;
260+
261+
return $this;
262+
}
263+
264+
private function requestBody(): array
265+
{
266+
$payload = [];
267+
if (null === $v = $this->logGroupName) {
268+
throw new InvalidArgument(sprintf('Missing parameter "logGroupName" for "%s". The value cannot be null.', __CLASS__));
269+
}
270+
$payload['logGroupName'] = $v;
271+
if (null !== $v = $this->logStreamNames) {
272+
$index = -1;
273+
$payload['logStreamNames'] = [];
274+
foreach ($v as $listValue) {
275+
++$index;
276+
$payload['logStreamNames'][$index] = $listValue;
277+
}
278+
}
279+
if (null !== $v = $this->logStreamNamePrefix) {
280+
$payload['logStreamNamePrefix'] = $v;
281+
}
282+
if (null !== $v = $this->startTime) {
283+
$payload['startTime'] = $v;
284+
}
285+
if (null !== $v = $this->endTime) {
286+
$payload['endTime'] = $v;
287+
}
288+
if (null !== $v = $this->filterPattern) {
289+
$payload['filterPattern'] = $v;
290+
}
291+
if (null !== $v = $this->nextToken) {
292+
$payload['nextToken'] = $v;
293+
}
294+
if (null !== $v = $this->limit) {
295+
$payload['limit'] = $v;
296+
}
297+
if (null !== $v = $this->interleaved) {
298+
@trigger_error(sprintf('The property "interleaved" of "%s" is deprecated by AWS.', __CLASS__), \E_USER_DEPRECATED);
299+
$payload['interleaved'] = (bool) $v;
300+
}
301+
302+
return $payload;
303+
}
304+
}

0 commit comments

Comments
 (0)