Skip to content

Commit

Permalink
Remove Application Key configuration since the backend no longer requ…
Browse files Browse the repository at this point in the history
…ires it
  • Loading branch information
nikita-tkachenko-datadog committed Sep 27, 2023
1 parent 87e8b6d commit 9e28ce4
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 164 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ The plugin can automatically configure Datadog <a target="_blank" href="https://

Before enabling Test Visibility, be sure to properly configure the plugin to submit data to Datadog.

To enable Test Visibility, go to the `Configure` page of the job or pipeline whose tests need to be traced, tick `Enable Datadog Test Visibility` checkbox in the `General` section and save your changes.
To enable Test Visibility, go to the `Configure` page of the job or pipeline whose tests need to be traced, tick `Enable Datadog Test Visibility` checkbox in the `General` section and save your changes.

Please bear in mind that Test Visibility is a separate Datadog product that is billed separately.

## Data collected

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public class DatadogGlobalConfiguration extends GlobalConfiguration {
private static final String TARGET_LOG_INTAKE_URL_PROPERTY = "DATADOG_JENKINS_PLUGIN_TARGET_LOG_INTAKE_URL";
private static final String TARGET_WEBHOOK_INTAKE_URL_PROPERTY = "DATADOG_JENKINS_TARGET_WEBHOOK_INTAKE_URL";
private static final String TARGET_API_KEY_PROPERTY = "DATADOG_JENKINS_PLUGIN_TARGET_API_KEY";
private static final String TARGET_APPLICATION_KEY_PROPERTY = "DATADOG_JENKINS_PLUGIN_TARGET_APPLICATION_KEY";
private static final String TARGET_LOG_COLLECTION_PORT_PROPERTY = "DATADOG_JENKINS_PLUGIN_TARGET_LOG_COLLECTION_PORT";
private static final String TARGET_TRACE_SERVICE_NAME_PROPERTY = "DATADOG_JENKINS_PLUGIN_TRACE_SERVICE_NAME";
private static final String HOSTNAME_PROPERTY = "DATADOG_JENKINS_PLUGIN_HOSTNAME";
Expand Down Expand Up @@ -141,9 +140,6 @@ public class DatadogGlobalConfiguration extends GlobalConfiguration {
private Secret targetApiKey = null;
private String targetCredentialsApiKey = null;
private Secret usedApiKey = null;
private Secret targetApplicationKey = null;
private String targetCredentialsApplicationKey = null;
private Secret usedApplicationKey = null;
private String targetHost = DEFAULT_TARGET_HOST_VALUE;
private Integer targetPort = DEFAULT_TARGET_PORT_VALUE;
private Integer targetLogCollectionPort = DEFAULT_TARGET_LOG_COLLECTION_PORT_VALUE;
Expand Down Expand Up @@ -199,11 +195,6 @@ private void loadEnvVariables(){
this.targetApiKey = Secret.fromString(targetApiKeyEnvVar);
}

String targetApplicationKeyEnvVar = System.getenv(TARGET_APPLICATION_KEY_PROPERTY);
if(StringUtils.isNotBlank(targetApplicationKeyEnvVar)){
this.targetApplicationKey = Secret.fromString(targetApplicationKeyEnvVar);
}

final DatadogAgentConfiguration agentConfig = DatadogAgentConfiguration.resolve(System.getenv());
if(StringUtils.isNotBlank(agentConfig.getHost())){
this.targetHost = agentConfig.getHost();
Expand Down Expand Up @@ -504,78 +495,6 @@ public FormValidation doCheckTargetCredentialsApiKey(
return FormValidation.ok();
}

/**
* Populates the targetCredentialsApplicationKey field from the configuration screen with all of the valid credentials
*
* @param item - The context within which to list available credentials
* @param targetCredentialsApplicationKey - A String containing the application key as a credential
* @return a ListBoxModel object used to display all of the available credentials.
*/
public ListBoxModel doFillTargetCredentialsApplicationKeyItems(
@AncestorInPath Item item,
@QueryParameter("targetCredentialsApplicationKey") String targetCredentialsApplicationKey
) {
StandardListBoxModel result = new StandardListBoxModel();
// If the users does not have permissions to list credentials, only list the current value
if (item == null) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return result.includeCurrentValue(targetCredentialsApplicationKey);
}
} else {
if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.includeCurrentValue(targetCredentialsApplicationKey);
}
}
return result.includeEmptyValue()
.includeMatchingAs(ACL.SYSTEM,
Jenkins.get(),
StringCredentials.class,
Collections.emptyList(),
CredentialsMatchers.instanceOf(StringCredentials.class))
.includeCurrentValue(targetCredentialsApplicationKey);
}

/**
* Tests the targetCredentialsApplicationKey field from the configuration screen, to check its' validity.
*
* @param item - The context within which to list available credentials.
* @param targetCredentialsApplicationKey - A String containing the API key as a credential
* @return a FormValidation object used to display a message to the user on the configuration
* screen.
*/
@RequirePOST
public FormValidation doCheckTargetCredentialsApplicationKey(
@AncestorInPath Item item,
@QueryParameter("targetCredentialsApplicationKey") String targetCredentialsApplicationKey
) {
// Don't validate for users that do not have permission to list credentials
if (item == null) {
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
} else {
if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
}
if (StringUtils.isBlank(targetCredentialsApplicationKey)) {
return FormValidation.ok();
}
if (targetCredentialsApplicationKey.startsWith("${") && targetCredentialsApplicationKey.endsWith("}")) {
return FormValidation.warning("Cannot validate expression based credentials");
}
if (CredentialsProvider.listCredentials(StringCredentials.class,
item,
ACL.SYSTEM,
Collections.emptyList(),
CredentialsMatchers.withId(targetCredentialsApplicationKey)).isEmpty()) {
return FormValidation.error("Cannot find currently selected credentials");
}
return FormValidation.ok();
}

