forked from ohioit/rundeck-http-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from rundeck-plugins/RUN-1537
RUN-1537: report the list of keys
- Loading branch information
Showing
7 changed files
with
96 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/edu/ohio/ais/rundeck/util/SecretBundleUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.ohio.ais.rundeck.util; | ||
|
||
import com.dtolabs.rundeck.core.execution.ExecutionContext; | ||
import com.dtolabs.rundeck.core.execution.proxy.DefaultSecretBundle; | ||
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle; | ||
import com.dtolabs.rundeck.core.storage.ResourceMeta; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SecretBundleUtil { | ||
|
||
public static List<String> getListSecrets(Map<String, Object> configuration) { | ||
List<String> listSecretPath = new ArrayList<>(); | ||
String passwordPath = (String)configuration.get("password"); | ||
|
||
if(passwordPath!=null && !passwordPath.isEmpty() ){ | ||
listSecretPath.add(passwordPath); | ||
} | ||
|
||
return listSecretPath; | ||
} | ||
|
||
public static SecretBundle getSecrets(ExecutionContext context, Map<String, Object> configuration){ | ||
DefaultSecretBundle secretBundle = new DefaultSecretBundle(); | ||
String passwordPath = (String)configuration.get("password"); | ||
|
||
if(passwordPath!=null && !passwordPath.isEmpty() ){ | ||
byte[] content = SecretBundleUtil.getStoragePassword(context,passwordPath); | ||
if(content!=null){ | ||
secretBundle.addSecret(passwordPath, content); | ||
} | ||
} | ||
return secretBundle; | ||
} | ||
|
||
public static byte[] getStoragePassword(ExecutionContext context, String path){ | ||
try(ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { | ||
ResourceMeta contents = context.getStorageTree().getResource(path).getContents(); | ||
contents.writeContent(byteArrayOutputStream); | ||
return byteArrayOutputStream.toByteArray(); | ||
} catch (Exception e) { | ||
context.getExecutionLogger().log(0, e.getMessage()); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters