Skip to content

chore: Refactor x509Provider to create a shared Utils class for Mtls#1907

Open
vverman wants to merge 10 commits intogoogleapis:mainfrom
vverman:refactor-x509-provider
Open

chore: Refactor x509Provider to create a shared Utils class for Mtls#1907
vverman wants to merge 10 commits intogoogleapis:mainfrom
vverman:refactor-x509-provider

Conversation

@vverman
Copy link
Copy Markdown
Contributor

@vverman vverman commented Mar 24, 2026

Fixes #1745

Addressed a concern raised by Andy refer.

Now X509Provider only exposes the necessary methods needed by the MtlsProvider interface

@vverman vverman requested review from a team as code owners March 24, 2026 02:24
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 24, 2026
@vverman vverman force-pushed the refactor-x509-provider branch from 1500bea to f78ed98 Compare March 24, 2026 03:02
@vverman vverman requested a review from lqiu96 March 24, 2026 03:04
*
* <p>For internal use only.
*/
public class SystemEnvironmentProvider implements EnvironmentProvider, Serializable {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

qq, what is the difference between SystemEnvironmentProvider and EnvironmentProvider?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An EnvProvider is an interface which can be implemented by test-classes to pass in their own env variables.

The SystemEnvProvider implements this EnvProvider and implements the associated functions such that the env-variables are fetched from the system env.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Got it. Can you add @internalapi to this class and for SystemPropertyProvider?

@lqiu96
Copy link
Copy Markdown
Member

lqiu96 commented Mar 24, 2026

feat: Refactor x509Provider

Since this is a refactor, I'm going to change the title to chore: ... to reflect the type of change in the release notes. Thank you for helping with our backlog!

@lqiu96 lqiu96 changed the title feat: Refactor x509Provider chore: Refactor x509Provider to create a shared Utils class for Mtls Mar 24, 2026
@marcosgtz7
Copy link
Copy Markdown

marcosgtz7 commented Mar 24, 2026 via email

import java.util.HashMap;
import java.util.Map;

public class TestPropertyProvider implements PropertyProvider {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

qq, is this TestPropertyProvider used anywhere in the tests? If not, can we remove it?

Copy link
Copy Markdown
Contributor Author

@vverman vverman Mar 27, 2026

Choose a reason for hiding this comment

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

Since this is used to test the System Properties, added in a test for the windows OS default file path in X509ProviderTest.

} else {
String osName = propProvider.getProperty("os.name", "").toLowerCase(Locale.US);
if (osName.indexOf("windows") >= 0) {
File appDataPath = new File(envProvider.getEnv("APPDATA"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If APPDATA is unset on Windows, envProvider.getEnv("APPDATA") returns null. Creating a new File(null) throws a NullPointerException.

We can align with how Linux handles its user.home fallback by checking user.home as a fallback when APPDATA is missing.

Copy link
Copy Markdown
Contributor Author

@vverman vverman Mar 27, 2026

Choose a reason for hiding this comment

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

I believe this is the same logic to detect the default 'directory' where the ADC file is, within the GoogleAuthUtils.getWellKnownCredentialsFile

I believe this should stay as is since the discovery for ADC and cert config should be the same and having a default for windows might lead to an unexpected outcome for cert_config as compared to ADC.

Do lmk your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth: Refactor X509Provider

4 participants