Skip to content

Commit

Permalink
Use ResourceLoader for keys
Browse files Browse the repository at this point in the history
Spring's ResourceLoader supports prefixing with `classpath:`. This way
we can use the `resources` directory locally but something else in k8s.
  • Loading branch information
zechmeister committed Oct 29, 2024
1 parent 514265d commit 6c12441
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;

@Configuration
public class FitConnectConfig {
private final ResourceLoader resourceLoader;

@Value("${fitConnect.sender.clientId}")
String senderClientId;

Expand All @@ -39,6 +41,10 @@ public class FitConnectConfig {
@Value("${fitConnect.subscriber.privateSigningKeyPath}")
String subscriberPrivateSigningKeyPath;

public FitConnectConfig(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

@Bean
public SenderClient senderClient() {
SenderConfig senderConfig =
Expand Down Expand Up @@ -73,7 +79,8 @@ public SubscriberClient subscriberClient() throws IOException, ParseException {
}

private JWK loadKey(String filePath) throws IOException, ParseException {
Path path = Paths.get(new ClassPathResource(filePath).getURI());
Resource resource = resourceLoader.getResource(filePath);
Path path = resource.getFile().toPath();
String jwkContent = Files.readString(path);

return JWK.parse(jwkContent);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-local.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ fitConnect:
subscriber:
clientId: subscriberClientId
clientSecret: s3cr3t
privateDecryptionKeyPath: decryption_key.json
privateSigningKeyPath: signing_key.json
privateDecryptionKeyPath: classpath:decryption_key.json
privateSigningKeyPath: classpath:signing_key.json
activeEnvironment: TEST
submission:
destination: destinationId
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ fitConnect:
subscriber:
clientId: subscriberClientId
clientSecret: s3cr3t
privateDecryptionKeyPath: decryption_key.json
privateSigningKeyPath: signing_key.json
privateDecryptionKeyPath: classpath:decryption_key.json
privateSigningKeyPath: classpath:signing_key.json
activeEnvironment: TEST
submission:
destination: destinationId
Expand Down

0 comments on commit 6c12441

Please sign in to comment.