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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea

target
target

**/dependency-reduced-pom.xml
.env
20 changes: 20 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.skyflow</groupId>
<artifactId>skyflow-java</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>common</artifactId>
<version>1.0.0</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
48 changes: 48 additions & 0 deletions common/src/main/java/com/skyflow/BaseSkyflow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.skyflow;

import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
import com.skyflow.enums.LogLevel;
import com.skyflow.logs.InfoLogs;
import com.skyflow.utils.BaseUtils;
import com.skyflow.utils.logger.LogUtil;

import java.util.LinkedHashMap;

class BaseSkyflow {
private final BaseSkyflowClientBuilder builder;

protected BaseSkyflow(BaseSkyflowClientBuilder builder) {
this.builder = builder;
}

public LogLevel getLogLevel() {
return this.builder.logLevel;
}

public VaultConfig getVaultConfig() {
Object[] array = this.builder.vaultConfigMap.values().toArray();
return (VaultConfig) array[0];
}

static class BaseSkyflowClientBuilder {
protected final LinkedHashMap<String, VaultConfig> vaultConfigMap;
protected Credentials skyflowCredentials;
protected LogLevel logLevel;

protected BaseSkyflowClientBuilder() {
this.vaultConfigMap = new LinkedHashMap<>();
this.skyflowCredentials = null;
this.logLevel = LogLevel.ERROR;
}

public BaseSkyflowClientBuilder setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel == null ? LogLevel.ERROR : logLevel;
LogUtil.setupLogger(this.logLevel);
LogUtil.printInfoLog(BaseUtils.parameterizedString(
InfoLogs.CURRENT_LOG_LEVEL.getLog(), String.valueOf(logLevel)
));
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;

public class Credentials {
public class Credentials implements Cloneable {
private String path;
private ArrayList<String> roles;
private String context;
Expand Down Expand Up @@ -63,4 +63,13 @@ public String getApiKey() {
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}

@Override
public Object clone() throws CloneNotSupportedException {
Credentials cloned = (Credentials) super.clone();
if (this.roles != null) {
cloned.roles = new ArrayList<>(this.roles);
}
return cloned;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.skyflow.enums.Env;

public class VaultConfig {
public class VaultConfig implements Cloneable {
private String vaultId;
private String clusterId;
private Env env;
Expand Down Expand Up @@ -46,4 +46,13 @@ public Credentials getCredentials() {
public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}

@Override
public Object clone() throws CloneNotSupportedException {
VaultConfig cloned = (VaultConfig) super.clone();
if (this.credentials != null) {
cloned.credentials = (Credentials) this.credentials.clone();
}
return cloned;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.skyflow.errors;

import com.skyflow.utils.Constants;
import com.skyflow.utils.SdkVersion;

public enum ErrorMessage {
// Client initialization
VaultIdAlreadyInConfigList("%s0 Validation error. VaultId is present in an existing config. Specify a new vaultId in config."),
VaultIdNotInConfigList("%s0 Validation error. VaultId is missing from the config. Specify the vaultIds from configs."),
OnlySingleVaultConfigAllowed("%s0 Validation error. A vault config already exists. Cannot add another vault config."),
ConnectionIdAlreadyInConfigList("%s0 Validation error. ConnectionId is present in an existing config. Specify a connectionId in config."),
ConnectionIdNotInConfigList("%s0 Validation error. ConnectionId is missing from the config. Specify the connectionIds from configs."),
EmptyCredentials("%s0 Validation error. Invalid credentials. Credentials must not be empty."),
Expand Down Expand Up @@ -145,15 +146,15 @@ public enum ErrorMessage {
FailedToDecodeFileFromResponse("%s0 Failed to decode the file from the response. Ensure the response is valid and try again."),
EmptyFileAndFilePathInDeIdentifyFile("%s0 Validation error. Both file and filePath are empty. Specify either file object or filePath, not both."),
PollingForResultsFailed("%s0 API error. Polling for results failed. Unable to retrieve the deidentified file"),
FailedtoSaveProcessedFile("%s0 Validation error. Failed to save the processed file. Ensure the output directory is valid and writable."),
FailedToSaveProcessedFile("%s0 Validation error. Failed to save the processed file. Ensure the output directory is valid and writable."),
InvalidAudioFileType("%s0 Validation error. The file type is not supported. Specify a valid file type mp3 or wav."),
// Generic
ErrorOccurred("%s0 API error. Error occurred.")
;
private final String message;

ErrorMessage(String message) {
this.message = message.replace("%s0", Constants.SDK_PREFIX);
this.message = message.replace("%s0", SdkVersion.getSdkPrefix());
}

public String getMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.skyflow.utils.Constants;
import com.skyflow.utils.BaseConstants;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,7 +70,7 @@ public String getRequestId() {
}

private void setRequestId(Map<String, List<String>> responseHeaders) {
List<String> ids = responseHeaders.get(Constants.REQUEST_ID_HEADER_KEY);
List<String> ids = responseHeaders.get(BaseConstants.REQUEST_ID_HEADER_KEY);
this.requestId = ids == null ? null : ids.get(0);
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public JsonArray getDetails() {

private void setDetails(Map<String, List<String>> responseHeaders) {
JsonElement detailsElement = ((JsonObject) responseBody.get("error")).get("details");
List<String> errorFromClientHeader = responseHeaders.get(Constants.ERROR_FROM_CLIENT_HEADER_KEY);
List<String> errorFromClientHeader = responseHeaders.get(BaseConstants.ERROR_FROM_CLIENT_HEADER_KEY);
if (detailsElement != null) {
this.details = detailsElement.getAsJsonArray();
}
Expand Down
28 changes: 28 additions & 0 deletions common/src/main/java/com/skyflow/generated/rest/ApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.skyflow.generated.rest;

import com.skyflow.generated.rest.core.ClientOptions;
import com.skyflow.generated.rest.core.Suppliers;
import com.skyflow.generated.rest.resources.authentication.AuthenticationClient;
import java.util.function.Supplier;

public class ApiClient {
protected final ClientOptions clientOptions;

protected final Supplier<AuthenticationClient> authenticationClient;

public ApiClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.authenticationClient = Suppliers.memoize(() -> new AuthenticationClient(clientOptions));
}

public AuthenticationClient authentication() {
return this.authenticationClient.get();
}

public static ApiClientBuilder builder() {
return new ApiClientBuilder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.skyflow.generated.rest;

import com.skyflow.generated.rest.core.ClientOptions;
import com.skyflow.generated.rest.core.Suppliers;
import com.skyflow.generated.rest.resources.authentication.AsyncAuthenticationClient;
import java.util.function.Supplier;

public class AsyncApiClient {
protected final ClientOptions clientOptions;

protected final Supplier<AsyncAuthenticationClient> authenticationClient;

public AsyncApiClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.authenticationClient = Suppliers.memoize(() -> new AsyncAuthenticationClient(clientOptions));
}

public AsyncAuthenticationClient authentication() {
return this.authenticationClient.get();
}

public static AsyncApiClientBuilder builder() {
return new AsyncApiClientBuilder();
}
}
Loading
Loading