Skip to content

Commit

Permalink
fix: Made config values optional to avoid troubles with native build. (
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniotarricone authored Aug 9, 2024
1 parent 3db062b commit 7584d2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package it.pagopa.swclient.mil.azureservices.identity.client.systemmanaged;

import java.net.URI;
import java.util.Optional;

import org.eclipse.microprofile.config.inject.ConfigProperty;

Expand Down Expand Up @@ -44,10 +45,10 @@ public class AzureSystemManagedIdentityClient implements AzureIdentityClient {
*
* @param identityEndpoint Endpoint to get access token by means of system managed identity
*/
AzureSystemManagedIdentityClient(@ConfigProperty(name = "IDENTITY_ENDPOINT", defaultValue = "") String identityEndpoint) {
AzureSystemManagedIdentityClient(@ConfigProperty(name = "IDENTITY_ENDPOINT") Optional<String> identityEndpoint) {
Log.trace("Azure System Managed Identity client initialization");
restClient = QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(identityEndpoint))
.baseUri(URI.create(identityEndpoint.orElseThrow()))
.build(AzureSystemManagedIdentityRestClient.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package it.pagopa.swclient.mil.azureservices.identity.client.workload;

import java.net.URI;
import java.util.Optional;

import org.eclipse.microprofile.config.inject.ConfigProperty;

Expand Down Expand Up @@ -45,11 +46,11 @@ public class AzureWorkloadIdentityClient implements AzureIdentityClient {
* @param tenantId Tenant ID
*/
AzureWorkloadIdentityClient(
@ConfigProperty(name = "AZURE_AUTHORITY_HOST", defaultValue = "") String authorityHost,
@ConfigProperty(name = "AZURE_TENANT_ID", defaultValue = "") String tenantId) {
@ConfigProperty(name = "AZURE_AUTHORITY_HOST") Optional<String> authorityHost,
@ConfigProperty(name = "AZURE_TENANT_ID") Optional<String> tenantId) {
Log.trace("Azure Workload Identity client initialization");
restClient = QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(authorityHost + tenantId))
.baseUri(URI.create(authorityHost.orElseThrow() + tenantId.orElseThrow()))
.build(AzureWorkloadIdentityRestClient.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URI;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -83,7 +84,7 @@ void given_requestToGetAccessToken_when_requestIsDone_then_returnAccessToken() {
/*
* Test.
*/
AzureSystemManagedIdentityClient client = new AzureSystemManagedIdentityClient("https://login.microsoftonline.com/");
AzureSystemManagedIdentityClient client = new AzureSystemManagedIdentityClient(Optional.of("https://login.microsoftonline.com/"));
client.getAccessToken(Scope.STORAGE)
.subscribe()
.withSubscriber(UniAssertSubscriber.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.URI;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -84,8 +85,8 @@ void given_requestToGetAccessToken_when_requestIsDone_then_returnAccessToken() {
* Test.
*/
AzureWorkloadIdentityClient client = new AzureWorkloadIdentityClient(
"https://login.microsoftonline.com/",
"da795842-fa15-4fd4-b556-f371ac9bafed");
Optional.of("https://login.microsoftonline.com/"),
Optional.of("da795842-fa15-4fd4-b556-f371ac9bafed"));
client.getAccessToken(Scope.STORAGE)
.subscribe()
.withSubscriber(UniAssertSubscriber.create())
Expand Down

0 comments on commit 7584d2f

Please sign in to comment.