/**
* Tests the hostname field from the configuration screen, to determine if
* the hostname is of a valid format, according to the RFC 1123.
Expand Down Expand Up @@ -765,8 +684,6 @@ public boolean configure(final StaplerRequest req, final JSONObject formData) th
this.setTargetWebhookIntakeURL(formData.getString("targetWebhookIntakeURL"));
this.setTargetApiKey(formData.getString("targetApiKey"));
this.setTargetCredentialsApiKey(formData.getString("targetCredentialsApiKey"));
this.setTargetApplicationKey(formData.getString("targetApplicationKey"));
this.setTargetCredentialsApplicationKey(formData.getString("targetCredentialsApplicationKey"));
this.setTargetHost(formData.getString("targetHost"));
String portStr = formData.getString("targetPort");
if (validatePort(portStr)) {
Expand Down Expand Up @@ -849,9 +766,6 @@ public boolean configure(final StaplerRequest req, final JSONObject formData) th
final Secret apiKeySecret = findSecret(formData.getString("targetApiKey"), formData.getString("targetCredentialsApiKey"));
this.setUsedApiKey(apiKeySecret);

final Secret applicationKeySecret = findSecret(formData.getString("targetApplicationKey"), formData.getString("targetCredentialsApplicationKey"));
this.setUsedApplicationKey(applicationKeySecret);

//When form is saved....
DatadogClient client = ClientFactory.getClient(DatadogClient.ClientType.valueOf(this.getReportWith()), this.getTargetApiURL(),
this.getTargetLogIntakeURL(), this.getTargetWebhookIntakeURL(), this.getUsedApiKey(), this.getTargetHost(),
Expand Down Expand Up @@ -1016,65 +930,6 @@ public void setTargetCredentialsApiKey(final String targetCredentialsApiKey) {
this.targetCredentialsApiKey = targetCredentialsApiKey;
}

/**
* Getter function for the targetApplicationKey global configuration.
*
* @return a Secret containing the targetApplicationKey global configuration.
*/
public Secret getTargetApplicationKey() {
return targetApplicationKey;
}

/**
* Setter function for the targetApplicationKey global configuration.
*
* @param targetApplicationKey = A string containing the plaintext representation of a
* DataDog Application Key
*/
@DataBoundSetter
public void setTargetApplicationKey(final String targetApplicationKey) {
this.targetApplicationKey = Secret.fromString(fixEmptyAndTrim(targetApplicationKey));
}

/**
* Getter function for the application key global configuration.
*
* @return a Secret containing the usedApplicationKey global configuration.
*/
public Secret getUsedApplicationKey() {
return usedApplicationKey;
}

/**
* Setter function for the application key global configuration..
*
* @param usedApplicationKey = A Secret containing the DataDog Application Key
*/
@DataBoundSetter
public void setUsedApplicationKey(final Secret usedApplicationKey) {
this.usedApplicationKey = usedApplicationKey;
}

/**
* Getter function for the targetCredentialsApplicationKey global configuration.
*
* @return a String containing the ID of the targetCredentialsApplicationKey global configuration.
*/
public String getTargetCredentialsApplicationKey() {
return targetCredentialsApplicationKey;
}

/**
* Setter function for the credentials targetCredentialsApplicationKey global configuration.
*
* @param targetCredentialsApplicationKey = A string containing the plaintext representation of a
* DataDog Application Key
*/
@DataBoundSetter
public void setTargetCredentialsApplicationKey(final String targetCredentialsApplicationKey) {
this.targetCredentialsApplicationKey = targetCredentialsApplicationKey;
}

/**
* Getter function for the targetHost global configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ private static Map<String, String> getCommonEnvVariables(DatadogGlobalConfigurat
variables.put("DD_CIVISIBILITY_AGENTLESS_ENABLED", "true");
variables.put("DD_SITE", getSite(datadogConfig.getTargetApiURL()));
variables.put("DD_API_KEY", Secret.toString(datadogConfig.getUsedApiKey()));
variables.put("DD_APPLICATION_KEY", Secret.toString(datadogConfig.getUsedApplicationKey()));
break;
case DSD:
variables.put("DD_AGENT_HOST", datadogConfig.getTargetHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@
</f:entry>

<f:validateButton title="${%Test Key}" progress="${%Testing...}" method="testConnection" with="targetApiKey,targetCredentialsApiKey,targetApiURL" checkMethod="post" />

<f:entry title="Datadog Application Key" field="targetApplicationKeyEntry" description="Optional, required only for Intelligent Test Runner in Tests Visibility">
<f:password field="targetApplicationKey" default="${targetApplicationKey}" checkMethod="post" />
</f:entry>
<f:entry title="Datadog Application Key (Select from Credentials)" field="targetCredentialsApplicationKeyEntry" description="Optional, required only for Intelligent Test Runner in Tests Visibility">
<f:select field="targetCredentialsApplicationKey" default="${targetCredentialsApplicationKey}" checkMethod="post" />
</f:entry>
</f:radioBlock>

<f:entry title="Logs">
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div>
Enable Datadog <a target="_blank" href="https://docs.datadoghq.com/continuous_integration/tests/">Test Visibility</a> for this job.
This requires <a target="_blank" href="/configure">configuring</a> Datadog Plugin connectivity.
Please bear in mind that Test Visibility is a separate Datadog product that is billed separately.
</div>

0 comments on commit 9e28ce4

Please sign in to comment.