Skip to content

Commit

Permalink
added API endpoint for listing all available config properties
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Apr 22, 2022
1 parent 6bc44ec commit f9139ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion para-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Default configuration file for PARA
para.security.protected.admin = ["/admin", "/admin/**", ["admin"]]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health"]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health", "/v1/_config/options"]
2 changes: 1 addition & 1 deletion para-jar/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ para.dao = "H2DAO"
para.search = "LuceneSearch"

para.security.protected.admin = ["/admin", "/admin/**", ["admin"]]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health"]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health", "/v1/_config/options"]
26 changes: 26 additions & 0 deletions para-server/src/main/java/com/erudika/para/server/rest/Api1.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ public Api1() {
idRes.addMethod(GET).produces(JSON).handledBy(readIdHandler());
registerResources(idRes.build());

Resource.Builder confRes = Resource.builder("_config");
confRes.addChildResource("options").addMethod(GET).produces(JSON).handledBy(configOptionsHandler());
registerResources(confRes.build());

// validation
Resource.Builder valRes = Resource.builder("_constraints");
valRes.addMethod(GET).produces(JSON).handledBy(getConstrHandler(null));
Expand Down Expand Up @@ -511,6 +515,28 @@ public Response apply(ContainerRequestContext ctx) {
};
}

/**
* @return response
*/
public static Inflector<ContainerRequestContext, Response> configOptionsHandler() {
return new Inflector<ContainerRequestContext, Response>() {
public Response apply(ContainerRequestContext ctx) {
String format = queryParam("format", ctx);
String groupby = queryParam("groupby", ctx);
String type = "text/plain";
if ("markdown".equalsIgnoreCase(format)) {
type = "text/markdown";
} else if ("hocon".equalsIgnoreCase(format)) {
type = "application/hocon";
} else if (StringUtils.isBlank(format) || "json".equalsIgnoreCase(format)) {
type = "application/json";
}
return Response.ok(Para.getConfig().renderConfigDocumentation(format,
StringUtils.isBlank(groupby) || "category".equalsIgnoreCase(groupby)), type).build();
}
};
}

/**
* @param a {@link App}
* @return response
Expand Down
2 changes: 1 addition & 1 deletion para-war/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ para.dao = "H2DAO"
para.search = "LuceneSearch"

para.security.protected.admin = ["/admin", "/admin/**", ["admin"]]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health"]
para.security.ignored = ["/", "/images/**", "/styles/**", "/scripts/**", "/v1/_setup", "/v1/_health", "/v1/_config/options"]

0 comments on commit f9139ec

Please sign in to comment.