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

Ojdbc provider hashicorp #142

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

Conversation

MouhsinElmajdouby
Copy link
Member

No description provided.

…ecrets to extract specific fields from JSON secrets.
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 16, 2025
… cache, and enhanced README with documentation. Included example properties and unit tests for validation.
Copy link
Member

@fmeheust fmeheust left a comment

Choose a reason for hiding this comment

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

I have only looked at the hcpvaultdedicated.authentication package for the moment. I will continue my review tomorrow.


## Centralized Config Providers
<dl>
<dt><a href="#hcp-vault-secrets-config-provider">HashiCorp Vault Dedicated Config Provider</a></dt>
Copy link
Member

Choose a reason for hiding this comment

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

Title does not match description, Vault Dedicated and Vault Secrets seem to be inverted. Title does not seem to match link either


<pre>
jdbc:oracle:thin:@config-hcpvaultdedicated://{secret-path}[?option1=value1&option2=value2...]
</pre>
Copy link
Member

Choose a reason for hiding this comment

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

What are option1, option2 .... ?

* @param authToken The optional Bearer token for authorization. Can be null or empty.
* @param namespace The optional Vault namespace. Can be null or empty.
* @return A configured {@link HttpURLConnection}. Never null.
* @throws Exception if the connection cannot be established.
Copy link
Member

Choose a reason for hiding this comment

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

There are other reasons than "the connection cannot be established" for a connection to be thrown.

* the response as a string.
*
* @param conn The configured HTTP connection. Must not be null.
* @param payload The payload to send. Must not be null.
Copy link
Member

Choose a reason for hiding this comment

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

Since the code assumes that it is an UTF8 String, maybe it should be documented.

public static String sendGetRequestAndGetResponse(HttpURLConnection conn) throws Exception {
int responseCode = conn.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
String errorResponse = "";
Copy link
Member

Choose a reason for hiding this comment

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

Error handling code is duplicated, could be extracted to a method that would be used in both calls. Since the HttpURLConnection can only be used for a single request, is there a point in separating open and send ?

* @param generator the token generator function.
* @return a {@code DedicatedVaultCredentials} instance.
*/
private static DedicatedVaultToken createScopedToken(
Copy link
Member

Choose a reason for hiding this comment

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

Does the token really have a scope? Or is it just a token that is cached and expires?


switch (method) {
case VAULT_TOKEN:
return createTokenCredentials(parameterSet);
Copy link
Member

Choose a reason for hiding this comment

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

Can't this token be cached too, buy with a null expiration time ? That would avoid having a special case.

case VAULT_TOKEN:
return createTokenCredentials(parameterSet);
case USERPASS:
return createScopedToken(parameterSet, method, DedicatedVaultTokenFactory::createUserpassToken);
Copy link
Member

Choose a reason for hiding this comment

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

Could the token generator function be moved to the Enum and maybe the function that generates the cache key as well?

return cachedToken;
});

if (validCachedToken.getToken() instanceof OpaqueAccessToken) {
Copy link
Member

Choose a reason for hiding this comment

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

If the token is declared as OpaqueAccessToken, this won't be needed.

URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(method);
conn.setRequestProperty("Content-Type", contentType);
Copy link
Member

Choose a reason for hiding this comment

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

Seems strange to me to set the contentType on createConnection and not on send. How can you know the content before you send ?

Copy link
Member

@fmeheust fmeheust left a comment

Choose a reason for hiding this comment

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

These are the rest of my comments for package hcpvaultdedicated.

OracleJsonObject secretJsonObj =
new OracleJsonFactory()
.createJsonTextValue(inputStream)
.asJsonObject();
Copy link
Member

Choose a reason for hiding this comment

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

Lines 97 - 103: isn't that what JsonUtil.parseJsonResponse does? Shouldn't it be used instead?

.request(parameters)
.getContent();

return new ByteArrayInputStream(secretString.getBytes());
Copy link
Member

Choose a reason for hiding this comment

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

In other places in the code UTF8 encoding has been used but not here, why?

}

@Override
public String getParserType(String arg0) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you give the correct name to the argument (even though it is not used)?

*/
private static String parseSecretJson(String secretJson, String secretPath) {
try (InputStream is = new ByteArrayInputStream(secretJson.getBytes(UTF_8))) {
OracleJsonObject rootObject = JSON_FACTORY.createJsonTextValue(is).asJsonObject();
Copy link
Member

Choose a reason for hiding this comment

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

Here again, is there a reason for creating JsonUtil.parseJsonResponse if it is not used?

* @throws IllegalArgumentException if the value is unrecognized.
*/
private static DedicatedVaultAuthenticationMethod parseAuthentication(String value) {
switch (value.toUpperCase()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you use DedicatedAuthenticationMethod.valueOf(String) instead?

/**
* The username for Userpass authentication. Required for Userpass method.
*/
public static final Parameter<String> USERNAME = Parameter.create(REQUIRED);
Copy link
Member

Choose a reason for hiding this comment

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

Why are all authentication parameters declared here, if they are never used in this class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants