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

Proposed by Spencer Seidel
Status: Merged
Approved by: Newell Jensen
Approved revision: 8b02097f51ef934314e9ef95cedd3c7457c81dd1
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-sslkeys-api-annotations
Merge into: maas:master
Diff against target: 159 lines (+82/-12)
3 files modified
src/maasserver/api/examples/account.json (+15/-0)
src/maasserver/api/ssh_keys.py (+8/-0)
src/maasserver/api/ssl_keys.py (+59/-12)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
MAAS Lander unittests Pending
Review via email: mp+359162@code.launchpad.net

Commit message

Added API annotations for ssl_keys and examples. Also added missing success status codes to ssh_keys.

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

Looks good.

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
2index 67ac321..9b95c6a 100644
3--- a/src/maasserver/api/examples/account.json
4+++ b/src/maasserver/api/examples/account.json
5@@ -37,5 +37,20 @@
6 "id": 11,
7 "keysource": "lp:user",
8 "resource_uri": "/MAAS/api/2.0/account/prefs/sshkeys/11/"
9+ },
10+ "ssl-keys-list": [
11+ {
12+ "key": "-----BEGIN CERTIFICATE-----\r\nMIIDYDCCAkigAwIBAgIJANv2xTlvnerlMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\r\nBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\r\naWRnaXRzIFB0eSBMdGQwHhcNMTgxMTIxMjMxNjUwWhcNMjgxMTE4MjMxNjUwWjBF\r\nMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\r\nZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\r\nCgKCAQEAqD8WoD9CWZ6gpwN7nGZfWjVMYRs2Mv+aaureSQudpE53XOGTrMBBxon2\r\nJNp6a1BwpOIl1sbTsYPDyOVhZZ4vRdHQ2pGSW8b4eKQqaB8Ae9w55gMxvUgK1e6t\r\nIe8Quhb7bs2UsaG/6vDRJetmSiX6ASjcBNG/0X6IJGsw0J5m+sgKLJwb49ZU72eZ\r\nGNwV1nJcz741AMpKU4apeafmSYQSfie+kSP9uDqekNzSDx615+HrClSdGwwya1P/\r\nE6Xb3WvgRnh30HJpZG61E6+vUfYYJtowLaj0gaWY6ohjkVHmgfIvHTVI7p7d0jZ4\r\nZvZgw2nWDSm/qV/Cl2embYWVUyctaQIDAQABo1MwUTAdBgNVHQ4EFgQUmZyWKIt8\r\nlUJUBj7f8kiOEs/Xih8wHwYDVR0jBBgwFoAUmZyWKIt8lUJUBj7f8kiOEs/Xih8w\r\nDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAje7KLWW/tf2tx2/g\r\nXmkltSQLfhL+mTVCUm3LaxDrDR5Iw0igngBekxACyqy20OyVl26bybYxAAGIZC+s\r\nax24ARKizUhd/FTFya7Xc4bEvWOcytcODUOBCuAmbRn/saeGVC+b81OjF+ndkXso\r\nweQ7YADaZQQD8ZkaPCzz8jQBe4AL48lA7TovHDDk68XDgYkcyArvGsQpo1527NYZ\r\nngMT9th7eWeHD+AAo9LGE9D4+6FoPo0Wloq9pCarM7q53Vp7pEOwar8Z3N9+Wms3\r\nrw4e59fnqslCXdztMO7Y4VTsyRUR6c9tEou560i48PXIYuGHf17ioouGg50XPT5Z\r\nFnCh/w==\r\n-----END CERTIFICATE-----",
13+ "id": 1,
14+ "resource_uri": "/MAAS/api/2.0/account/prefs/sslkeys/1/"
15+ }
16+ ],
17+ "ssl-keys-create": {
18+ "key": "-----BEGIN CERTIFICATE-----\r\nMIIDYDCCAkigAwIBAgIJANv2xTlvnerlMA0GCSqGSI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je7KLWW/tf2tx2/g\r\nXmkltSQLfhL+mTVCUm3LaxDrDR5Iw0igngBekxACyqy20OyVl26bybYxAAGIZC+s\r\nax24ARKizUhd/FTFya7Xc4bEvWOcytcODUOBCuAmbRn/saeGVC+b81OjF+ndkXso\r\nweQ7YADaZQQD8ZkaPCzz8jQBe4AL48lA7TovHDDk68XDgYkcyArvGsQpo1527NYZ\r\nngMT9th7eWeHD+AAo9LGE9D4+6FoPo0Wloq9pCarM7q53Vp7pEOwar8Z3N9+Wms3\r\nrw4e59fnqslCXdztMO7Y4VTsyRUR6c9tEou560i48PXIYuGHf18ioouGg50XPT5Z\r\nFnCh/w==\r\n-----END CERTIFICATE-----",
23+ "id": 2
24 }
25 }
26diff --git a/src/maasserver/api/ssh_keys.py b/src/maasserver/api/ssh_keys.py
27index eda9c17..58d29be 100644
28--- a/src/maasserver/api/ssh_keys.py
29+++ b/src/maasserver/api/ssh_keys.py
30@@ -180,6 +180,12 @@ class SSHKeyHandler(OperationsHandler):
31
32 @param (int) "id" [required=true] An SSH key ID.
33
34+ @success (http-status-code) "200" 200
35+ @success (json) "success-json" A JSON object containing a list of
36+ imported keys.
37+ @success-example "success-json" [exkey=ssh-keys-get] placeholder
38+ text
39+
40 @error (http-status-code) "404" 404
41 @error (content) "not-found" The requested SSH key is not found.
42 @error-example "not-found"
43@@ -194,6 +200,8 @@ class SSHKeyHandler(OperationsHandler):
44
45 @param (int) "id" [required=true] An SSH key ID.
46
47+ @success (http-status-code) "204" 204
48+
49 @error (http-status-code) "404" 404
50 @error (content) "not-found" The requested SSH key is not found.
51 @error-example "not-found"
52diff --git a/src/maasserver/api/ssl_keys.py b/src/maasserver/api/ssl_keys.py
53index 10dcf33..1e5d0a0 100644
54--- a/src/maasserver/api/ssl_keys.py
55+++ b/src/maasserver/api/ssl_keys.py
56@@ -38,14 +38,32 @@ class SSLKeysHandler(OperationsHandler):
57 update = delete = None
58
59 def read(self, request):
60- """List all keys belonging to the requesting user."""
61+ """@description-title List keys
62+ @description List all keys belonging to the requesting user.
63+
64+ @success (http-status-code) "200" 200
65+ @success (json) "success-json" A JSON object containing a list of SSL
66+ keys.
67+ @success-example "success-json" [exkey=ssl-keys-list] placeholder text
68+ """
69 return SSLKey.objects.filter(user=request.user).order_by('id')
70
71 def create(self, request):
72- """Add a new SSL key to the requesting user's account.
73+ """@description-title Add a new SSL key
74+ @description Add a new SSL key to the requesting user's account.
75+
76+ @param (string) "key" [required=true,formatting=true] An SSL key
77+ should be provided in the request payload as form data with the name
78+ 'key':
79+
80+ key: "key data"
81+
82+ - ``key data``: The contents of a pem file.
83
84- The request payload should contain the SSL key data in form
85- data whose name is "key".
86+ @success (http-status-code) "201" 201
87+ @success (json) "success-json" A JSON object containing the new key.
88+ @success-example "success-json" [exkey=ssl-keys-create] placeholder
89+ text
90 """
91 form = SSLKeyForm(user=request.user, data=request.data)
92 if form.is_valid():
93@@ -65,7 +83,8 @@ class SSLKeysHandler(OperationsHandler):
94
95
96 class SSLKeyHandler(OperationsHandler):
97- """Manage an SSL key.
98+ """
99+ Manage an SSL key.
100
101 SSL keys can be retrieved or deleted.
102 """
103@@ -76,10 +95,26 @@ class SSLKeyHandler(OperationsHandler):
104 create = update = None
105
106 def read(self, request, id):
107- """GET an SSL key.
108-
109- Returns 404 if the key with `id` is not found.
110- Returns 401 if the key does not belong to the requesting user.
111+ """@description-title Retrieve an SSL key
112+ @description Retrieves an SSL key with the given ID.
113+
114+ @param (int) "id" [required=true] An SSL key ID.
115+
116+ @success (http-status-code) "200" 200
117+ @success (json) "success-json" A JSON object containing a list of
118+ imported keys.
119+ @success-example "success-json" [exkey=ssl-keys-get] placeholder
120+ text
121+
122+ @error (http-status-code) "404" 404
123+ @error (content) "not-found" The requested SSH key is not found.
124+ @error-example "not-found"
125+ Not Found
126+
127+ @error (http-status-code) "403" 403
128+ @error (content) "no-perms" The requesting user does not own the key.
129+ @error-example "no-perms"
130+ Can't get a key you don't own.
131 """
132 key = get_object_or_404(SSLKey, id=id)
133 if key.user != request.user:
134@@ -88,10 +123,22 @@ class SSLKeyHandler(OperationsHandler):
135 return key
136
137 def delete(self, request, id):
138- """DELETE an SSL key.
139+ """@description-title Delete an SSL key
140+ @description Deletes the SSL key with the given ID.
141+
142+ @param (int) "id" [required=true] An SSH key ID.
143+
144+ @success (http-status-code) "204" 204
145+
146+ @error (http-status-code) "404" 404
147+ @error (content) "not-found" The requested SSH key is not found.
148+ @error-example "not-found"
149+ Not Found
150
151- Returns 401 if the key does not belong to the requesting user.
152- Returns 204 if the key is successfully deleted.
153+ @error (http-status-code) "403" 403
154+ @error (content) "no-perms" The requesting user does not own the key.
155+ @error-example "no-perms"
156+ Can't delete a key you don't own.
157 """
158 key = get_object_or_404(SSLKey, id=id)
159 if key.user != request.user:

Subscribers

People subscribed via source and target branches