Skip to content

Commit 4b1d478

Browse files
authored
tasks: initial support for dry-run mode (#179)
1 parent 3f0b236 commit 4b1d478

File tree

29 files changed

+308
-101
lines changed

29 files changed

+308
-101
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
<scm.connection>scm:git:https://github.com/walmartlabs/concord-plugins.git</scm.connection>
6666

67-
<concord.version>2.14.0</concord.version>
67+
<concord.version>2.19.0</concord.version>
6868
<gson.version>2.10</gson.version>
6969
<okhttp3.version>3.14.9</okhttp3.version>
7070
<wiremock.version>3.5.2</wiremock.version>

tasks/akeyless/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,4 @@
262262
</plugin>
263263
</plugins>
264264
</build>
265-
</project>
265+
</project>

tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/AkeylessCommon.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,9 +41,14 @@ public class AkeylessCommon {
4141
private ApiClient apiClient;
4242
private SecretExporter secretExporter;
4343
private static final Map<String, BiFunction<Variables, SecretExporter, Auth>> authBuilders = createAuthBuilders();
44+
private final boolean dryRunMode;
4445

4546
public AkeylessCommon() {
46-
// empty default constructor
47+
this(false);
48+
}
49+
50+
public AkeylessCommon(boolean dryRunMode) {
51+
this.dryRunMode = dryRunMode;
4752
}
4853

4954
private static Map<String, BiFunction<Variables, SecretExporter, Auth>> createAuthBuilders() {
@@ -167,6 +172,11 @@ private AkeylessTaskResult createSecret(TaskParams.CreateSecretParams params) {
167172
V2Api api = getApi(params);
168173
String accessToken = getAccessToken(api);
169174

175+
if (dryRunMode) {
176+
log.info("Dry-run mode enabled: Skipping secret creation");
177+
return AkeylessTaskResult.of(true, null, null);
178+
}
179+
170180
api.createSecret(new CreateSecret()
171181
.token(accessToken)
172182
.name(params.path())
@@ -189,6 +199,11 @@ private AkeylessTaskResult updateSecretVal(TaskParams.UpdateSecretParams params)
189199
V2Api api = getApi(params);
190200
String accessToken = getAccessToken(api);
191201

202+
if (dryRunMode) {
203+
log.info("Dry-run mode enabled: Skipping secret update");
204+
return AkeylessTaskResult.of(true, null, null);
205+
}
206+
192207
api.updateSecretVal(new UpdateSecretVal()
193208
.token(accessToken)
194209
.value(params.value())
@@ -211,6 +226,11 @@ private AkeylessTaskResult deleteItem(TaskParams.DeleteItemParams params) {
211226
V2Api api = getApi(params);
212227
String accessToken = getAccessToken(api);
213228

229+
if (dryRunMode) {
230+
log.info("Dry-run mode enabled: Skipping item delete");
231+
return AkeylessTaskResult.of(true, null, null);
232+
}
233+
214234
api.deleteItem(new DeleteItem()
215235
.token(accessToken)
216236
.name(params.path())

tasks/akeyless/src/main/java/com/walmartlabs/concord/plugins/akeyless/v2/AkeylessTask.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
1111
* You may obtain a copy of the License at
12-
*
12+
*
1313
* http://www.apache.org/licenses/LICENSE-2.0
14-
*
14+
*
1515
* Unless required by applicable law or agreed to in writing, software
1616
* distributed under the License is distributed on an "AS IS" BASIS,
1717
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,6 +34,7 @@
3434
import java.util.Map;
3535

3636
@Named("akeyless")
37+
@DryRunReady
3738
public class AkeylessTask implements Task {
3839

3940
private final Map<String, Object> defaults;
@@ -48,11 +49,11 @@ public AkeylessTask(Context ctx, SecretService secretService) {
4849
this.defaults.put("sessionToken", ctx.processConfiguration().processInfo().sessionToken());
4950
this.defaults.put("txId", ctx.processInstanceId().toString());
5051
this.policyDefaults = ctx.defaultVariables().toMap();
51-
this.delegate = new AkeylessCommon();
52+
this.delegate = new AkeylessCommon(ctx.processConfiguration().dryRun());
5253
}
5354

5455
@Override
55-
public TaskResult.SimpleResult execute(Variables input) throws Exception {
56+
public TaskResult.SimpleResult execute(Variables input) {
5657
final TaskParams params = createParams(input);
5758

5859
AkeylessTaskResult result = delegate.execute(params, secretExporter);

tasks/aws/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<dependency>
7878
<groupId>com.fasterxml.jackson.datatype</groupId>
7979
<artifactId>jackson-datatype-jsr310</artifactId>
80+
<scope>provided</scope>
8081
</dependency>
8182
<dependency>
8283
<groupId>org.junit.jupiter</groupId>

tasks/aws/src/main/java/com/walmartlabs/concord/plugins/aws/EcrTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424
import com.fasterxml.jackson.databind.SerializationFeature;
2525
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
26-
import com.walmartlabs.concord.runtime.v2.sdk.Context;
27-
import com.walmartlabs.concord.runtime.v2.sdk.Task;
28-
import com.walmartlabs.concord.runtime.v2.sdk.TaskResult;
29-
import com.walmartlabs.concord.runtime.v2.sdk.Variables;
26+
import com.walmartlabs.concord.runtime.v2.sdk.*;
3027
import org.slf4j.Logger;
3128
import org.slf4j.LoggerFactory;
3229
import software.amazon.awssdk.regions.Region;
@@ -42,6 +39,7 @@
4239
import static java.util.Objects.requireNonNull;
4340

4441
@Named("awsEcr")
42+
@DryRunReady
4543
public class EcrTask implements Task {
4644

4745
private static final Logger log = LoggerFactory.getLogger(EcrTask.class);
@@ -113,6 +111,11 @@ private TaskResult deleteImage(Variables input) {
113111
var imageIds = assertImageIds(input);
114112
var debug = input.getBoolean("debug", context.processConfiguration().debug());
115113

114+
if (context.processConfiguration().dryRun()) {
115+
log.info("Dry-run mode enabled: Skipping image deletion");
116+
return TaskResult.success();
117+
}
118+
116119
try (var client = EcrClient.builder()
117120
.region(region)
118121
.build()) {

0 commit comments

Comments
 (0)