Skip to content

Commit 91c78f4

Browse files
committed
SSH key
1 parent 5c22629 commit 91c78f4

File tree

6 files changed

+283
-3
lines changed

6 files changed

+283
-3
lines changed

coderd/apidoc/docs.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,72 @@ const docTemplate = `{
21922192
}
21932193
}
21942194
},
2195+
"/users/{user}/gitsshkey": {
2196+
"get": {
2197+
"security": [
2198+
{
2199+
"CoderSessionToken": []
2200+
}
2201+
],
2202+
"produces": [
2203+
"application/json"
2204+
],
2205+
"tags": [
2206+
"Users"
2207+
],
2208+
"summary": "Get user Git SSH key",
2209+
"operationId": "get-user-git-ssh-key",
2210+
"parameters": [
2211+
{
2212+
"type": "string",
2213+
"description": "User ID, name, or me",
2214+
"name": "user",
2215+
"in": "path",
2216+
"required": true
2217+
}
2218+
],
2219+
"responses": {
2220+
"200": {
2221+
"description": "OK",
2222+
"schema": {
2223+
"$ref": "#/definitions/codersdk.GitSSHKey"
2224+
}
2225+
}
2226+
}
2227+
},
2228+
"put": {
2229+
"security": [
2230+
{
2231+
"CoderSessionToken": []
2232+
}
2233+
],
2234+
"produces": [
2235+
"application/json"
2236+
],
2237+
"tags": [
2238+
"Users"
2239+
],
2240+
"summary": "Regenerate user SSH key",
2241+
"operationId": "regenerate-user-ssh-key",
2242+
"parameters": [
2243+
{
2244+
"type": "string",
2245+
"description": "User ID, name, or me",
2246+
"name": "user",
2247+
"in": "path",
2248+
"required": true
2249+
}
2250+
],
2251+
"responses": {
2252+
"200": {
2253+
"description": "OK",
2254+
"schema": {
2255+
"$ref": "#/definitions/codersdk.GitSSHKey"
2256+
}
2257+
}
2258+
}
2259+
}
2260+
},
21952261
"/users/{user}/keys": {
21962262
"post": {
21972263
"security": [
@@ -4661,6 +4727,26 @@ const docTemplate = `{
46614727
}
46624728
}
46634729
},
4730+
"codersdk.GitSSHKey": {
4731+
"type": "object",
4732+
"properties": {
4733+
"created_at": {
4734+
"type": "string",
4735+
"format": "date-time"
4736+
},
4737+
"public_key": {
4738+
"type": "string"
4739+
},
4740+
"updated_at": {
4741+
"type": "string",
4742+
"format": "date-time"
4743+
},
4744+
"user_id": {
4745+
"type": "string",
4746+
"format": "uuid"
4747+
}
4748+
}
4749+
},
46644750
"codersdk.GoogleInstanceIdentityToken": {
46654751
"type": "object",
46664752
"required": [

coderd/apidoc/swagger.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,64 @@
19241924
}
19251925
}
19261926
},
1927+
"/users/{user}/gitsshkey": {
1928+
"get": {
1929+
"security": [
1930+
{
1931+
"CoderSessionToken": []
1932+
}
1933+
],
1934+
"produces": ["application/json"],
1935+
"tags": ["Users"],
1936+
"summary": "Get user Git SSH key",
1937+
"operationId": "get-user-git-ssh-key",
1938+
"parameters": [
1939+
{
1940+
"type": "string",
1941+
"description": "User ID, name, or me",
1942+
"name": "user",
1943+
"in": "path",
1944+
"required": true
1945+
}
1946+
],
1947+
"responses": {
1948+
"200": {
1949+
"description": "OK",
1950+
"schema": {
1951+
"$ref": "#/definitions/codersdk.GitSSHKey"
1952+
}
1953+
}
1954+
}
1955+
},
1956+
"put": {
1957+
"security": [
1958+
{
1959+
"CoderSessionToken": []
1960+
}
1961+
],
1962+
"produces": ["application/json"],
1963+
"tags": ["Users"],
1964+
"summary": "Regenerate user SSH key",
1965+
"operationId": "regenerate-user-ssh-key",
1966+
"parameters": [
1967+
{
1968+
"type": "string",
1969+
"description": "User ID, name, or me",
1970+
"name": "user",
1971+
"in": "path",
1972+
"required": true
1973+
}
1974+
],
1975+
"responses": {
1976+
"200": {
1977+
"description": "OK",
1978+
"schema": {
1979+
"$ref": "#/definitions/codersdk.GitSSHKey"
1980+
}
1981+
}
1982+
}
1983+
}
1984+
},
19271985
"/users/{user}/keys": {
19281986
"post": {
19291987
"security": [
@@ -4172,6 +4230,26 @@
41724230
}
41734231
}
41744232
},
4233+
"codersdk.GitSSHKey": {
4234+
"type": "object",
4235+
"properties": {
4236+
"created_at": {
4237+
"type": "string",
4238+
"format": "date-time"
4239+
},
4240+
"public_key": {
4241+
"type": "string"
4242+
},
4243+
"updated_at": {
4244+
"type": "string",
4245+
"format": "date-time"
4246+
},
4247+
"user_id": {
4248+
"type": "string",
4249+
"format": "uuid"
4250+
}
4251+
}
4252+
},
41754253
"codersdk.GoogleInstanceIdentityToken": {
41764254
"type": "object",
41774255
"required": ["json_web_token"],

coderd/gitsshkey.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import (
1212
"github.com/coder/coder/codersdk"
1313
)
1414

15+
// @Summary Regenerate user SSH key
16+
// @ID regenerate-user-ssh-key
17+
// @Security CoderSessionToken
18+
// @Produce json
19+
// @Tags Users
20+
// @Param user path string true "User ID, name, or me"
21+
// @Success 200 {object} codersdk.GitSSHKey
22+
// @Router /users/{user}/gitsshkey [put]
1523
func (api *API) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
1624
var (
1725
ctx = r.Context()
@@ -73,6 +81,14 @@ func (api *API) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
7381
})
7482
}
7583

