Skip to content
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

feat: add system properties credentials provider & include it in default credentials provider chain #1037

Merged
merged 8 commits into from
Sep 7, 2023

Conversation

0marperez
Copy link
Contributor

@0marperez 0marperez commented Aug 31, 2023

Issue #

closes #1033

Description of changes

-Created system properties credentials provider
-Added it to the default credentials provider chain as the first one

It's essentially a copy of the environment credentials provider

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@0marperez 0marperez marked this pull request as ready for review August 31, 2023 21:15
@0marperez 0marperez requested a review from a team as a code owner August 31, 2023 21:15
Copy link
Member

@lauzadis lauzadis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty great first attempt! I had a few smaller comments

{
"id": "ec4b3c6c-c63f-499d-a032-026139b4627e",
"type": "feature",
"description": "Add Jvm credentails provider and make it first in default chain credentials provider",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "Jvm credentails" -> "JVM system property credentials"

private val SECRET_ACCESS_KEY = AwsSdkSetting.AwsSecretAccessKey.sysProp
private val SESSION_TOKEN = AwsSdkSetting.AwsSessionToken.sysProp

public class JvmCredentialsProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd call this the JvmSystemPropertyCredentialsProvider. There can be different types of credentials providers used on JVM, so JvmCredentialsProvider seems too vague to me.

Same comment applies everywhere just "JVM" is used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree JvmCredentialsProvider is too vague but I don't think the JVM part is important. Sure, it'd only work on JVM for now but there may be other future platforms which have some kind of system properties. I'd suggest SystemPropertyCredentialsProvider.

public constructor() : this(PlatformProvider.System::getProperty)

private fun requireProperty(variable: String): String =
getProperty(variable) ?: throw ProviderConfigurationException("Missing value for JVM system properties `$variable`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "for JVM system property"

Comment on lines 23 to 24
public constructor(private val getProperty: (String) -> String?) : CredentialsProvider {
public constructor() : this(PlatformProvider.System::getProperty)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of two constructors you can just have one which defaults to PlatformProvider.System::getProperty

public constructor(private val getProperty: (String) -> String? = PlatformProvider.System::getProperty)

@@ -47,6 +48,7 @@ class DefaultChainCredentialsProviderTest {

class DefaultChainPlatformProvider(
private val env: Map<String, String>,
private val jvm: Map<String, String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: jvmSystemProperties

Copy link
Contributor

@ianbotsf ianbotsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment about JVM not being the important part applies for names/strings/docs across the whole PR.

private val SECRET_ACCESS_KEY = AwsSdkSetting.AwsSecretAccessKey.sysProp
private val SESSION_TOKEN = AwsSdkSetting.AwsSessionToken.sysProp

public class JvmCredentialsProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Needs KDocs, which should indicate exactly which system properties will be used.

getProperty(variable) ?: throw ProviderConfigurationException("Missing value for JVM system properties `$variable`")

override suspend fun resolve(attributes: Attributes): Credentials {
coroutineContext.trace<EnvironmentCredentialsProvider> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Copy/paste error

@0marperez 0marperez changed the title feat: add jvm credentials provider & include it in default credentials provider chain feat: add system properties credentials provider & include it in default credentials provider chain Sep 1, 2023
@sonarcloud
Copy link

sonarcloud bot commented Sep 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@0marperez 0marperez merged commit 1ed3546 into main Sep 7, 2023
11 of 12 checks passed
@0marperez 0marperez deleted the jvm-credentials-provider branch September 7, 2023 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetch credentials from JVM system properties
3 participants