Skip to content

Commit 0176a44

Browse files
authored
Merge pull request #10 from keboola/adamvyborny-COM-1550-improve-logging
Improve logging
2 parents 15c57e6 + e01db7f commit 0176a44

5 files changed

Lines changed: 74 additions & 20 deletions

File tree

.github/workflows/push.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'GitHub Actions'
2+
'on':
3+
- push
4+
concurrency: 'ci-${{ github.ref }}'
5+
env:
6+
APP_IMAGE: keboola/google-client-bundle
7+
DOCKERHUB_USER: '${{ secrets.DOCKERHUB_USER }}'
8+
DOCKERHUB_TOKEN: '${{ secrets.DOCKERHUB_TOKEN }}'
9+
10+
CLIENT_ID: '${{ secrets.CLIENT_ID }}'
11+
CLIENT_SECRET: '${{ secrets.CLIENT_SECRET }}'
12+
REFRESH_TOKEN: '${{ secrets.REFRESH_TOKEN }}'
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-latest
16+
steps:
17+
-
18+
name: 'Check out the repo'
19+
uses: actions/checkout@v2
20+
-
21+
name: 'Docker login'
22+
if: env.DOCKERHUB_TOKEN
23+
run: 'docker login --username "$DOCKERHUB_USER" --password "$DOCKERHUB_TOKEN"'
24+
-
25+
name: 'Build image'
26+
run: 'docker build -t $APP_IMAGE .'
27+
-
28+
name: 'Run tests'
29+
run: |
30+
docker run \
31+
-e CLIENT_ID \
32+
-e CLIENT_SECRET \
33+
-e REFRESH_TOKEN \
34+
${{env.APP_IMAGE}} composer ci

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Keboola Google API Client
2-
[![Build Status](https://travis-ci.org/keboola/google-client-bundle.svg?branch=master)](https://travis-ci.org/keboola/google-client-bundle)
32

43
Basic client for Google APIs

src/Google/RestApi.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,10 @@ protected function logRetryRequest(
278278
?ResponseInterface $response = null
279279
): void {
280280
if ($this->logger !== null) {
281-
$headersForLog = array_map(function ($item, $key) {
282-
if (strtolower($key) === 'authorization') {
283-
return '*****';
284-
}
285-
return $item;
286-
}, $request->getHeaders(), array_keys($request->getHeaders()));
281+
$headersForLog = $request->getHeaders();
282+
if (array_key_exists('authorization', array_change_key_case($headersForLog, CASE_LOWER))) {
283+
$headersForLog['Authorization'] = '*****';
284+
}
287285

288286
$context = [
289287
'request' => [
@@ -300,9 +298,14 @@ protected function logRetryRequest(
300298
'reason' => $response->getReasonPhrase(),
301299
'body' => $response->getBody()->getContents(),
302300
];
303-
}
304301

305-
$this->logger->info(sprintf('Retrying request (%sx)', $retries), $context);
302+
$this->logger->info(
303+
sprintf('Retrying request (%sx) - reason: %s', $retries, $response->getReasonPhrase()),
304+
$context
305+
);
306+
} else {
307+
$this->logger->info(sprintf('Retrying request (%sx)', $retries), $context);
308+
}
306309
}
307310
}
308311

tests/RestApiTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,35 @@ public function testRetries(): void
118118

119119
foreach ($this->testHandler->getRecords() as $key => $value) {
120120
$this->assertEquals(Logger::INFO, $value['level']);
121-
$this->assertEquals(sprintf('Retrying request (%dx)', $key), $value['message']);
121+
$this->assertEquals(sprintf('Retrying request (%dx) - reason: Not Found', $key), $value['message']);
122+
$this->assertEquals(
123+
[
124+
'request' => [
125+
'uri' => 'https://www.googleapis.com/auth/invalid-scope',
126+
'headers' => [
127+
'User-Agent' => ['GuzzleHttp/6.5.5 curl/7.74.0 PHP/7.4.30'],
128+
'Host' => ['www.googleapis.com'],
129+
'Accept' => ['application/json'],
130+
'Authorization' => '*****',
131+
132+
],
133+
'method' => 'GET',
134+
'body' => '',
135+
],
136+
'response' => [
137+
'statusCode' => 404,
138+
'reason' => 'Not Found',
139+
'body' => 'You are receiving this error either because your input OAuth2 scope name is ' .
140+
"invalid or it refers to a newer scope that is outside the domain of this legacy API.\n\n" .
141+
'This API was built at a time when the scope name format was not yet standardized. This ' .
142+
'is no longer the case and all valid scope names (both old and new) are catalogued at ' .
143+
'https://developers.google.com/identity/protocols/oauth2/scopes. Use that webpage to' .
144+
' lookup (manually) the scope name associated with the API you are trying to call and use' .
145+
" it to craft your OAuth2 request.\n",
146+
],
147+
],
148+
$value['context']
149+
);
122150
}
123151
}
124152

0 commit comments

Comments
 (0)