Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.*;

/**
* Created by reneschollmeyer on 18.08.17.
Expand All @@ -27,6 +26,9 @@ public class SecretTests extends AbstractTest {

private final String secretId = "520405bc-c7c5-41ea-97ad-6c67a8d41a9e";
private final String secretName = "test_secret";
private final String content_type = "application/octet-stream";

private final Date expiration = new Date(1451330264394l);

public void testListSecretsByName() throws IOException {
respondWith(SECRETS_JSON);
Expand All @@ -47,14 +49,25 @@ public void testGetSecret() throws IOException {
Secret secret = osv3().barbican().secrets().get(secretId);
assertNotNull(secret);
assertNotNull(secret.getName());
assertEquals(secret.getExpiration(), expiration);
assertTrue(!secret.getContentTypes().isEmpty());
assertEquals(secret.getContentTypes().get("default"), content_type);
}

public void testCreateSecret() throws IOException {
respondWithCodeAndResource(201, SECRET_CREATE_JSON);
Secret test = Builders.secret()
.name("test-secret")
.algorithm("aes")
.bitLength(256)
.expiration(new Date())
.mode("cbc")
.secretType("opaque")
.payload("test-payload")
.payloadContentType("text/plain")
.build();
Secret result = osv3().barbican().secrets().create(test);
assertNotNull(result);
assertNotNull(result.getSecretReference());
}

Expand Down
24 changes: 19 additions & 5 deletions core/src/main/java/org/openstack4j/model/barbican/Secret.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import org.openstack4j.common.Buildable;
import org.openstack4j.model.ModelEntity;
import org.openstack4j.model.barbican.builder.SecretCreateBuilder;
import org.openstack4j.model.common.ActionResponse;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* Created by reneschollmeyer on 02.08.17.
Expand All @@ -21,12 +20,12 @@ public interface Secret extends ModelEntity, Buildable<SecretCreateBuilder> {
/**
* @return bit length of the secret. Must be greater than zero.
*/
int getBitLength();
Integer getBitLength();

/**
* @return content type of the secret.
*/
List<String> getContentTypes();
Map<String, String> getContentTypes();

/**
* @return system generated creation time.
Expand All @@ -46,7 +45,7 @@ public interface Secret extends ModelEntity, Buildable<SecretCreateBuilder> {
/**
* @return expiration of the secret.
*/
String getExpiration();
Date getExpiration();

/**
* @return mode of the secret.
Expand All @@ -72,4 +71,19 @@ public interface Secret extends ModelEntity, Buildable<SecretCreateBuilder> {
* @return current status of the secret.
*/
String getStatus();

/**
* @return stored secret data.
*/
String getPayload();

/**
* @return content type of the secret data.
*/
String getPayloadContentType();

/**
* @return encoding used for the data.
*/
String getPayloadContentEncoding();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.openstack4j.common.Buildable;
import org.openstack4j.model.barbican.Secret;

import java.util.Date;

/**
* Created by reneschollmeyer on 02.08.17.
*/
Expand All @@ -13,4 +15,55 @@ public interface SecretCreateBuilder extends Buildable.Builder<SecretCreateBuild
* @return
*/
SecretCreateBuilder name(String name);

/**
* @param expiration UTC Timestamp. If set, the secret will not be available after this time.
* @return
*/
SecretCreateBuilder expiration(Date expiration);

/**
* @param algorithm Metadata provided by a user or system for informational purposes.
* @return
*/
SecretCreateBuilder algorithm(String algorithm);

/**
* @param bitLength Metadata provided by a user or system for informational purposes.
* Value must be greater than zero.
* @return
*/
SecretCreateBuilder bitLength(Integer bitLength);

/**
* @param mode Metadata provided by a user or system for informational purposes.
* @return
*/
SecretCreateBuilder mode(String mode);

/**
* @param payload The secret’s data to be stored.
* @return
*/
SecretCreateBuilder payload(String payload);

/**
* @param payloadContentType The media type for the content of the payload
* (required if payload is included).
* @return
*/
SecretCreateBuilder payloadContentType(String payloadContentType);

