Merge ~rmescandon/snappy-hwe-snaps/+git/wifi-ap:document-api-request-from-cli into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Roberto Mier Escandon
Status: Needs review
Proposed branch: ~rmescandon/snappy-hwe-snaps/+git/wifi-ap:document-api-request-from-cli
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 138 lines (+110/-0)
3 files modified
docs/faq.md (+38/-0)
docs/metadata.yaml (+4/-0)
docs/rest-api-from-command-line.md (+68/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Needs Fixing
Simon Fels Approve
Jim Hodapp (community) Approve
Gary.Wang Approve
Review via email: mp+331186@code.launchpad.net

Description of the change

Added a pair of FAQs related with errors reported using REST API from cli

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Gary.Wang (gary-wzl77) wrote :

Thanks! Just left one comment.
Also, would you mind adjusting the content position a little bit? i.e.

## Why isn't the AP automatically enabled after I've installed the snap?
...
...
...
## Can I send REST API queries from the command line?
...
...
...

If this still doesn't help, feel free to file a [bug report](report-bug.md)
...
...

review: Needs Fixing
4f91907... by Roberto Mier Escandon

added Usage section in navigation
moved rest api use from cli to a newer page
rephrased

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 6759986e9fb2592956e629d1ce1da0bf8171abfb

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/582/

Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
71f74a3... by Roberto Mier Escandon

updated docs with more info and more addressed comments

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 4f91907db6d7c243947d257348b67ba5eb20f780

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/583/

Revision history for this message
Gary.Wang (gary-wzl77) wrote :

LGTM. Thanks!

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 5bf7ab72c3d0f51ffd83822b18b34c219f6fb26f

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/585/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 71f74a3020cf3c6cd396ac4f3dd7a11326d40abe

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/588/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looking good, some things to fix.

review: Needs Fixing
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 71f74a3020cf3c6cd396ac4f3dd7a11326d40abe

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/589/

c67db71... by Roberto Mier Escandon

corrected english

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Jim Hodapp (jhodapp) wrote :

One more thing to fix.

review: Needs Fixing
92106f8... by Roberto Mier Escandon

final? addressing

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: c67db71684ef1171142198f1e515d1e18b2bb31d

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/591/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Jim Hodapp (jhodapp) wrote :

LGTM!

review: Approve
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/596/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/597/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/598/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/599/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/601/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/600/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/602/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/603/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/625/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/626/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/624/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/627/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/630/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/628/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/629/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 92106f8f50d979d1cdd5ef39529c2324cff8303c

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/635/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)

Unmerged commits

92106f8... by Roberto Mier Escandon

final? addressing

c67db71... by Roberto Mier Escandon

corrected english

71f74a3... by Roberto Mier Escandon

updated docs with more info and more addressed comments

4f91907... by Roberto Mier Escandon

added Usage section in navigation
moved rest api use from cli to a newer page
rephrased

6759986... by Roberto Mier Escandon

