// SetEnvironmentVariableByApplicationNameAndSpace adds an
// EnvironmentVariablePair to an application. It must be restarted for changes
// to take effect.
512783
func (actor *Actor) SetEnvironmentVariableByApplicationNameAndSpace(appName string, spaceGUID string, envPair EnvironmentVariablePair) (Warnings, error) {
	app, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
	if err != nil {
		return warnings, err
	}

	_, v3Warnings, apiErr := actor.CloudControllerClient.UpdateApplicationEnvironmentVariables(
		app.GUID,
		ccv3.EnvironmentVariables{
			envPair.Key: {Value: envPair.Value, IsSet: true},
		})
	warnings = append(warnings, v3Warnings...)
	return warnings, apiErr
}
328941
func (s *DescribeEnvironmentResourcesInput) SetEnvironmentName(v string) *DescribeEnvironmentResourcesInput {
	s.EnvironmentName = &v
	return s
}
1020044
func (s *DescribeEnvironmentsInput) SetEnvironmentNames(v []*string) *DescribeEnvironmentsInput {
	s.EnvironmentNames = v
	return s
}
787378
func (client *Client) UpdateApplicationEnvironmentVariables(appGUID string, envVars EnvironmentVariables) (EnvironmentVariables, Warnings, error) {
	bodyBytes, err := json.Marshal(envVars)
	if err != nil {
		return EnvironmentVariables{}, nil, err
	}

	request, err := client.newHTTPRequest(requestOptions{
		URIParams:   internal.Params{"app_guid": appGUID},
		RequestName: internal.PatchApplicationEnvironmentVariablesRequest,
		Body:        bytes.NewReader(bodyBytes),
	})
	if err != nil {
		return EnvironmentVariables{}, nil, err
	}

	var responseEnvVars EnvironmentVariables
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &responseEnvVars,
	}
	err = client.connection.Make(request, &response)
	return responseEnvVars, response.Warnings, err
}
1345228
func (s *ContainerOverrides) SetEnvironment(v []*KeyValuePair) *ContainerOverrides {
	s.Environment = v
	return s
}
167617
func (s *DescribeConfigurationOptionsInput) SetEnvironmentName(v string) *DescribeConfigurationOptionsInput {
	s.EnvironmentName = &v
	return s
}
744860
func (s *ContainerProperties) SetEnvironment(v []*KeyValuePair) *ContainerProperties {
	s.Environment = v
	return s
}
134968
func setupEnvironmentVariables(a []string) map[string]string {
	r := make(map[string]string)
	for _, s := range a {
		arr := strings.SplitN(s, "=", 2)
		if len(arr) == 2 {
			r[arr[0]] = arr[1]
		}
	}
	return r
}
388585
func (s *ContainerOverride) SetEnvironment(v []*KeyValuePair) *ContainerOverride {
	s.Environment = v
	return s
}
1309022
func (s *DescribeEnvironmentResourcesOutput) SetEnvironmentResources(v *EnvironmentResourceDescription) *DescribeEnvironmentResourcesOutput {
	s.EnvironmentResources = v
	return s
}
1262166
func (actor Actor) SetApplicationDropletByApplicationNameAndSpace(appName string, spaceGUID string, dropletGUID string) (Warnings, error) {
	allWarnings := Warnings{}
	application, warnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
	allWarnings = append(allWarnings, warnings...)
	if err != nil {
		return allWarnings, err
	}
	_, apiWarnings, err := actor.CloudControllerClient.SetApplicationDroplet(application.GUID, dropletGUID)
	actorWarnings := Warnings(apiWarnings)
	allWarnings = append(allWarnings, actorWarnings...)

	if newErr, ok := err.(ccerror.UnprocessableEntityError); ok {
		return allWarnings, actionerror.AssignDropletError{Message: newErr.Message}
	}

	return allWarnings, err
}
43517
func (s *ApplicationDetail) SetApplicationName(v string) *ApplicationDetail {
	s.ApplicationName = &v
	return s
}
743325
func (s *CreateApplicationInput) SetRuntimeEnvironment(v string) *CreateApplicationInput {
	s.RuntimeEnvironment = &v
	return s
}
781956
func (s *CreateEnvironmentInput) SetEnvironmentName(v string) *CreateEnvironmentInput {
	s.EnvironmentName = &v
	return s
}
32985
func (s *CreateEnvironmentInput) SetApplicationName(v string) *CreateEnvironmentInput {
	s.ApplicationName = &v
	return s
}
1172651
func (s *DescribeEnvironmentHealthOutput) SetEnvironmentName(v string) *DescribeEnvironmentHealthOutput {
	s.EnvironmentName = &v
	return s
}
1363013
func SetEnvVariable(key, value string) error {
	if strings.TrimSpace(value) == "" {
		return nil
	}
	err := os.Setenv(key, value)
	if err != nil {
		return fmt.Errorf("Failed to set: %s = %s. %s", key, value, err.Error())
	}
	return nil
}