Merge ~jsseidel/maas:jsseidel-sshkeys-api-annotations into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Newell Jensen
Approved revision: 600ee406609e549be3030e5dba6d738f2fa670f5
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-sshkeys-api-annotations
Merge into: maas:master
Diff against target: 171 lines (+108/-13)
2 files modified
src/maasserver/api/examples/account.json (+41/-0)
src/maasserver/api/ssh_keys.py (+67/-13)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Newell Jensen (community) Approve
Review via email: mp+359155@code.launchpad.net

Commit message

Added api annotations to ssh-keys and examples.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Looks good. One inline suggestion.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b jsseidel-sshkeys-api-annotations lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 600ee406609e549be3030e5dba6d738f2fa670f5

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/examples/account.json b/src/maasserver/api/examples/account.json
2new file mode 100644
3index 0000000..67ac321
4--- /dev/null
5+++ b/src/maasserver/api/examples/account.json
6@@ -0,0 +1,41 @@
7+{
8+ "ssh-keys-list": [
9+ {
10+ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/L1pGwyIs9mxP1MkuPVrEMfcl+qEg9wChnN/n4fGwFIJ9vXFBV8pu8rvcsigx/Ar2wZRHGIO/cwHeC+rR+jG5zw4ZyD5d+ISfVoyKsOviAQzXJTCjdx4aLItVA6LYZiv8Z3fondqpzFuVph+D/hc1sBNxlPJcFF3RJcCTf92xYyQfUlZo/RYPHzgWDYWYScoZXOxLms2ZKtyuqQFyKmlcTzlTWoYGeTtqEq5OCWG/PSlTopGqRtoZXSATAOfCDH1kyOqAtehtn6ehZ013u4Kb8d8nD66SeLOBG5xQUbm7U1LkfVLGMrXlJOhrJ58JsNTx9sq8ouNO9VknbhvWD5aH user@mymachine",
11+ "id": 5,
12+ "keysource": "lp:user",
13+ "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/5/"
14+ },
15+ {
16+ "key": "ssh-rsa AAAAB3NzaC1tc2EAAAADAQABAAABAQC5zQ1NvtYWGYKpLgW0QWBiGyt225JRAO9Wa9mlNG5Otq7PJ6PkIMZKrmfZnpYFoMe8gzY/FT5wqfzzKBxvHPFkSS24MIiRN6VDlE0rZJnugd2ijpmYKXwVMHFHWIbBLqES3ssO3VePF67Y4Agt7JRqDlF2C9ttQXXbu23fvccpDIzt6tPtPDJzNo3M1JexxRNMuyb0moNeHISGTTFCL8LSuVn8MvpqXLqBqR5Q0nchgym+f6nWQMknpLNA0531W/2ZOMa2h5vtWDoVPisGmOzlV41dpDOWG4wr120Yn6Q8thTh2tQbS0/UjThPnjrUjs9nJxg5X0MPkzEuoXo3KWEh user2@myothermachine",
17+ "id": 6,
18+ "keysource": "lp:user2",
19+ "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/6/"
20+ }
21+ ],
22+ "ssh-keys-create": {
23+ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRShb/bGd0DSYljfCwFI4D12wDk/qW9cSb3T++mytvfmXsisf8+ql5qEr+a0hsn6hkOMTcwdC5q/fVEo/P4KXj1DI9XEJ+j2sRj3Lw/bn+mpFmSsEUmv+PLzpQSX0JXOu2N8VjfgINJSXRrAmk6cmuc4Ro119dkYu/i7VIHiWSan0FY+P6ipaqien/m7mc1M1JhDyfO6ubQAfsP49+vqP+RmXPLhjmtf4yBVMnQavITtRctFBXf7PyvPgSrSCNS+M6+FZIjS79ctEpi8HUZDOCCZ7xS5vuJNtPcp3vwBOUNzVStBi/GzNYdbhubQnlHGzLJRBp64OWVasn/pkBfXUB",
24+ "keysource": null,
25+ "id": 12
26+ },
27+ "ssh-keys-import": [
28+ {
29+ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC/L1pGwyIs9mxP1MkuPVrEMfcl+qEg9wChnN/n4fGwFIJ9vXFBV8pu8rvcsigx/Ar2wZRHGIO/cwHeC+rR+jG5zw4ZyD5d+ISfVoyKsOviAQzXJTCjdx4aLItVA6LYZiv8Z3fondqpzFuVph+D/hc1sBNxlPJcFF3RJcCTf92xYyQfUlZo/RYPHzgWDYWYScoZXOxLms2ZKtyuqQFyKmlcTzlTWoYGeTtqEq5OCWG/PSlTopGqRtoZXSATAOfCDH1kyOqAtehtn6ehZ013u4Kb8d8nD66SeLOBG5xQUbm7U1LkfVLGMrXlJOhrJ58JsNTx9sq8ouNO9VknbhvWD5aH user@mymachine",
30+ "id": 5,
31+ "keysource": "lp:user",
32+ "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/5/"
33+ },
34+ {
35+ "key": "ssh-rsa AAAAB3NzaC1tc2EAAAADAQABAAABAQC5zQ1NvtYWGYKpLgW0QWBiGyt225JRAO9Wa9mlNG5Otq7PJ6PkIMZKrmfZnpYFoMe8gzY/FT5wqfzzKBxvHPFkSS24MIiRN6VDlE0rZJnugd2ijpmYKXwVMHFHWIbBLqES3ssO3VePF67Y4Agt7JRqDlF2C9ttQXXbu23fvccpDIzt6tPtPDJzNo3M1JexxRNMuyb0moNeHISGTTFCL8LSuVn8MvpqXLqBqR5Q0nchgym+f6nWQMknpLNA0531W/2ZOMa2h5vtWDoVPisGmOzlV41dpDOWG4wr120Yn6Q8thTh2tQbS0/UjThPnjrUjs9nJxg5X0MPkzEuoXo3KWEh user2@myothermachine",
36+ "id": 6,
37+ "keysource": "lp:user2",
38+ "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/6/"
39+ }
40+ ],
41+ "ssh-keys-get": {
42+ "key": "ssh-rsa AAAAB7NzaC1yc2EAAAADAQABAAABAQDhaFwhxa50r2InCHaSSCOB+PP572+Hra6CzFexUQBABJDHfcbbvFeAkjWIUIH9bAVolkHulDegc/6JbMy6p9E8TMqi4dQ1FV4VX/cFtbfJPlLVOrysTKuarRGnh0/1nKnYedfwpjF4HubuI55bgU/Strx/UYCr/WiFHSS7ExpnJJcuIwKeN1tZtVdVKy4j//EPt7GipBcAjpIB0hpFxBdxlm7GswDU+WZNEbSaNN6mkupVwkQdBdoaywlUl6iStzI7moAiIE37uSzi8xcovLBpHsfVKQyY1pSqC7E3L+qdu4MlioKiyYlsvaIk8BVj0QLGmGqvWZGUKcZF4OJxA15B jsseidel@linmbpro",
43+ "id": 11,
44+ "keysource": "lp:user",
45+ "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/11/"
46+ }
47+}
48diff --git a/src/maasserver/api/ssh_keys.py b/src/maasserver/api/ssh_keys.py
49index b26e157..eda9c17 100644
50--- a/src/maasserver/api/ssh_keys.py
51+++ b/src/maasserver/api/ssh_keys.py
52@@ -55,14 +55,35 @@ class SSHKeysHandler(OperationsHandler):
53 update = delete = None
54
55 def read(self, request):
56- """List all keys belonging to the requesting user."""
57+ """@description-title List SSH keys
58+ @description List all keys belonging to the requesting user.
59+
60+ @success (http-status-code) "200" 200
61+ @success (json) "success-json" A JSON object containing a list of
62+ available SSH keys.
63+ @success-example "success-json" [exkey=ssh-keys-list] placeholder text
64+ """
65 return SSHKey.objects.filter(user=request.user)
66
67 def create(self, request):
68- """Add a new SSH key to the requesting or supplied user's account.
69+ """@description-title Add a new SSH key
70+ @description Add a new SSH key to the requesting or supplied user's
71+ account.
72+
73+ @param (string) "key" [required=true,formatting=true] A public SSH key
74+ should be provided in the request payload as form data with the name
75+ 'key':
76+
77+ key: "key-type public-key-data"
78
79- The request payload should contain the public SSH key data in form
80- data whose name is "key".
81+ - ``key-type``: ecdsa-sha2-nistp256, ecdsa-sha2-nistp384,
82+ ecdsa-sha2-nistp521, ssh-dss, ssh-ed25519, ssh-rsa
83+ - ``public key data``: Base64-encoded key data.
84+
85+ @success (http-status-code) "201" 201
86+ @success (json) "success-json" A JSON object containing the new key.
87+ @success-example "success-json" [exkey=ssh-keys-create] placeholder
88+ text
89 """
90 user = request.user
91 username = get_optional_param(request.POST, 'user')
92@@ -94,10 +115,26 @@ class SSHKeysHandler(OperationsHandler):
93
94 @operation(idempotent=False, exported_as='import')
95 def import_ssh_keys(self, request):
96- """Import the requesting user's SSH keys.
97+ """@description-title Import SSH keys
98+ @description Import the requesting user's SSH keys for a given protocol
99+ and authorization ID in protocol:auth_id format.
100+
101+ @param (string) "keysource" [required=true,formatting=true] The source
102+ of the keys to import should be provided in the request payload as form
103+ data:
104+
105+ E.g.
106
107- Import SSH keys for a given protocol and authorization ID in
108- protocol:auth_id format.
109+ source:user
110+
111+ - ``source``: lp (Launchpad), gh (GitHub)
112+ - ``user``: User login
113+
114+ @success (http-status-code) "200" 200
115+ @success (json) "success-json" A JSON object containing a list of
116+ imported keys.
117+ @success-example "success-json" [exkey=ssh-keys-import] placeholder
118+ text
119 """
120 keysource = request.data.get('keysource', None)
121 if keysource is not None:
122@@ -126,7 +163,8 @@ class SSHKeysHandler(OperationsHandler):
123
124
125 class SSHKeyHandler(OperationsHandler):
126- """Manage an SSH key.
127+ """
128+ Manage an SSH key.
129
130 SSH keys can be retrieved or deleted.
131 """
132@@ -137,18 +175,34 @@ class SSHKeyHandler(OperationsHandler):
133 create = update = None
134
135 def read(self, request, id):
136- """GET an SSH key.
137+ """@description-title Retrieve an SSH key
138+ @description Retrieves an SSH key with the given ID.
139
140- Returns 404 if the key does not exist.
141+ @param (int) "id" [required=true] An SSH key ID.
142+
143+ @error (http-status-code) "404" 404
144+ @error (content) "not-found" The requested SSH key is not found.
145+ @error-example "not-found"
146+ Not Found
147 """
148 key = get_object_or_404(SSHKey, id=id)
149 return key
150
151 def delete(self, request, id):
152- """DELETE an SSH key.
153+ """@description-title Delete an SSH key
154+ @description Deletes the SSH key with the given ID.
155+
156+ @param (int) "id" [required=true] An SSH key ID.
157+
158+ @error (http-status-code) "404" 404
159+ @error (content) "not-found" The requested SSH key is not found.
160+ @error-example "not-found"
161+ Not Found
162
163- Returns 404 if the key does not exist.
164- Returns 401 if the key does not belong to the calling user.
165+ @error (http-status-code) "403" 403
166+ @error (content) "no-perms" The requesting user does not own the key.
167+ @error-example "no-perms"
168+ Can't delete a key you don't own.
169 """
170 key = get_object_or_404(SSHKey, id=id)
171 if key.user != request.user:

Subscribers

People subscribed via source and target branches