84+
// @Summary Get user Git SSH key
85+
// @ID get-user-git-ssh-key
86+
// @Security CoderSessionToken
87+
// @Produce json
88+
// @Tags Users
89+
// @Param user path string true "User ID, name, or me"
90+
// @Success 200 {object} codersdk.GitSSHKey
91+
// @Router /users/{user}/gitsshkey [get]
7692
func (api *API) gitSSHKey(rw http.ResponseWriter, r *http.Request) {
7793
ctx := r.Context()
7894
user := httpmw.UserParam(r)

codersdk/gitsshkey.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
)
1313

1414
type GitSSHKey struct {
15-
UserID uuid.UUID `json:"user_id"`
16-
CreatedAt time.Time `json:"created_at"`
17-
UpdatedAt time.Time `json:"updated_at"`
15+
UserID uuid.UUID `json:"user_id" format:"uuid"`
16+
CreatedAt time.Time `json:"created_at" format:"date-time"`
17+
UpdatedAt time.Time `json:"updated_at" format:"date-time"`
1818
PublicKey string `json:"public_key"`
1919
}
2020

docs/api/schemas.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,26 @@ CreateParameterRequest is a structure used to create a new parameter value for a
21732173
| `type` | string | false | | |
21742174
| `validate_url` | string | false | | |
21752175

2176+
## codersdk.GitSSHKey
2177+
2178+
```json
2179+
{
2180+
"created_at": "2019-08-24T14:15:22Z",
2181+
"public_key": "string",
2182+
"updated_at": "2019-08-24T14:15:22Z",
2183+
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
2184+
}
2185+
```
2186+
2187+
### Properties
2188+
2189+
| Name | Type | Required | Restrictions | Description |
2190+
| ------------ | ------ | -------- | ------------ | ----------- |
2191+
| `created_at` | string | false | | |
2192+
| `public_key` | string | false | | |
2193+
| `updated_at` | string | false | | |
2194+
| `user_id` | string | false | | |
2195+
21762196
## codersdk.GoogleInstanceIdentityToken
21772197

21782198
```json

docs/api/users.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,86 @@ curl -X DELETE http://coder-server:8080/api/v2/users/{user} \
421421

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

424+
## Get user Git SSH key
425+
426+
### Code samples
427+
428+
```shell
429+
# Example request using curl
430+
curl -X GET http://coder-server:8080/api/v2/users/{user}/gitsshkey \
431+
-H 'Accept: application/json' \
432+
-H 'Coder-Session-Token: API_KEY'
433+
```
434+
435+
`GET /users/{user}/gitsshkey`
436+
437+
### Parameters
438+
439+
| Name | In | Type | Required | Description |
440+
| ------ | ---- | ------ | -------- | -------------------- |
441+
| `user` | path | string | true | User ID, name, or me |
442+
443+
### Example responses
444+
445+
> 200 Response
446+
447+
```json
448+
{
449+
"created_at": "2019-08-24T14:15:22Z",
450+
"public_key": "string",
451+
"updated_at": "2019-08-24T14:15:22Z",
452+
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
453+
}
454+
```
455+
456+
### Responses
457+
458+
| Status | Meaning | Description | Schema |
459+
| ------ | ------------------------------------------------------- | ----------- | -------------------------------------------------- |
460+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.GitSSHKey](schemas.md#codersdkgitsshkey) |
461+
462+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
463+
464+
## Regenerate user SSH key
465+
466+
### Code samples
467+
468+
```shell
469+
# Example request using curl
470+
curl -X PUT http://coder-server:8080/api/v2/users/{user}/gitsshkey \
471+
-H 'Accept: application/json' \
472+
-H 'Coder-Session-Token: API_KEY'
473+
```
474+
475+
`PUT /users/{user}/gitsshkey`
476+
477+
### Parameters
478+
479+
| Name | In | Type | Required | Description |
480+
| ------ | ---- | ------ | -------- | -------------------- |
481+
| `user` | path | string | true | User ID, name, or me |
482+
483+
### Example responses
484+
485+
> 200 Response
486+
487+
```json
488+
{
489+
"created_at": "2019-08-24T14:15:22Z",
490+
"public_key": "string",
491+
"updated_at": "2019-08-24T14:15:22Z",
492+
"user_id": "a169451c-8525-4352-b8ca-070dd449a1a5"
493+
}
494+
```
495+
496+
### Responses
497+
498+
| Status | Meaning | Description | Schema |
499+
| ------ | ------------------------------------------------------- | ----------- | -------------------------------------------------- |
500+
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.GitSSHKey](schemas.md#codersdkgitsshkey) |
501+
502+
To perform this operation, you must be authenticated. [Learn more](authentication.md).
503+
424504
## Create new session key
425505

426506
### Code samples

0 commit comments

Comments
 (0)