summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2018-03-13 12:59:37 -0700
committerGirish Havaldar <hg0071052@techmahindra.com>2018-03-15 17:00:33 +0000
commit9b16de820c0bef5643746bdeb3186714a85281f1 (patch)
tree44cfb4ed3f1f22de9bc69edd62b83d3f033cfa99
parent75dd5474ec6a2a1c4fbf513e82ba6f4ae08f85f6 (diff)
Update listsecret return to send a JSON object
Instead of sending JSONArray, retrun JSON object for consistency and client processing Issue-ID: AAF-172 Change-Id: I17d2e2c2865a817c8016987f998c87259413f306 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
-rw-r--r--sms-service/doc/api_swagger.html26
-rw-r--r--sms-service/doc/api_swagger.yaml31
-rw-r--r--sms-service/src/sms/handler/handler.go11
-rw-r--r--sms-service/src/sms/handler/handler_test.go11
4 files changed, 54 insertions, 25 deletions
diff --git a/sms-service/doc/api_swagger.html b/sms-service/doc/api_swagger.html
index 94a72aa..7f987a3 100644
--- a/sms-service/doc/api_swagger.html
+++ b/sms-service/doc/api_swagger.html
@@ -181,7 +181,7 @@ font-style: italic;
<body>
<h1>Secret Management Service</h1>
<div class="app-desc">This is a service that provides secret management facilities</div>
- <div class="app-desc">More information: <a href=""></a></div>
+ <div class="app-desc">More information: <a href="https://helloreverb.com">https://helloreverb.com</a></div>
<div class="app-desc">Contact Info: <a href="kiran.k.kamineni@intel.com">kiran.k.kamineni@intel.com</a></div>
<div class="app-desc">Version: 1.0.0</div>
<div class="app-desc">BasePath:/v1/sms/</div>
@@ -295,8 +295,8 @@ font-style: italic;
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
- "name" : "aeiou",
- "uuid" : "aeiou"
+ "name" : "name",
+ "uuid" : "uuid"
}</code></pre>
<h3 class="field-label">Produces</h3>
@@ -356,7 +356,7 @@ font-style: italic;
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"ttl" : 0,
- "token" : "aeiou"
+ "token" : "token"
}</code></pre>
<h3 class="field-label">Produces</h3>
@@ -397,15 +397,15 @@ font-style: italic;
<h3 class="field-label">Return type</h3>
<div class="return-type">
+ <a href="#inline_response_200_2">inline_response_200_2</a>
- array[String]
</div>
<!--Todo: process Response Object and its headers, schema, examples -->
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
- <pre class="example"><code>[ "secret1", "secret2", "secret3" ]</code></pre>
+ <pre class="example"><code>"{\"secretnames\":[\"secretname1\",\"secretname2\",\"secretname3\"]}"</code></pre>
<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
@@ -417,7 +417,7 @@ font-style: italic;
<h3 class="field-label">Responses</h3>
<h4 class="field-label">200</h4>
Successful operation
-
+ <a href="#inline_response_200_2">inline_response_200_2</a>
<h4 class="field-label">404</h4>
Invalid Path or Path not found
<a href="#"></a>
@@ -552,7 +552,7 @@ font-style: italic;
"Age" : 40,
"admin" : true
},
- "name" : "aeiou"
+ "name" : "name"
}</code></pre>
<h3 class="field-label">Produces</h3>
@@ -596,7 +596,7 @@ font-style: italic;
<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
- "sealstatus" : "aeiou"
+ "sealstatus" : "sealstatus"
}</code></pre>
<h3 class="field-label">Produces</h3>
@@ -672,6 +672,7 @@ font-style: italic;
<li><a href="#body"><code>body</code> - </a></li>
<li><a href="#inline_response_200"><code>inline_response_200</code> - </a></li>
<li><a href="#inline_response_200_1"><code>inline_response_200_1</code> - </a></li>
+ <li><a href="#inline_response_200_2"><code>inline_response_200_2</code> - </a></li>
</ol>
<div class="model">
@@ -720,5 +721,12 @@ font-style: italic;
<div class="param">sealstatus (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> seal status of backend </div>
</div> <!-- field-items -->
</div>
+ <div class="model">
+ <h3><a name="inline_response_200_2"><code>inline_response_200_2</code> - </a> <a class="up" href="#__Models">Up</a></h3>
+
+ <div class="field-items">
+ <div class="param">secretnames (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">array[String]</a></span> Array of strings referencing the secret names </div>
+ </div> <!-- field-items -->
+ </div>
</body>
</html>
diff --git a/sms-service/doc/api_swagger.yaml b/sms-service/doc/api_swagger.yaml
index 08e3c18..61cd091 100644
--- a/sms-service/doc/api_swagger.yaml
+++ b/sms-service/doc/api_swagger.yaml
@@ -89,12 +89,14 @@ paths:
properties:
unsealshard:
type: string
- description: Unseal shard that will be used along with other shards to unseal backend
+ description: >-
+ Unseal shard that will be used along with other shards to
+ unseal backend
responses:
'201':
description: Submitted unseal key
'404':
- description: Invalid Path or Path not found
+ description: Invalid Path or Path not found
/domain:
post:
tags:
@@ -182,10 +184,15 @@ paths:
'200':
description: Successful operation
schema:
- type: array
- items:
- type: string
- example: ['secret1', 'secret2', 'secret3']
+ type: object
+ properties:
+ secretnames:
+ type: array
+ items:
+ type: string
+ description: Array of strings referencing the secret names
+ example:
+ secretnames: ["secretname1", "secretname2", "secretname3"]
'404':
description: Invalid Path or Path not found
'/domain/{domainName}/secret/{secretName}':
@@ -239,9 +246,9 @@ paths:
description: Invalid Path or Path not found
securityDefinitions:
token:
- type: "apiKey"
- name: "token"
- in: "header"
+ type: apiKey
+ name: token
+ in: header
definitions:
Credential:
type: object
@@ -273,9 +280,9 @@ definitions:
additionalProperties:
type: object
example:
- "name": "john"
- "Age": 40
- "admin": true
+ name: john
+ Age: 40
+ admin: true
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
diff --git a/sms-service/src/sms/handler/handler.go b/sms-service/src/sms/handler/handler.go
index 4456806..f2800fc 100644
--- a/sms-service/src/sms/handler/handler.go
+++ b/sms-service/src/sms/handler/handler.go
@@ -131,14 +131,21 @@ func (h handler) listSecretHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
domName := vars["domName"]
- sec, err := h.secretBackend.ListSecret(domName)
+ secList, err := h.secretBackend.ListSecret(domName)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
- jdata, err := json.Marshal(sec)
+ // Creating an anonymous struct to store the returned list of data
+ var retStruct = struct {
+ SecretNames []string `json:"secretnames"`
+ }{
+ secList,
+ }
+
+ jdata, err := json.Marshal(retStruct)
if err != nil {
smslogger.WriteError(err.Error())
http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/sms-service/src/sms/handler/handler_test.go b/sms-service/src/sms/handler/handler_test.go
index e1b5b34..5e9e965 100644
--- a/sms-service/src/sms/handler/handler_test.go
+++ b/sms-service/src/sms/handler/handler_test.go
@@ -249,9 +249,16 @@ func TestListSecretHandler(t *testing.T) {
t.Errorf("Expected statusCreated return code. Got: %v", rr.Code)
}
- expected := []string{"testsecret1", "testsecret2"}
+ var expected = struct {
+ SecretNames []string `json:"secretnames"`
+ }{
+ []string{"testsecret1", "testsecret2"},
+ }
+
+ var got struct {
+ SecretNames []string `json:"secretnames"`
+ }
- var got []string
json.NewDecoder(rr.Body).Decode(&got)
if reflect.DeepEqual(expected, got) == false {