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

Fix OCI config file configuration #823

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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 @@ -15,6 +15,7 @@
*/
package io.micronaut.oraclecloud.core;

import io.micronaut.context.annotation.BootstrapContextCompatible;
import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.util.Toggleable;
Expand All @@ -25,15 +26,16 @@
* Configuration properties for the local OCI config file (eg: {@code $USE_HOME/.oci/config}).
*
* @param profile The profile to use.
* @param configPath A custom path for the OCI configuration file.
* @param path A custom path for the OCI configuration file.
* @param enabled Whether to enable or disable using the OCI configuration file.
* @param sessionToken Whether to enable the configuration of a {@link com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider}.
*
* @author Álvaro Sánchez-Mariscal
* @since 3.6.0
*/
@ConfigurationProperties(PREFIX)
public record OracleCloudConfigFileConfigurationProperties(@Nullable String profile, @Nullable String configPath, @Nullable Boolean enabled, @Nullable Boolean sessionToken) implements Toggleable {
@BootstrapContextCompatible
public record OracleCloudConfigFileConfigurationProperties(@Nullable String profile, @Nullable String path, @Nullable Boolean enabled, @Nullable Boolean sessionToken) implements Toggleable {

public static final String PREFIX = OracleCloudCoreFactory.ORACLE_CLOUD + ".config";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class OracleCloudCoreFactory {

public static final String OKE_WORKLOAD_IDENTITY_PREFIX = OracleCloudCoreFactory.ORACLE_CLOUD + ".config.oke-workload-identity";

private final OracleCloudConfigFileConfigurationProperties ociConfigFileConfiguration;
private OracleCloudConfigFileConfigurationProperties ociConfigFileConfiguration;

/**
* @param profile The configured profile
Expand All @@ -93,7 +93,7 @@ protected OracleCloudCoreFactory(@Nullable @Property(name = ORACLE_CLOUD + ".con
* @param ociConfigFileConfiguration The OCI config file configuration properties
*/
@Inject
protected OracleCloudCoreFactory(OracleCloudConfigFileConfigurationProperties ociConfigFileConfiguration) {
protected OracleCloudCoreFactory(@Nullable OracleCloudConfigFileConfigurationProperties ociConfigFileConfiguration) {
this.ociConfigFileConfiguration = ociConfigFileConfiguration;
}

Expand Down Expand Up @@ -271,13 +271,15 @@ protected SessionTokenAuthenticationDetailsProvider sessionTokenAuthenticationDe
* @return The configured profile.
*/
public Optional<String> getProfile() {
return Optional.ofNullable(ociConfigFileConfiguration.profile());
return Optional.ofNullable(ociConfigFileConfiguration)
.map(OracleCloudConfigFileConfigurationProperties::profile);
}

/**
* @return The configured config path.
*/
public Optional<String> getConfigPath() {
return Optional.ofNullable(ociConfigFileConfiguration.configPath());
return Optional.ofNullable(ociConfigFileConfiguration)
.map(OracleCloudConfigFileConfigurationProperties::path);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package io.micronaut.discovery.cloud
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider
import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider
import io.micronaut.context.ApplicationContext
import io.micronaut.context.env.Environment
import io.micronaut.oraclecloud.core.OracleCloudConfigFileConfigurationProperties
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.TempDir

import java.nio.file.Path

import static io.micronaut.oraclecloud.core.OracleCloudCoreFactory.ORACLE_CLOUD_CONFIG_PATH


class OracleCloudConfigFileConfigurationPropertiesSpec extends Specification {

Expand Down Expand Up @@ -40,7 +41,7 @@ security_token_file=${testPath}/oci_api_key.pem
void 'it is enabled by default'() {
given:
def ctx = ApplicationContext.run([
(OracleCloudConfigFileConfigurationProperties.PREFIX + ".config-path"): ociConfig.absolutePath
(ORACLE_CLOUD_CONFIG_PATH): ociConfig.absolutePath
])

expect:
Expand All @@ -54,7 +55,7 @@ security_token_file=${testPath}/oci_api_key.pem
void 'it can be disabled even if config file exists'() {
given:
def ctx = ApplicationContext.run([
(OracleCloudConfigFileConfigurationProperties.PREFIX + ".config-path"): ociConfig.absolutePath,
(ORACLE_CLOUD_CONFIG_PATH): ociConfig.absolutePath,
(OracleCloudConfigFileConfigurationProperties.PREFIX + ".enabled"): false
])

Expand All @@ -69,7 +70,7 @@ security_token_file=${testPath}/oci_api_key.pem
void 'it can enable session token authentication'() {
given:
def ctx = ApplicationContext.run([
(OracleCloudConfigFileConfigurationProperties.PREFIX + ".config-path"): ociConfig.absolutePath,
(ORACLE_CLOUD_CONFIG_PATH): ociConfig.absolutePath,
(OracleCloudConfigFileConfigurationProperties.PREFIX + ".session-token"): true
])

Expand Down
Loading