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

Overall code health improvements #187

Merged
merged 35 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e11b197
fix compile encoding issue
jetersen Aug 24, 2019
6750d9f
fix javadoc compile issue
jetersen Aug 24, 2019
753cb97
fix testcontainer deprecation and use extend generic container pattern
jetersen Aug 24, 2019
b62b6f5
fix up logical tests after #176
jetersen Aug 24, 2019
ffc8839
Java 5: unnecessary boxing
jetersen Aug 24, 2019
0f21b6e
Java 5: unnecessary unboxing
jetersen Aug 24, 2019
ae2f6e7
Java 7: explicit type replaced with <>
jetersen Aug 24, 2019
00894c2
Java 8: anonymous type replaced with method reference
jetersen Aug 24, 2019
e301c78
Java 8: anonymous type replaced with lambda
jetersen Aug 24, 2019
891047b
convert field to local
jetersen Aug 24, 2019
7f40bec
suppress deprecation in AppIdTests
jetersen Aug 24, 2019
7c14dba
fix `SslContextFactory` deprecation by using `SslContextFactory.Server`
jetersen Aug 24, 2019
b9133ee
add checkstyle
jetersen Aug 24, 2019
de96c0a
fix trailing whitespace
jetersen Aug 24, 2019
1a464c9
fix final newline
jetersen Aug 24, 2019
8676208
add GitHub Action CI
jetersen Aug 25, 2019
67dddfc
add Travis CI
jetersen Aug 25, 2019
3e0eeda
Skip testcontainers if Docker is not available
jetersen Aug 25, 2019
ad34a13
Use UTF-8 Charset constant
jetersen Aug 25, 2019
735815b
remove redundant private modifier on enum
jetersen Aug 25, 2019
66182c2
pointless comparison of boolean
jetersen Aug 25, 2019
eafd359
unnecessary null check before equals call
jetersen Aug 25, 2019
aaa52b2
Simplify stream chains
jetersen Aug 25, 2019
a738b4b
string concatenation used in a string builder :sweat:
jetersen Aug 25, 2019
f0f4953
string concatenation in a loop :sweat:
jetersen Aug 25, 2019
87b6cbb
condition is covered by instanceOf
jetersen Aug 25, 2019
ff5f5b6
unnecessary initialization of `StringBuilder`
jetersen Aug 25, 2019
764219b
simplify clone of ArrayList
jetersen Aug 25, 2019
7f3756f
simplify assertNull
jetersen Aug 25, 2019
50230cd
Use `Integer.valueOf` instead
jetersen Aug 25, 2019
e7cae4a
info log level for CI
jetersen Aug 25, 2019
3128912
use in-memory keystore to avoid file locks
jetersen Aug 25, 2019
a684096
code style and import order
jetersen Aug 25, 2019
3231da3
Changed the list() methods to return a LogicalResult so the status co…
Aug 26, 2019
ace3e0f
Merge branch 'master' into chore/overallCodeHealth
jetersen Aug 26, 2019
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
25 changes: 25 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: Build on JDK ${{ matrix.java }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [9, 11, 12]
os: [ubuntu-latest, windows-latest]
include:
# TODO(casz) remove once https://github.com/testcontainers/testcontainers-java/pull/1780 is available
- os: 'ubuntu-latest'
tasks: 'integrationTest'

steps:
- uses: actions/checkout@v1
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Build with Gradle
run: ./gradlew build ${{ matrix.tasks }} -s --info
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
.idea
.idea/*
!.idea/codeStyles/
.testcontainers-tmp*

vault-java-driver.iml
Expand Down
125 changes: 125 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: java

dist: xenial

services:
- docker

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

matrix:
include:
- jdk: openjdk12
- jdk: openjdk11
- jdk: openjdk9

script:
- ./gradlew build integrationTest -s --info

notifications:
email: false
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'checkstyle'

group 'com.bettercloud'
archivesBaseName = 'vault-java-driver'
Expand All @@ -18,7 +19,7 @@ repositories {
dependencies {
testCompile('junit:junit:4.12')
testCompile('org.mockito:mockito-core:2.28.2')
testCompile('org.testcontainers:testcontainers:1.11.3')
testCompile('org.testcontainers:testcontainers:1.12.0')
testCompile('org.eclipse.jetty:jetty-server:9.4.19.v20190610')
testCompile('org.slf4j:slf4j-api:1.7.26')
testCompile('org.bouncycastle:bcprov-jdk15on:1.62')
Expand Down Expand Up @@ -46,10 +47,14 @@ compileJava {
options.compilerArgs = ['--release', '8']
}

compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

task compileModuleInfoJava(type: JavaCompile) {
classpath = files()
source = 'src/main/java/module-info.java'
destinationDir = compileJava.destinationDir
options.encoding = compileJava.options.encoding

doFirst {
options.compilerArgs = [
Expand Down Expand Up @@ -207,4 +212,3 @@ uploadArchives {
}
}
}

24 changes: 24 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<module name="FileTabCharacter"/>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
</module>
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="message" value="Trailing spaces are not allowed."/>
</module>
<module name="TreeWalker">
<module name="ImportOrder">
<property name="separatedStaticGroups" value="true"/>
<property name="option" value="bottom"/>
</module>
<module name="UnusedImports"/>
<module name="AvoidStarImport"/>
</module>
</module>
19 changes: 9 additions & 10 deletions src/main/java/com/bettercloud/vault/SslConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.bettercloud.vault;

import com.bettercloud.vault.api.Auth;

import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
Expand All @@ -31,6 +25,11 @@
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;

/**
* <p>A container for SSL-related configuration options, meant to be stored within a {@link VaultConfig} instance.</p>
Expand Down Expand Up @@ -444,13 +443,13 @@ public SslConfig build() throws VaultException {
this.environmentLoader = new EnvironmentLoader();
}
if (this.verifyObject == null && environmentLoader.loadVariable(VAULT_SSL_VERIFY) != null) {
this.verify = Boolean.valueOf(environmentLoader.loadVariable(VAULT_SSL_VERIFY));
this.verify = Boolean.parseBoolean(environmentLoader.loadVariable(VAULT_SSL_VERIFY));
} else if (this.verifyObject != null) {
this.verify = verifyObject;
} else {
this.verify = true;
}
if (this.verify == true && this.pemUTF8 == null && environmentLoader.loadVariable(VAULT_SSL_CERT) != null) {
if (this.verify && this.pemUTF8 == null && environmentLoader.loadVariable(VAULT_SSL_CERT) != null) {
final File pemFile = new File(environmentLoader.loadVariable(VAULT_SSL_CERT));
try (final InputStream input = new FileInputStream(pemFile)) {
this.pemUTF8 = inputStreamToUTF8(input);
Expand Down Expand Up @@ -487,7 +486,7 @@ protected String getPemUTF8() {
* @throws VaultException
*/
private void buildSsl() throws VaultException {
if (verify == true) {
if (verify) {
if (keyStore != null || trustStore != null) {
this.sslContext = buildSslContextFromJks();
} else if (pemUTF8 != null || clientPemUTF8 != null || clientKeyPemUTF8 != null) {
Expand Down Expand Up @@ -625,7 +624,7 @@ private KeyStore inputStreamToKeyStore(final InputStream inputStream, final Stri
*/
private static String inputStreamToUTF8(final InputStream input) throws IOException {
final BufferedReader in = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
final StringBuilder utf8 = new StringBuilder("");
final StringBuilder utf8 = new StringBuilder();
String str;
while ((str = in.readLine()) != null) {
// String concatenation is less efficient, but for some reason the line-breaks (which are necessary
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/bettercloud/vault/Vault.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.bettercloud.vault.rest.Rest;
import com.bettercloud.vault.rest.RestException;
import com.bettercloud.vault.rest.RestResponse;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/bettercloud/vault/VaultConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public VaultConfig secretsEnginePathMap(final Map<String, String> secretEngineVe
this.secretsEnginePathMap = new ConcurrentHashMap<>(secretEngineVersions);
return this;
}

/**
* <p>Sets the secrets Engine version be used by Vault for the provided path.</p>
*
* @param path the path to use for accessing Vault secrets.
* Example "/secret/foo"
* @param version The key-value engine version used for this path.
* @return This object, with a new entry in the secrets paths map, ready for additional builder-pattern method calls or else finalization with
* @return This object, with a new entry in the secrets paths map, ready for additional builder-pattern method calls or else finalization with
* the build() method
*/
public VaultConfig putSecretsEngineVersionForPath(String path, String version) {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/bettercloud/vault/api/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.bettercloud.vault.response.LookupResponse;
import com.bettercloud.vault.rest.Rest;
import com.bettercloud.vault.rest.RestResponse;

import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.List;
Expand Down Expand Up @@ -252,7 +251,10 @@ public AuthResponse createToken(final TokenRequest tokenRequest, final String to
if (tokenRequest.numUses != null) jsonObject.add("num_uses", tokenRequest.numUses);
final String requestJson = jsonObject.toString();

final StringBuilder urlBuilder = new StringBuilder(config.getAddress()).append("/v1/auth/" + mount + "/create");//NOPMD
final StringBuilder urlBuilder = new StringBuilder(config.getAddress())//NOPMD
.append("/v1/auth/")
.append(mount)
.append("/create");
if (tokenRequest.role != null) {
urlBuilder.append("/").append(tokenRequest.role);
}
Expand Down Expand Up @@ -1228,7 +1230,7 @@ public LookupResponse lookupSelf(final String tokenAuthMount) throws VaultExcept
throw new VaultException("Vault responded with HTTP status code: " + restResponse.getStatus(), restResponse.getStatus());
}
final String mimeType = restResponse.getMimeType();
if (mimeType == null || !"application/json".equals(mimeType)) {
if (!"application/json".equals(mimeType)) {
throw new VaultException("Vault responded with MIME type: " + mimeType, restResponse.getStatus());
}
return new LookupResponse(restResponse, retryCount);
Expand Down Expand Up @@ -1291,7 +1293,7 @@ public LogicalResponse lookupWrap() throws VaultException {
restResponse.getStatus());
}
final String mimeType = restResponse.getMimeType();
if (mimeType == null || !"application/json".equals(mimeType)) {
if (!"application/json".equals(mimeType)) {
throw new VaultException("Vault responded with MIME type: " + mimeType, restResponse.getStatus());
}
return new LogicalResponse(restResponse, retryCount, Logical.logicalOperations.authentication);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/bettercloud/vault/api/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.bettercloud.vault.rest.Rest;
import com.bettercloud.vault.rest.RestException;
import com.bettercloud.vault.rest.RestResponse;

import java.util.HashSet;
import java.util.Set;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/bettercloud/vault/api/Leases.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.bettercloud.vault.response.VaultResponse;
import com.bettercloud.vault.rest.Rest;
import com.bettercloud.vault.rest.RestResponse;

import java.nio.charset.StandardCharsets;


Expand Down
Loading