Skip to content

Fix fallback to config file when partial OCI API Key credentials are provided (Fixes #159) #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,24 @@ private static AbstractAuthenticationDetailsProvider getAuthenticationDetails(
* Returns authentication details using the following API key-based
* methods:
* <ol>
* <li>Simple authentication: if any of the credentials, including tenant ID
* , user ID, fingerprint, private key, or passphrase, are provided in
* the given {@code parameters}</li>
* <li>Simple authentication: if all required credentials (tenant ID,
* user ID, fingerprint, and private key are provided in the given
* {@code parameters}</li>
* <li>Config File (API key) authentication: otherwise</li>
* </ol>
* @return API key-based authentication details
*/
private static AuthenticationDetailsProvider
apiKeyBasedAuthentication(ParameterSet parameters) {
if (parameters.contains(TENANT_ID)
|| parameters.contains(USER_ID)
|| parameters.contains(FINGERPRINT)
|| parameters.contains(PRIVATE_KEY)
|| parameters.contains(PASS_PHRASE)
|| parameters.contains(REGION)) {
boolean hasAllRequiredKeys =
parameters.contains(TENANT_ID)
&& parameters.contains(USER_ID)
&& parameters.contains(FINGERPRINT)
&& parameters.contains(PRIVATE_KEY);

if(hasAllRequiredKeys)
return simpleAuthentication(parameters);
}

return configFileAuthentication(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ public void testConfigFile() {
.build());
}

/**
* Verifies partial API_KEY credentials fallback to config file.
*/
@Test
public void testApiKeyPartialCredentials() {
verifyAuthenticationDetails(
buildParameterSet(AuthenticationMethod.API_KEY)
.add("Test OCI_USER", AuthenticationDetailsFactory.USER_ID, "dummy-user-id")
.build());
}

/**
* Verifies {@link AuthenticationMethod#CLOUD_SHELL}
*/
Expand Down