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
2 changes: 1 addition & 1 deletion .github/workflows/shared-build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if: ${{ inputs.tag == 'beta' || inputs.tag == 'public' }}
run: |
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
BRANCH_NAME=$(git branch -r --contains $TAG_COMMIT | grep -o 'origin/.*' | sed 's|origin/||' | head -n 1)
BRANCH_NAME=$(git for-each-ref --points-at="$TAG_COMMIT" --format='%(refname:short)' refs/remotes/origin | grep -v '/HEAD$' | sed 's#^origin/##' | head -n 1)
if [ -z "$BRANCH_NAME" ]; then
echo "Error: Could not resolve branch for the tag."
exit 1
Expand Down
19 changes: 10 additions & 9 deletions common/src/main/java/com/skyflow/BaseSkyflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Map;


abstract class BaseSkyflow<Self extends BaseSkyflow, V extends BaseVaultConfig> implements ISkyflow<Self, V, Credentials> {
abstract class BaseSkyflow<Self extends BaseSkyflow<Self, V>, V extends BaseVaultConfig> implements ISkyflow<Self, V, Credentials> {
protected final BaseSkyflowClientBuilder<V> builder;

protected BaseSkyflow(BaseSkyflowClientBuilder<V> builder) {
Expand Down Expand Up @@ -124,8 +124,8 @@ protected final void addVaultConfigTemplate(V vaultConfig) throws SkyflowExcepti
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.VaultIdAlreadyInConfigList.getMessage());
}
this.vaultConfigMap.put(vaultId, vaultConfigCopy);
onVaultConfigAdded(vaultConfigCopy);
this.vaultConfigMap.put(vaultId, vaultConfigCopy);
}

protected final void updateVaultConfigTemplate(V vaultConfig) throws SkyflowException {
Expand All @@ -139,8 +139,9 @@ protected final void updateVaultConfigTemplate(V vaultConfig) throws SkyflowExce
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
}
V previousConfig = this.vaultConfigMap.get(vaultId);
V merged = mergeVaultConfig(vaultConfig, previousConfig);
V merged = mergeVaultConfig(vaultConfig, cloneVaultConfig(previousConfig));
onVaultConfigUpdated(merged);
this.vaultConfigMap.put(vaultId, merged);
}

protected final void removeVaultConfigTemplate(String vaultId) throws SkyflowException {
Expand All @@ -158,30 +159,30 @@ protected final void addSkyflowCredentialsTemplate(Credentials credentials) thro
try {
credentialsCopy = (Credentials) credentials.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
throw new SkyflowException(e.getMessage(), e);
}
this.skyflowCredentials = credentialsCopy;
onCredentialsUpdated(credentialsCopy);
this.skyflowCredentials = credentialsCopy;
}

protected abstract void validateVaultConfig(V vaultConfig) throws SkyflowException;

protected abstract boolean hasVaultClient(String vaultId);

