harness-drone/handler/api/secrets/find.go
2019-04-14 17:06:16 -07:00

34 lines
839 B
Go

// 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)
}
}