added a pair of faqs related with api rest access from cli

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/docs/faq.md b/docs/faq.md
2index a2b705c..9ad08bb 100644
3--- a/docs/faq.md
4+++ b/docs/faq.md
5@@ -14,6 +14,44 @@ Yes this is possible. However, there are known limitations if the device only ha
6 one WiFi network device. (e.g. both need to operate on the same channel). See
7 [Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details.
8
9+## I am sending an HTTP post request from the command line to the wifi-ap management service but I receive a HTTP 500 error code. Why?
10+
11+Review your request and be sure double quotes are correctly escaped. The following
12+request will result in an error as quotes are not properly escaped:
13+
14+```
15+$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{"disabled":"false"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control
16+
17+
18+HTTP/1.1 500 Internal Server Error
19+Date: Fri, 22 Sep 2017 08:35:57 GMT
20+Content-Length: 146
21+Content-Type: text/plain; charset=utf-8
22+
23+{"result":{"kind":"internal-error","message":"Error reading the request body"},"status":"Internal Server Error","status-code":500,"type":"error"}
24+```
25+
26+If quotes are properly escaped then the request will be accepted by the service:
27+
28+```
29+$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{\"disabled\":\"false\"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control
30+
31+
32+HTTP/1.1 200 OK
33+Date: Fri, 22 Sep 2017 08:39:05 GMT
34+Content-Length: 60
35+Content-Type: text/plain; charset=utf-8
36+
37+{"result":{},"status":"OK","status-code":200,"type":"sync"}
38+```
39+Also, it's recommended to put the JSON post data into a text file and redirect command input
40+from that file during your testing as it makes the post data easier to read and edit.
41+``` bash
42+$ sudo nc -U /var/snap/wifi-ap/current/sockets/control < _post_content_file_
43+```
44+
45+You can find more information related to this [here](rest-api-from-command-line.md)
46+
47 ## Why isn't the AP automatically enabled after I've installed the snap?
48
49 Normally it should automatically come up if this isn't disabled through the
50diff --git a/docs/metadata.yaml b/docs/metadata.yaml
51index 4ecfe02..0cf387c 100644
52--- a/docs/metadata.yaml
53+++ b/docs/metadata.yaml
54@@ -15,6 +15,10 @@ navigation:
55 location: secure-access-point.md
56 - title: Simultaneous STA / AP Mode
57 location: simultaneous-sta-ap-mode.md
58+ - title: Usage
59+ children:
60+ - title: REST API from command line
61+ location: rest-api-from-command-line.md
62 - title: Reference
63 children:
64 - title: Commands
65diff --git a/docs/rest-api-from-command-line.md b/docs/rest-api-from-command-line.md
66new file mode 100644
67index 0000000..fb317ac
68--- /dev/null
69+++ b/docs/rest-api-from-command-line.md
70@@ -0,0 +1,68 @@
71+---
72+title: "REST API From Command Line"
73+table_of_contents: False
74+---
75+
76+# REST API From Command Line
77+
78+The wifi-ap snap exposes a REST API for its management that can be accessed
79+through a local Unix domain socket. One of the options to make use of that
80+API is using the command line as client.
81+
82+You can see the details of the available API operations [here] (reference/rest-api.md)
83+
84+# Prerequisites
85+
86+You can use `nc` to send queries and print the response from the command line. `nc` is included
87+in the default set of installed packages in Ubuntu Classic and as part of the core snap when
88+you use Ubuntu Core or snaps. If not available please install via:
89+
90+```
91+$ apt install netcat
92+```
93+
94+# Perform REST API Operations
95+
96+From command line, you can query for current snap configuration by executing:
97+
98+```
99+$ printf "GET /v1/configuration HTTP/1.1\r\n Host: www.example.com\r\n\r\n" | sudo nc -U /var/snap/wifi-ap/current/sockets/control
100+```
101+
102+That should result in a successful response whose JSON formatted content holds a current
103+configuration of the wifi-ap service:
104+```
105+HTTP/1.1 200 OK
106+Date: Fri, 22 Sep 2017 09:39:33 GMT
107+Content-Length: 497
108+Content-Type: text/plain; charset=utf-8
109+
110+{"result":{"debug":false,"dhcp.lease-time":"12h","dhcp.range-start":"10.0.60.3","dhcp.range-stop":"10.0.60.20","disabled":false,"share.disabled":false,"share.network-interface":"eth0","wifi.address":"10.0.60.1","wifi.channel":"6","wifi.hostapd-driver":"nl80211","wifi.interface":"wlan0","wifi.interface-mode":"direct","wifi.netmask":"255.255.255.0","wifi.operation-mode":"g","wifi.security":"open","wifi.security-passphrase":"","wifi.ssid":"Ubuntu"},"status":"OK","status-code":200,"type":"sync"}
111+```
112+
113+The configuration can be modified by sending a POST request with the params to
114+set and its new values in a JSON formatted content type body. Some HTTP headers must
115+be set in the request:
116+ * *Host*: Hostname where wifi-ap snap is installed
117+ * *Content-type*: Its value must be set to `application/json`
118+ * *Content-length*: Must match the exact number of characters the request body has
119+
120+```
121+$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{\"disabled\":\"false\"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control
122+```
123+
124+A sucessful server reply means that the configuration has been updated as desired:
125+
126+```
127+HTTP/1.1 200 OK
128+Date: Fri, 22 Sep 2017 09:43:31 GMT
129+Content-Length: 60
130+Content-Type: text/plain; charset=utf-8
131+
132+{"result":{},"status":"OK","status-code":200,"type":"sync"}
133+```
134+
135+
136+!!! Note:
137+ In case you need to provide body content, you have to escape the
138+ double quote to not receive a malformed request error.

Subscribers

People subscribed via source and target branches