func()

in testutils/fakekubeapi/fakekubeapi.go [148:186]


func (f *Server) processPut(r *http.Request, w http.ResponseWriter) {
	ctx, cancel := context.WithTimeout(r.Context(), f.timeout)
	defer cancel()

	glog.Infof("Processing PUT request %v", r)
	if !secretsURLRegex.MatchString(r.URL.EscapedPath()) {
		http.Error(w, fmt.Sprintf("unexpected uri: %s", r.URL.EscapedPath()), http.StatusNotFound)
		return
	}

	b, err := ioutil.ReadAll(r.Body)
	if err != nil {
		http.Error(w, fmt.Sprintf("failed to read the body of the request, error: %v", err), http.StatusBadRequest)
		return
	}

	s := &corev1.Secret{}
	if err := json.Unmarshal(b, s); err != nil {
		http.Error(w, fmt.Sprintf("failed to unmarshal request, error: %v", err), http.StatusBadRequest)
		return
	}

	f.recordSecretPut(*s)

	glog.Infoln("Sending secret for encryption to kms-plugin.")
	if _, err := f.kms.Encrypt(ctx, &msgspb.EncryptRequest{Version: "v1beta1", Plain: b}); err != nil {
		m := fmt.Sprintf("failed to transform secret, error: %v", err)
		glog.Warning(m)
		http.Error(w, m, http.StatusServiceUnavailable)
		return
	}
	glog.Info("kms-plugin processed the encryption request.")

	w.Header().Set("Content-Type", "application/json")
	if err := json.NewEncoder(w).Encode(s); err != nil {
		http.Error(w, fmt.Sprintf("failed to write response for secret put, error: %v", err), http.StatusBadRequest)
		return
	}
}