Skip to content

Commit

Permalink
command executor java doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
madhavikdb committed Nov 19, 2019
1 parent 81e1fa0 commit b4cd996
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public static CommandResult executeAndGetResults(String command) {
}

/**
* Executes command with the given input,
* if command execution fails it returns CommandResult with null CommandOutput and exit code as 1.
* Executes command with the given input.
*
*
* @param command
* @param stdInput it is passed to the process as input
* @return commandResult
* @param stdInput it is passed to the command as input
* @return commandResult if command execution fails it returns CommandResult with null CommandOutput and exit code as 1.
*/
public static CommandResult executeAndGetResults(String command, String stdInput) {
try {
Expand Down Expand Up @@ -127,7 +127,7 @@ public static boolean executeInDir(String command, File commandOutputFile, Strin
* else Asynchronously copy command output in
* {@link CommandResult#setCommandOutput(String)} waits for the process to
* complete
* if standard input is specified, it is passed as input to the process.
* if standard input is specified, it is passed as input to the command.
*
* @param command
* @param file
Expand Down Expand Up @@ -158,12 +158,7 @@ private static CommandResult _execute(String command, File file, String dir, Str
processBuilder.redirectOutput(file);
}
Process process = processBuilder.start();

try {
handleStandardInput(process, command, stdInput);
} catch (HyscaleException e) {
throw e;
}
handleStandardInput(process, command, stdInput);

boolean readOutput = false;
StringWriter strWriter = new StringWriter();
Expand Down Expand Up @@ -203,6 +198,15 @@ private static boolean copyOutput(Process process, StringWriter strWriter) {
});
}


/**
* Passes input to command.
*
* @param process
* @param command
* @param stdInput
* @throws HyscaleException
*/
private static void handleStandardInput(Process process, String command, String stdInput) throws HyscaleException {
if (StringUtils.isNotBlank(stdInput)) {
try (OutputStream processStdin = process.getOutputStream()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ public DockerCredHelper(String helperFunction) {
* @return CredsStoreEntity object containing username and password if found ,else returns null.
*/
public CredsStoreEntity get(String registryUrl) {
String s = null;
StringBuilder stringBuilder = new StringBuilder();
String command = stringBuilder.append(DOCKER_CREDENTIAL).append(getHelperFunction()).append(ToolConstants.SPACE).append(GET).toString();
try {
CommandResult result = CommandExecutor.executeAndGetResults(command, registryUrl);
ObjectMapper mapper = ObjectMapperFactory.jsonMapper();
if(StringUtils.isNotBlank(result.getCommandOutput())&& result.getExitCode()!=1) {
if(result!=null && StringUtils.isNotBlank(result.getCommandOutput())&& result.getExitCode()!=1) {
CredsStoreEntity credsStore = mapper.readValue(result.getCommandOutput(), CredsStoreEntity.class);
if (StringUtils.isNotBlank(credsStore.getServerURL()) && StringUtils.isNotBlank(credsStore.getUsername()) && StringUtils.isNotBlank(credsStore.getSecret())) {
return credsStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ private ImageRegistry from(CredsStoreEntity credsStoreEntity) {

/**
* returns ImageRegistry from Auths of local docker config if found else returns null.
<<<<<<< c2653ba73f1c6cd7e2ae08f4346d491ad20d99ad
* <p> Example of Auths:
* "auths": {
* "registry": {
Expand All @@ -65,9 +64,6 @@ private ImageRegistry from(CredsStoreEntity credsStoreEntity) {
* }
* if auth exists with matching registry returns credentials by base64 decoding auth and spliting them by colon
* and creates ImageRegistry object.
=======
*
>>>>>>> docker credStore and credHelper support changes
* @param auths
* @return ImageRegistry
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void init() throws HyscaleException {
/**returns image registry credentials if found in docker config in the credHelpers,credsStore or Auths else returns null.
*
* @param registry
* @return ImageRegistry object
* @return ImageRegistry object if found in credHelpers,credsStore or Auths else returns null.
*/
@Override
public ImageRegistry getImageRegistry(String registry) throws HyscaleException {
Expand Down Expand Up @@ -108,7 +108,7 @@ public ImageRegistry getImageRegistry(String registry) throws HyscaleException {
* or directly credsStore if specified else returns null.
*
* @param pattern
* @return docker credential helper
* @return docker credential helper else returns null
*/
public DockerCredHelper getDockerCredHelper(String pattern) {
String helperFunc = dockerConfig.getCredHelpers() != null ? getHelperFunction(pattern) : null;
Expand Down

0 comments on commit b4cd996

Please sign in to comment.