Skip to content

Commit

Permalink
chore: add credentials->source tests
Browse files Browse the repository at this point in the history
- Add tests cases to cover credentials sets the correct source when resolved.
- Fix the sso, sso_legacy, and process metrics. They should be all a profile based metric.
  • Loading branch information
yenfryherrerafeliz committed Nov 15, 2024
1 parent f6ed0f9 commit 0ac671a
Show file tree
Hide file tree
Showing 6 changed files with 670 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Credentials/CredentialProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public static function process($profile = null, $filename = null)
$processData['SessionToken'],
$expires,
$accountId,
CredentialSources::PROCESS
CredentialSources::PROFILE_PROCESS
)
);
};
Expand Down Expand Up @@ -927,7 +927,7 @@ private static function getSsoCredentials($profiles, $ssoProfileName, $filename,
$ssoCredentials['sessionToken'],
$expiration,
$ssoProfile['sso_account_id'],
CredentialSources::SSO
CredentialSources::PROFILE_SSO
)
);
}
Expand Down Expand Up @@ -988,7 +988,7 @@ private static function getSsoCredentialsLegacy($profiles, $ssoProfileName, $fil
$ssoCredentials['sessionToken'],
$expiration,
$ssoProfile['sso_account_id'],
CredentialSources::SSO_LEGACY
CredentialSources::PROFILE_SSO_LEGACY
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Credentials/CredentialSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CredentialSources
const PROFILE = 'profile';
const IMDS = 'instance_profile_provider';
const ECS = 'ecs';
const SSO = 'sso';
const SSO_LEGACY = 'sso_legacy';
const PROCESS = 'process';
const PROFILE_SSO = 'profile_sso';
const PROFILE_SSO_LEGACY = 'profile_sso_legacy';
const PROFILE_PROCESS = 'profile_process';
}
2 changes: 1 addition & 1 deletion src/Credentials/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
$this->token = $token;
$this->expires = $expires;
$this->accountId = $accountId;
$this->source = $source;
$this->source = $source ?? CredentialSources::STATIC;
}

public static function __set_state(array $state)
Expand Down
18 changes: 9 additions & 9 deletions src/MetricsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ final class MetricsBuilder
const CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN = "q";
const CREDENTIALS_HTTP = "z";
const CREDENTIALS_IMDS = "0";
const CREDENTIALS_PROCESS = "w";
const CREDENTIALS_SSO = "s";
const CREDENTIALS_SSO_LEGACY = "u";
const CREDENTIALS_PROFILE_PROCESS = "v";
const CREDENTIALS_PROFILE_SSO = "r";
const CREDENTIALS_PROFILE_SSO_LEGACY = "t";

/** @var int */
private static $MAX_METRICS_SIZE = 1024; // 1KB or 1024 B
Expand Down Expand Up @@ -229,12 +229,12 @@ private function appendCredentialsMetric(
MetricsBuilder::CREDENTIALS_HTTP,
CredentialSources::PROFILE_STS_WEB_ID_TOKEN =>
MetricsBuilder::CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN,
CredentialSources::PROCESS =>
MetricsBuilder::CREDENTIALS_PROCESS,
CredentialSources::SSO =>
MetricsBuilder::CREDENTIALS_SSO,
CredentialSources::SSO_LEGACY =>
MetricsBuilder::CREDENTIALS_SSO_LEGACY,
CredentialSources::PROFILE_PROCESS =>
MetricsBuilder::CREDENTIALS_PROFILE_PROCESS,
CredentialSources::PROFILE_SSO =>
MetricsBuilder::CREDENTIALS_PROFILE_SSO,
CredentialSources::PROFILE_SSO_LEGACY =>
MetricsBuilder::CREDENTIALS_PROFILE_SSO_LEGACY,
];
if (isset($credentialsMetricMapping[$source])) {
$this->append($credentialsMetricMapping[$source]);
Expand Down
Loading

0 comments on commit 0ac671a

Please sign in to comment.