Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring and optimization #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 5 additions & 11 deletions src/main/java/com/bettercloud/vault/api/LogicalUtilities.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.bettercloud.vault.api;

import com.bettercloud.vault.json.JsonObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;


public class LogicalUtilities {
Expand All @@ -15,12 +14,7 @@ public class LogicalUtilities {
* @return The path potentially mutated, based on the operation
*/
private static List<String> getPathSegments(final String path) {
final List<String> segments = new ArrayList<>();
final StringTokenizer tokenizer = new StringTokenizer(path, "/");
while (tokenizer.hasMoreTokens()) {
segments.add(tokenizer.nextToken());
}
return segments;
return Arrays.asList(path.split("/"));
}

/**
Expand Down Expand Up @@ -64,10 +58,10 @@ public static String addQualifierToPath(final List<String> segments, final int p
*/
public static String adjustPathForReadOrWrite(final String path, final int prefixPathLength,
final Logical.logicalOperations operation) {
final List<String> pathSegments = getPathSegments(path);
if (operation.equals(Logical.logicalOperations.readV2) || operation
.equals(Logical.logicalOperations.writeV2)) {
// Version 2
final List<String> pathSegments = getPathSegments(path);
final StringBuilder adjustedPath = new StringBuilder(
addQualifierToPath(pathSegments, prefixPathLength, "data"));
if (path.endsWith("/")) {
Expand All @@ -93,10 +87,10 @@ public static String adjustPathForReadOrWrite(final String path, final int prefi
*/
public static String adjustPathForList(final String path, int prefixPathDepth,
final Logical.logicalOperations operation) {
final List<String> pathSegments = getPathSegments(path);
final StringBuilder adjustedPath = new StringBuilder();
if (operation.equals(Logical.logicalOperations.listV2)) {
// Version 2
final List<String> pathSegments = getPathSegments(path);
adjustedPath.append(addQualifierToPath(pathSegments, prefixPathDepth, "metadata"));
if (path.endsWith("/")) {
adjustedPath.append("/");
Expand All @@ -122,8 +116,8 @@ public static String adjustPathForList(final String path, int prefixPathDepth,
*/
public static String adjustPathForDelete(final String path, final int prefixPathDepth,
final Logical.logicalOperations operation) {
final List<String> pathSegments = getPathSegments(path);
if (operation.equals(Logical.logicalOperations.deleteV2)) {
final List<String> pathSegments = getPathSegments(path);
final StringBuilder adjustedPath = new StringBuilder(
addQualifierToPath(pathSegments, prefixPathDepth, "metadata"));
if (path.endsWith("/")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LogicalResponse extends VaultResponse {

private Map<String, String> data = new HashMap<>();
private List<String> listData = new ArrayList<>();
private JsonObject dataObject = null;
private JsonObject dataObject;
private String leaseId;
private Boolean renewable;
private Long leaseDuration;
Expand Down Expand Up @@ -79,7 +79,6 @@ private void parseResponseData(final Logical.logicalOperations operation) {
if (operation.equals(Logical.logicalOperations.readV2)) {
jsonObject = jsonObject.get("data").asObject();
}
data = new HashMap<>();
dataObject = jsonObject.get("data").asObject();
for (final JsonObject.Member member : dataObject) {
final JsonValue jsonValue = member.getValue();
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/bettercloud/vault/response/PkiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import com.bettercloud.vault.api.pki.Credential;
import com.bettercloud.vault.api.pki.RoleOptions;
import com.bettercloud.vault.rest.RestResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

/**
* This class is a container for the information returned by Vault in PKI backend API
Expand Down Expand Up @@ -152,12 +151,7 @@ private List<String> parseCsvToList(final String input) {
if (input == null) {
return null;
}
final List<String> returnValue = new ArrayList<>();
final StringTokenizer tokenizer = new StringTokenizer(input, ",");
while (tokenizer.hasMoreTokens()) {
returnValue.add(tokenizer.nextToken());
}
return returnValue;
return Arrays.asList(input.split(","));
}

/**
Expand Down