Skip to content

Commit

Permalink
[#950] improvment(common): Add a method in ConfigEntry called create …
Browse files Browse the repository at this point in the history
…to support configurations with no default value
  • Loading branch information
Heng Qin committed Dec 13, 2023
1 parent 94aac03 commit 7d4ad6d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ConfigEntry<T> {
@Getter private boolean isDeprecated;

private boolean isOptional;
private boolean isNoDefault;

/**
* Creates a new ConfigEntry instance.
Expand Down Expand Up @@ -101,6 +102,11 @@ void setOptional() {
this.isOptional = true;
}

/** Marks this configuration as no default value. */
void setNoDefault() {
this.isNoDefault = true;
}

/**
* Creates a new ConfigEntry instance based on this configuration entry with a default value.
*
Expand Down Expand Up @@ -134,6 +140,20 @@ public ConfigEntry<Optional<T>> createWithOptional() {
return conf;
}

/**
* Creates a new ConfigEntry instance based on this configuration entry with no default value.
*
* @return A new ConfigEntry instance with no default value.
*/
public ConfigEntry<T> createWithNoDefault() {
ConfigEntry<T> conf =
new ConfigEntry<>(key, version, doc, alternatives, isPublic, isDeprecated);
conf.setValueConverter(valueConverter);
conf.setStringConverter(stringConverter);
conf.setNoDefault();
return conf;
}

/**
* Reads the configuration value.
*
Expand All @@ -155,6 +175,8 @@ public T readFrom(Map<String, String> properties) throws NoSuchElementException
if (value == null) {
if (defaultValue != null) {
return defaultValue;
} else if (isNoDefault) {
return null;
} else if (!isOptional) {
throw new NoSuchElementException("No configuration found for key " + key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface OAuthConfig extends Configs {
.doc("The signing key of JWT when Gravitino uses OAuth as the authenticator")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

ConfigEntry<String> SIGNATURE_ALGORITHM_TYPE =
new ConfigBuilder(OAUTH_CONFIG_PREFIX + "signAlgorithmType")
Expand All @@ -47,12 +47,12 @@ public interface OAuthConfig extends Configs {
.doc("The uri of the default OAuth server")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

ConfigEntry<String> DEFAULT_TOKEN_PATH =
new ConfigBuilder(OAUTH_CONFIG_PREFIX + "tokenPath")
.doc("The path for token of the default OAuth server")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ public final class JettyServerConfig {
.doc("Path to the key store file")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

public static final ConfigEntry<String> SSL_KEYSTORE_PASSWORD =
new ConfigBuilder("keyStorePassword")
.doc("Password to the key store")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

public static final ConfigEntry<String> SSL_MANAGER_PASSWORD =
new ConfigBuilder("managerPassword")
.doc("Manager password to the key store")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

public static final ConfigEntry<String> SSL_KEYSTORE_TYPE =
new ConfigBuilder("keyStoreType")
Expand Down Expand Up @@ -155,14 +155,14 @@ public final class JettyServerConfig {
.doc("Path to the trust store file")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

public static final ConfigEntry<String> SSL_TRUST_STORE_PASSWORD =
new ConfigBuilder("trustStorePassword")
.doc("Password to the trust store")
.version("0.3.0")
.stringConf()
.createWithDefault("");
.createWithNoDefault();

public static final ConfigEntry<String> SSL_TRUST_STORE_TYPE =
new ConfigBuilder("trustStoreType")
Expand Down

0 comments on commit 7d4ad6d

Please sign in to comment.