Fixed AuthMethodResponse for Vault 0.6.1 compatibility

This commit is contained in:
Stefan Kalscheuer 2016-09-01 20:26:14 +02:00
parent 4c68e74a38
commit 847cce7bfb
5 changed files with 41 additions and 26 deletions

View File

@ -14,7 +14,7 @@ Java Vault Connector is a connector library for [Vault](https://www.vaultproject
* Write secrets * Write secrets
* List secrets * List secrets
* Connector Factory with builder pattern * Connector Factory with builder pattern
* Tested against Vault 0.6.0 * Tested against Vault 0.6.1
**Usage Example** **Usage Example**
@ -38,7 +38,7 @@ String secret = vault.readSecret("some/secret/key").getValue();
<dependency> <dependency>
<groupId>de.stklcode.jvault</groupId> <groupId>de.stklcode.jvault</groupId>
<artifactId>connector</artifactId> <artifactId>connector</artifactId>
<version>0.1.1</version> <version>0.2.0</version>
</dependency> </dependency>
``` ```

View File

@ -6,7 +6,7 @@
<groupId>de.stklcode.jvault</groupId> <groupId>de.stklcode.jvault</groupId>
<artifactId>connector</artifactId> <artifactId>connector</artifactId>
<version>0.1.2-SNAPSHOT</version> <version>0.2.0-SNAPSHOT</version>
<build> <build>
<plugins> <plugins>

View File

@ -159,7 +159,7 @@ public class HTTPVaultConnector implements VaultConnector {
String response = requestGet(PATH_AUTH, new HashMap<>()); String response = requestGet(PATH_AUTH, new HashMap<>());
/* Parse response */ /* Parse response */
AuthMethodsResponse amr = jsonMapper.readValue(response, AuthMethodsResponse.class); AuthMethodsResponse amr = jsonMapper.readValue(response, AuthMethodsResponse.class);
return amr.getSupportedMethods().stream().map(AuthMethod::getType).collect(Collectors.toList()); return amr.getSupportedMethods().values().stream().map(AuthMethod::getType).collect(Collectors.toList());
} catch (IOException e) { } catch (IOException e) {
throw new InvalidResponseException("Unable to parse response", e); throw new InvalidResponseException("Unable to parse response", e);
} catch (URISyntaxException ignored) { } catch (URISyntaxException ignored) {

View File

@ -1,11 +1,12 @@
package de.stklcode.jvault.connector.model.response; package de.stklcode.jvault.connector.model.response;
import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.stklcode.jvault.connector.exception.InvalidResponseException; import de.stklcode.jvault.connector.exception.InvalidResponseException;
import de.stklcode.jvault.connector.model.response.embedded.AuthMethod; import de.stklcode.jvault.connector.model.response.embedded.AuthMethod;
import java.util.ArrayList; import java.io.IOException;
import java.util.List; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -14,19 +15,27 @@ import java.util.Map;
* @author Stefan Kalscheuer * @author Stefan Kalscheuer
* @since 0.1 * @since 0.1
*/ */
public class AuthMethodsResponse implements VaultResponse { @JsonIgnoreProperties(ignoreUnknown = true)
public class AuthMethodsResponse extends VaultDataResponse {
private Map<String, AuthMethod> supportedMethods;
private List<AuthMethod> supportedMethods; public AuthMethodsResponse() {
this.supportedMethods = new HashMap<>();
@JsonAnySetter
public void setMethod(String path, Map<String, String> data) throws InvalidResponseException {
if (supportedMethods == null)
supportedMethods = new ArrayList<>();
supportedMethods.add(new AuthMethod(path, data.get("description"), data.get("type")));
} }
public List<AuthMethod> getSupportedMethods() { @Override
public void setData(Map<String, Object> data) throws InvalidResponseException {
ObjectMapper mapper = new ObjectMapper();
for (String path : data.keySet()) {
try {
this.supportedMethods.put(path, mapper.readValue(mapper.writeValueAsString(data.get(path)), AuthMethod.class));
} catch (IOException e) {
throw new InvalidResponseException();
}
}
}
public Map<String, AuthMethod> getSupportedMethods() {
return supportedMethods; return supportedMethods;
} }
} }

View File

@ -1,8 +1,11 @@
package de.stklcode.jvault.connector.model.response.embedded; package de.stklcode.jvault.connector.model.response.embedded;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import de.stklcode.jvault.connector.model.AuthBackend; import de.stklcode.jvault.connector.model.AuthBackend;
import java.util.Map;
/** /**
* Embedded authentication method response. * Embedded authentication method response.
* *
@ -12,12 +15,15 @@ import de.stklcode.jvault.connector.model.AuthBackend;
public class AuthMethod { public class AuthMethod {
private AuthBackend type; private AuthBackend type;
private String rawType; private String rawType;
private String path;
@JsonProperty("description")
private String description; private String description;
public AuthMethod(String path, String description, String type) { @JsonProperty("config")
this.path = path; private Map<String, String> config;
this.description = description;
@JsonSetter("type")
public void setType(String type) {
this.rawType = type; this.rawType = type;
this.type = AuthBackend.forType(type); this.type = AuthBackend.forType(type);
} }
@ -30,11 +36,11 @@ public class AuthMethod {
return rawType; return rawType;
} }
public String getPath() {
return path;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
public Map<String, String> getConfig() {
return config;
}
} }