summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiran <kiran.k.kamineni@intel.com>2018-02-23 15:11:48 -0800
committerKiran <kiran.k.kamineni@intel.com>2018-02-23 15:11:56 -0800
commit6b5294a9f48c19eb48153182bbeb9077f0697394 (patch)
treeff2b02887849ad658f53b131e0004d7cec11afd1
parente3d682c5f14994c2b85ff26ddf6ae3148b499de3 (diff)
Adding deletesecret functionality
Adding deletesecret functionality in backend and handler Issue-ID: AAF-142 Change-Id: I09dfc78af72dff1d60ce25cc22053d72948f7433 Signed-off-by: Kiran <kiran.k.kamineni@intel.com>
-rw-r--r--sms-service/src/sms/backend/vault.go14
-rw-r--r--sms-service/src/sms/handler/handler.go6
2 files changed, 18 insertions, 2 deletions
diff --git a/sms-service/src/sms/backend/vault.go b/sms-service/src/sms/backend/vault.go
index 7fc1747..259b4f3 100644
--- a/sms-service/src/sms/backend/vault.go
+++ b/sms-service/src/sms/backend/vault.go
@@ -153,7 +153,7 @@ func (v *Vault) CreateSecret(dom string, sec Secret) error {
dom = v.vaultMount + "/" + dom
- // Vault write return is empty on successful write
+ // Vault return is empty on successful write
_, err = v.vaultClient.Logical().Write(dom+"/"+sec.Name, sec.Values)
if err != nil {
return errors.New("Unable to create Secret at provided path")
@@ -171,6 +171,18 @@ func (v *Vault) DeleteSecretDomain(name string) error {
// DeleteSecret deletes a secret mounted on the path provided
func (v *Vault) DeleteSecret(dom string, name string) error {
+ err := v.checkToken()
+ if err != nil {
+ return errors.New("Token checking returned an error" + err.Error())
+ }
+
+ dom = v.vaultMount + "/" + dom
+
+ // Vault return is empty on successful delete
+ _, err = v.vaultClient.Logical().Delete(dom + "/" + name)
+ if err != nil {
+ return errors.New("Unable to delete Secret at provided path")
+ }
return nil
}
diff --git a/sms-service/src/sms/handler/handler.go b/sms-service/src/sms/handler/handler.go
index 3798023..e9c7eab 100644
--- a/sms-service/src/sms/handler/handler.go
+++ b/sms-service/src/sms/handler/handler.go
@@ -121,7 +121,11 @@ func (h handler) deleteSecretHandler(w http.ResponseWriter, r *http.Request) {
domName := vars["domName"]
secName := vars["secretName"]
- h.secretBackend.DeleteSecret(domName, secName)
+ err := h.secretBackend.DeleteSecret(domName, secName)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
}
// struct that tracks various status items for SMS and backend