Skip to content

Commit

Permalink
Fixing some bugs to get the list of keys on the job page, and fixing …
Browse files Browse the repository at this point in the history
…the API call
  • Loading branch information
ltamaster committed Mar 16, 2018
1 parent 5c04f71 commit acc6b4c
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public class VaultStoragePlugin implements StoragePlugin, Configurable, Describa
public VaultStoragePlugin() {}

private static final String VAULT_STORAGE_KEY = "data";
private static final String RUNDECK_DATA_TYPE = "Rundeck-data-type";
private static final String RUNDECK_KEY_TYPE = "Rundeck-key-type";
private static final String RUNDECK_CONTENT_MASK = "Rundeck-content-mask";
private static final String PRIVATE_KEY_MIME_TYPE = "application/octet-stream";
private static final String PUBLIC_KEY_MIME_TYPE = "application/pgp-keys";
private static final String PASSWORD_MIME_TYPE = "application/x-rundeck-data-password";


private String vaultPrefix;
private Logical vault;

Expand All @@ -78,6 +86,19 @@ private boolean isDir(String key) {
return key.endsWith("/");
}

private boolean isVaultDir(String key) {
try{
if(vault.list(getVaultPath(key)).size() > 0){
return true;
}else{
return false;
}
} catch (VaultException e) {
log.info("error:" + e.getMessage());
return false;
}
}

private enum KeyType {
RESOURCE,
DIRECTORY,
Expand Down Expand Up @@ -164,6 +185,17 @@ private Resource<ResourceMeta> loadResource(Path path, String event) {
} catch (ParseException e) {
}

String type=payload.get(StorageUtil.RES_META_RUNDECK_CONTENT_TYPE);
if (type.equals(PRIVATE_KEY_MIME_TYPE)) {
builder.setMeta(RUNDECK_CONTENT_MASK, "content");
builder.setMeta(RUNDECK_KEY_TYPE, "private");
}else if (type.equals(PUBLIC_KEY_MIME_TYPE)){
builder.setMeta(RUNDECK_KEY_TYPE, "public");
}else if (type.equals(PASSWORD_MIME_TYPE)){
builder.setMeta(RUNDECK_CONTENT_MASK, "content");
builder.setMeta(RUNDECK_DATA_TYPE, "password");
}

ByteArrayInputStream baiStream = new ByteArrayInputStream(data.getBytes());
return new ResourceBase<>(path,
StorageUtil.withStream(baiStream, builder.getResourceMeta()),
Expand Down Expand Up @@ -210,7 +242,12 @@ private Set<Resource<ResourceMeta>> listResources(Path path, KeyType type) {
@Override
public boolean hasPath(Path path) {
try {
return vault.list(getVaultPath(path.getPath())).size() > 0;
if(vault.list(getVaultPath(path.getPath())).size() > 0){
return true;
}

//check if the path is a key
return hasResource(path);
} catch (VaultException e) {
return false;
}
Expand Down Expand Up @@ -251,7 +288,11 @@ public boolean hasDirectory(String path) {

@Override
public Resource<ResourceMeta> getPath(Path path) {
return loadDir(path);
if (isVaultDir(path.toString())) {
return loadDir(path);
} else {
return loadResource(path, "read");
}
}

@Override
Expand Down

0 comments on commit acc6b4c

Please sign in to comment.