Skip to content

Commit

Permalink
Change gcp token creation to use Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
collado-mike committed Oct 15, 2024
1 parent 48433d5 commit 77fdb2f
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -217,15 +218,17 @@ public void setDefaultRealms(List<String> defaultRealms) {
}

public Supplier<GoogleCredentials> getGcpCredentialsProvider() {
return gcpAccessToken != null
? () -> GoogleCredentials.create(gcpAccessToken)
: () -> {
try {
return GoogleCredentials.getApplicationDefault();
} catch (IOException e) {
throw new RuntimeException("Failed to get GCP credentials", e);
}
};
return () ->
Optional.ofNullable(gcpAccessToken)
.map(GoogleCredentials::create)
.orElseGet(
() -> {
try {
return GoogleCredentials.getApplicationDefault();
} catch (IOException e) {
throw new RuntimeException("Failed to get GCP credentials", e);
}
});
}

@JsonProperty("gcp_credentials")
Expand Down

0 comments on commit 77fdb2f

Please sign in to comment.