-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for RabbitMQ dynamic credentials from Vault
- Loading branch information
Showing
19 changed files
with
643 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../java/io/quarkus/smallrye/reactivemessaging/rabbitmq/runtime/CredentialsProviderLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.quarkus.smallrye.reactivemessaging.rabbitmq.runtime; | ||
|
||
import static io.quarkus.credentials.CredentialsProvider.EXPIRATION_TIMESTAMP_PROPERTY_NAME; | ||
import static io.quarkus.credentials.CredentialsProvider.PASSWORD_PROPERTY_NAME; | ||
import static io.quarkus.credentials.CredentialsProvider.USER_PROPERTY_NAME; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Map; | ||
|
||
import io.quarkus.credentials.CredentialsProvider; | ||
|
||
public class CredentialsProviderLink implements com.rabbitmq.client.impl.CredentialsProvider { | ||
|
||
private final CredentialsProvider credentialsProvider; | ||
private final String credentialsProviderName; | ||
private String username; | ||
private String password; | ||
private Instant expiresAt; | ||
|
||
public CredentialsProviderLink(CredentialsProvider credentialsProvider, String credentialsProviderName) { | ||
this.credentialsProvider = credentialsProvider; | ||
this.credentialsProviderName = credentialsProviderName; | ||
this.expiresAt = Instant.MIN; | ||
} | ||
|
||
private void refreshIfExpired() { | ||
if (expiresAt.isAfter(Instant.now())) { | ||
return; | ||
} | ||
refresh(); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
refreshIfExpired(); | ||
return username; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
refreshIfExpired(); | ||
return password; | ||
} | ||
|
||
@Override | ||
public Duration getTimeBeforeExpiration() { | ||
return Duration.between(Instant.now(), expiresAt); | ||
} | ||
|
||
@Override | ||
public void refresh() { | ||
Map<String, String> credentials = credentialsProvider.getCredentials(credentialsProviderName); | ||
username = credentials.get(USER_PROPERTY_NAME); | ||
password = credentials.get(PASSWORD_PROPERTY_NAME); | ||
expiresAt = Instant.parse(credentials.getOrDefault(EXPIRATION_TIMESTAMP_PROPERTY_NAME, getDefaultExpiresAt())); | ||
} | ||
|
||
private String getDefaultExpiresAt() { | ||
return Instant.now().plusSeconds(10).toString(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rc/main/java/io/quarkus/smallrye/reactivemessaging/rabbitmq/runtime/RabbitMQRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.smallrye.reactivemessaging.rabbitmq.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.credentials.CredentialsProvider; | ||
import io.quarkus.credentials.runtime.CredentialsProviderFinder; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class RabbitMQRecorder { | ||
|
||
public RuntimeValue<CredentialsProviderLink> configureOptions(String credentialsProviderName, | ||
Optional<String> credentialsProviderBeanName) { | ||
|
||
CredentialsProvider credentialsProvider = CredentialsProviderFinder.find(credentialsProviderBeanName.orElse(null)); | ||
|
||
return new RuntimeValue<>(new CredentialsProviderLink(credentialsProvider, credentialsProviderName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.