Skip to content

Commit

Permalink
tasks: initial support for dry-run mode (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
brig authored Nov 5, 2024
1 parent 3f0b236 commit 4b1d478
Show file tree
Hide file tree
Showing 29 changed files with 308 additions and 101 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

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

<concord.version>2.14.0</concord.version>
<concord.version>2.19.0</concord.version>
<gson.version>2.10</gson.version>
<okhttp3.version>3.14.9</okhttp3.version>
<wiremock.version>3.5.2</wiremock.version>
Expand Down
2 changes: 1 addition & 1 deletion tasks/akeyless/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -41,9 +41,14 @@ public class AkeylessCommon {
private ApiClient apiClient;
private SecretExporter secretExporter;
private static final Map<String, BiFunction<Variables, SecretExporter, Auth>> authBuilders = createAuthBuilders();
private final boolean dryRunMode;

public AkeylessCommon() {
// empty default constructor
this(false);
}

public AkeylessCommon(boolean dryRunMode) {
this.dryRunMode = dryRunMode;
}

private static Map<String, BiFunction<Variables, SecretExporter, Auth>> createAuthBuilders() {
Expand Down Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -34,6 +34,7 @@
import java.util.Map;

@Named("akeyless")
@DryRunReady
public class AkeylessTask implements Task {

private final Map<String, Object> defaults;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tasks/aws/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
Loading

0 comments on commit 4b1d478

Please sign in to comment.