in gcp/runtimeconfig.go [33:69]
func runSetRuntimeConfigVar(action *specs.SetRuntimeConfigVarGcpAction, httpClient *http.Client) string {
configUrl, err := url.Parse(action.RuntimeConfigSelfLink)
if err != nil {
return fmt.Sprintf("Invalid runtime config self link: %s", action.RuntimeConfigSelfLink)
}
configPath := strings.Join(strings.Split(configUrl.Path, "/")[2:], "/")
payload := VariablePayload{
Name: fmt.Sprintf("%s/variables/%s", configPath, action.VariablePath),
Value: action.Base64Value,
}
accessToken, err := fetchAccessToken(httpClient)
if err != nil {
return fmt.Sprintf("Unable to fetch access token: %v", err)
}
body, err := json.Marshal(payload)
if err != nil {
glog.Fatalf("Unexpected failure when constructing payload: %v", err)
}
req, err := http.NewRequest(
http.MethodPost, fmt.Sprintf("%s/variables", configUrl.String()), bytes.NewReader(body))
if err != nil {
glog.Fatalf("Unexpected failure when constructing POST request: %v", err)
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", accessToken))
req.Header.Add("Content-Type", "application/json")
glog.V(1).Infof("About to send request: %+v", req)
glog.V(1).Infof("Body: %s", body)
res, err := httpClient.Do(req)
if err != nil {
return fmt.Sprintf("POST request error: %v", err)
}
if res.StatusCode != http.StatusOK {
return fmt.Sprintf("POST request status: %v %v", res.StatusCode, res.Status)
}
return ""
}