-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support lazy SecretKeysHandlers (#961)
- Loading branch information
Showing
4 changed files
with
109 additions
and
56 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
31 changes: 31 additions & 0 deletions
31
implementation/src/main/java/io/smallrye/config/SecretKeysHandlerFactory.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 |
---|---|---|
@@ -1,10 +1,41 @@ | ||
package io.smallrye.config; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import io.smallrye.common.annotation.Experimental; | ||
|
||
@Experimental("") | ||
public interface SecretKeysHandlerFactory { | ||
SecretKeysHandler getSecretKeysHandler(ConfigSourceContext context); | ||
|
||
String getName(); | ||
|
||
class LazySecretKeysHandler implements SecretKeysHandler { | ||
private final SecretKeysHandlerFactory factory; | ||
private final AtomicReference<SecretKeysHandler> handler = new AtomicReference<>(); | ||
|
||
public LazySecretKeysHandler(final SecretKeysHandlerFactory factory) { | ||
this.factory = factory; | ||
} | ||
|
||
public SecretKeysHandler get(ConfigSourceContext configSourceContext) { | ||
if (handler.get() == null) { | ||
handler.compareAndSet(null, factory.getSecretKeysHandler(configSourceContext)); | ||
} | ||
return handler.get(); | ||
} | ||
|
||
@Override | ||
public String decode(final String secret) { | ||
if (handler.get() == null) { | ||
throw new IllegalStateException(); | ||
} | ||
return handler.get().decode(secret); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return factory.getName(); | ||
} | ||
} | ||
} |
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