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
diff --git a/docs/faq.md b/docs/faq.md
index a2b705c..9ad08bb 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -14,6 +14,44 @@ Yes this is possible. However, there are known limitations if the device only ha
14one WiFi network device. (e.g. both need to operate on the same channel). See14one WiFi network device. (e.g. both need to operate on the same channel). See
15[Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details.15[Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details.
1616
17## 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?
18
19Review your request and be sure double quotes are correctly escaped. The following
20request will result in an error as quotes are not properly escaped:
21
22```
23$ 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
24
25
26HTTP/1.1 500 Internal Server Error
27Date: Fri, 22 Sep 2017 08:35:57 GMT
28Content-Length: 146
29Content-Type: text/plain; charset=utf-8
30
31{"result":{"kind":"internal-error","message":"Error reading the request body"},"status":"Internal Server Error","status-code":500,"type":"error"}
32```
33
34If quotes are properly escaped then the request will be accepted by the service:
35
36```
37$ 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
38
39
40HTTP/1.1 200 OK
41Date: Fri, 22 Sep 2017 08:39:05 GMT
42Content-Length: 60
43Content-Type: text/plain; charset=utf-8
44
45{"result":{},"status":"OK","status-code":200,"type":"sync"}
46```
47Also, it's recommended to put the JSON post data into a text file and redirect command input
48from that file during your testing as it makes the post data easier to read and edit.
49``` bash
50$ sudo nc -U /var/snap/wifi-ap/current/sockets/control < _post_content_file_
51```
52
53You can find more information related to this [here](rest-api-from-command-line.md)
54
17## Why isn't the AP automatically enabled after I've installed the snap?55## Why isn't the AP automatically enabled after I've installed the snap?
1856
19Normally it should automatically come up if this isn't disabled through the57Normally it should automatically come up if this isn't disabled through the
diff --git a/docs/metadata.yaml b/docs/metadata.yaml
index 4ecfe02..0cf387c 100644
--- a/docs/metadata.yaml
+++ b/docs/metadata.yaml
@@ -15,6 +15,10 @@ navigation:
15 location: secure-access-point.md15 location: secure-access-point.md
16 - title: Simultaneous STA / AP Mode16 - title: Simultaneous STA / AP Mode
17 location: simultaneous-sta-ap-mode.md17 location: simultaneous-sta-ap-mode.md
18 - title: Usage
19 children:
20 - title: REST API from command line
21 location: rest-api-from-command-line.md
18 - title: Reference22 - title: Reference
19 children:23 children:
20 - title: Commands24 - title: Commands
diff --git a/docs/rest-api-from-command-line.md b/docs/rest-api-from-command-line.md
21new file mode 10064425new file mode 100644
index 0000000..fb317ac
--- /dev/null
+++ b/docs/rest-api-from-command-line.md
@@ -0,0 +1,68 @@
1---
2title: "REST API From Command Line"
3table_of_contents: False
4---
5
6# REST API From Command Line
7
8The wifi-ap snap exposes a REST API for its management that can be accessed
9through a local Unix domain socket. One of the options to make use of that
10API is using the command line as client.
11
12You can see the details of the available API operations [here] (reference/rest-api.md)
13
14# Prerequisites
15
16You can use `nc` to send queries and print the response from the command line. `nc` is included
17in the default set of installed packages in Ubuntu Classic and as part of the core snap when
18you use Ubuntu Core or snaps. If not available please install via:
19
20```
21$ apt install netcat
22```
23
24# Perform REST API Operations
25
26From command line, you can query for current snap configuration by executing:
27
28```
29$ 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
30```
31
32That should result in a successful response whose JSON formatted content holds a current
33configuration of the wifi-ap service:
34```
35HTTP/1.1 200 OK
36Date: Fri, 22 Sep 2017 09:39:33 GMT
37Content-Length: 497
38Content-Type: text/plain; charset=utf-8
39
40{"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"}
41```
42
43The configuration can be modified by sending a POST request with the params to
44set and its new values in a JSON formatted content type body. Some HTTP headers must
45be set in the request:
46 * *Host*: Hostname where wifi-ap snap is installed
47 * *Content-type*: Its value must be set to `application/json`
48 * *Content-length*: Must match the exact number of characters the request body has
49
50```
51$ 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
52```
53
54A sucessful server reply means that the configuration has been updated as desired:
55
56```
57HTTP/1.1 200 OK
58Date: Fri, 22 Sep 2017 09:43:31 GMT
59Content-Length: 60
60Content-Type: text/plain; charset=utf-8
61
62{"result":{},"status":"OK","status-code":200,"type":"sync"}
63```
64
65
66!!! Note:
67 In case you need to provide body content, you have to escape the
68 double quote to not receive a malformed request error.

Subscribers

People subscribed via source and target branches