Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/main/java/io/tiledb/cloud/TileDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TileDBClient{
private static String password;
private static String basePath;

private static boolean verifyingSsl = true;
private static boolean verifyingSsl;

private static boolean loginInfoIsInJSONFile;

Expand All @@ -42,8 +42,9 @@ public class TileDBClient{
apiKey = "";
username = "";
password = "";
basePath = "https://api.tiledb.com/v1";
basePath = "https://api.tiledb.com/v1"; //default is TileDB
loginInfoIsInJSONFile = true;
verifyingSsl = true;

// set path according to OS
if (System.getProperty("os.name").toLowerCase().contains("windows")){
Expand Down Expand Up @@ -99,6 +100,16 @@ private static boolean loadCloudJSONFileFromHome() throws IOException {
logger.log(Level.INFO, "Found verifySSL from disk");
}

if (object.has("host")){
String host = object.getString("host");
if (host.equals("https://api.tiledb.com")){
basePath = host + "/v1";
} else {
basePath = host;
}
logger.log(Level.INFO, "Found host from disk");
}

// check if credentials are adequate for logging in
if ((Objects.equals(apiKey, "") && (Objects.equals(password, "") && !Objects.equals(username, ""))
|| (Objects.equals(apiKey, "") && ((Objects.equals(password, "") || Objects.equals(username, "")))))){
Expand Down Expand Up @@ -132,6 +143,11 @@ private void findCredentials(TileDBLogin tileDBLogin) {
* @param tileDBLogin The Login object
*/
private void populateFieldsFromLogin(TileDBLogin tileDBLogin) {
if (!tileDBLogin.getHost().equals("")){
basePath = tileDBLogin.getHost();
} else {
basePath = "https://api.tiledb.com/v1";
}
apiKey = tileDBLogin.getApiKey();
username = tileDBLogin.getUsername();
password = tileDBLogin.getPassword();
Expand All @@ -155,7 +171,11 @@ private void writeAuthJSONFileToHome() {
jsonObject.put("api_key", apiKeyObject);
jsonObject.put("username", username);
jsonObject.put("password", password);
jsonObject.put("host", "https://api.tiledb.com");
if (basePath.equals("https://api.tiledb.com/v1")){
jsonObject.put("host", "https://api.tiledb.com");
}else{
jsonObject.put("host", basePath);
}
jsonObject.put("verify_ssl", verifyingSsl);
try {
File file = new File(homeDir + cloudFilePath);
Expand Down
45 changes: 44 additions & 1 deletion src/main/java/io/tiledb/cloud/TileDBLogin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.tiledb.cloud;

import io.tiledb.cloud.rest_api.ApiException;

public class TileDBLogin {
/** The client password */
private String password;
Expand All @@ -22,13 +24,54 @@ public class TileDBLogin {
/** True if the user wants their current login input to overwrite the last one */
private boolean overwritePrevious;

public TileDBLogin(String username, String password, String apiKey, boolean verifySSL, boolean rememberMe, boolean overwritePrevious) {
/**
* Constructor
*
* @param username The username
* @param password The password
* @param apiKey The User's api token. Can be found in the TileDB console at https://www.console.tiledb.com
* @param verifySSL True to verify SSL
* @param rememberMe True if the user wants their login credentials to be remembered
* @param overwritePrevious True if the user wants their current login input to overwrite the last one
*/
public TileDBLogin(String username, String password, String apiKey, boolean verifySSL,
boolean rememberMe, boolean overwritePrevious) {
this.password = password;
this.username = username;
this.apiKey = apiKey;
this.verifySSL = verifySSL;
this.rememberMe = rememberMe;
this.overwritePrevious = overwritePrevious;
this.host = "";
}

/**
* Constructor
*
* @param username The username
* @param password The password
* @param apiKey The User's api token. Can be found in the TileDB console at https://www.console.tiledb.com
* @param verifySSL True to verify SSL
* @param rememberMe True if the user wants their login credentials to be remembered
* @param overwritePrevious True if the user wants their current login input to overwrite the last one
* @param host The host name
*/
public TileDBLogin(String username, String password, String apiKey, boolean verifySSL,
boolean rememberMe, boolean overwritePrevious, String host) throws ApiException {
if (host.equals("https://api.tiledb.com/v2")){
throw new ApiException("https://api.tiledb.com/v2 is not yet supported");
}
this.password = password;
this.username = username;
this.apiKey = apiKey;
this.verifySSL = verifySSL;
this.rememberMe = rememberMe;
this.host = host;
this.overwritePrevious = overwritePrevious;
}

public String getHost() {
return host;
}

public TileDBLogin() {
Expand Down