Skip to content

Commit 69dffad

Browse files
committed
Fixed http api
Removed body from DELETE routes, as javascript HTTP client used in frontend don't support it. Added back client names to url instead of query params / body.
1 parent b594335 commit 69dffad

File tree

7 files changed

+352
-215
lines changed

7 files changed

+352
-215
lines changed

api.proto

+8-12
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,26 @@ service C2 {
1717
// Create a new client
1818
rpc NewClient(NewClientRequest) returns (NewClientResponse) {
1919
option (google.api.http) = {
20-
post : "/e4/client"
20+
post : "/e4/client/{client.name}"
2121
body : "*"
2222
};
2323
}
2424
// Remove a client
2525
rpc RemoveClient(RemoveClientRequest) returns (RemoveClientResponse) {
2626
option (google.api.http) = {
27-
delete : "/e4/client"
28-
body : "*"
27+
delete : "/e4/client/{client.name}"
2928
};
3029
}
3130
// Instruct the C2 server to send a reset command to the client
3231
rpc ResetClient(ResetClientRequest) returns (ResetClientResponse) {
3332
option (google.api.http) = {
34-
put : "/e4/client"
35-
body : "*"
33+
put : "/e4/client/{client.name}"
3634
};
3735
}
3836
// Generate a new key for the client
3937
rpc NewClientKey(NewClientKeyRequest) returns (NewClientKeyResponse) {
4038
option (google.api.http) = {
41-
patch : "/e4/client"
39+
patch : "/e4/client/{client.name}"
4240
body : "*"
4341
};
4442
}
@@ -57,27 +55,25 @@ service C2 {
5755
// Associate a topic with a client
5856
rpc NewTopicClient(NewTopicClientRequest) returns (NewTopicClientResponse) {
5957
option (google.api.http) = {
60-
put : "/e4/client/topic"
61-
body : "*"
58+
put : "/e4/client/{client.name}/topic/{topic}"
6259
};
6360
}
6461
// Remove a topic / client association
6562
rpc RemoveTopicClient(RemoveTopicClientRequest) returns (RemoveTopicClientResponse) {
6663
option (google.api.http) = {
67-
delete : "/e4/client/topic"
68-
body : "*"
64+
delete : "/e4/client/{client.name}/topic/{topic}"
6965
};
7066
}
7167
// Count the number of topics for a client
7268
rpc CountTopicsForClient(CountTopicsForClientRequest) returns (CountTopicsForClientResponse) {
7369
option (google.api.http) = {
74-
get : "/e4/client/topics/count"
70+
get : "/e4/client/{client.name}/topics/count"
7571
};
7672
}
7773
// Retrieve paginated topics for a client
7874
rpc GetTopicsForClient(GetTopicsForClientRequest) returns (GetTopicsForClientResponse) {
7975
option (google.api.http) = {
80-
get : "/e4/client/topics"
76+
get : "/e4/client/{client.name}/topics"
8177
};
8278
}
8379
// Count the number of clients for a topic

doc/api.swagger.json

+44-66
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"application/json"
1616
],
1717
"paths": {
18-
"/e4/client": {
18+
"/e4/client/{client.name}": {
1919
"delete": {
2020
"summary": "Remove a client",
2121
"operationId": "RemoveClient",
@@ -29,12 +29,10 @@
2929
},
3030
"parameters": [
3131
{
32-
"name": "body",
33-
"in": "body",
32+
"name": "client.name",
33+
"in": "path",
3434
"required": true,
35-
"schema": {
36-
"$ref": "#/definitions/pbRemoveClientRequest"
37-
}
35+
"type": "string"
3836
}
3937
],
4038
"tags": [
@@ -53,6 +51,12 @@
5351
}
5452
},
5553
"parameters": [
54+
{
55+
"name": "client.name",
56+
"in": "path",
57+
"required": true,
58+
"type": "string"
59+
},
5660
{
5761
"name": "body",
5862
"in": "body",
@@ -79,12 +83,10 @@
7983
},
8084
"parameters": [
8185
{
82-
"name": "body",
83-
"in": "body",
86+
"name": "client.name",
87+
"in": "path",
8488
"required": true,
85-
"schema": {
86-
"$ref": "#/definitions/pbResetClientRequest"
87-
}
89+
"type": "string"
8890
}
8991
],
9092
"tags": [
@@ -103,6 +105,12 @@
103105
}
104106
},
105107
"parameters": [
108+
{
109+
"name": "client.name",
110+
"in": "path",
111+
"required": true,
112+
"type": "string"
113+
},
106114
{
107115
"name": "body",
108116
"in": "body",
@@ -117,7 +125,7 @@
117125
]
118126
}
119127
},
120-
"/e4/client/topic": {
128+
"/e4/client/{client.name}/topic/{topic}": {
121129
"delete": {
122130
"summary": "Remove a topic / client association",
123131
"operationId": "RemoveTopicClient",
@@ -131,12 +139,16 @@
131139
},
132140
"parameters": [
133141
{
134-
"name": "body",
135-
"in": "body",
142+
"name": "client.name",
143+
"in": "path",
136144
"required": true,
137-
"schema": {
138-
"$ref": "#/definitions/pbRemoveTopicClientRequest"
139-
}
145+
"type": "string"
146+
},
147+
{
148+
"name": "topic",
149+
"in": "path",
150+
"required": true,
151+
"type": "string"
140152
}
141153
],
142154
"tags": [
@@ -156,20 +168,24 @@
156168
},
157169
"parameters": [
158170
{
159-
"name": "body",
160-
"in": "body",
171+
"name": "client.name",
172+
"in": "path",
161173
"required": true,
162-
"schema": {
163-
"$ref": "#/definitions/pbNewTopicClientRequest"
164-
}
174+
"type": "string"
175+
},
176+
{
177+
"name": "topic",
178+
"in": "path",
179+
"required": true,
180+
"type": "string"
165181
}
166182
],
167183
"tags": [
168184
"C2"
169185
]
170186
}
171187
},
172-
"/e4/client/topics": {
188+
"/e4/client/{client.name}/topics": {
173189
"get": {
174190
"summary": "Retrieve paginated topics for a client",
175191
"operationId": "GetTopicsForClient",
@@ -184,8 +200,8 @@
184200
"parameters": [
185201
{
186202
"name": "client.name",
187-
"in": "query",
188-
"required": false,
203+
"in": "path",
204+
"required": true,
189205
"type": "string"
190206
},
191207
{
@@ -208,7 +224,7 @@
208224
]
209225
}
210226
},
211-
"/e4/client/topics/count": {
227+
"/e4/client/{client.name}/topics/count": {
212228
"get": {
213229
"summary": "Count the number of topics for a client",
214230
"operationId": "CountTopicsForClient",
@@ -223,8 +239,8 @@
223239
"parameters": [
224240
{
225241
"name": "client.name",
226-
"in": "query",
227-
"required": false,
242+
"in": "path",
243+
"required": true,
228244
"type": "string"
229245
}
230246
],
@@ -588,59 +604,21 @@
588604
"pbNewClientResponse": {
589605
"type": "object"
590606
},
591-
"pbNewTopicClientRequest": {
592-
"type": "object",
593-
"properties": {
594-
"client": {
595-
"$ref": "#/definitions/pbClient"
596-
},
597-
"topic": {
598-
"type": "string"
599-
}
600-
}
601-
},
602607
"pbNewTopicClientResponse": {
603608
"type": "object"
604609
},
605610
"pbNewTopicResponse": {
606611
"type": "object"
607612
},
608-
"pbRemoveClientRequest": {
609-
"type": "object",
610-
"properties": {
611-
"client": {
612-
"$ref": "#/definitions/pbClient"
613-
}
614-
}
615-
},
616613
"pbRemoveClientResponse": {
617614
"type": "object"
618615
},
619-
"pbRemoveTopicClientRequest": {
620-
"type": "object",
621-
"properties": {
622-
"client": {
623-
"$ref": "#/definitions/pbClient"
624-
},
625-
"topic": {
626-
"type": "string"
627-
}
628-
}
629-
},
630616
"pbRemoveTopicClientResponse": {
631617
"type": "object"
632618
},
633619
"pbRemoveTopicResponse": {
634620
"type": "object"
635621
},
636-
"pbResetClientRequest": {
637-
"type": "object",
638-
"properties": {
639-
"client": {
640-
"$ref": "#/definitions/pbClient"
641-
}
642-
}
643-
},
644622
"pbResetClientResponse": {
645623
"type": "object"
646624
},

pkg/c2test/http.go

+7-24
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,9 @@ func HTTPApi(resChan chan<- TestResult, httpClient *http.Client, host string) {
7979

8080
for i := 0; i < TESTCLIENTS; i++ {
8181
// Create a new client on the C2
82-
url = fmt.Sprintf("%s/e4/client", host)
82+
url = fmt.Sprintf("%s/e4/client/%s", host, testClients[i].Name)
8383

8484
newClientBody := pb.NewClientRequest{
85-
Client: &pb.Client{
86-
Name: testClients[i].Name,
87-
},
8885
Key: testClients[i].Key,
8986
}
9087

@@ -117,15 +114,8 @@ func HTTPApi(resChan chan<- TestResult, httpClient *http.Client, host string) {
117114
resChan <- TestResult{Name: "Create Topic", Result: true, Critical: false, Error: nil}
118115

119116
// Add the topic to the client.
120-
url = fmt.Sprintf("%s/e4/client/topic", host)
121-
newTopicClientBody := &pb.NewTopicClientRequest{
122-
Client: &pb.Client{
123-
Name: testClients[0].Name,
124-
},
125-
Topic: testtopics[0].TopicName,
126-
}
127-
128-
if _, err = testHTTPReq("Add Topic to Client", httpClient, "PUT", url, newTopicClientBody, 200); err != nil {
117+
url = fmt.Sprintf("%s/e4/client/%s/topic/%s", host, testClients[0].Name, testtopics[0].TopicName)
118+
if _, err = testHTTPReq("Add Topic to Client", httpClient, "PUT", url, nil, 200); err != nil {
129119
resChan <- TestResult{
130120
Name: "Add Topic to Client",
131121
Result: false,
@@ -137,7 +127,7 @@ func HTTPApi(resChan chan<- TestResult, httpClient *http.Client, host string) {
137127
resChan <- TestResult{Name: "Add Topic to Client", Result: true, Critical: false, Error: nil}
138128

139129
// Check the M2M link returns the topic we added
140-
url = fmt.Sprintf("%s/e4/client/topics?client.name=%s&offset=0&count=10", host,
130+
url = fmt.Sprintf("%s/e4/client/%s/topics?offset=0&count=10", host,
141131
testClients[0].Name)
142132
if resp, err = testHTTPReq("M2M Find Added Topic", httpClient, "GET", url, nil, 200); err != nil {
143133
resChan <- TestResult{
@@ -172,15 +162,8 @@ func HTTPApi(resChan chan<- TestResult, httpClient *http.Client, host string) {
172162
resChan <- TestResult{Name: "M2M Find Added Topic", Result: true, Critical: false, Error: nil}
173163

174164
// Remove the topic from the client (but not the C2)
175-
url = fmt.Sprintf("%s/e4/client/topic", host)
176-
removeTopicClientBody := &pb.RemoveTopicClientRequest{
177-
Client: &pb.Client{
178-
Name: testClients[0].Name,
179-
},
180-
Topic: testtopics[0].TopicName,
181-
}
182-
183-
if _, err = testHTTPReq("Remove Topic from Client", httpClient, "DELETE", url, removeTopicClientBody, 200); err != nil {
165+
url = fmt.Sprintf("%s/e4/client/%s/topic/%s", host, testClients[0].Name, testtopics[0].TopicName)
166+
if _, err = testHTTPReq("Remove Topic from Client", httpClient, "DELETE", url, nil, 200); err != nil {
184167
resChan <- TestResult{
185168
Name: "Remove Topic from Client",
186169
Result: false,
@@ -192,7 +175,7 @@ func HTTPApi(resChan chan<- TestResult, httpClient *http.Client, host string) {
192175
resChan <- TestResult{Name: "Remove Topic from Client", Result: true, Critical: false, Error: nil}
193176

194177
// Check Topic appears to have been removed from the client
195-
url = fmt.Sprintf("%s/e4/client/topics?client.name=%s&offset=0&count=10", host,
178+
url = fmt.Sprintf("%s/e4/client/%s/topics?offset=0&count=10", host,
196179
testClients[0].Name)
197180
if resp, err = testHTTPReq("Test M2M Doesn't Show Removed Topic", httpClient, "GET", url, nil, 200); err != nil {
198181
resChan <- TestResult{

0 commit comments

Comments
 (0)