/**
* @param payloadContentEncoding The encoding used for the payload to be able to include
* it in the JSON request (required if payload is encoded).
* @return
*/
SecretCreateBuilder payloadContentEncoding(String payloadContentEncoding);

/**
* @param secretType Used to indicate the type of secret being stored.
* @return
*/
SecretCreateBuilder secretType(String secretType);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openstack4j.openstack.barbican.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.openstack4j.model.barbican.Secret;
Expand All @@ -8,6 +9,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* Created by reneschollmeyer on 02.08.17.
Expand All @@ -18,17 +20,17 @@ public class BarbicanSecret implements Secret {
@JsonProperty("algorithm")
private String algorithm;
@JsonProperty("bit_length")
private int bitLength;
@JsonProperty("content-types")
private List<String> contentTypes;
private Integer bitLength;
@JsonProperty("content_types")
private Map<String, String> contentTypes;
@JsonProperty("created")
private Date createTime;
@JsonProperty("updated")
private Date updateTime;
@JsonProperty("creator_id")
private String creatorId;
@JsonProperty("expiration")
private String expiration;
private Date expiration;
@JsonProperty("mode")
private String mode;
@JsonProperty("secret_ref")
Expand All @@ -37,6 +39,12 @@ public class BarbicanSecret implements Secret {
private String secretType;
@JsonProperty("status")
private String status;
@JsonProperty("payload")
private String payload;
@JsonProperty("payload_content_type")
private String payloadContentType;
@JsonProperty("payload_content_encoding")
private String payloadContentEncoding;

/**
* {@inheritDoc}
Expand All @@ -50,15 +58,15 @@ public String getAlgorithm() {
* {@inheritDoc}
*/
@Override
public int getBitLength() {
public Integer getBitLength() {
return bitLength;
}

/**
* {@inheritDoc}
*/
@Override
public List<String> getContentTypes() {
public Map<String, String> getContentTypes() {
return contentTypes;
}

Expand Down Expand Up @@ -90,7 +98,7 @@ public String getCreatorId() {
* {@inheritDoc}
*/
@Override
public String getExpiration() {
public Date getExpiration() {
return expiration;
}

Expand Down Expand Up @@ -134,12 +142,30 @@ public String getStatus() {
return status;
}

/**
* {@inheritDoc}
*/
@Override
public String getPayload() { return payload; }

/**
* {@inheritDoc}
*/
@Override
public String getPayloadContentType() { return payloadContentType; }

/**
* {@inheritDoc}
*/
@Override
public String getPayloadContentEncoding() { return payloadContentEncoding; }

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return MoreObjects.toStringHelper(this).omitNullValues()
return MoreObjects.toStringHelper(this)
.add("algorithm", algorithm).add("bit_length", bitLength)
.add("content_types", contentTypes).add("created", createTime)
.add("creator_id", creatorId).add("expiration", expiration)
Expand Down Expand Up @@ -198,6 +224,78 @@ public SecretCreateBuilder name(String name) {
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder expiration(Date expiration) {
internalSecret.expiration = expiration;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder algorithm(String algorithm) {
internalSecret.algorithm = algorithm;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder bitLength(Integer bitLength) {
internalSecret.bitLength = bitLength;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder mode(String mode) {
internalSecret.mode = mode;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder payload(String payload) {
internalSecret.payload = payload;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder payloadContentType(String payloadContentType) {
internalSecret.payloadContentType = payloadContentType;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder payloadContentEncoding(String payloadContentEncoding) {
internalSecret.payloadContentEncoding = payloadContentEncoding;
return this;
}

/**
* {@inheritDoc}
*/
@Override
public SecretCreateBuilder secretType(String secretType) {
internalSecret.secretType = secretType;
return this;
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public ActionResponse delete(String secretId) {
@Override
public Secret create(Secret secret) {
checkNotNull(secret);
return put(BarbicanSecret.class, uri(RESOURCE_PATH)).entity(secret).execute();
return post(BarbicanSecret.class, uri(RESOURCE_PATH)).entity(secret).execute();
}
}