This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from rapid7/support-agent-task-credentials
Implement RuntimeDataProvider to pre-fetch API Key for task
- Loading branch information
Showing
11 changed files
with
105 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/rapid7/ias/bamboo/impl/InsightAppSecRuntimeDataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.rapid7.ias.bamboo.impl; | ||
|
||
import com.atlassian.bamboo.ResultKey; | ||
import com.atlassian.bamboo.credentials.CredentialsAccessor; | ||
import com.atlassian.bamboo.credentials.CredentialsData; | ||
import com.atlassian.bamboo.security.SecureToken; | ||
import com.atlassian.bamboo.security.SecureTokenService; | ||
import com.atlassian.bamboo.serialization.WhitelistedSerializable; | ||
import com.atlassian.bamboo.task.RuntimeTaskDataProvider; | ||
import com.atlassian.bamboo.task.TaskDefinition; | ||
import com.atlassian.bamboo.task.runtime.RuntimeTaskDefinition; | ||
import com.atlassian.bamboo.v2.build.CommonContext; | ||
import com.atlassian.bamboo.v2.build.agent.messages.AuthenticableMessage; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.inject.Inject; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static com.atlassian.bamboo.credentials.UsernamePasswordCredentialType.CFG_PASSWORD; | ||
|
||
public class InsightAppSecRuntimeDataProvider implements RuntimeTaskDataProvider, IasConstants { | ||
@Inject | ||
private CredentialsAccessor credentialsAccessor; | ||
|
||
@NotNull | ||
@Override | ||
public Map<String, String> populateRuntimeTaskData(@NotNull TaskDefinition taskDefinition, | ||
@NotNull CommonContext commonContext) { | ||
final Map<String, String> configuration = taskDefinition.getConfiguration(); | ||
final Map<String, String> result = new HashMap<>(); | ||
|
||
// Get Shared Credential for API auth | ||
propagateSharedCredentialsValues(InsightAppSecScanTaskConfigurator.SELECTED_CREDENTIAL, taskDefinition, configuration, result); | ||
|
||
return result; | ||
} | ||
|
||
private void propagateSharedCredentialsValues(String sharedCredentialsKey, @NotNull TaskDefinition taskDefinition, | ||
Map<String, String> configuration, Map<String, String> result) { | ||
final String credentialsId = configuration.get(sharedCredentialsKey); | ||
if (StringUtils.isNotBlank(credentialsId)) { | ||
final CredentialsData credentials = credentialsAccessor.getCredentials(Long.parseLong(credentialsId)); | ||
if (credentials == null) { | ||
throw new IllegalStateException("Can't find API Key as shared credentials with id " + credentialsId | ||
+ " for task " | ||
+ (StringUtils.isEmpty(taskDefinition.getUserDescription()) ? taskDefinition.getPluginKey() : taskDefinition.getUserDescription())); | ||
} | ||
|
||
// We only need password field for api_key; we don't use the name | ||
final String password = credentials.getConfiguration().get(CFG_PASSWORD); | ||
result.put(CFG_PASSWORD, password); | ||
} | ||
} | ||
|
||
@Override | ||
public void processRuntimeTaskData(@NotNull RuntimeTaskDefinition runtimeTaskDefinition, @NotNull CommonContext commonContext) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters