Skip to content

Commit 5c22629

Browse files
committed
Keys
1 parent 14a1654 commit 5c22629

File tree

4 files changed

+241
-0
lines changed

4 files changed

+241
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,85 @@ const docTemplate = `{
23042304
}
23052305
}
23062306
},
2307+
"/users/{user}/keys/{keyid}": {
2308+
"get": {
2309+
"security": [
2310+
{
2311+
"CoderSessionToken": []
2312+
}
2313+
],
2314+
"produces": [
2315+
"application/json"
2316+
],
2317+
"tags": [
2318+
"Users"
2319+
],
2320+
"summary": "Get API key",
2321+
"operationId": "get-user-tokens",
2322+
"parameters": [
2323+
{
2324+
"type": "string",
2325+
"description": "User ID, name, or me",
2326+
"name": "user",
2327+
"in": "path",
2328+
"required": true
2329+
},
2330+
{
2331+
"type": "string",
2332+
"format": "uuid",
2333+
"description": "Key ID",
2334+
"name": "keyid",
2335+
"in": "path",
2336+
"required": true
2337+
}
2338+
],
2339+
"responses": {
2340+
"200": {
2341+
"description": "OK",
2342+
"schema": {
2343+
"$ref": "#/definitions/codersdk.APIKey"
2344+
}
2345+
}
2346+
}
2347+
},
2348+
"delete": {
2349+
"security": [
2350+
{
2351+
"CoderSessionToken": []
2352+
}
2353+
],
2354+
"produces": [
2355+
"application/json"
2356+
],
2357+
"tags": [
2358+
"Users"
2359+
],
2360+
"summary": "Delete API key",
2361+
"operationId": "delete-user-tokens",
2362+
"parameters": [
2363+
{
2364+
"type": "string",
2365+
"description": "User ID, name, or me",
2366+
"name": "user",
2367+
"in": "path",
2368+
"required": true
2369+
},
2370+
{
2371+
"type": "string",
2372+
"format": "uuid",
2373+
"description": "Key ID",
2374+
"name": "keyid",
2375+
"in": "path",
2376+
"required": true
2377+
}
2378+
],
2379+
"responses": {
2380+
"204": {
2381+
"description": "No Content"
2382+
}
2383+
}
2384+
}
2385+
},
23072386
"/users/{user}/password": {
23082387
"put": {
23092388
"security": [

coderd/apidoc/swagger.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,77 @@
20242024
}
20252025
}
20262026
},
2027+
"/users/{user}/keys/{keyid}": {
2028+
"get": {
2029+
"security": [
2030+
{
2031+
"CoderSessionToken": []
2032+
}
2033+
],
2034+
"produces": ["application/json"],
2035+
"tags": ["Users"],
2036+
"summary": "Get API key",
2037+
"operationId": "get-user-tokens",
2038+
"parameters": [
2039+
{
2040+
"type": "string",
2041+
"description": "User ID, name, or me",
2042+
"name": "user",
2043+
"in": "path",
2044+
"required": true
2045+
},
2046+
{
2047+
"type": "string",
2048+
"format": "uuid",
2049+
"description": "Key ID",
2050+
"name": "keyid",
2051+
"in": "path",
2052+
"required": true
2053+
}
2054+
],
2055+
"responses": {
2056+
"200": {
2057+
"description": "OK",
2058+
"schema": {
2059+
"$ref": "#/definitions/codersdk.APIKey"
2060+
}
2061+
}
2062+
}
2063+
},
2064+
"delete": {
2065+
"security": [
2066+
{
2067+
"CoderSessionToken": []
2068+
}
2069+
],
2070+
"produces": ["application/json"],
2071+
"tags": ["Users"],
2072+
"summary": "Delete API key",
2073+
"operationId": "delete-user-tokens",
2074+
"parameters": [
2075+
{
2076+
"type": "string",
2077+
"description": "User ID, name, or me",
2078+
"name": "user",
2079+
"in": "path",
2080+
"required": true
2081+
},
2082+
{
2083+
"type": "string",
2084+
"format": "uuid",
2085+
"description": "Key ID",
2086+
"name": "keyid",
2087+
"in": "path",
2088+
"required": true
2089+
}
2090+
],
2091+
"responses": {
2092+
"204": {
2093+
"description": "No Content"
2094+
}
2095+
}
2096+
}
2097+
},
20272098
"/users/{user}/password": {
20282099
"put": {
20292100
"security": [

coderd/apikey.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) {
131131
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.GenerateAPIKeyResponse{Key: cookie.Value})
132132
}
133133

134+
// @Summary Get API key
135+
// @ID get-user-tokens
136+
// @Security CoderSessionToken
137+
// @Produce json
138+
// @Tags Users
139+
// @Param user path string true "User ID, name, or me"
140+
// @Param keyid path string true "Key ID" format(uuid)
141+
// @Success 200 {object} codersdk.APIKey
142+
// @Router /users/{user}/keys/{keyid} [get]
134143
func (api *API) apiKey(rw http.ResponseWriter, r *http.Request) {
135144
var (
136145
ctx = r.Context()
@@ -199,6 +208,15 @@ func (api *API) tokens(rw http.ResponseWriter, r *http.Request) {
199208
httpapi.Write(ctx, rw, http.StatusOK, apiKeys)
200209
}
201210

211+
// @Summary Delete API key
212+
// @ID delete-user-tokens
213+
// @Security CoderSessionToken
214+
// @Produce json
215+
// @Tags Users
216+
// @Param user path string true "User ID, name, or me"
217+
// @Param keyid path string true "Key ID" format(uuid)
218+
// @Success 204
219+
// @Router /users/{user}/keys/{keyid} [delete]
202220
func (api *API) deleteAPIKey(rw http.ResponseWriter, r *http.Request) {
203221
var (
204222
ctx = r.Context()

docs/api/users.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,79 @@ curl -X POST http://coder-server:8080/api/v2/users/{user}/keys/tokens \
581581

582582
To perform this operation, you must be authenticated. [Learn more](authentication.md).
583583

584+
## Get API key
585+
586+
### Code samples
587+
588+
```shell
589+
# Example request using curl
590+
curl -X GET http://coder-server:8080/api/v2/users/{user}/keys/{keyid} \
591+
-H 'Accept: application/json' \
592+
-H 'Coder-Session-Token: API_KEY'
593+
```
594+
595+
`GET /users/{user}/keys/{keyid}`
596+
597+
### Parameters
598+
599+
| Name | In | Type | Required | Description |
600+
| ------- | ---- | ------------ | -------- | -------------------- |
601+
| `user` | path | string | true | User ID, name, or me |
602+
| `keyid` | path | string(uuid) | true | Key ID |
603+
604+
### Example responses
605+
606+
> 200 Response
607+
608+
```json
609+
{
610+
"created_at": "2019-08-24T14:15:22Z",
611+
"expires_at": "2019-08-24T14:15:22Z",
612+
"id": "string",
613+
"last_used": "2019-08-24T14:15:22Z",
614+
"lifetime_seconds": 0,
615+
"login_type": "password",
616+
"scope": "all",
617+
"updated_at": "2019-08-24T14:15:22Z",
618+
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
619+
}
620+
```
621+
622+
### Responses
623+
624+
| Status | Meaning | Description | Schema |
625+
| ------ | ------------------------------------------------------- | ----------- | -------------------------------------------- |
626+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.APIKey](schemas.md#codersdkapikey) |
627+
628+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
629+
630+
## Delete API key
631+
632+
### Code samples
633+
634+
```shell
635+
# Example request using curl
636+
curl -X DELETE http://coder-server:8080/api/v2/users/{user}/keys/{keyid} \
637+
-H 'Coder-Session-Token: API_KEY'
638+
```
639+
640+
`DELETE /users/{user}/keys/{keyid}`
641+
642+
### Parameters
643+
644+
| Name | In | Type | Required | Description |
645+
| ------- | ---- | ------------ | -------- | -------------------- |
646+
| `user` | path | string | true | User ID, name, or me |
647+
| `keyid` | path | string(uuid) | true | Key ID |
648+
649+
### Responses
650+
651+
| Status | Meaning | Description | Schema |
652+
| ------ | --------------------------------------------------------------- | ----------- | ------ |
653+
| 204 | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | No Content | |
654+
655+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
656+
584657
## Update user password
585658

586659
### Code samples

0 commit comments

Comments
 (0)