-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
AppConfigDataClient
in AWS SDK (#60)
- Loading branch information
1 parent
5f1c8a8
commit c708115
Showing
18 changed files
with
1,024 additions
and
20 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
40 changes: 40 additions & 0 deletions
40
...main/java/io/github/lavenderses/aws_app_config_openfeature_provider/model/Credential.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,40 @@ | ||
package io.github.lavenderses.aws_app_config_openfeature_provider.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A class to mask secret string to avoid it appeared in logging or something. | ||
* This works completely exactly except {@code toString} method. For example, comparison or equality. | ||
*/ | ||
@Getter | ||
@AllArgsConstructor | ||
@Builder(toBuilder = true) | ||
public final class Credential implements Comparable<Credential> { | ||
|
||
@NotNull | ||
@NonNull | ||
private final String rawValue; | ||
|
||
@Override | ||
public String toString() { | ||
return "Masked credentials(***)"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof Credential credential) { | ||
return rawValue.equals(credential.rawValue); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int compareTo(@NotNull Credential o) { | ||
return rawValue.compareTo(o.rawValue); | ||
} | ||
} |
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
85 changes: 85 additions & 0 deletions
85
..._config_openfeature_provider/proxy/appconfig_data_client/AwsAppConfigDataClientProxy.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,85 @@ | ||
package io.github.lavenderses.aws_app_config_openfeature_provider.proxy.appconfig_data_client; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.github.lavenderses.aws_app_config_openfeature_provider.AwsAppConfigClientOptions; | ||
import io.github.lavenderses.aws_app_config_openfeature_provider.app_config_model.AppConfigValue; | ||
import io.github.lavenderses.aws_app_config_openfeature_provider.proxy.AbstractAwsAppConfigProxy; | ||
import io.github.lavenderses.aws_app_config_openfeature_provider.proxy.config.AwsAppConfigDataClientProxyConfig; | ||
import jakarta.annotation.PreDestroy; | ||
import org.intellij.lang.annotations.Language; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jetbrains.annotations.VisibleForTesting; | ||
import software.amazon.awssdk.services.appconfigdata.AppConfigDataClient; | ||
|
||
import static java.util.Objects.isNull; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Provider implementation proxy for accessing AWS AppConfig instance via AWS AppConfig client from SDK. | ||
* <br/> | ||
* You can use this with the client instance you prepared. Or just pass the configuration class, then this class creates | ||
* and manages it. | ||
*/ | ||
public final class AwsAppConfigDataClientProxy extends AbstractAwsAppConfigProxy { | ||
|
||
private final CachedFeatureFlagManager cachedFeatureFlagManager; | ||
|
||
@VisibleForTesting | ||
AwsAppConfigDataClientProxy( | ||
@NotNull final CachedFeatureFlagManager cachedFeatureFlagManager | ||
) { | ||
super(); | ||
|
||
this.cachedFeatureFlagManager = requireNonNull(cachedFeatureFlagManager, "cachedFeatureFlagManager"); | ||
} | ||
|
||
/** | ||
* Constructor for configuring {@link AppConfigDataClient} with your own configuration. | ||
* <br/> | ||
* When you use this constructor, this provider implementation library is responsible for closing | ||
* {@link AppConfigDataClient} resource. You don't have to worry about. | ||
* | ||
* @param config a configuration to {@link AppConfigDataClient} | ||
*/ | ||
public AwsAppConfigDataClientProxy( | ||
@NotNull final AwsAppConfigClientOptions options, | ||
@NotNull final AwsAppConfigDataClientProxyConfig config | ||
) { | ||
super(); | ||
|
||
cachedFeatureFlagManager = new CachedFeatureFlagManager( | ||
/* options = */ options, | ||
/* config = */ config, | ||
/* startSession = */ true | ||
); | ||
} | ||
|
||
@PreDestroy | ||
@Override | ||
public void close() throws Exception { | ||
cachedFeatureFlagManager.close(); | ||
} | ||
|
||
/** | ||
* Get the feature flag value as JSON schema (see {@link AppConfigValue} for the schema).<br/> | ||
* Note that return value is not validated, this is just raw value from AWS AppConfig. | ||
* | ||
* @param key feature flag key | ||
* @return JSON schema response from AWS AppConfigInstance | ||
*/ | ||
@Language("json") | ||
@Nullable | ||
@Override | ||
public String getRawFlagObject(@NotNull final String key) { | ||
final JsonNode featureFlagJsonValue = cachedFeatureFlagManager.getCachedFeatureFlagByKeyFrom( | ||
/* key = */ requireNonNull(key, "key") | ||
); | ||
|
||
if (isNull(featureFlagJsonValue)) { | ||
return null; | ||
} else { | ||
return featureFlagJsonValue.toString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.