github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/api/cloudcontroller/ccv3/environment_variables.go (about) 1 package ccv3 2 3 import ( 4 "bytes" 5 "encoding/json" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 9 "code.cloudfoundry.org/cli/types" 10 ) 11 12 // EnvironmentVariableGroups represents all environment variables on an application 13 type EnvironmentVariableGroups struct { 14 SystemProvided map[string]interface{} `json:"system_env_json"` 15 ApplicationProvided map[string]interface{} `json:"application_env_json"` 16 UserProvided map[string]interface{} `json:"environment_variables"` 17 RunningGroup map[string]interface{} `json:"running_env_json"` 18 StagingGroup map[string]interface{} `json:"staging_env_json"` 19 } 20 21 // EnvironmentVariables represents the environment variables that can be set on application by user 22 type EnvironmentVariables struct { 23 Variables map[string]types.FilteredString `json:"var"` 24 } 25 26 // GetApplicationEnvironmentVariables fetches all the environment variables on 27 // an application by groups. 28 func (client *Client) GetApplicationEnvironmentVariables(appGUID string) (EnvironmentVariableGroups, Warnings, error) { 29 request, err := client.newHTTPRequest(requestOptions{ 30 URIParams: internal.Params{"app_guid": appGUID}, 31 RequestName: internal.GetApplicationEnvironmentVariables, 32 }) 33 if err != nil { 34 return EnvironmentVariableGroups{}, nil, err 35 } 36 37 var responseEnvVars EnvironmentVariableGroups 38 response := cloudcontroller.Response{ 39 Result: &responseEnvVars, 40 } 41 err = client.connection.Make(request, &response) 42 return responseEnvVars, response.Warnings, err 43 } 44 45 // PatchApplicationUserProvidedEnvironmentVariables updates the user provided environment 46 // variables on an applicaiton. A restart is required for changes to take effect. 47 func (client *Client) PatchApplicationUserProvidedEnvironmentVariables(appGUID string, envVars EnvironmentVariables) (EnvironmentVariables, Warnings, error) { 48 bodyBytes, err := json.Marshal(envVars) 49 if err != nil { 50 return EnvironmentVariables{}, nil, err 51 } 52 53 request, err := client.newHTTPRequest(requestOptions{ 54 URIParams: internal.Params{"app_guid": appGUID}, 55 RequestName: internal.PatchApplicationUserProvidedEnvironmentVariablesRequest, 56 Body: bytes.NewReader(bodyBytes), 57 }) 58 if err != nil { 59 return EnvironmentVariables{}, nil, err 60 } 61 62 var responseEnvVars EnvironmentVariables 63 response := cloudcontroller.Response{ 64 Result: &responseEnvVars, 65 } 66 err = client.connection.Make(request, &response) 67 return responseEnvVars, response.Warnings, err 68 }