harness-drone/handler/api/secrets/delete.go

39 lines
912 B
Go
Raw Permalink Normal View History

2019-04-15 00:06:16 +00:00
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Drone Non-Commercial License
// that can be found in the LICENSE file.
// +build !oss
package secrets
import (
"net/http"
"github.com/drone/drone/core"
"github.com/drone/drone/handler/api/render"
"github.com/go-chi/chi"
)
// HandleDelete returns an http.HandlerFunc that processes http
// requests to delete the secret.
func HandleDelete(secrets core.GlobalSecretStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
namespace = chi.URLParam(r, "namespace")
name = chi.URLParam(r, "name")
)
s, err := secrets.FindName(r.Context(), namespace, name)
if err != nil {
render.NotFound(w, err)
return
}
err = secrets.Delete(r.Context(), s)
if err != nil {
render.InternalError(w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
}