Skip to content

Commit 5eda456

Browse files
adding host as a constructor parameter in TileDBLogin
1 parent d11170e commit 5eda456

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

src/main/java/io/tiledb/cloud/TileDBClient.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TileDBClient{
2222
private static String password;
2323
private static String basePath;
2424

25-
private static boolean verifyingSsl = true;
25+
private static boolean verifyingSsl;
2626

2727
private static boolean loginInfoIsInJSONFile;
2828

@@ -42,8 +42,9 @@ public class TileDBClient{
4242
apiKey = "";
4343
username = "";
4444
password = "";
45-
basePath = "https://api.tiledb.com/v1";
45+
basePath = "https://api.tiledb.com/v1"; //default is TileDB
4646
loginInfoIsInJSONFile = true;
47+
verifyingSsl = true;
4748

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

103+
if (object.has("host")){
104+
String host = object.getString("host");
105+
if (host.equals("https://api.tiledb.com")){
106+
basePath = host + "/v1";
107+
} else {
108+
basePath = host;
109+
}
110+
logger.log(Level.INFO, "Found host from disk");
111+
}
112+
102113
// check if credentials are adequate for logging in
103114
if ((Objects.equals(apiKey, "") && (Objects.equals(password, "") && !Objects.equals(username, ""))
104115
|| (Objects.equals(apiKey, "") && ((Objects.equals(password, "") || Objects.equals(username, "")))))){
@@ -132,6 +143,11 @@ private void findCredentials(TileDBLogin tileDBLogin) {
132143
* @param tileDBLogin The Login object
133144
*/
134145
private void populateFieldsFromLogin(TileDBLogin tileDBLogin) {
146+
if (!tileDBLogin.getHost().equals("")){
147+
basePath = tileDBLogin.getHost();
148+
} else {
149+
basePath = "https://api.tiledb.com/v1";
150+
}
135151
apiKey = tileDBLogin.getApiKey();
136152
username = tileDBLogin.getUsername();
137153
password = tileDBLogin.getPassword();
@@ -155,7 +171,11 @@ private void writeAuthJSONFileToHome() {
155171
jsonObject.put("api_key", apiKeyObject);
156172
jsonObject.put("username", username);
157173
jsonObject.put("password", password);
158-
jsonObject.put("host", "https://api.tiledb.com");
174+
if (basePath.equals("https://api.tiledb.com/v1")){
175+
jsonObject.put("host", "https://api.tiledb.com");
176+
}else{
177+
jsonObject.put("host", basePath);
178+
}
159179
jsonObject.put("verify_ssl", verifyingSsl);
160180
try {
161181
File file = new File(homeDir + cloudFilePath);

src/main/java/io/tiledb/cloud/TileDBLogin.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.tiledb.cloud;
22

3+
import io.tiledb.cloud.rest_api.ApiException;
4+
35
public class TileDBLogin {
46
/** The client password */
57
private String password;
@@ -22,13 +24,54 @@ public class TileDBLogin {
2224
/** True if the user wants their current login input to overwrite the last one */
2325
private boolean overwritePrevious;
2426

25-
public TileDBLogin(String username, String password, String apiKey, boolean verifySSL, boolean rememberMe, boolean overwritePrevious) {
27+
/**
28+
* Constructor
29+
*
30+
* @param username The username
31+
* @param password The password
32+
* @param apiKey The User's api token. Can be found in the TileDB console at https://www.console.tiledb.com
33+
* @param verifySSL True to verify SSL
34+
* @param rememberMe True if the user wants their login credentials to be remembered
35+
* @param overwritePrevious True if the user wants their current login input to overwrite the last one
36+
*/
37+
public TileDBLogin(String username, String password, String apiKey, boolean verifySSL,
38+
boolean rememberMe, boolean overwritePrevious) {
2639
this.password = password;
2740
this.username = username;
2841
this.apiKey = apiKey;
2942
this.verifySSL = verifySSL;
3043
this.rememberMe = rememberMe;
3144
this.overwritePrevious = overwritePrevious;
45+
this.host = "";
46+
}
47+
48+
/**
49+
* Constructor
50+
*
51+
* @param username The username
52+
* @param password The password
53+
* @param apiKey The User's api token. Can be found in the TileDB console at https://www.console.tiledb.com
54+
* @param verifySSL True to verify SSL
55+
* @param rememberMe True if the user wants their login credentials to be remembered
56+
* @param overwritePrevious True if the user wants their current login input to overwrite the last one
57+
* @param host The host name
58+
*/
59+
public TileDBLogin(String username, String password, String apiKey, boolean verifySSL,
60+
boolean rememberMe, boolean overwritePrevious, String host) throws ApiException {
61+
if (host.equals("https://api.tiledb.com/v2")){
62+
throw new ApiException("https://api.tiledb.com/v2 is not yet supported");
63+
}
64+
this.password = password;
65+
this.username = username;
66+
this.apiKey = apiKey;
67+
this.verifySSL = verifySSL;
68+
this.rememberMe = rememberMe;
69+
this.host = host;
70+
this.overwritePrevious = overwritePrevious;
71+
}
72+
73+
public String getHost() {
74+
return host;
3275
}
3376

3477
public TileDBLogin() {

0 commit comments

Comments
 (0)