Skip to content

Commit

Permalink
Merge pull request #346 from ialarmedalien/kbase_test_token_env_var
Browse files Browse the repository at this point in the history
Check KBASE_TEST_TOKEN env var if no dev token is found
  • Loading branch information
sychan authored Feb 27, 2020
2 parents 8def489 + ef10268 commit 2ea5555
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ language: java
python:
- "2.7"

jdk:
- openjdk8

sudo: required

services:
Expand Down Expand Up @@ -42,4 +45,4 @@ script:
- make
- kb-sdk validate


5 changes: 2 additions & 3 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/sh

if [ "z$1" = "zshell" ] ; then
exec $DSHELL -l
elif [ "z$1" = "zsetup" ] ; then
cat << EOF
G=\$(docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls kbase/kb-sdk -l /var/run/docker.sock|awk '{print \$4}');
alias kb-sdk='docker run -it --rm -v \$HOME:\$HOME -u \$(id -u) -w \$(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=\$USER -e DSHELL=\$SHELL --group-add \$G kbase/kb-sdk'
alias kb-sdk='docker run -it --rm -v \$HOME:\$HOME -u \$(id -u) -w \$(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=\$USER -e DSHELL=\$SHELL -e KBASE_TEST_TOKEN=\$KBASE_TEST_TOKEN --group-add \$G kbase/kb-sdk'
EOF
elif [ "z$1" = "zgenscript" ] ; then
cat << EOF
Expand All @@ -16,7 +15,7 @@ if [ ! -e \$HOME/.kbsdk.cache ] ; then
docker run -i -v /var/run/docker.sock:/var/run/docker.sock --entrypoint ls kbase/kb-sdk -l /var/run/docker.sock|awk '{print \$4}' > \$HOME/.kbsdk.cache
fi
exec docker run -it --rm -v \$HOME:\$HOME -u \$(id -u) -w \$(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=\$USER -e DSHELL=\$SHELL --group-add \$(cat \$HOME/.kbsdk.cache) kbase/kb-sdk \$@
exec docker run -it --rm -v \$HOME:\$HOME -u \$(id -u) -w \$(pwd) -v /var/run/docker.sock:/var/run/docker.sock -e DUSER=\$USER -e DSHELL=\$SHELL -e KBASE_TEST_TOKEN=\$KBASE_TEST_TOKEN --group-add \$(cat \$HOME/.kbsdk.cache) kbase/kb-sdk \$@
EOF
elif [ "z$1" = "zsdkbase" ] || [ "z$1" = "zpull-base-image" ] ; then
echo "Pulling and tagging the base image"
Expand Down
41 changes: 23 additions & 18 deletions src/java/us/kbase/mobu/tester/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ConfigLoader {
private final String catalogUrl;
private final Map<String, String> secureCfgParams;

public ConfigLoader(Properties props, boolean testMode,
public ConfigLoader(Properties props, boolean testMode,
String configPathInfo, boolean tryHomeCfg) throws Exception {
if (configPathInfo == null) {
configPathInfo = "test_local/test.cfg";
Expand All @@ -47,7 +47,12 @@ public ConfigLoader(Properties props, boolean testMode,
String tokenString = props.getProperty(testPrefix + "token");
if (tokenString != null && tokenString.trim().isEmpty()) {
tokenString = null;
String test_token = System.getenv("KBASE_TEST_TOKEN");
if (test_token != null && !test_token.trim().isEmpty()) {
tokenString = test_token;
}
}

if (user == null && tokenString == null) {
throw new IllegalStateException("Error: KBase account credentials are not set in " +
configPathInfo);
Expand All @@ -60,7 +65,7 @@ public ConfigLoader(Properties props, boolean testMode,
token = auth.validateToken(tokenString);
} else {
if (password == null || password.trim().isEmpty()) {
System.out.println("You haven't preset your password in " +configPathInfo +
System.out.println("You haven't preset your password in " +configPathInfo +
" file. Please enter it now.");
password = new String(System.console().readPassword("Password: "));
}
Expand All @@ -86,51 +91,51 @@ public ConfigLoader(Properties props, boolean testMode,
}
}
}

public String getAuthUrl() {
return authUrl;
}

public String getAuthAllowInsecure() {
return authAllowInsecure;
}

public AuthToken getToken() {
return token;
}

public String getEndPoint() {
return endPoint;
}

public String getCatalogUrl() {
return catalogUrl;
}

public String getHandleUrl() {
return handleUrl;
}

public String getJobSrvUrl() {
return jobSrvUrl;
}

public String getNjswUrl() {
return njswUrl;
}

public String getShockUrl() {
return shockUrl;
}

public String getSrvWizUrl() {
return srvWizUrl;
}

public String getWsUrl() {
return wsUrl;
}

public void generateConfigProperties(File configPropsFile) throws Exception {
PrintWriter pw = new PrintWriter(configPropsFile);
try {
Expand All @@ -143,7 +148,7 @@ public void generateConfigProperties(File configPropsFile) throws Exception {
pw.println("srv_wiz_url = " + srvWizUrl);
pw.println("njsw_url = " + njswUrl);
pw.println("auth_service_url = " + authUrl);
pw.println("auth_service_url_allow_insecure = " +
pw.println("auth_service_url_allow_insecure = " +
(authAllowInsecure == null ? "false" : authAllowInsecure));
for (String param : secureCfgParams.keySet()) {
pw.println(param + " = " + secureCfgParams.get(param));
Expand All @@ -152,16 +157,16 @@ public void generateConfigProperties(File configPropsFile) throws Exception {
pw.close();
}
}

public CallbackServerConfig buildCallbackServerConfig(
URL callbackUrl, Path workDir, LineLogger logger) throws Exception {
return new CallbackServerConfigBuilder(
new URL(endPoint), new URL(wsUrl), new URL(shockUrl), new URL(jobSrvUrl),
new URL(handleUrl), new URL(srvWizUrl), new URL(njswUrl), new URL(authUrl),
authAllowInsecure, new URL(catalogUrl), callbackUrl, workDir, null, logger).build();
}
private static String getConfigUrl(Properties props, String key, String endPoint,

private static String getConfigUrl(Properties props, String key, String endPoint,
String defaultUrlSuffix) {
String ret = props.getProperty(key);
return ret == null ? (endPoint + "/" + defaultUrlSuffix) : ret;
Expand Down

0 comments on commit 2ea5555

Please sign in to comment.