@SuppressWarnings("unchecked")
protected final V cloneVaultConfig(V vaultConfig) {
protected final V cloneVaultConfig(V vaultConfig) throws SkyflowException {
try {
return (V) vaultConfig.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
throw new SkyflowException(e.getMessage(), e);
}
}

protected final String extractVaultId(V vaultConfig) {
return vaultConfig.getVaultId();
}

protected final V mergeVaultConfig(V incoming, V existing) {
protected final V mergeVaultConfig(V incoming, V existing) throws SkyflowException {
if (incoming.getEnv() != null) {
existing.setEnv(incoming.getEnv());
}
Expand All @@ -192,7 +193,7 @@ protected final V mergeVaultConfig(V incoming, V existing) {
try {
existing.setCredentials((Credentials) incoming.getCredentials().clone());
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
throw new SkyflowException(e.getMessage(), e);
}
}
return existing;
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/com/skyflow/BaseVaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected OkHttpClient buildSharedHttpClient(Supplier<String> tokenSupplier) {
.build();
}

protected void prioritiseCredentials(BaseCredentials vaultSpecificCredentials) throws SkyflowException {
protected synchronized void prioritiseCredentials(BaseCredentials vaultSpecificCredentials) throws SkyflowException {
try {
BaseCredentials original = this.finalCredentials;
if (vaultSpecificCredentials != null) {
Expand Down Expand Up @@ -88,7 +88,7 @@ protected void prioritiseCredentials(BaseCredentials vaultSpecificCredentials) t
}
}

protected void setBearerToken(BaseCredentials vaultSpecificCredentials) throws SkyflowException {
protected synchronized void setBearerToken(BaseCredentials vaultSpecificCredentials) throws SkyflowException {
prioritiseCredentials(vaultSpecificCredentials);
BaseValidations.validateCredentials(this.finalCredentials);
if (this.finalCredentials.getApiKey() != null) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/com/skyflow/ISkyflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.SkyflowException;

public interface ISkyflow<Self, V extends BaseVaultConfig, C extends BaseCredentials> {
public interface ISkyflow<Self extends ISkyflow<Self, V, C>, V extends BaseVaultConfig, C extends BaseCredentials> {
Self addVaultConfig(V vaultConfig) throws SkyflowException;

Self updateVaultConfig(V vaultConfig) throws SkyflowException;
Expand Down
11 changes: 10 additions & 1 deletion common/src/main/java/com/skyflow/config/BaseCredentials.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyflow.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class BaseCredentials implements Cloneable {
Expand Down Expand Up @@ -69,7 +70,15 @@ public void setContext(Map<String, Object> context) {
}

@Override
@SuppressWarnings("unchecked")
public Object clone() throws CloneNotSupportedException {
return super.clone();
BaseCredentials copy = (BaseCredentials) super.clone();
if (this.roles != null) {
copy.roles = new ArrayList<>(this.roles);
}
if (this.context instanceof Map) {
copy.context = new HashMap<>((Map<String, Object>) this.context);
}
return copy;
}
}
1 change: 1 addition & 0 deletions common/src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public enum ErrorMessage {
BearerTokenExpired("%s0 Validation error. Bearer token is invalid or expired. Please provide a valid bearer token."),

// Insert
InsertRequestNull("%s0 Validation error. InsertRequest object is null. Specify a valid InsertRequest object."),
TableKeyError("%s0 Validation error. 'table' key is missing from the payload. Specify a 'table' key."),
EmptyTable("%s0 Validation error. 'table' can't be empty. Specify a table."),
ValuesKeyError("%s0 Validation error. 'values' key is missing from the payload. Specify a 'values' key."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void setHttpStatus() {
}

public int getHttpCode() {
return httpCode;
return httpCode == null ? 0 : httpCode;
}

public JsonArray getDetails() {
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/com/skyflow/logs/ErrorLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum ErrorLogs {
EMPTY_TABLE_NAME("Invalid %s1 request. Table name can not be empty."),
VALUES_IS_REQUIRED("Invalid %s1 request. Values are required."),
EMPTY_VALUES("Invalid %s1 request. Values can not be empty."),
INSERT_REQUEST_NULL("Invalid %s1 request. Insert request can not be null."),
RECORDS_IS_REQUIRED("Invalid %s1 request. Records are required."),
EMPTY_RECORDS("Invalid %s1 request. Records can not be empty."),
INVALID_RECORD("Invalid %s1 request. Invalid record. Specify a valid record."),
Expand Down
9 changes: 7 additions & 2 deletions common/src/main/java/com/skyflow/utils/BaseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,14 @@ public static PrivateKey getPrivateKeyFromPem(String pemKey) throws SkyflowExcep
if (pemKey.contains(PKCS8PrivateHeader)) {
privateKeyContent = privateKeyContent.replace(PKCS8PrivateHeader, "");
privateKeyContent = privateKeyContent.replace(PKCS8PrivateFooter, "");
privateKeyContent = privateKeyContent.replace("\n", "");
privateKeyContent = privateKeyContent.replace("\r\n", "");
privateKey = parsePkcs8PrivateKey(Base64.getDecoder().decode(privateKeyContent));
privateKeyContent = privateKeyContent.replace("\n", "");
try {
privateKey = parsePkcs8PrivateKey(Base64.getDecoder().decode(privateKeyContent));
} catch (IllegalArgumentException e) {
LogUtil.printErrorLog(ErrorLogs.INVALID_KEY_SPEC.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.InvalidKeySpec.getMessage());
}
} else {
LogUtil.printErrorLog(ErrorLogs.JWT_INVALID_FORMAT.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.JwtInvalidFormat.getMessage());
Expand Down
2 changes: 1 addition & 1 deletion common/src/test/java/com/skyflow/BaseSkyflowTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public Env getEnv() {
}

@Test
public void testMergeVaultConfigWithNullClusterIdFallsBackToPreviousClusterId() {
public void testMergeVaultConfigWithNullClusterIdFallsBackToPreviousClusterId() throws SkyflowException {
BaseVaultConfig existing = newConfig(vaultID, clusterID, Env.DEV);
BaseVaultConfig incoming = new BaseVaultConfig();
incoming.setVaultId(vaultID);
Expand Down
195 changes: 195 additions & 0 deletions flowvault/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?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/maven-v4_0_0.xsd">
<parent>
<artifactId>skyflow</artifactId>
<groupId>com.skyflow</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>skyflow-flowvault-java</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<version>1.0.0</version>
<description>Skyflow V3 SDK for the Java programming language</description>
<url>https://github.com/skyflowapi/skyflow-java/tree/main</url>
<developers>
<developer>
<id>skyflow</id>
<name>skyflow</name>
</developer>
</developers>
<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>https://github.com/skyflowapi/skyflow-java/blob/main/LICENSE</url>
</license>
</licenses>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.skyflow:common</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jfrog</id>
<distributionManagement>
<repository>
<id>central</id>
<name>prekarilabs.jfrog.io-releases</name>
<url>https://prekarilabs.jfrog.io/artifactory/skyflow-java</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>prekarilabs.jfrog.io-snapshots</name>
<url>https://prekarilabs.jfrog.io/artifactory/skyflow-java</url>
</snapshotRepository>
</distributionManagement>
</profile>
<profile>
<id>maven-central</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<tokenAuth>true</tokenAuth>
<autoPublish>true</autoPublish>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>central</id>
<url>https://central.sonatype.com/api/v1/publisher/upload</url>
</repository>
<snapshotRepository>
<id>central-snapshots</id>
<url>https://central.sonatype.com/api/v1/publisher/upload</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.18.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.18.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>2.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.12.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>powermock-module-junit4-common</artifactId>
<groupId>org.powermock</groupId>
</exclusion>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>powermock-api-support</artifactId>
<groupId>org.powermock</groupId>
</exclusion>
<exclusion>
<artifactId>mockito-core</artifactId>
<groupId>org.mockito</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>8</maven.compiler.target>
<maven.deploy.skip>false</maven.deploy.skip>
<maven.compiler.source>8</maven.compiler.source>
<sdk.version>${project.version}</sdk.version>
</properties>
</project>
2 changes: 1 addition & 1 deletion flowvault/src/main/java/com/skyflow/VaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void setCommonCredentials(Credentials commonCredentials) throws Skyflo
super.prioritiseCredentials(this.vaultConfig.getCredentials());
}

protected void setBearerToken() throws SkyflowException {
protected synchronized void setBearerToken() throws SkyflowException {
super.setBearerToken(this.vaultConfig.getCredentials());
if (apiClient == null) {
updateExecutorInHTTP();
Expand Down
Loading
Loading