Skip to content

Commit

Permalink
Use context.execIdForLogStore to validate s3object metadata and use c…
Browse files Browse the repository at this point in the history
…ontext.outputfilepath if references an s3 object
  • Loading branch information
L2JE committed Sep 7, 2023
1 parent f5878ba commit c238669
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class S3LogFileStoragePlugin implements ExecutionFileStoragePlugin, AWSCr
public static final String DEFAULT_PATH_FORMAT = "project/${job.project}/${job.execid}";
public static final String DEFAULT_REGION = "us-east-1";
public static final String META_EXECID = "execid";

public static final String META_ID_FOR_LOGSTORE = "execIdForLogStore";

public static final String _PREFIX_META = "rundeck.";

public static final String META_USERNAME = "username";
Expand Down Expand Up @@ -188,7 +191,7 @@ public void initialize(Map<String, ?> context) {
if (!configpath.contains("${job.execid}") && configpath.endsWith("/")) {
configpath = path + "/${job.execid}";
}
expandedPath = expandPath(configpath, context);
expandedPath = (context.get("isRemoteFilePath") != null && context.get("isRemoteFilePath").equals("true")) ? String.valueOf(context.get("outputfilepath").toString()) : expandPath(configpath, context);
if (null == expandedPath || "".equals(expandedPath.trim())) {
throw new IllegalArgumentException("expanded value of path was empty");
}
Expand Down Expand Up @@ -268,7 +271,7 @@ private static Map<String, String> stringMap(final Map<String, ?> context) {

public boolean isAvailable(final String filetype) throws ExecutionFileStorageException {
HashMap<String, Object> expected = new HashMap<>();
expected.put(metaKey(META_EXECID), context.get(META_EXECID));
expected.put(metaKey(META_EXECID), context.get(META_ID_FOR_LOGSTORE));
return isPathAvailable(resolvedFilepath(expandedPath, filetype), expected);
}

Expand Down Expand Up @@ -394,7 +397,7 @@ public boolean deleteFile(String filetype) throws IOException, ExecutionFileStor
try{

HashMap<String, Object> expected = new HashMap<>();
expected.put(metaKey(META_EXECID), context.get(META_EXECID));
expected.put(metaKey(META_EXECID), context.get(META_ID_FOR_LOGSTORE));
String filePath = resolvedFilepath(expandedPath, filetype);

amazonS3.deleteObject(getBucket(), filePath);
Expand Down

0 comments on commit c238669

Please sign in to comment.