Skip to content

Commit 9626364

Browse files
refactor(storage-api-client): use constants for authType values
Replace plain strings with AUTH_TYPE_STORAGE_TOKEN and AUTH_TYPE_BEARER constants as requested in PR review. Co-Authored-By: Tomáš Fejfar <tomas.fejfar@keboola.com>
1 parent 8d72a77 commit 9626364

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/Keboola/StorageApi/Client.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,18 @@ class Client
6666
public const FILE_PROVIDER_AZURE = 'azure';
6767
public const FILE_PROVIDER_GCP = 'gcp';
6868

69+
// Authentication types
70+
public const AUTH_TYPE_STORAGE_TOKEN = 'storage-token';
71+
public const AUTH_TYPE_BEARER = 'bearer';
72+
6973
// Errors
7074
public const ERROR_CANNOT_DOWNLOAD_FILE = 'Cannot download file "%s" (ID %s) from Storage, please verify the contents of the file and that the file has not expired.';
7175

7276
// Token string
7377
public $token;
7478

75-
// Authentication type: 'storage-token' (default) or 'bearer'
76-
private string $authType = 'storage-token';
79+
// Authentication type: AUTH_TYPE_STORAGE_TOKEN (default) or AUTH_TYPE_BEARER
80+
private string $authType = self::AUTH_TYPE_STORAGE_TOKEN;
7781

7882
// current run id sent with all request
7983
private $runId = null;
@@ -168,8 +172,12 @@ public function __construct(array $config = [])
168172
$this->token = $config['token'];
169173

170174
if (isset($config['authType'])) {
171-
if (!in_array($config['authType'], ['storage-token', 'bearer'], true)) {
172-
throw new \InvalidArgumentException('authType must be either "storage-token" or "bearer"');
175+
if (!in_array($config['authType'], [self::AUTH_TYPE_STORAGE_TOKEN, self::AUTH_TYPE_BEARER], true)) {
176+
throw new \InvalidArgumentException(sprintf(
177+
'authType must be either "%s" or "%s"',
178+
self::AUTH_TYPE_STORAGE_TOKEN,
179+
self::AUTH_TYPE_BEARER,
180+
));
173181
}
174182
$this->authType = $config['authType'];
175183
}
@@ -2892,7 +2900,7 @@ protected function request($method, $url, $options = [], $responseFileName = nul
28922900
'Accept-Encoding' => 'gzip',
28932901
'User-Agent' => $this->getUserAgent(),
28942902
];
2895-
if ($this->authType === 'bearer') {
2903+
if ($this->authType === self::AUTH_TYPE_BEARER) {
28962904
$defaultHeaders['Authorization'] = 'Bearer ' . $this->token;
28972905
} else {
28982906
$defaultHeaders['X-StorageApi-Token'] = $this->token;

0 commit comments

Comments
 (0)