Search in sources :

Example 11 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class EnvironmentVariableTest method addToIfExists_shouldNotAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIDoesNotExistInContext.

@Test
public void addToIfExists_shouldNotAddEnvironmentVariableToEnvironmentVariableContextWhenVariableIDoesNotExistInContext() {
    final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    final EnvironmentVariable environmentVariable = new EnvironmentVariable("foo", "bar");
    when(environmentVariableContext.hasProperty("foo")).thenReturn(false);
    environmentVariable.addToIfExists(environmentVariableContext);
    verify(environmentVariableContext, times(0)).setProperty("foo", "bar", false);
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 12 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class EnvironmentVariablesTest method addTo_shouldAddEnvironmentVariablesToEnvironmentVariableContext.

@Test
public void addTo_shouldAddEnvironmentVariablesToEnvironmentVariableContext() {
    final EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    final EnvironmentVariables environmentVariables = new EnvironmentVariables(new EnvironmentVariable("foo", "bar"), new EnvironmentVariable("baz", "car", true));
    environmentVariables.addTo(environmentVariableContext);
    verify(environmentVariableContext, times(1)).setProperty("foo", "bar", false);
    verify(environmentVariableContext, times(1)).setProperty("baz", "car", true);
}
Also used : EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 13 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class PluggableSCMMaterial method populateEnvironmentContext.

@Override
public void populateEnvironmentContext(EnvironmentVariableContext context, MaterialRevision materialRevision, File workingDir) {
    context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", "LABEL"), materialRevision.getRevision().getRevision(), false);
    for (ConfigurationProperty configurationProperty : scmConfig.getConfiguration()) {
        context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", configurationProperty.getConfigurationKey().getName()), configurationProperty.getValue(), configurationProperty.isSecure());
    }
    HashMap<String, String> additionalData = materialRevision.getLatestModification().getAdditionalDataMap();
    if (additionalData != null) {
        for (Map.Entry<String, String> entry : additionalData.entrySet()) {
            boolean isSecure = false;
            for (EnvironmentVariableContext.EnvironmentVariable secureEnvironmentVariable : context.getSecureEnvironmentVariables()) {
                String urlEncodedValue = null;
                try {
                    urlEncodedValue = URLEncoder.encode(secureEnvironmentVariable.value(), "UTF-8");
                } catch (UnsupportedEncodingException e) {
                }
                boolean isSecureEnvironmentVariableEncoded = !StringUtils.isBlank(urlEncodedValue) && !secureEnvironmentVariable.value().equals(urlEncodedValue);
                if (isSecureEnvironmentVariableEncoded && entry.getValue().contains(urlEncodedValue)) {
                    isSecure = true;
                    break;
                }
            }
            String key = entry.getKey();
            String value = entry.getValue();
            context.setProperty(getEnvironmentVariableKey("GO_SCM_%s_%s", key), value, isSecure);
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldListAllEnvironmentVariablesDefinedForAConfigRepoEnvironment.

@Test
public void shouldListAllEnvironmentVariablesDefinedForAConfigRepoEnvironment() throws Exception {
    EnvironmentsConfig environmentConfigs = new EnvironmentsConfig();
    BasicEnvironmentConfig localPart = environment("uat");
    localPart.addEnvironmentVariable("Var1", "Value1");
    localPart.addEnvironmentVariable("Var2", "Value2");
    BasicEnvironmentConfig remotePart = remote("uat");
    remotePart.addEnvironmentVariable("remote-var1", "remote-value-1");
    environmentConfigs.add(new MergeEnvironmentConfig(localPart, remotePart));
    environmentConfigService.sync(environmentConfigs);
    EnvironmentVariableContext environmentVariableContext = environmentConfigService.environmentVariableContextFor("uat-pipeline");
    assertThat(environmentVariableContext.getProperties().size(), is(4));
    assertThat(environmentVariableContext.getProperty("GO_ENVIRONMENT_NAME"), is("uat"));
    assertThat(environmentVariableContext.getProperty("Var1"), is("Value1"));
    assertThat(environmentVariableContext.getProperty("Var2"), is("Value2"));
    assertThat(environmentVariableContext.getProperty("remote-var1"), is("remote-value-1"));
}
Also used : MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 15 with EnvironmentVariableContext

use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldListAllEnvironmentVariablesDefinedForRemoteOnlyEnvironment.

@Test
public void shouldListAllEnvironmentVariablesDefinedForRemoteOnlyEnvironment() throws Exception {
    EnvironmentsConfig environmentConfigs = new EnvironmentsConfig();
    BasicEnvironmentConfig remotePart = remote("uat");
    remotePart.addEnvironmentVariable("remote-var1", "remote-value-1");
    environmentConfigs.add(new MergeEnvironmentConfig(remotePart));
    environmentConfigService.sync(environmentConfigs);
    EnvironmentVariableContext environmentVariableContext = environmentConfigService.environmentVariableContextFor("uat-pipeline");
    assertThat(environmentVariableContext.getProperties().size(), is(2));
    assertThat(environmentVariableContext.getProperty("GO_ENVIRONMENT_NAME"), is("uat"));
    assertThat(environmentVariableContext.getProperty("remote-var1"), is("remote-value-1"));
}
Also used : MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Aggregations

EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)94 Test (org.junit.Test)74 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)19 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)16 File (java.io.File)14 Date (java.util.Date)13 Modification (com.thoughtworks.go.domain.materials.Modification)12 Modifications (com.thoughtworks.go.domain.materials.Modifications)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)9 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)9 Before (org.junit.Before)8 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)7 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)6 Materials (com.thoughtworks.go.config.materials.Materials)6 Builder (com.thoughtworks.go.domain.builder.Builder)6 HashMap (java.util.HashMap)6 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)5 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5