Skip to content

Commit

Permalink
Merge pull request #581 from pdowler/master
Browse files Browse the repository at this point in the history
vault: implement pass through params on files endpoint
  • Loading branch information
pdowler authored May 3, 2024
2 parents 2c04674 + a5993bd commit ccea9ef
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
2 changes: 1 addition & 1 deletion vault/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# tags with and without build number so operators use the versioned
# tag but we always keep a timestamped tag in case a semantic tag gets
# replaced accidentally
VER=1.0.4
VER=1.0.5
TAGS="${VER} ${VER}-$(date --utc +"%Y%m%dT%H%M%S")"
unset VER
2 changes: 1 addition & 1 deletion vault/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
runtime 'org.opencadc:cadc-gms:[1.0.5,)'

intTestCompile 'org.opencadc:cadc-test-vosi:[1.0.11,)'
intTestCompile 'org.opencadc:cadc-test-vos:[2.1.6,)'
intTestCompile 'org.opencadc:cadc-test-vos:[2.1.9,)'
}

configurations {
Expand Down
4 changes: 1 addition & 3 deletions vault/src/intTest/java/org/opencadc/vault/FilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@

package org.opencadc.vault;

import ca.nrc.cadc.util.FileUtil;
import ca.nrc.cadc.util.Log4jInit;
import java.io.File;
import java.net.URI;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

Expand All @@ -91,5 +88,6 @@ public FilesTest() {
super(Constants.RESOURCE_ID, Constants.ADMIN_CERT);

enableTestDataNodePermission(Constants.ALT_CERT);
enableTestPassthroughParams(true);
}
}
7 changes: 4 additions & 3 deletions vault/src/main/java/org/opencadc/vault/VaultInitAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private void initBackgroundWorkers() {
if (str != null) {
boolean enableDataNodeSizeWorker = Boolean.valueOf(str);
if (!enableDataNodeSizeWorker) {
log.info("initBackgroundWorkers: DataNodeSizeWorker disabled");
log.info("initBackgroundWorkers: " + DataNodeSizeSync.class.getSimpleName() + " disabled");
return;
}
}
Expand Down Expand Up @@ -505,6 +505,7 @@ private void initBackgroundWorkers() {
async.setOffline(offline);
this.dataNodeSizeSyncThread = new Thread(async);
dataNodeSizeSyncThread.setDaemon(true);
dataNodeSizeSyncThread.setName(DataNodeSizeSync.class.getSimpleName());
dataNodeSizeSyncThread.start();

// store in JNDI so availability can set offline
Expand All @@ -513,10 +514,10 @@ private void initBackgroundWorkers() {
try {
ctx.unbind(jndiDataNodeSizeSync);
} catch (NamingException ignore) {
log.debug("unbind previous JNDI key (" + jndiPreauthKeys + ") failed... ignoring");
log.debug("unbind previous JNDI key (" + jndiDataNodeSizeSync + ") failed... ignoring");
}
ctx.bind(jndiDataNodeSizeSync, async);
log.info("initBackgroundWorkers: created JNDI key: " + jndiDataNodeSizeSync);
log.info("initBackgroundWorkers: " + DataNodeSizeSync.class.getSimpleName() + " enabled; created JNDI key: " + jndiDataNodeSizeSync);
} catch (Exception ex) {
throw new RuntimeException("check/init ArtifactSync failed", ex);
}
Expand Down
34 changes: 32 additions & 2 deletions vault/src/main/java/org/opencadc/vault/files/GetAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.net.TransientException;
import java.net.HttpURLConnection;
import java.util.List;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Iterator;
import javax.security.auth.Subject;
import org.apache.log4j.Logger;
import org.opencadc.vault.VaultTransferGenerator;
Expand Down Expand Up @@ -129,9 +131,37 @@ public void doAction() throws Exception {
throw new TransientException("No location found for file " + Utils.getPath(node));
}
Protocol proto = rn.protos.get(0);
String loc = proto.getEndpoint();
URI redirect = URI.create(proto.getEndpoint());
String loc = appendParams(redirect);
log.debug("Location: " + loc);
syncOutput.setHeader("Location", loc);
syncOutput.setCode(HttpURLConnection.HTTP_SEE_OTHER);
}

// pass through request params to minoc
// TODO: this makes slightly better use of the StringBuilder than the code in raven
// should put this method into cadc-inventory-server, static in ProtocolsGenerator?
String appendParams(URI redirect) throws Exception {
StringBuilder sb = new StringBuilder();
for (String param : syncInput.getParameterNames()) {
Iterator<String> values = syncInput.getParameters(param).iterator();
while (values.hasNext()) {
if (sb.length() > 0) {
sb.append("&");
}
sb.append(param);
sb.append("=");
sb.append(URLEncoder.encode(values.next(), "UTF-8"));
}
}
if (sb.length() > 0) {
if (redirect.getQuery() != null) {
sb.insert(0, "&");
} else {
sb.insert(0, "?");
}
}
sb.insert(0, redirect.toASCIIString());
return sb.toString();
}
}
45 changes: 45 additions & 0 deletions vault/src/main/webapp/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@ paths:
description: Service busy
default:
description: Unexpected error
parameters:
- name: SUB
in: query
description: 'PROTOTYPE: SUB-region of a FITS file image using cfitsio syntax. Multiple SUB parameters are allowed and will generate MEF output in file order. Examples: entire extensions (SUB=[1]&SUB=[SCI,2]), or more general purpose (SUB=[SCI,3][400:500]).'
required: false
type: string
collectionFormat: multi
- name: POS
in: query
description: The positional regions to be extracted from the data (SODA-1.0).
required: false
type: string
- name: CIRCLE
in: query
description: The spatial region using the CIRCLE xtype defined in DALI (SODA-1.0).
required: false
type: string
- name: POLYGON
in: query
description: The spatial region using the POLYGON xtype defined in DALI (SODA-1.0).
required: false
type: string
- name: BAND
in: query
description: The wavelength interval(s) using the INTERVAL xtype defined in DALI (SODA-1.0).
required: false
type: string
- name: TIME
in: query
description: The time interval(s) using the INTERVAL xtype defined in DALI (SODA-1.0).
required: false
type: string
- name: POL
in: query
type: array
collectionFormat: multi
items:
type: string
description: The polarization state(s) (Stokes), supports multiple values (SODA-1.0).
required: false
- name: META
in: query
description: 'PROTOTYPE: extract METAdata (headers) from a file. A single parameter META=true is supported for FITS files. Output will be a plain text rendition of the headers.'
required: false
type: boolean
head:
description: |
Get the metadata of the specified file.
Expand Down

0 comments on commit ccea9ef

Please sign in to comment.