From 4b1d4787125e6a06488d77508f76ffe16cf2c9ed Mon Sep 17 00:00:00 2001 From: Yury Brigadirenko Date: Tue, 5 Nov 2024 16:48:55 -0500 Subject: [PATCH] tasks: initial support for dry-run mode (#179) --- pom.xml | 2 +- tasks/akeyless/pom.xml | 2 +- .../plugins/akeyless/AkeylessCommon.java | 26 +++- .../plugins/akeyless/v2/AkeylessTask.java | 9 +- tasks/aws/pom.xml | 1 + .../concord/plugins/aws/EcrTask.java | 11 +- .../concord/plugins/git/GitHubTask.java | 114 +++++++++++++++--- .../concord/plugins/git/GitTask.java | 14 ++- .../concord/plugins/git/v1/GitTaskV1.java | 6 +- .../concord/plugins/git/v2/GitTaskV2.java | 7 +- .../concord/plugins/git/v2/GithubTaskV2.java | 13 +- .../concord/plugins/git/v2/GitTaskV2Test.java | 8 +- .../hashivault/HashiVaultTaskCommon.java | 17 ++- .../plugins/hashivault/v2/HashiVaultTask.java | 11 +- .../hashivault/model/MockContextV2.java | 6 +- .../concord/plugins/jira/JiraTaskCommon.java | 48 +++++++- .../concord/plugins/jira/v2/JiraTaskV2.java | 7 +- .../plugins/jira/v2/JiraTaskV2Test.java | 12 +- .../plugins/jsonpath/v2/JsonPathTaskV2.java | 10 +- .../concord/plugins/ldap/v2/LdapTaskV2.java | 5 +- .../concord/plugins/s3/S3Task.java | 6 +- .../concord/plugins/s3/S3TaskCommon.java | 14 ++- .../concord/plugins/s3/v2/S3TaskV2.java | 12 +- .../concord/plugins/s3/S3TaskV2Test.java | 6 +- tasks/terraform/pom.xml | 1 + .../plugins/xmlutils/v2/XmlUtilsTaskV2.java | 2 + .../concord/plugins/zoom/ZoomClient.java | 9 +- .../concord/plugins/zoom/ZoomTaskCommon.java | 17 ++- .../concord/plugins/zoom/v2/ZoomTaskV2.java | 13 +- 29 files changed, 308 insertions(+), 101 deletions(-) diff --git a/pom.xml b/pom.xml index a523a3fa..2bd77ac1 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ scm:git:https://github.com/walmartlabs/concord-plugins.git - 2.14.0 + 2.19.0 2.10 3.14.9 3.5.2 diff --git a/tasks/akeyless/pom.xml b/tasks/akeyless/pom.xml index 83837ef1..6ddae2b7 100644 --- a/tasks/akeyless/pom.xml +++ b/tasks/akeyless/pom.xml @@ -262,4 +262,4 @@ - \ No newline at end of file + diff --git a/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/AkeylessCommon.java b/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/AkeylessCommon.java index b0d81bfb..2a22a631 100644 --- a/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/AkeylessCommon.java +++ b/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/AkeylessCommon.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -41,9 +41,14 @@ public class AkeylessCommon { private ApiClient apiClient; private SecretExporter secretExporter; private static final Map> authBuilders = createAuthBuilders(); + private final boolean dryRunMode; public AkeylessCommon() { - // empty default constructor + this(false); + } + + public AkeylessCommon(boolean dryRunMode) { + this.dryRunMode = dryRunMode; } private static Map> createAuthBuilders() { @@ -167,6 +172,11 @@ private AkeylessTaskResult createSecret(TaskParams.CreateSecretParams params) { V2Api api = getApi(params); String accessToken = getAccessToken(api); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping secret creation"); + return AkeylessTaskResult.of(true, null, null); + } + api.createSecret(new CreateSecret() .token(accessToken) .name(params.path()) @@ -189,6 +199,11 @@ private AkeylessTaskResult updateSecretVal(TaskParams.UpdateSecretParams params) V2Api api = getApi(params); String accessToken = getAccessToken(api); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping secret update"); + return AkeylessTaskResult.of(true, null, null); + } + api.updateSecretVal(new UpdateSecretVal() .token(accessToken) .value(params.value()) @@ -211,6 +226,11 @@ private AkeylessTaskResult deleteItem(TaskParams.DeleteItemParams params) { V2Api api = getApi(params); String accessToken = getAccessToken(api); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping item delete"); + return AkeylessTaskResult.of(true, null, null); + } + api.deleteItem(new DeleteItem() .token(accessToken) .name(params.path()) diff --git a/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/v2/AkeylessTask.java b/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/v2/AkeylessTask.java index 2f896c59..a4076471 100644 --- a/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/v2/AkeylessTask.java +++ b/tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/v2/AkeylessTask.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,6 +34,7 @@ import java.util.Map; @Named("akeyless") +@DryRunReady public class AkeylessTask implements Task { private final Map defaults; @@ -48,11 +49,11 @@ public AkeylessTask(Context ctx, SecretService secretService) { this.defaults.put("sessionToken", ctx.processConfiguration().processInfo().sessionToken()); this.defaults.put("txId", ctx.processInstanceId().toString()); this.policyDefaults = ctx.defaultVariables().toMap(); - this.delegate = new AkeylessCommon(); + this.delegate = new AkeylessCommon(ctx.processConfiguration().dryRun()); } @Override - public TaskResult.SimpleResult execute(Variables input) throws Exception { + public TaskResult.SimpleResult execute(Variables input) { final TaskParams params = createParams(input); AkeylessTaskResult result = delegate.execute(params, secretExporter); diff --git a/tasks/aws/pom.xml b/tasks/aws/pom.xml index 0636ea6b..1c7f0783 100644 --- a/tasks/aws/pom.xml +++ b/tasks/aws/pom.xml @@ -77,6 +77,7 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 + provided org.junit.jupiter diff --git a/tasks/aws/src/main/java/com/walmartlabs/concord/plugins/aws/EcrTask.java b/tasks/aws/src/main/java/com/walmartlabs/concord/plugins/aws/EcrTask.java index b17dc082..3ef78fd9 100644 --- a/tasks/aws/src/main/java/com/walmartlabs/concord/plugins/aws/EcrTask.java +++ b/tasks/aws/src/main/java/com/walmartlabs/concord/plugins/aws/EcrTask.java @@ -23,10 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.Task; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import software.amazon.awssdk.regions.Region; @@ -42,6 +39,7 @@ import static java.util.Objects.requireNonNull; @Named("awsEcr") +@DryRunReady public class EcrTask implements Task { private static final Logger log = LoggerFactory.getLogger(EcrTask.class); @@ -113,6 +111,11 @@ private TaskResult deleteImage(Variables input) { var imageIds = assertImageIds(input); var debug = input.getBoolean("debug", context.processConfiguration().debug()); + if (context.processConfiguration().dryRun()) { + log.info("Dry-run mode enabled: Skipping image deletion"); + return TaskResult.success(); + } + try (var client = EcrClient.builder() .region(region) .build()) { diff --git a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitHubTask.java b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitHubTask.java index 66ee3449..219e8cf7 100644 --- a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitHubTask.java +++ b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitHubTask.java @@ -105,6 +105,16 @@ public class GitHubTask { private static final TypeReference>> LIST_OF_OBJECT_TYPE = new TypeReference>>() { }; + private final boolean dryRunMode; + + public GitHubTask() { + this(false); + } + + public GitHubTask(boolean dryRunMode) { + this.dryRunMode = dryRunMode; + } + public Map execute(Map in, Map defaults) { Action action = getAction(in); String gitHubUri = getUrl(defaults, in, API_URL_KEY); @@ -188,7 +198,7 @@ public Map execute(Map in, Map d } } - private static Map createPR(Map in, String gitHubUri) { + private Map createPR(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -214,6 +224,11 @@ private static Map createPR(Map in, String gitHu pr.setHead(new PullRequestMarker().setLabel(gitHubPRHead)); pr.setBase(new PullRequestMarker().setLabel(gitHubPRBase)); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping PR creation"); + return Map.of(); + } + PullRequest result = prService.createPullRequest(repo, pr); if (result != null) { log.info("Created PR# {}", result.getNumber()); @@ -247,7 +262,7 @@ private static Map getPRCommitList(Map in, Strin } } - private static Map commentPR(Map in, String gitHubUri) { + private Map commentPR(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -261,6 +276,11 @@ private static Map commentPR(Map in, String gitH IssueService issueService = new IssueService(client); PullRequestService prService = new PullRequestService(client); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping comment on PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Commenting PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); try { @@ -274,7 +294,7 @@ private static Map commentPR(Map in, String gitH } } - private static Map mergePR(Map in, String gitHubUri) { + private Map mergePR(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -285,6 +305,11 @@ private static Map mergePR(Map in, String gitHub client.setOAuth2Token(gitHubAccessToken); IRepositoryIdProvider repo = RepositoryId.create(gitHubOrgName, gitHubRepoName); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping merge in PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + try { log.info("Merging PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); @@ -304,7 +329,7 @@ private static Map mergePR(Map in, String gitHub } } - private static Map closePR(Map in, String gitHubUri) { + private Map closePR(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -314,6 +339,11 @@ private static Map closePR(Map in, String gitHub client.setOAuth2Token(gitHubAccessToken); IRepositoryIdProvider repo = RepositoryId.create(gitHubOrgName, gitHubRepoName); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping closing of PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + PullRequestService prService = new PullRequestService(client); try { log.info("Closing PR #{} in {}/{}", gitHubPRID, gitHubOrgName, gitHubRepoName); @@ -330,7 +360,7 @@ private static Map closePR(Map in, String gitHub } } - private static Map merge(Map in, String gitHubUri) { + private Map merge(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -350,6 +380,11 @@ private static Map merge(Map in, String gitHubUr params.put("head", head); params.put("commit_message", commitMessage); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping merging of {} in {}/{}", head, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Merging {} in {}/{}", head, gitHubOrgName, gitHubRepoName); try (InputStream ignored = client.postStream(uri, params)){ @@ -394,7 +429,7 @@ private static Map getCommit(Map in, String gitH } } - private static Map createTag(Map in, String gitHubUri) { + private Map createTag(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -426,6 +461,11 @@ private static Map createTag(Map in, String gitH tag.setObject(typedResource); tag.setTagger(commitUser); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of tag '{}' for commit '{}' in {}/{}", gitHubTagVersion, gitHubBranchSHA,gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Creating tag '{}' for commit '{}' in {}/{}", gitHubTagVersion, gitHubBranchSHA, gitHubOrgName, gitHubRepoName); DataService dataService = new DataService(client); @@ -452,7 +492,7 @@ private static Map createTag(Map in, String gitH } } - private static Map deleteTag(Map in, String gitHubUri) { + private Map deleteTag(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -467,6 +507,11 @@ private static Map deleteTag(Map in, String gitH Tag tag = new Tag(); tag.setTag(gitHubTagName); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping deletion of tag '{}' in {}/{}", gitHubTagName, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Deleting tag '{}' in {}/{}", gitHubTagName, gitHubOrgName, gitHubRepoName); DataService dataService = new DataService(client); @@ -481,7 +526,7 @@ private static Map deleteTag(Map in, String gitH } } - private static Map deleteBranch(Map in, String gitHubUri) { + private Map deleteBranch(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -493,6 +538,11 @@ private static Map deleteBranch(Map in, String g client.setOAuth2Token(gitHubAccessToken); IRepositoryIdProvider repo = RepositoryId.create(gitHubOrgName, gitHubRepoName); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping deletion of branch '{}' in {}/{}", gitHubBranchName, gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Deleting branch '{}' in {}/{}", gitHubBranchName, gitHubOrgName, gitHubRepoName); DataService dataService = new DataService(client); @@ -507,7 +557,7 @@ private static Map deleteBranch(Map in, String g } } - private static Map addStatus(Map in, String gitHubUri) { + private Map addStatus(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -518,7 +568,13 @@ private static Map addStatus(Map in, String gitH String description = getString(in, STATUS_CHECK_DESCRIPTION, null); String context = getString(in, STATUS_CHECK_CONTEXT, "default"); - log.info("Creating status check ({}) in {}/{} repo with sha '{}'", + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of a status check ({}) in {}/{} repository with sha '{}'", + state, gitHubOrgName, gitHubRepoName, commitSha); + return Map.of(); + } + + log.info("Creating a status check ({}) in {}/{} repository with sha '{}'", state, gitHubOrgName, gitHubRepoName, commitSha); GitHubClient client = createClient(gitHubUri); @@ -573,7 +629,7 @@ private static Map getStatuses(Map in, String gi } } - private static Map forkRepo(Map in, String gitHubUri) { + private Map forkRepo(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -581,6 +637,11 @@ private static Map forkRepo(Map in, String gitHu GitHubClient client = createClient(gitHubUri); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping forking of repository {}/{}", gitHubOrgName, gitHubRepoName); + return Map.of(); + } + try { //Connect to GitHub client.setOAuth2Token(gitHubAccessToken); @@ -593,7 +654,7 @@ private static Map forkRepo(Map in, String gitHu repoService.forkRepository(repo, targetOrg); log.info("Fork action completed"); } else { - log.info("Forking '{}/{}' into your personal repo...", gitHubOrgName, gitHubRepoName); + log.info("Forking '{}/{}' into your personal repository...", gitHubOrgName, gitHubRepoName); repoService.forkRepository(repo); log.info("Fork action completed"); } @@ -765,13 +826,18 @@ private Map getPRFiles(Map in, String gitHubUri) } } - private static Map createRepo(Map in, String gitHubUri) { + private Map createRepo(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); GitHubClient client = createClient(gitHubUri); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of a repository in {}/{}", gitHubOrgName, gitHubRepoName); + return Map.of(); + } + log.info("Creating repository '{}' in '{}' organization", gitHubRepoName, gitHubOrgName); try { @@ -803,13 +869,18 @@ private static Map createRepo(Map in, String git } } - private static Map deleteRepo(Map in, String gitHubUri) { + private Map deleteRepo(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); GitHubClient client = createClient(gitHubUri); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping deletion of repository {} in {}", gitHubRepoName, gitHubOrgName); + return Map.of(); + } + log.info("Deleting repository '{}' from '{}' organization", gitHubRepoName, gitHubOrgName); try { @@ -907,7 +978,7 @@ private static Map getContent(Map in, String git } } - private static Map createHook(Map in, String gitHubUri) { + private Map createHook(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -935,6 +1006,11 @@ private static Map createHook(Map in, String git .setEvents(assertList(in, GITHUB_HOOK_EVENTS)) .setConfig(config); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of a hook in {}/{}", gitHubOrgName, gitHubRepoName); + return Map.of(); + } + try { if (MapUtils.getBoolean(in, GITHUB_HOOK_REPLACE, false)) { List hooks = service.getHooks(repo); @@ -952,7 +1028,7 @@ private static Map createHook(Map in, String git } } - private static Map createIssue(Map in, String gitHubUri) { + private Map createIssue(Map in, String gitHubUri) { String gitHubAccessToken = assertString(in, GITHUB_ACCESSTOKEN); String gitHubOrgName = assertString(in, GITHUB_ORGNAME); String gitHubRepoName = assertString(in, GITHUB_REPONAME); @@ -971,6 +1047,12 @@ private static Map createIssue(Map in, String gi .map(l -> new Label().setName(l)) .collect(Collectors.toList())); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of an issue in {}/{}", gitHubOrgName, gitHubRepoName); + return Map.of(); + } + + log.info("Creating issue in {}/{}", gitHubOrgName, gitHubRepoName); try { diff --git a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitTask.java b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitTask.java index 791d8cdc..03cb263a 100644 --- a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitTask.java +++ b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/GitTask.java @@ -91,10 +91,12 @@ public class GitTask { private final GitSecretService secretService; private final Path processWorkDir; + private final boolean dryRunMode; - public GitTask(GitSecretService secretService, Path processWorkDir) { + public GitTask(GitSecretService secretService, Path processWorkDir, boolean dryRunMode) { this.secretService = secretService; this.processWorkDir = processWorkDir; + this.dryRunMode = dryRunMode; } public Map execute(Map in, Map defaults) throws Exception { @@ -373,6 +375,11 @@ private Map doCreateNewBranch(Map in) throws Exc return handleError("Error while cloning the repository", e, in, dstDir, secret); } + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of branch '{}'", newBranchName); + return Map.of(); + } + try (Git git = Git.open(dstDir.toFile())) { git.checkout().setCreateBranch(true).setName(newBranchName).call(); log.info("Created new branch '{}' from '{}'", newBranchName, getHeadSHA(dstDir)); @@ -412,6 +419,11 @@ private Map doMergeNewBranch(Map in) throws Exce return handleError("Error while cloning the repository", e, in, dstDir, secret); } + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping merging of '{}' with '{}'", sourceBranch, destinationBranch); + return Map.of(); + } + try (Git git = Git.open(dstDir.toFile())) { //Merge Branch and Push to Origin if there are no conflicts String sourceBranch_ref = REFS_REMOTES.concat(sourceBranch); diff --git a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v1/GitTaskV1.java b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v1/GitTaskV1.java index 1bc3732b..92756b9d 100644 --- a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v1/GitTaskV1.java +++ b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v1/GitTaskV1.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -50,7 +50,7 @@ public GitTaskV1(SecretService secretService) { @Override public void execute(Context ctx) throws Exception { - Map result = new GitTask(new SecretServiceV1(secretService, ctx), ContextUtils.getWorkDir(ctx)) + Map result = new GitTask(new SecretServiceV1(secretService, ctx), ContextUtils.getWorkDir(ctx), false) .execute(ctx.toMap(), defaults); String out = ContextUtils.getString(ctx, OUT_KEY, DEFAULT_OUT_VAR_KEY); diff --git a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2.java b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2.java index 7065f066..4a976103 100644 --- a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2.java +++ b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,6 +32,7 @@ import java.util.Map; @Named("git") +@DryRunReady public class GitTaskV2 implements Task { private final Context context; @@ -40,7 +41,7 @@ public class GitTaskV2 implements Task { @Inject public GitTaskV2(Context context) { this.context = context; - this.delegate = new GitTask(new SecretServiceV2(context.secretService()), context.workingDirectory()); + this.delegate = new GitTask(new SecretServiceV2(context.secretService()), context.workingDirectory(), context.processConfiguration().dryRun()); } @Override diff --git a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GithubTaskV2.java b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GithubTaskV2.java index 84c921b4..75a3236a 100644 --- a/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GithubTaskV2.java +++ b/tasks/git/src/main/java/com/walmartlabs/concord/plugins/git/v2/GithubTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,10 +21,7 @@ */ import com.walmartlabs.concord.plugins.git.GitHubTask; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.Task; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import javax.inject.Inject; import javax.inject.Named; @@ -32,15 +29,17 @@ @Named("github") @SuppressWarnings("unused") +@DryRunReady public class GithubTaskV2 implements Task { - private final GitHubTask delegate = new GitHubTask(); + private final GitHubTask delegate; private final Map defaults; @Inject public GithubTaskV2(Context ctx) { this.defaults = ctx.defaultVariables().toMap(); + this.delegate = new GitHubTask(ctx.processConfiguration().dryRun()); } @Override diff --git a/tasks/git/src/test/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2Test.java b/tasks/git/src/test/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2Test.java index 417634b7..6331f4b1 100644 --- a/tasks/git/src/test/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2Test.java +++ b/tasks/git/src/test/java/com/walmartlabs/concord/plugins/git/v2/GitTaskV2Test.java @@ -25,10 +25,7 @@ import com.walmartlabs.concord.plugins.git.GitTask; import com.walmartlabs.concord.plugins.git.TokenSecret; import com.walmartlabs.concord.plugins.git.Utils; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables; -import com.walmartlabs.concord.runtime.v2.sdk.SecretService; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; +import com.walmartlabs.concord.runtime.v2.sdk.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -66,6 +63,9 @@ public void test() throws Exception { when(context.workingDirectory()).thenReturn(workDir); when(context.defaultVariables()).thenReturn(new MapBackedVariables(Collections.emptyMap())); + ProcessConfiguration processConfiguration = mock(ProcessConfiguration.class); + when(context.processConfiguration()).thenReturn(processConfiguration); + GitTaskV2 task = new GitTaskV2(context); TaskResult.SimpleResult result = task.execute(new MapBackedVariables(input)); assertTrue(result.ok()); diff --git a/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/HashiVaultTaskCommon.java b/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/HashiVaultTaskCommon.java index 525b0c6d..9ecadc8f 100644 --- a/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/HashiVaultTaskCommon.java +++ b/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/HashiVaultTaskCommon.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,8 +34,14 @@ public class HashiVaultTaskCommon { Logger log = LoggerFactory.getLogger(HashiVaultTaskCommon.class); + private final boolean dryRunMode; + public HashiVaultTaskCommon() { - // empty default constructor + this(false); + } + + public HashiVaultTaskCommon(boolean dryRun) { + this.dryRunMode = dryRun; } private static VaultConfig buildConfig(TaskParams params) { @@ -113,6 +119,11 @@ private Map readValue(Vault vault, TaskParams params) { } private void writeValue(Vault vault, TaskParams params) { + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping write to vault"); + return; + } + try { final LogicalResponse r = vault.withRetries(3, 5000).logical() .withNameSpace(params.ns()) diff --git a/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/v2/HashiVaultTask.java b/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/v2/HashiVaultTask.java index 14d205aa..2cdcd576 100644 --- a/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/v2/HashiVaultTask.java +++ b/tasks/hashivault/src/main/java/com/walmartlabs/concord/plugins/hashivault/v2/HashiVaultTask.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -33,21 +33,24 @@ @Named("hashivault") +@DryRunReady public class HashiVaultTask implements Task { private final Map defaults; private final SecretService secretService; + private final boolean dryRunMode; @Inject public HashiVaultTask(Context ctx, SecretService secretService) { this.secretService = secretService; this.defaults = ctx.variables().getMap(TaskParams.DEFAULT_PARAMS_KEY, Collections.emptyMap()); + this.dryRunMode = ctx.processConfiguration().dryRun(); } @Override - public TaskResult.SimpleResult execute(Variables input) throws Exception { + public TaskResult.SimpleResult execute(Variables input) { final TaskParams params = createParams(input); - final HashiVaultTaskCommon delegate = new HashiVaultTaskCommon(); + final HashiVaultTaskCommon delegate = new HashiVaultTaskCommon(dryRunMode); final HashiVaultTaskResult result = delegate.execute(params); final Map data = new HashMap<>(1); data.put("data", result.data()); diff --git a/tasks/hashivault/src/test/java/com/walmartlabs/concord/plugins/hashivault/model/MockContextV2.java b/tasks/hashivault/src/test/java/com/walmartlabs/concord/plugins/hashivault/model/MockContextV2.java index beb6b587..3e8197d5 100644 --- a/tasks/hashivault/src/test/java/com/walmartlabs/concord/plugins/hashivault/model/MockContextV2.java +++ b/tasks/hashivault/src/test/java/com/walmartlabs/concord/plugins/hashivault/model/MockContextV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -84,7 +84,7 @@ public ApiConfiguration apiConfiguration() { @Override public ProcessConfiguration processConfiguration() { - return null; + return ProcessConfiguration.builder().build(); } @Override diff --git a/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/JiraTaskCommon.java b/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/JiraTaskCommon.java index db8c9895..44b01de3 100644 --- a/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/JiraTaskCommon.java +++ b/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/JiraTaskCommon.java @@ -49,9 +49,15 @@ public class JiraTaskCommon { private static final String SECRET_KEY = "secret"; private final JiraSecretService secretService; + private final boolean dryRunMode; public JiraTaskCommon(JiraSecretService secretService) { + this(secretService, false); + } + + public JiraTaskCommon(JiraSecretService secretService, boolean dryRunMode) { this.secretService = secretService; + this.dryRunMode = dryRunMode; } public Map execute(TaskParams in) { @@ -167,6 +173,11 @@ Map createIssue(CreateIssueParams in) { Map objFields = Collections.singletonMap("fields", objMain); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of a new issue in '{}'", projectKey); + return Map.of(); + } + log.info("Creating new issue in '{}'...", projectKey); Map results = getClient(in) @@ -192,6 +203,11 @@ Map createComponent(CreateComponentParams in) { String projectKey = in.projectKey(); String componentName = in.componentName(); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping creation of component '{}'", componentName); + return Map.of(); + } + try { Map m = new HashMap<>(); m.put("name", componentName); @@ -215,6 +231,11 @@ Map createComponent(CreateComponentParams in) { void deleteComponent(DeleteComponentParams in) { int componentId = in.componentId(); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping deletion of component #{}", componentId); + return; + } + try { getClient(in) .url(in.jiraUrl() + "component/" + componentId) @@ -237,6 +258,11 @@ void addAttachment(AddAttachmentParams in) { throw new IllegalArgumentException("File not found: " + filePath); } + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping attachment to #{}", issueKey); + return; + } + try { getClient(in) .url(in.jiraUrl() + "issue/" + issueKey + "/attachments") @@ -252,9 +278,14 @@ void addComment(AddCommentParams in) { String issueKey = in.issueKey(); String comment = in.comment(); boolean debug = in.debug(); + Map m = Collections.singletonMap("body", comment); + + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping issue #{} comment: '{}'", issueKey, comment); + return; + } try { - Map m = Collections.singletonMap("body", comment); getClient(in) .url(in.jiraUrl() + "issue/" + issueKey + "/comment") @@ -297,6 +328,11 @@ void transition(TransitionParams in) { Map objFields = Collections.singletonMap("fields", objMain); objupdate = ConfigurationUtils.deepMerge(objFields, ConfigurationUtils.deepMerge(objTransition, objupdate)); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping transition of issue #{}", issueKey); + return; + } + getClient(in) .url(in.jiraUrl() + "issue/" + issueKey + "/transitions") .jiraAuth(buildAuth(in)) @@ -312,6 +348,11 @@ void transition(TransitionParams in) { void deleteIssue(DeleteIssueParams in) { String issueKey = in.issueKey(); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping deletion of issue #{}", issueKey); + return; + } + try { getClient(in) .url(in.jiraUrl() + "issue/" + issueKey) @@ -329,6 +370,11 @@ void updateIssue(UpdateIssueParams in) { String issueKey = in.issueKey(); Map fields = in.fields(); + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping update for issue #{}", issueKey); + return; + } + log.info("Updating {} fields for issue #{}", fields, issueKey); try { diff --git a/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2.java b/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2.java index 5fbb3ca0..ade6f4d6 100644 --- a/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2.java +++ b/tasks/jira/src/main/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,6 +31,7 @@ import java.util.Map; @Named("jira") +@DryRunReady public class JiraTaskV2 implements Task { private final Context context; @@ -39,7 +40,7 @@ public class JiraTaskV2 implements Task { @Inject public JiraTaskV2(Context context) { this.context = context; - this.delegate = new JiraTaskCommon(new V2SecretService(context.secretService())); + this.delegate = new JiraTaskCommon(new V2SecretService(context.secretService()), context.processConfiguration().dryRun()); } @Override diff --git a/tasks/jira/src/test/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2Test.java b/tasks/jira/src/test/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2Test.java index 52129691..8f276e61 100644 --- a/tasks/jira/src/test/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2Test.java +++ b/tasks/jira/src/test/java/com/walmartlabs/concord/plugins/jira/v2/JiraTaskV2Test.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,11 +22,7 @@ import com.walmartlabs.concord.plugins.jira.JiraTaskCommon; import com.walmartlabs.concord.plugins.jira.TaskParams; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables; -import com.walmartlabs.concord.runtime.v2.sdk.SecretService; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -66,6 +62,8 @@ class JiraTaskV2Test { @BeforeEach public void setup() { + when(context.processConfiguration()).thenReturn(ProcessConfiguration.builder().build()); + task = spy(new JiraTaskV2(context)); input = new HashMap<>(); defaultVariables = new MapBackedVariables(Map.of()); diff --git a/tasks/jsonpath/src/main/java/com/walmartlabs/concord/plugins/jsonpath/v2/JsonPathTaskV2.java b/tasks/jsonpath/src/main/java/com/walmartlabs/concord/plugins/jsonpath/v2/JsonPathTaskV2.java index 3728bbc6..81c5354a 100644 --- a/tasks/jsonpath/src/main/java/com/walmartlabs/concord/plugins/jsonpath/v2/JsonPathTaskV2.java +++ b/tasks/jsonpath/src/main/java/com/walmartlabs/concord/plugins/jsonpath/v2/JsonPathTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,16 +22,14 @@ import com.walmartlabs.concord.plugins.jsonpath.JsonPathTaskCommon; import com.walmartlabs.concord.plugins.jsonpath.TaskParams; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.Task; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import javax.inject.Inject; import javax.inject.Named; import java.io.IOException; @Named("jsonPath") +@DryRunReady @SuppressWarnings("unused") public class JsonPathTaskV2 implements Task { diff --git a/tasks/ldap/src/main/java/com/walmartlabs/concord/plugins/ldap/v2/LdapTaskV2.java b/tasks/ldap/src/main/java/com/walmartlabs/concord/plugins/ldap/v2/LdapTaskV2.java index f624de57..e415cca6 100644 --- a/tasks/ldap/src/main/java/com/walmartlabs/concord/plugins/ldap/v2/LdapTaskV2.java +++ b/tasks/ldap/src/main/java/com/walmartlabs/concord/plugins/ldap/v2/LdapTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -34,6 +34,7 @@ @Named("ldap") @SuppressWarnings("unused") +@DryRunReady public class LdapTaskV2 implements Task { private final Context context; diff --git a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3Task.java b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3Task.java index 93be79bc..7abc7795 100644 --- a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3Task.java +++ b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3Task.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -46,7 +46,7 @@ public void execute(Context ctx) throws Exception { } private static S3TaskCommon delegate(Context ctx) { - return new S3TaskCommon(ContextUtils.getWorkDir(ctx)); + return new S3TaskCommon(ContextUtils.getWorkDir(ctx), false); } private static class ContextVariables implements Variables { diff --git a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3TaskCommon.java b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3TaskCommon.java index a8322db8..d785604e 100644 --- a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3TaskCommon.java +++ b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/S3TaskCommon.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -47,9 +47,11 @@ public class S3TaskCommon { private static final Logger log = LoggerFactory.getLogger(S3TaskCommon.class); private final Path workDir; + private final boolean dryRunMode; - public S3TaskCommon(Path workDir) { + public S3TaskCommon(Path workDir, boolean dryRun) { this.workDir = workDir; + this.dryRunMode = dryRun; } public Result execute(TaskParams in) throws Exception { @@ -89,6 +91,12 @@ private Result putObject(PutObjectParams in) { String bucketName = in.bucketName(); String key = in.key(); + + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping upload to bucket {}/{}", bucketName, key); + return new PutObjectResult(null, null); + } + log.info("Putting an object into {}/{}...", bucketName, key); AmazonS3 s3 = createClient(in); diff --git a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/v2/S3TaskV2.java b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/v2/S3TaskV2.java index b0f0ce99..41bb007d 100644 --- a/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/v2/S3TaskV2.java +++ b/tasks/s3/src/main/java/com/walmartlabs/concord/plugins/s3/v2/S3TaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,10 +24,7 @@ import com.walmartlabs.concord.plugins.s3.Result; import com.walmartlabs.concord.plugins.s3.S3TaskCommon; import com.walmartlabs.concord.plugins.s3.TaskParams; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.Task; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import com.walmartlabs.concord.sdk.MapUtils; import javax.inject.Inject; @@ -35,6 +32,7 @@ import java.util.Map; @Named("s3") +@DryRunReady public class S3TaskV2 implements Task { private final Context context; @@ -43,7 +41,7 @@ public class S3TaskV2 implements Task { @Inject public S3TaskV2(Context context) { this.context = context; - this.delegate = new S3TaskCommon(context.workingDirectory()); + this.delegate = new S3TaskCommon(context.workingDirectory(), context.processConfiguration().dryRun()); } @Override diff --git a/tasks/s3/src/test/java/com/walmartlabs/concord/plugins/s3/S3TaskV2Test.java b/tasks/s3/src/test/java/com/walmartlabs/concord/plugins/s3/S3TaskV2Test.java index 27bea544..57477a60 100644 --- a/tasks/s3/src/test/java/com/walmartlabs/concord/plugins/s3/S3TaskV2Test.java +++ b/tasks/s3/src/test/java/com/walmartlabs/concord/plugins/s3/S3TaskV2Test.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +24,7 @@ import com.walmartlabs.concord.plugins.s3.v2.S3TaskV2; import com.walmartlabs.concord.runtime.v2.sdk.Context; import com.walmartlabs.concord.runtime.v2.sdk.MapBackedVariables; +import com.walmartlabs.concord.runtime.v2.sdk.ProcessConfiguration; import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -72,6 +73,7 @@ void localMockTestV2() throws Exception { args.put(TaskParams.PutObjectParams.AUTH_KEY, Collections.singletonMap("basic", auth)); Context context = Mockito.mock(Context.class); + when(context.processConfiguration()).thenReturn(ProcessConfiguration.builder().build()); when(context.variables()).thenReturn(new MapBackedVariables(Collections.emptyMap())); when(context.defaultVariables()).thenReturn(new MapBackedVariables(Collections.emptyMap())); diff --git a/tasks/terraform/pom.xml b/tasks/terraform/pom.xml index dd9a1a70..931745fd 100644 --- a/tasks/terraform/pom.xml +++ b/tasks/terraform/pom.xml @@ -72,6 +72,7 @@ org.apache.commons commons-compress + provided diff --git a/tasks/xml/src/main/java/com/walmartlabs/concord/plugins/xmlutils/v2/XmlUtilsTaskV2.java b/tasks/xml/src/main/java/com/walmartlabs/concord/plugins/xmlutils/v2/XmlUtilsTaskV2.java index 64ab50ba..6c198a76 100644 --- a/tasks/xml/src/main/java/com/walmartlabs/concord/plugins/xmlutils/v2/XmlUtilsTaskV2.java +++ b/tasks/xml/src/main/java/com/walmartlabs/concord/plugins/xmlutils/v2/XmlUtilsTaskV2.java @@ -22,6 +22,7 @@ import com.walmartlabs.concord.plugins.xmlutils.XmlUtilsTaskCommon; import com.walmartlabs.concord.runtime.v2.sdk.Context; +import com.walmartlabs.concord.runtime.v2.sdk.DryRunReady; import com.walmartlabs.concord.runtime.v2.sdk.Task; import javax.inject.Inject; @@ -31,6 +32,7 @@ @Named("xmlUtils") @SuppressWarnings("unused") +@DryRunReady public class XmlUtilsTaskV2 implements Task { private final XmlUtilsTaskCommon delegate; diff --git a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomClient.java b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomClient.java index ad268cf1..f8f30fc1 100644 --- a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomClient.java +++ b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomClient.java @@ -63,9 +63,11 @@ public class ZoomClient implements AutoCloseable { private final CloseableHttpClient client; private final ObjectMapper objectMapper = new ObjectMapper(); + private final boolean dryRunMode; - public ZoomClient(ZoomConfiguration cfg) { + public ZoomClient(ZoomConfiguration cfg, boolean dryRunMode) { this.retryCount = cfg.retryCount(); + this.dryRunMode = dryRunMode; this.connManager = createConnManager(); this.client = createClient(cfg, connManager); } @@ -102,6 +104,11 @@ public Result message(String robotJid, String headText, String bodyText, String params.put("content", objHead); } + if (dryRunMode) { + log.info("Dry-run mode enabled: Skipping sending of the message"); + return new Result(true, null, null); + } + return exec(params, rootApi); } diff --git a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomTaskCommon.java b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomTaskCommon.java index d5fddd47..ab90e436 100644 --- a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomTaskCommon.java +++ b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/ZoomTaskCommon.java @@ -29,6 +29,16 @@ public class ZoomTaskCommon { private static final Logger log = LoggerFactory.getLogger(ZoomTaskCommon.class); + private final boolean dryRunMode; + + public ZoomTaskCommon() { + this(false); + } + + public ZoomTaskCommon(boolean dryRunMode) { + this.dryRunMode = dryRunMode; + } + public Result execute(TaskParams in) { log.info("Starting '{}' action...", in.action()); @@ -43,8 +53,11 @@ public Result execute(TaskParams in) { } private Result sendMessage(SendMessageParams in) { - try (ZoomClient client = new ZoomClient(in)) { + try (ZoomClient client = new ZoomClient(in, dryRunMode)) { Result r = client.message(in.robotJid(), in.headText(), in.bodyText(), in.channelId(), in.accountId(), in.rootApi()); + if (dryRunMode) { + return r; + } if (!r.isOk()) { log.warn("Error sending a zoom message: {}", r.getError()); @@ -54,7 +67,7 @@ private Result sendMessage(SendMessageParams in) { return r; } catch (Exception e) { if (!in.ignoreErrors()) { - log.error("call ['{}', '{}', '{}'] -> error", in.channelId(), in.headText(), e); + log.error("call ['{}', '{}'] -> error", in.channelId(), in.headText(), e); throw new RuntimeException("zoom task error: ", e); } diff --git a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/v2/ZoomTaskV2.java b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/v2/ZoomTaskV2.java index db963210..7c3e0b0f 100644 --- a/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/v2/ZoomTaskV2.java +++ b/tasks/zoom/src/main/java/com/walmartlabs/concord/plugins/zoom/v2/ZoomTaskV2.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,23 +23,22 @@ import com.walmartlabs.concord.plugins.zoom.Result; import com.walmartlabs.concord.plugins.zoom.TaskParams; import com.walmartlabs.concord.plugins.zoom.ZoomTaskCommon; -import com.walmartlabs.concord.runtime.v2.sdk.Context; -import com.walmartlabs.concord.runtime.v2.sdk.Task; -import com.walmartlabs.concord.runtime.v2.sdk.TaskResult; -import com.walmartlabs.concord.runtime.v2.sdk.Variables; +import com.walmartlabs.concord.runtime.v2.sdk.*; import javax.inject.Inject; import javax.inject.Named; @Named("zoom") +@DryRunReady public class ZoomTaskV2 implements Task { private final Context context; - private final ZoomTaskCommon delegate = new ZoomTaskCommon(); + private final ZoomTaskCommon delegate; @Inject public ZoomTaskV2(Context context) { this.context = context; + this.delegate = new ZoomTaskCommon(context.processConfiguration().dryRun()); } @Override