@@ -47,9 +47,16 @@ public function __construct(
4747 string $ internalQueueApiUrl ,
4848 ?string $ internalQueueToken ,
4949 ?string $ storageApiToken ,
50+ ?string $ applicationToken ,
5051 array $ options = [],
5152 ) {
52- $ this ->validateConfiguration ($ internalQueueApiUrl , $ internalQueueToken , $ storageApiToken , $ options );
53+ $ this ->validateConfiguration (
54+ $ internalQueueApiUrl ,
55+ $ internalQueueToken ,
56+ $ storageApiToken ,
57+ $ applicationToken ,
58+ $ options ,
59+ );
5360 if (!empty ($ options ['backoffMaxTries ' ])) {
5461 $ options ['backoffMaxTries ' ] = intval ($ options ['backoffMaxTries ' ]);
5562 } else {
@@ -59,7 +66,13 @@ public function __construct(
5966 $ options ['userAgent ' ] = self ::DEFAULT_USER_AGENT ;
6067 }
6168
62- $ this ->guzzle = $ this ->initClient ($ internalQueueApiUrl , $ internalQueueToken , $ storageApiToken , $ options );
69+ $ this ->guzzle = $ this ->initClient (
70+ $ internalQueueApiUrl ,
71+ $ internalQueueToken ,
72+ $ storageApiToken ,
73+ $ applicationToken ,
74+ $ options ,
75+ );
6376 $ this ->existingJobFactory = $ existingJobFactory ;
6477 $ this ->logger = $ logger ;
6578 }
@@ -68,15 +81,24 @@ private function validateConfiguration(
6881 string $ internalQueueApiUrl ,
6982 ?string $ internalQueueToken ,
7083 ?string $ storageApiToken ,
84+ ?string $ applicationToken ,
7185 array $ options ,
7286 ): void {
7387 $ validator = Validation::createValidator ();
7488 $ errors = $ validator ->validate ($ internalQueueApiUrl , [new Url ()]);
75- if ($ internalQueueToken === null && $ storageApiToken === null ) {
76- throw new ClientException ('Both InternalApiToken and StorageAPIToken are empty. ' );
89+
90+ $ providedTokens = array_filter (
91+ [$ internalQueueToken , $ storageApiToken , $ applicationToken ],
92+ fn (?string $ token ) => $ token !== null ,
93+ );
94+
95+ if (count ($ providedTokens ) === 0 ) {
96+ throw new ClientException (
97+ 'No token provided (internalQueueToken, storageApiToken and applicationToken are empty) ' ,
98+ );
7799 }
78- if ($ internalQueueToken !== null && $ storageApiToken !== null ) {
79- throw new ClientException ('Both InternalApiToken and StorageAPIToken are non-empty. Use only one. ' );
100+ if (count ( $ providedTokens ) > 1 ) {
101+ throw new ClientException ('More than one authentication token provided ' );
80102 }
81103 if ($ internalQueueToken !== null ) {
82104 $ errors ->addAll (
@@ -88,6 +110,11 @@ private function validateConfiguration(
88110 $ validator ->validate ($ storageApiToken , [new NotBlank ()]),
89111 );
90112 }
113+ if ($ applicationToken !== null ) {
114+ $ errors ->addAll (
115+ $ validator ->validate ($ applicationToken , [new NotBlank ()]),
116+ );
117+ }
91118 if (!empty ($ options ['backoffMaxTries ' ])) {
92119 $ errors ->addAll ($ validator ->validate ($ options ['backoffMaxTries ' ], [new Range (['min ' => 0 , 'max ' => 100 ])]));
93120 }
@@ -347,6 +374,7 @@ private function initClient(
347374 string $ url ,
348375 ?string $ internalToken ,
349376 ?string $ storageToken ,
377+ ?string $ applicationToken ,
350378 array $ options = [],
351379 ): GuzzleClient {
352380 // Initialize handlers (start with those supplied in constructor)
@@ -359,7 +387,7 @@ private function initClient(
359387 $ handlerStack ->push (Middleware::retry ($ this ->createDefaultDecider ($ options ['backoffMaxTries ' ])));
360388 // Set handler to set default headers
361389 $ handlerStack ->push (Middleware::mapRequest (
362- function (RequestInterface $ request ) use ($ internalToken , $ storageToken , $ options ) {
390+ function (RequestInterface $ request ) use ($ internalToken , $ storageToken , $ applicationToken , $ options ) {
363391 $ request = $ request ->withHeader ('User-Agent ' , $ options ['userAgent ' ])
364392 ->withHeader ('Content-type ' , 'application/json ' );
365393 if ($ internalToken !== null ) {
@@ -368,6 +396,9 @@ function (RequestInterface $request) use ($internalToken, $storageToken, $option
368396 if ($ storageToken !== null ) {
369397 $ request = $ request ->withHeader ('X-StorageApi-Token ' , $ storageToken );
370398 }
399+ if ($ applicationToken !== null ) {
400+ $ request = $ request ->withHeader ('X-KBC-ManageApiToken ' , $ applicationToken );
401+ }
371402 return $ request ;
372403 },
373404 ));
0 commit comments