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

35 lines
839 B
Go
Raw 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"
)
// HandleFind returns an http.HandlerFunc that writes json-encoded
// secret details to the the response body.
func HandleFind(secrets core.GlobalSecretStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var (
namespace = chi.URLParam(r, "namespace")
name = chi.URLParam(r, "name")
)
secret, err := secrets.FindName(r.Context(), namespace, name)
if err != nil {
render.NotFound(w, err)
return
}
safe := secret.Copy()
render.JSON(w, safe, 200)
}
}