From c23866922a0f4d66196ae91347ebe71db95e8b0a Mon Sep 17 00:00:00 2001 From: L2JE Date: Wed, 6 Sep 2023 17:57:28 -0300 Subject: [PATCH 1/4] Use context.execIdForLogStore to validate s3object metadata and use context.outputfilepath if references an s3 object --- .../java/org/rundeck/plugins/S3LogFileStoragePlugin.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java index e014593..6cfc985 100644 --- a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java +++ b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java @@ -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"; @@ -188,7 +191,7 @@ public void initialize(Map 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"); } @@ -268,7 +271,7 @@ private static Map stringMap(final Map context) { public boolean isAvailable(final String filetype) throws ExecutionFileStorageException { HashMap 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); } @@ -394,7 +397,7 @@ public boolean deleteFile(String filetype) throws IOException, ExecutionFileStor try{ HashMap 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); From 88f6c91a697124a403faa552917e36dccfaef6ab Mon Sep 17 00:00:00 2001 From: L2JE Date: Thu, 28 Sep 2023 15:51:47 -0300 Subject: [PATCH 2/4] consider execIdForLogstore in exec context for tests --- .../java/org/rundeck/plugins/S3LogFileStoragePluginTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/rundeck/plugins/S3LogFileStoragePluginTest.java b/src/test/java/org/rundeck/plugins/S3LogFileStoragePluginTest.java index 069ac9d..0405cec 100644 --- a/src/test/java/org/rundeck/plugins/S3LogFileStoragePluginTest.java +++ b/src/test/java/org/rundeck/plugins/S3LogFileStoragePluginTest.java @@ -64,6 +64,7 @@ public void expandJobId() { private HashMap testContext() { HashMap stringHashMap = new HashMap(); stringHashMap.put("execid", "testexecid"); + stringHashMap.put(S3LogFileStoragePlugin.META_ID_FOR_LOGSTORE, "testexecid"); stringHashMap.put("project", "testproject"); stringHashMap.put("url", "http://rundeck:4440/execution/5/show"); stringHashMap.put("serverUrl", "http://rundeck:4440"); From c2ba062c59105a3774101f1ed4f6fc6f4a4fdf44 Mon Sep 17 00:00:00 2001 From: L2JE Date: Tue, 17 Oct 2023 13:48:12 -0300 Subject: [PATCH 3/4] implement getConfiguredPathTemplate to return configured path --- .../java/org/rundeck/plugins/S3LogFileStoragePlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java index 6cfc985..e62541e 100644 --- a/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java +++ b/src/main/java/org/rundeck/plugins/S3LogFileStoragePlugin.java @@ -275,6 +275,11 @@ public boolean isAvailable(final String filetype) throws ExecutionFileStorageExc return isPathAvailable(resolvedFilepath(expandedPath, filetype), expected); } + @Override + public String getConfiguredPathTemplate() { + return this.path; + } + protected boolean isPathAvailable(final String key, Map expectedMeta) throws ExecutionFileStorageException { From 72a0286e17f85a333d6b6deab3b17344922490d8 Mon Sep 17 00:00:00 2001 From: L2JE Date: Wed, 25 Oct 2023 12:15:19 -0300 Subject: [PATCH 4/4] Upgrade core dependency to 4.17.2-rc1-20231025 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 90e148e..7fbfbfd 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ apply plugin: 'pl.allegro.tech.build.axion-release' sourceCompatibility = 1.8 ext.rundeckPluginVersion= '1.2' -ext.rundeckVersion='2.6.5' +ext.rundeckVersion='4.17.2-rc1-20231025' /** * Set this to a comma-separated list of full classnames of your implemented Rundeck @@ -108,4 +108,4 @@ jar { } } //set jar task to depend on copyToLib -jar.dependsOn(copyToLib) \ No newline at end of file +jar.dependsOn(copyToLib)