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
5 changes: 3 additions & 2 deletions .github/workflows/internal-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ jobs:
server-password: ${{ secrets.ARTIFACTORY_PASSWORD }}
gpg-key: ${{ secrets.JFROG_GPG_KEY }}
gpg-passphrase: ${{ secrets.JFROG_GPG_PASSPHRASE }}


skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
10 changes: 5 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
uses: gsactions/commit-message-checker@v1
with:
pattern: '(\[?[A-Z]{1,5}-[1-9][0-9]*)|(\[AUTOMATED\])|(Merge)|(Release).+$'
flags: 'gm'
excludeDescription: 'true'
checkAllCommitMessages: 'true'
flags: "gm"
excludeDescription: "true"
checkAllCommitMessages: "true"
accessToken: ${{ secrets.PAT_ACTIONS }}
error: 'One of your your commit messages is not matching the format with JIRA ID Ex: ( SDK-123 commit message )'
error: "One of your your commit messages is not matching the format with JIRA ID Ex: ( SDK-123 commit message )"
Test:
runs-on: ubuntu-latest
steps:
Expand All @@ -40,7 +40,7 @@ jobs:
echo TEST_REUSABLE_TOKEN=${{ secrets.TEST_REUSABLE_TOKEN }} >> .env

- name: Build & Run tests with Maven
run: mvn -B package -DTEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} -DTEST_DATA_CREDENTIALS_FILE=${{ secrets.TEST_DATA_CREDENTIALS_FILE }} -f pom.xml
run: mvn -B package -f pom.xml

- name: Codecov
uses: codecov/codecov-action@v2.1.0
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ jobs:
server-password: ${{ secrets.OSSRH_PASSWORD }}
gpg-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

