Skip to content

Commit

Permalink
Include plugin configs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek3255 committed Feb 20, 2024
1 parent 355cadd commit 169c594
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
48 changes: 35 additions & 13 deletions src/main/java/io/supertokens/config/CoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import io.supertokens.cliOptions.CLIOptions;
import io.supertokens.config.annotations.ConfigDescription;
import io.supertokens.config.annotations.ConfigYamlOnly;
import io.supertokens.config.annotations.DifferentAcrossTenants;
import io.supertokens.config.annotations.EnumProperty;
import io.supertokens.config.annotations.IgnoreForAnnotationCheck;
import io.supertokens.config.annotations.NotConflictingInApp;
import io.supertokens.pluginInterface.LOG_LEVEL;
import io.supertokens.pluginInterface.exceptions.InvalidConfigException;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.utils.SemVer;
import io.supertokens.webserver.Utils;
import io.supertokens.webserver.WebserverAPI;
Expand Down Expand Up @@ -77,37 +77,31 @@ public class CoreConfig {

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("Time in milliseconds for how long a password reset token / link is valid for. [Default: 3600000 (1 hour)]")
private long password_reset_token_lifetime = 3600000; // in MS

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("Time in milliseconds for how long an email verification token / link is valid for. [Default: 24 * 3600 * 1000 (1 day)]")
private long email_verification_token_lifetime = 24 * 3600 * 1000; // in MS

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("The maximum number of code input attempts per login before the user needs to restart. (Default: 5)")
private int passwordless_max_code_input_attempts = 5;

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("Time in milliseconds for how long a passwordless code is valid for. [Default: 900000 (15 mins)]")
private long passwordless_code_lifetime = 900000; // in MS

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("The maximum number of invalid TOTP attempts that will trigger rate limiting. (Default: 5)")
private int totp_max_attempts = 5;

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("The time in seconds for which the user will be rate limited once totp_max_attempts is crossed. [Default: 900 (15 mins)]")
private int totp_rate_limit_cooldown_sec = 900; // in seconds (Default 15 mins)

Expand Down Expand Up @@ -226,13 +220,11 @@ public class CoreConfig {

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("Regex for allowing requests from IP addresses that match with the value. For example, use the value of 127\\.\\d+\\.\\d+\\.\\d+|::1|0:0:0:0:0:0:0:1 to allow only localhost to query the core")
private String ip_allow_regex = null;

@IgnoreForAnnotationCheck
@JsonProperty
@DifferentAcrossTenants
@ConfigDescription("Regex for denying requests from IP addresses that match with the value. Comment this value to deny no IP address.")
private String ip_deny_regex = null;

Expand Down Expand Up @@ -638,6 +630,29 @@ void normalizeAndValidate(Main main, boolean includeConfigFilePath) throws Inval
}
}

try {
String[] allowedPasswordHashingAlgos = CoreConfig.class.getDeclaredField("password_hashing_alg")
.getAnnotation(EnumProperty.class).value();

if (!Arrays.asList(allowedPasswordHashingAlgos).contains(password_hashing_alg)) {
throw new InvalidConfigException("password_hashing_alg property is not set correctly");
}
} catch (NoSuchFieldException e) {
throw new InvalidConfigException("password_hashing_alg field not found");
}

try {
String[] allowedLogLevels = CoreConfig.class.getDeclaredField("log_level")
.getAnnotation(EnumProperty.class).value();

if (!Arrays.asList(allowedLogLevels).contains(log_level)) {
throw new InvalidConfigException("log_level property is not set correctly");
}
} catch (NoSuchFieldException e) {
throw new InvalidConfigException("log_level field not found");
}


// Normalize
if (ip_allow_regex != null) {
ip_allow_regex = ip_allow_regex.trim();
Expand Down Expand Up @@ -727,8 +742,8 @@ void normalizeAndValidate(Main main, boolean includeConfigFilePath) throws Inval

if (supertokens_saas_load_only_cud != null) {
try {
supertokens_saas_load_only_cud =
Utils.normalizeAndValidateConnectionUriDomain(supertokens_saas_load_only_cud, true);
supertokens_saas_load_only_cud = Utils
.normalizeAndValidateConnectionUriDomain(supertokens_saas_load_only_cud, true);
} catch (ServletException e) {
throw new InvalidConfigException("supertokens_saas_load_only_cud is invalid");
}
Expand Down Expand Up @@ -779,7 +794,7 @@ static void assertThatCertainConfigIsNotSetForAppOrTenants(JsonObject config) th
}
}

public static JsonArray getConfigFieldsJson() {
public static JsonArray getConfigFieldsJson(Main main) {
JsonArray result = new JsonArray();

for (String fieldId : CoreConfig.getValidFields()) {
Expand All @@ -797,7 +812,7 @@ public static JsonArray getConfigFieldsJson() {
? field.getAnnotation(ConfigDescription.class).value()
: "");
fieldJson.addProperty("isDifferentAcrossTenants",
field.isAnnotationPresent(DifferentAcrossTenants.class));
!field.isAnnotationPresent(NotConflictingInApp.class));

String type = "string";

Expand All @@ -824,6 +839,13 @@ public static JsonArray getConfigFieldsJson() {
continue;
}
}

JsonArray storageFields = StorageLayer.getBaseStorage(main).getConfigFieldsJson();

for (JsonElement field : storageFields) {
result.add(field);
}

return result;
}

Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/java/io/supertokens/inmemorydb/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.supertokens.inmemorydb;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.supertokens.Main;
import io.supertokens.ProcessState;
Expand Down Expand Up @@ -2758,6 +2759,11 @@ public Set<String> getValidFieldsInConfig() {
return SQLiteConfig.getValidFields();
}

@Override
public JsonArray getConfigFieldsJson() {
return new JsonArray();
}

@Override
public void setLogLevels(Set<LOG_LEVEL> logLevels) {
Config.setLogLevels(this, logLevels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected boolean checkAPIKey(HttpServletRequest req) {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
JsonArray config = CoreConfig.getConfigFieldsJson();
JsonArray config = CoreConfig.getConfigFieldsJson(main);
JsonObject result = new JsonObject();
result.addProperty("status", "OK");
result.add("config", config);
Expand Down

0 comments on commit 169c594

Please sign in to comment.