From adf8846c28fe50dbe6379b976d32f15392e2ee9f Mon Sep 17 00:00:00 2001 From: ssbkang Date: Fri, 28 Jun 2019 22:45:34 +1200 Subject: [PATCH] Add hideFields() --- api/http/handler/deploymentkeys/deploymentkey_create.go | 2 ++ api/http/handler/deploymentkeys/deploymentkey_inspect.go | 2 ++ api/http/handler/deploymentkeys/deploymentkey_list.go | 4 ++++ api/http/handler/deploymentkeys/handler.go | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/api/http/handler/deploymentkeys/deploymentkey_create.go b/api/http/handler/deploymentkeys/deploymentkey_create.go index c0953a752..da60a3084 100644 --- a/api/http/handler/deploymentkeys/deploymentkey_create.go +++ b/api/http/handler/deploymentkeys/deploymentkey_create.go @@ -49,5 +49,7 @@ func (handler *Handler) deploymentkeyCreate(w http.ResponseWriter, r *http.Reque return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the deployment key inside the database", err} } + hideFields(deploymentkey) + return response.JSON(w, deploymentkey) } diff --git a/api/http/handler/deploymentkeys/deploymentkey_inspect.go b/api/http/handler/deploymentkeys/deploymentkey_inspect.go index 4cff8fdd3..d80e0d3cb 100644 --- a/api/http/handler/deploymentkeys/deploymentkey_inspect.go +++ b/api/http/handler/deploymentkeys/deploymentkey_inspect.go @@ -23,5 +23,7 @@ func (handler *Handler) deploymentkeyInspect(w http.ResponseWriter, r *http.Requ return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a deployment key with the specified identifier inside the database", err} } + hideFields(deploymentkey) + return response.JSON(w, deploymentkey) } diff --git a/api/http/handler/deploymentkeys/deploymentkey_list.go b/api/http/handler/deploymentkeys/deploymentkey_list.go index 172ae5a23..9a9adf505 100644 --- a/api/http/handler/deploymentkeys/deploymentkey_list.go +++ b/api/http/handler/deploymentkeys/deploymentkey_list.go @@ -14,5 +14,9 @@ func (handler *Handler) deploymentkeyList(w http.ResponseWriter, r *http.Request return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve deploymentkeys from the database", err} } + for idx := range deploymentkeys { + hideFields(&deploymentkeys[idx]) + } + return response.JSON(w, deploymentkeys) } diff --git a/api/http/handler/deploymentkeys/handler.go b/api/http/handler/deploymentkeys/handler.go index 81119bd12..125039757 100644 --- a/api/http/handler/deploymentkeys/handler.go +++ b/api/http/handler/deploymentkeys/handler.go @@ -15,6 +15,10 @@ type Handler struct { DeploymentKeyService portainer.DeploymentKeyService } +func hideFields(deploymentkey *portainer.DeploymentKey) { + deploymentkey.PrivateKey = "" +} + // NewHandler creates a handler to manage settings operations. func NewHandler(bouncer *security.RequestBouncer) *Handler { h := &Handler{