skyflow-credentials: ${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
test-expired-token: ${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
test-reusable-token: ${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
29 changes: 19 additions & 10 deletions .github/workflows/shared-build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ on:
workflow_call:
inputs:
ref:
description: 'Git reference to use (e.g., main or branch name)'
description: "Git reference to use (e.g., main or branch name)"
required: true
type: string

is-internal:
description: 'Flag for internal release'
description: "Flag for internal release"
required: true
type: boolean

server-id:
description: 'Id of the repository'
description: "Id of the repository"
required: true
type: string

profile:
description: 'Profile to pick from pom.xml'
description: "Profile to pick from pom.xml"
required: true
type: string
secrets:
Expand All @@ -34,6 +34,15 @@ on:
gpg-passphrase:
required: true

skyflow-credentials:
required: true

test-expired-token:
required: true

test-reusable-token:
required: true

jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -46,8 +55,8 @@ jobs:
- name: Set up maven or jfrog repository
uses: actions/setup-java@v1
with:
java-version: '1.8'
distribution: 'adopt'
java-version: "1.8"
distribution: "adopt"
server-id: ${{ inputs.server-id }}
server-username: SERVER_USERNAME
server-password: SERVER_PASSWORD
Expand Down Expand Up @@ -87,9 +96,9 @@ jobs:
id: create-env
run: |
touch .env
echo SKYFLOW_CREDENTIALS=${{ secrets.SKYFLOW_CREDENTIALS }} >> .env
echo TEST_EXPIRED_TOKEN=${{ secrets.TEST_EXPIRED_TOKEN }} >> .env
echo TEST_REUSABLE_TOKEN=${{ secrets.TEST_REUSABLE_TOKEN }} >> .env
echo SKYFLOW_CREDENTIALS=${{ secrets.skyflow-credentials }} >> .env
echo TEST_EXPIRED_TOKEN=${{ secrets.test-expired-token }} >> .env
echo TEST_REUSABLE_TOKEN=${{ secrets.test-reusable-token }} >> .env

- name: Create credentials json
id: create-json
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.skyflow</groupId>
<artifactId>skyflow-java</artifactId>
<version>1.15.0-dev.4ea53e6</version>
<version>1.15.0-dev.a0537e8</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/skyflow/Skyflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,23 @@ public LogLevel getLogLevel() {
return this.builder.logLevel;
}

public VaultController vault() {
String vaultId = (String) this.builder.vaultClientsMap.keySet().toArray()[0];
public VaultController vault() throws SkyflowException {
Object[] array = this.builder.vaultClientsMap.keySet().toArray();
if (array.length < 1) {
LogUtil.printErrorLog(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
}
String vaultId = (String) array[0];
return this.vault(vaultId);
}

public VaultController vault(String vaultId) {
return this.builder.vaultClientsMap.get(vaultId);
public VaultController vault(String vaultId) throws SkyflowException {
VaultController controller = this.builder.vaultClientsMap.get(vaultId);
if (controller == null) {
LogUtil.printErrorLog(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
}
return controller;
}

public ConnectionController connection() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/skyflow/errors/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum ErrorMessage {
NoTokenGenerationMeansPassed("%s0 Initialization failed. Invalid credentials. Specify any one from 'path', 'credentialsString', 'token' or 'apiKey'."),
EmptyCredentialFilePath("%s0 Initialization failed. Invalid credentials. Credentials file path must not be empty."),
EmptyCredentialsString("%s0 Initialization failed. Invalid credentials. Credentials string must not be empty."),
EmptyToken("%s0 Initialization failed. Invalid credentials. Token mut not be empty."),
EmptyToken("%s0 Initialization failed. Invalid credentials. Token must not be empty."),
EmptyApikey("%s0 Initialization failed. Invalid credentials. Api key must not be empty."),
InvalidApikey("%s0 Initialization failed. Invalid credentials. Specify valid api key."),
EmptyRoles("%s0 Initialization failed. Invalid roles. Specify at least one role."),
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/skyflow/utils/HttpUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

public final class HttpUtility {

private static final String LINE_FEED = "\r\n";
private static String requestID;

public static String getRequestID() {
return requestID;
}

private static final String LINE_FEED = "\r\n";

public static String sendRequest(String method, URL url, JsonObject params, Map<String, String> headers) throws IOException, SkyflowException {

HttpURLConnection connection = null;
Expand Down Expand Up @@ -55,7 +54,7 @@ public static String sendRequest(String method, URL url, JsonObject params, Map<
input = formatJsonToFormEncodedString(params).getBytes(StandardCharsets.UTF_8);
} else if (requestContentType.contains("multipart/form-data")) {
input = formatJsonToMultiPartFormDataString(params, boundary).getBytes(StandardCharsets.UTF_8);
}else {
} else {
input = params.toString().getBytes(StandardCharsets.UTF_8);
}

Expand All @@ -66,7 +65,7 @@ public static String sendRequest(String method, URL url, JsonObject params, Map<

int status = connection.getResponseCode();
String requestID = connection.getHeaderField("x-request-id");
HttpUtility.requestID = requestID;
HttpUtility.requestID = requestID.split(",")[0];

Reader streamReader;
if (status > 299) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/skyflow/utils/validations/Validations.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.skyflow.utils.validations;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.skyflow.config.ConnectionConfig;
import com.skyflow.config.Credentials;
import com.skyflow.config.VaultConfig;
Expand Down Expand Up @@ -132,8 +134,9 @@ public static void validateInvokeConnectionRequest(InvokeConnectionRequest invok
}

if (requestBody != null) {
Map<String, String> requestBodyMap = (Map<String, String>) requestBody;
if (requestBodyMap.isEmpty()) {
Gson gson = new Gson();
JsonObject bodyObject = gson.toJsonTree(requestBody).getAsJsonObject();
if (bodyObject.isEmpty()) {
LogUtil.printErrorLog(Utils.parameterizedString(
ErrorLogs.EMPTY_REQUEST_BODY.getLog(), InterfaceName.INVOKE_CONNECTION.getName()));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyRequestBody.getMessage());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.skyflow.vault.connection;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class InvokeConnectionResponse {
private JsonObject response;
private final JsonObject data;
private final JsonObject metadata;

public InvokeConnectionResponse(JsonObject response) {
this.response = response;
public InvokeConnectionResponse(JsonObject data, JsonObject metadata) {
this.data = data;
this.metadata = metadata;
}

public JsonObject getResponse() {
return response;
public JsonObject getData() {
return data;
}

public JsonObject getMetadata() {
return metadata;
}

@Override
public String toString() {
Gson gson = new Gson();
JsonObject responseObject = JsonParser.parseString(gson.toJson(this)).getAsJsonObject();
responseObject = responseObject.remove("response").getAsJsonObject();
return responseObject.toString();
Gson gson = new GsonBuilder().serializeNulls().create();
return gson.toJson(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@
}

String response = HttpUtility.sendRequest(requestMethod.name(), new URL(filledURL), requestBody, headers);
connectionResponse = new InvokeConnectionResponse((JsonObject) JsonParser.parseString(response));
JsonObject data = JsonParser.parseString(response).getAsJsonObject();
JsonObject metadata = new JsonObject();
metadata.addProperty("requestId", HttpUtility.getRequestID());
connectionResponse = new InvokeConnectionResponse(data, metadata);

Check warning on line 70 in src/main/java/com/skyflow/vault/controller/ConnectionController.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/skyflow/vault/controller/ConnectionController.java#L67-L70

Added lines #L67 - L70 were not covered by tests
LogUtil.printInfoLog(InfoLogs.INVOKE_CONNECTION_REQUEST_RESOLVED.getLog());
} catch (IOException e) {
LogUtil.printErrorLog(ErrorLogs.INVOKE_CONNECTION_REQUEST_REJECTED.getLog());
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/skyflow/SkyflowTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ public void testGettingNonExistentVaultConfigInSkyflowClient() {
}
}

@Test
public void testGettingAlreadyRemovedVaultFromEmptyConfigs() {
try {
Skyflow skyflowClient = Skyflow.builder().build();
skyflowClient.vault();
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.VaultIdNotInConfigList.getMessage(), e.getMessage());
}
}

@Test
public void testGettingAlreadyRemovedVaultFromNonEmptyConfigs() {
try {
VaultConfig primaryConfig = new VaultConfig();
primaryConfig.setVaultId(vaultID);
primaryConfig.setClusterId(clusterID);
primaryConfig.setEnv(Env.SANDBOX);

VaultConfig secondaryConfig = new VaultConfig();
secondaryConfig.setVaultId(vaultID + "123");
secondaryConfig.setClusterId(clusterID);
secondaryConfig.setEnv(Env.SANDBOX);
Skyflow skyflowClient = Skyflow.builder().addVaultConfig(primaryConfig).addVaultConfig(secondaryConfig).build();
skyflowClient.removeVaultConfig(vaultID);
skyflowClient.vault(vaultID);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
Assert.assertEquals(ErrorMessage.VaultIdNotInConfigList.getMessage(), e.getMessage());
}
}


@Test
public void testAddingInvalidConnectionConfigInSkyflowBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,17 @@ public void testEmptyRequestBodyInInvokeConnectionRequestValidations() {
@Test
public void testInvokeConnectionResponse() {
try {
JsonObject responseObject = new JsonObject();
responseObject.addProperty("test_key_1", "test_value_1");
responseObject.addProperty("test_key_2", "test_value_2");
InvokeConnectionResponse connectionResponse = new InvokeConnectionResponse(responseObject);
Assert.assertEquals(2, connectionResponse.getResponse().size());
Assert.assertEquals(responseObject.toString(), connectionResponse.toString());
JsonObject data = new JsonObject();
data.addProperty("test_key_1", "test_value_1");
data.addProperty("test_key_2", "test_value_2");
JsonObject metadata = new JsonObject();
metadata.addProperty("requestId", "12345");
InvokeConnectionResponse connectionResponse = new InvokeConnectionResponse(data, metadata);
String responseString = "{\"data\":{\"test_key_1\":\"test_value_1\",\"test_key_2\":\"test_value_2\"}," +
"\"metadata\":{\"requestId\":\"12345\"}}";
Assert.assertEquals(2, connectionResponse.getData().size());
Assert.assertEquals(responseString, connectionResponse.toString());
Assert.assertEquals(1, connectionResponse.getMetadata().size());
} catch (Exception e) {
Assert.fail(INVALID_EXCEPTION_THROWN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void setup() {
@Test
public void testInvalidRequestInInvokeConnectionMethod() {
try {
HashMap<String,String> requestBody = new HashMap<>();
HashMap<String, String> requestBody = new HashMap<>();
InvokeConnectionRequest connectionRequest = InvokeConnectionRequest.builder().requestBody(requestBody).build();
Skyflow skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addConnectionConfig(connectionConfig).build();
skyflowClient.connection().invoke(connectionRequest);
Expand Down
Loading