Skip to content

Commit

Permalink
Change the getCacheKey implentation to not return null on executable …
Browse files Browse the repository at this point in the history
…source
  • Loading branch information
Hectorhammett committed Jun 13, 2024
1 parent 4fab0d5 commit 3b6557b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/CredentialSource/ExecutableSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __construct(
*/
public function getCacheKey(): ?string
{
return null;
return $this->command . $this->outputFile;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Credentials/ExternalAccountCredentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,12 @@ public function fetchAuthToken(callable $httpHandler = null)
*/
public function getCacheKey(): ?string
{
$cacheKey = $this->auth->getSubjectTokenFetcher()->getCacheKey();

if ($cacheKey === null) {
return null;
}

$scopeOrAudience = $this->auth->getAudience();
if (!$scopeOrAudience) {
$scopeOrAudience = $this->auth->getScope();
}

return $cacheKey .
return $this->auth->getSubjectTokenFetcher()->getCacheKey() .
$scopeOrAudience .
$this->serviceAccountImpersonationUrl .
$this->auth->getSubjectTokenType() .
Expand Down
7 changes: 5 additions & 2 deletions tests/Credentials/ExternalAccountCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,16 @@ public function testExecutableSourceCacheKey()
{
$this->baseCreds['credential_source'] = [
'executable' => [
'command' => 'ls -al'
'command' => 'ls -al',
'output_file' => './output.txt'
]
];

$credentials = new ExternalAccountCredentials('scope1', $this->baseCreds);
$cacheKey = $credentials->getCacheKey();
$this->assertNull($cacheKey);

$expectedCacheKey = 'ls -al./output.txtscope1';
$this->assertEquals($cacheKey, $expectedCacheKey);
}

/**
Expand Down

0 comments on commit 3b6557b

Please sign in to comment.