@Test public void backendS3operationsWhenPutActionSpecified() throws IOException, InterruptedException { TerraformPlanFileUtils planFileUtils = new TerraformPlanFileUtils(executable, logger); String s3BucketKey = "s3: properties.put("planOutputFile", s3BucketKey); planFileUtils.backendS3operations("PUT", s3BucketKey, properties); Mockito.verify(executable, Mockito.times(1)).execute("aws s3 cp test.json s3: }
protected void backendS3operations(String action, String s3Key, Properties properties ) throws IOException { try { String bucketName = s3Key.split("/")[2]; String fileName = s3Key.substring(s3Key.lastIndexOf("/")).replaceAll("/", ""); if (action.equals("GET")) { executable.execute(String.format("aws s3api get-object --bucket %1$s --key %2$s %3$s", bucketName, fileName, fileName)); } else if (action.equals("PUT")) { if (properties.containsKey("kmsKeyId")) { LOGGER.debug("uploading plan files to Amazon S3 with kms encryption"); executable.execute(String.format("aws s3 cp %1$s %2$s --sse aws:kms --sse-kms-key-id %3$s", fileName, s3Key, properties.getProperty("kmsKeyId"))); } else { LOGGER.debug("uploading plan files to Amazon S3 with default encryption (SSE:256)"); executable.execute(String.format("aws s3 cp %1$s %2$s", fileName, s3Key)); } } } catch (InterruptedException e) { e.printStackTrace(); } }
TerraformPlanFileUtils { protected void backendS3operations(String action, String s3Key, Properties properties ) throws IOException { try { String bucketName = s3Key.split("/")[2]; String fileName = s3Key.substring(s3Key.lastIndexOf("/")).replaceAll("/", ""); if (action.equals("GET")) { executable.execute(String.format("aws s3api get-object --bucket %1$s --key %2$s %3$s", bucketName, fileName, fileName)); } else if (action.equals("PUT")) { if (properties.containsKey("kmsKeyId")) { LOGGER.debug("uploading plan files to Amazon S3 with kms encryption"); executable.execute(String.format("aws s3 cp %1$s %2$s --sse aws:kms --sse-kms-key-id %3$s", fileName, s3Key, properties.getProperty("kmsKeyId"))); } else { LOGGER.debug("uploading plan files to Amazon S3 with default encryption (SSE:256)"); executable.execute(String.format("aws s3 cp %1$s %2$s", fileName, s3Key)); } } } catch (InterruptedException e) { e.printStackTrace(); } } }
TerraformPlanFileUtils { protected void backendS3operations(String action, String s3Key, Properties properties ) throws IOException { try { String bucketName = s3Key.split("/")[2]; String fileName = s3Key.substring(s3Key.lastIndexOf("/")).replaceAll("/", ""); if (action.equals("GET")) { executable.execute(String.format("aws s3api get-object --bucket %1$s --key %2$s %3$s", bucketName, fileName, fileName)); } else if (action.equals("PUT")) { if (properties.containsKey("kmsKeyId")) { LOGGER.debug("uploading plan files to Amazon S3 with kms encryption"); executable.execute(String.format("aws s3 cp %1$s %2$s --sse aws:kms --sse-kms-key-id %3$s", fileName, s3Key, properties.getProperty("kmsKeyId"))); } else { LOGGER.debug("uploading plan files to Amazon S3 with default encryption (SSE:256)"); executable.execute(String.format("aws s3 cp %1$s %2$s", fileName, s3Key)); } } } catch (InterruptedException e) { e.printStackTrace(); } } TerraformPlanFileUtils(String tfRootDir, Logger logger);  TerraformPlanFileUtils(Executable executable, Logger logger); }
TerraformPlanFileUtils { protected void backendS3operations(String action, String s3Key, Properties properties ) throws IOException { try { String bucketName = s3Key.split("/")[2]; String fileName = s3Key.substring(s3Key.lastIndexOf("/")).replaceAll("/", ""); if (action.equals("GET")) { executable.execute(String.format("aws s3api get-object --bucket %1$s --key %2$s %3$s", bucketName, fileName, fileName)); } else if (action.equals("PUT")) { if (properties.containsKey("kmsKeyId")) { LOGGER.debug("uploading plan files to Amazon S3 with kms encryption"); executable.execute(String.format("aws s3 cp %1$s %2$s --sse aws:kms --sse-kms-key-id %3$s", fileName, s3Key, properties.getProperty("kmsKeyId"))); } else { LOGGER.debug("uploading plan files to Amazon S3 with default encryption (SSE:256)"); executable.execute(String.format("aws s3 cp %1$s %2$s", fileName, s3Key)); } } } catch (InterruptedException e) { e.printStackTrace(); } } TerraformPlanFileUtils(String tfRootDir, Logger logger);  TerraformPlanFileUtils(Executable executable, Logger logger); String executePlanFileOperation(Properties properties); }
TerraformPlanFileUtils { protected void backendS3operations(String action, String s3Key, Properties properties ) throws IOException { try { String bucketName = s3Key.split("/")[2]; String fileName = s3Key.substring(s3Key.lastIndexOf("/")).replaceAll("/", ""); if (action.equals("GET")) { executable.execute(String.format("aws s3api get-object --bucket %1$s --key %2$s %3$s", bucketName, fileName, fileName)); } else if (action.equals("PUT")) { if (properties.containsKey("kmsKeyId")) { LOGGER.debug("uploading plan files to Amazon S3 with kms encryption"); executable.execute(String.format("aws s3 cp %1$s %2$s --sse aws:kms --sse-kms-key-id %3$s", fileName, s3Key, properties.getProperty("kmsKeyId"))); } else { LOGGER.debug("uploading plan files to Amazon S3 with default encryption (SSE:256)"); executable.execute(String.format("aws s3 cp %1$s %2$s", fileName, s3Key)); } } } catch (InterruptedException e) { e.printStackTrace(); } } TerraformPlanFileUtils(String tfRootDir, Logger logger);  TerraformPlanFileUtils(Executable executable, Logger logger); String executePlanFileOperation(Properties properties);  }