Search in sources :

Example 1 with FetchArtifactEnvironmentVariable

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());
    }
}
Also used : FetchArtifactEnvironmentVariable(com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable)

Example 2 with FetchArtifactEnvironmentVariable

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")));
}
Also used : RunIfConfigs(com.thoughtworks.go.domain.RunIfConfigs) FetchArtifactEnvironmentVariable(com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Aggregations

FetchArtifactEnvironmentVariable (com.thoughtworks.go.plugin.access.artifact.models.FetchArtifactEnvironmentVariable)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 Test (org.junit.jupiter.api.Test)1