Skip to content

Commit

Permalink
youcat: fix init to make admin fully optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Jul 18, 2024
1 parent 3ccfcbf commit e45731b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
14 changes: 7 additions & 7 deletions youcat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ See <a href="https://github.com/opencadc/tap/tree/master/cadc-tap-tmp">cadc-tap-

The youcat.properties configures some admin and optional functions of the service.
```
# configure the admin user
# (optional) configure the admin user
org.opencadc.youcat.adminUser = {identity}
# (optional) configure schema creation in the database (default: false)
# (optional) schema creation in the database (default: false)
org.opencadc.youcat.createSchemaInDB = true|false
```
The admin user can use the youcat API to create a new schema for a user. This will add the
schema to the `tap_schema.schemas` table and enable the user to create tables in that
schema. If the optional _createSchemaInDB_ flag is set to true, a schema created by admin
will be created in the database in addition to being added to the `tap_schema`. If false,
`youcat` will not create the schema in the database and just assume it exists and that the
`tapadm` pool has permission to create objects (tables and indices) in it.
schema to the `tap_schema.schemas` table with the specified owner and enable the owner to
further manage that schema. If the optional _createSchemaInDB_ flag is set to true, a schema
created by admin will be created in the database in addition to being added to the `tap_schema`.
If false, `youcat` will not create the schema in the database and just assume it exists and
that the `tapadm` pool has permission to create objects (tables and indices) in it.

As hard-coded behaviours of `youcat` are extracted from the build and made configurable,
the configuration options will usually be in this file (see **development plans** below).
Expand Down
22 changes: 12 additions & 10 deletions youcat/src/main/java/org/opencadc/youcat/YoucatInitAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ private void initConfig() {
sb.append("incomplete config: ");
boolean ok = true;

String username = mvp.getFirstPropertyValue(YOUCAT_ADMIN);
String adminUser = mvp.getFirstPropertyValue(YOUCAT_ADMIN);
sb.append("\n\t" + YOUCAT_ADMIN + ": ");
if (username == null) {
if (adminUser == null) {
sb.append("MISSING");
ok = false;
} else {
sb.append("OK");
}
Expand All @@ -130,16 +129,19 @@ private void initConfig() {
throw new InvalidConfigException(sb.toString());
}

HttpPrincipal hp = new HttpPrincipal(username);
Boolean createSchemaInDB = true;
if (yc != null && "false".equals(yc)) {
createSchemaInDB = false;
Boolean createSchemaInDB = false; // default: false for backwards compat
if (yc != null && "true".equals(yc)) {
createSchemaInDB = true;
}
try {
Context ctx = new InitialContext();
ctx.bind(jndiAdminKey, hp);
ctx.bind(jndiCreateSchemaKey, createSchemaInDB);
log.info("init: admin=" + hp + " createSchemaInDB=" + createSchemaInDB);
if (adminUser != null) {
ctx.bind(jndiAdminKey, new HttpPrincipal(adminUser));
}
if (createSchemaInDB != null) {
ctx.bind(jndiCreateSchemaKey, createSchemaInDB);
}
log.info("init: admin=" + adminUser + " createSchemaInDB=" + createSchemaInDB);
} catch (Exception ex) {
log.error("Failed to create JNDI key(s): " + jndiAdminKey + "|" + jndiCreateSchemaKey, ex);
}
Expand Down

0 comments on commit e45731b

Please sign in to comment.