use of com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable in project gocd by gocd.
the class FetchPluggableArtifactBuilder method updateEnvironmentVariableContextWith.
private void updateEnvironmentVariableContextWith(DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext, List<FetchArtifactEnvironmentVariable> newEnvironmentVariables) {
for (FetchArtifactEnvironmentVariable variable : newEnvironmentVariables) {
String name = variable.name();
String message = format(" NOTE: Setting new environment variable: %s = %s", name, variable.displayValue());
if (environmentVariableContext.hasProperty(name)) {
message = format("WARNING: Replacing environment variable: %s = %s (previously: %s)", name, variable.displayValue(), environmentVariableContext.getPropertyForDisplay(name));
}
publisher.taggedConsumeLine(TaggedStreamConsumer.OUT, message);
environmentVariableContext.setProperty(name, variable.value(), variable.isSecure());
}
}
use of com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable in project gocd by gocd.
the class FetchPluggableArtifactBuilderTest method shouldUpdateEnvironmentVariableContextAfterFetchingArtifact.
@Test
public void shouldUpdateEnvironmentVariableContextAfterFetchingArtifact() {
final FetchPluggableArtifactBuilder builder = new FetchPluggableArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "", jobIdentifier, artifactStore, fetchPluggableArtifactTask.getConfiguration(), fetchPluggableArtifactTask.getArtifactId(), sourceOnServer, metadataDest, checksumFileHandler);
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
environmentVariableContext.setProperty("VAR1", "old-value1", false);
environmentVariableContext.setProperty("VAR2", "old-value2", true);
environmentVariableContext.setProperty("VAR3", "old-value3", true);
environmentVariableContext.setProperty("VAR4", "old-value4", true);
when(artifactExtension.fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), any(), anyMap(), eq(metadataDest.getParent()))).thenReturn(Arrays.asList(new FetchArtifactEnvironmentVariable("VAR1", "value1-is-now-secure", true), new FetchArtifactEnvironmentVariable("VAR2", "value2-is-now-insecure", false), new FetchArtifactEnvironmentVariable("VAR3", "value3-but-secure-is-unchanged", true), new FetchArtifactEnvironmentVariable("VAR5", "new-value5-insecure", false), new FetchArtifactEnvironmentVariable("VAR6", "new-value6-secure", true)));
builder.build(publisher, environmentVariableContext, null, artifactExtension, registry, "utf-8");
Map<String, String> newVariablesAfterFetchArtifact = environmentVariableContext.getProperties();
assertThat(newVariablesAfterFetchArtifact.size(), is(6));
assertVariable(environmentVariableContext, "VAR1", "value1-is-now-secure", true);
assertVariable(environmentVariableContext, "VAR2", "value2-is-now-insecure", false);
assertVariable(environmentVariableContext, "VAR3", "value3-but-secure-is-unchanged", true);
assertVariable(environmentVariableContext, "VAR4", "old-value4", true);
assertVariable(environmentVariableContext, "VAR5", "new-value5-insecure", false);
assertVariable(environmentVariableContext, "VAR6", "new-value6-secure", true);
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(publisher, atLeastOnce()).taggedConsumeLine(eq(OUT), captor.capture());
assertThat(captor.getAllValues(), hasItems("WARNING: Replacing environment variable: VAR1 = ******** (previously: old-value1)", "WARNING: Replacing environment variable: VAR2 = value2-is-now-insecure (previously: ********)", "WARNING: Replacing environment variable: VAR3 = ******** (previously: ********)", " NOTE: Setting new environment variable: VAR5 = new-value5-insecure", " NOTE: Setting new environment variable: VAR6 = ********"));
String consoleOutput = String.join(" -- ", captor.getAllValues());
assertThat(consoleOutput, not(containsString("value1-is-now-secure")));
assertThat(consoleOutput, not(containsString("value3-but-secure-is-unchanged")));
assertThat(consoleOutput, not(containsString("new-value6-secure")));
}
Aggregations