8000 docs: API users by mtojek · Pull Request #5620 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

docs: API users #5620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a3fbe72
docs: audit, deploymentconfig, files, parameters
mtojek Dec 22, 2022
fbe1d70
Swagger comments in workspacebuilds.go
mtojek Jan 2, 2023
96daf47
structs in workspacebuilds.go
mtojek Jan 2, 2023
663ec87
workspaceagents: instance identity
mtojek Jan 2, 2023
fc00d7e
workspaceagents.go in progress
mtojek Jan 2, 2023
67a85b9
workspaceagents.go in progress
mtojek Jan 2, 2023
ce8c7ea
Agents
mtojek Jan 2, 2023
d2a9af5
workspacebuilds.go
mtojek Jan 2, 2023
f37c6b3
/workspaces
mtojek Jan 3, 2023
250982a
templates.go, templateversions.go
mtojek Jan 3, 2023
ff622a7
templateversion.go in progress
mtojek Jan 3, 2023
9dd385c
cancel
mtojek Jan 3, 2023
f96351a
templateversions
mtojek Jan 3, 2023
15de3b6
wip
mtojek Jan 3, 2023
596cdbd
Merge branch 'main' into 3522-workspacebuilds-1
mtojek Jan 3, 2023
eb4ba48
Merge
mtojek Jan 3, 2023
e314c24
x-apidocgen
mtojek Jan 4, 2023
97cd7ac
NullTime hack not needed anymore
mtojek Jan 4, 2023
ae06598
Fix: x-apidocgen
mtojek Jan 4, 2023
c82eb01
Merge branch '3522-workspacebuilds-1' into 3522-templates-1
mtojek Jan 4, 2023
77815d3
Merge branch '3522-templates-1' into 3522-organizations-1
mtojek Jan 4, 2023
7aa0f65
Members
mtojek Jan 4, 2023
b93398e
Fixes
mtojek Jan 4, 2023
5c96bd5
Fix
mtojek Jan 4, 2023
4667f07
WIP
mtojek Jan 5, 2023
0cd9c4a
Merge branch 'main' into 3522-templates-1
mtojek Jan 5, 2023
5405c0c
WIP
mtojek Jan 9, 2023
801cad1
Merge branch '3522-users-1' into 3522-organizations-1
mtojek Jan 9, 2023
0dc1d2a
Users
mtojek Jan 9, 2023
9285425
Logout
mtojek Jan 9, 2023
6979a7f
User profile
mtojek Jan 9, 2023
62a26f9
Status suspend activate
mtojek Jan 9, 2023
b1f389b
User roles
mtojek Jan 9, 2023
14a1654
User tokens
mtojek Jan 9, 2023
5c22629
Keys
mtojek Jan 9, 2023
91c78f4
SSH key
mtojek Jan 9, 2023
c06a636
All
mtojek Jan 9, 2023
ee6dbb1
Typo
mtojek Jan 9, 2023
8f22f8d
Fix
mtojek Jan 9, 2023
03ba246
Merge branch 'main' into 3522-organizations-1
mtojek Jan 11, 2023
1f12415
Fix
mtojek Jan 11, 2023
8773c10
Fix: LoginWithPasswordRequest
mtojek Jan 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs: audit, deploymentconfig, files, parameters
  • Loading branch information
mtojek committed Dec 22, 2022
commit a3fbe72717ee213e0cabf36cebbefd3a8130a82e
1,491 changes: 1,329 additions & 162 deletions coderd/apidoc/docs.go

Large diffs are not rendered by default.

1,119 changes: 1,106 additions & 13 deletions coderd/apidoc/swagger.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions coderd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ import (
"github.com/coder/coder/codersdk"
)

// @Summary Get audit logs
// @ID get-audit-logs
// @Security CoderSessionToken
// @Produce json
// @Tags Audit
// @Param q query string true "Search query"
// @Param after_id query string false "After ID" format(uuid)
// @Param limit query int false "Page limit"
// @Param offset query int false "Page offset"
// @Success 200 {object} codersdk.AuditLogResponse
// @Router /audit [get]
func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceAuditLog) {
Expand Down Expand Up @@ -77,6 +88,14 @@ func (api *API) auditLogs(rw http.ResponseWriter, r *http.Request) {
})
}

// @Summary Generate fake audit log
// @ID generate-fake-audit-logs
// @Security CoderSessionToken
// @Accept json
// @Tags Audit
// @Param request body codersdk.CreateTestAuditLogRequest true "Audit log request"
// @Success 204
// @Router /audit/testgenerate [post]
func (api *API) generateFakeAuditLog(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if !api.Authorize(r, rbac.ActionCreate, rbac.ResourceAuditLog) {
Expand Down
7 changes: 7 additions & 0 deletions coderd/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
"github.com/coder/coder/coderd/rbac"
)

// @Summary Get deployment config
// @ID get-deployment-config
// @Security CoderSessionToken
// @Produce json
// @Tags General
// @Success 200 {object} codersdk.DeploymentConfig
// @Router /config/deployment [get]
func (api *API) deploymentConfig(rw http.ResponseWriter, r *http.Request) {
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentConfig) {
httpapi.Forbidden(rw)
Expand Down
18 changes: 18 additions & 0 deletions coderd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ const (
tarMimeType = "application/x-tar"
)

// @Summary Upload file
// @Description Notice: Swagger 2.0 doesn't support file upload with a `content-type` different than `application/x-www-form-urlencoded`.
// @ID update-file
// @Security CoderSessionToken
// @Produce json
// @Accept application/x-tar
// @Tags Files
// @Param Content-Type header string true "Content-Type must be `application/x-tar`" default(application/x-tar)
// @Param file formData file true "File to be uploaded"
// @Success 201 {object} codersdk.UploadResponse
// @Router /files [post]
func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
apiKey := httpmw.APIKey(r)
Expand Down Expand Up @@ -88,6 +99,13 @@ func (api *API) postFile(rw http.ResponseWriter, r *http.Request) {
})
}

// @Summary Get file by ID
// @ID get-file-by-id
// @Security CoderSessionToken
// @Tags Files
// @Param fileID path string true "File ID" format(uuid)
// @Success 200
// @Router /files/{fileID} [get]
func (api *API) fileByID(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down
30 changes: 30 additions & 0 deletions coderd/parameters.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ import (
"github.com/coder/coder/codersdk"
)

// @Summary Create parameter
// @ID create-parameter
// @Security CoderSessionToken
// @Accept json
// @Produce json
// @Tags Parameters
// @Param request body codersdk.CreateParameterRequest true "Parameter request"
// @Param scope path string true "Scope" Enums(template,workspace,import_job)
// @Param id path string true "ID" format(uuid)
// @Success 201 {object} codersdk.Parameter
// @Router /parameters/{scope}/{id} [post]
func (api *API) postParameter(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
scope, scopeID, valid := readScopeAndID(ctx, rw, r)
Expand Down Expand Up @@ -78,6 +89,15 @@ func (api *API) postParameter(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(ctx, rw, http.StatusCreated, convertParameterValue(parameterValue))
}

// @Summary Get parameters
// @ID get-parameters
// @Security CoderSessionToken
// @Produce json
// @Tags Parameters
// @Param scope path string true "Scope" Enums(template,workspace,import_job)
// @Param id path string true "ID" format(uuid)
// @Success 200 {array} codersdk.Parameter
// @Router /parameters/{scope}/{id} [get]
func (api *API) parameters(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
scope, scopeID, valid := readScopeAndID(ctx, rw, r)
Expand Down Expand Up @@ -116,6 +136,16 @@ func (api *API) parameters(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(ctx, rw, http.StatusOK, apiParameterValues)
}

// @Summary Delete parameter
// @ID delete-parameter
// @Security CoderSessionToken
// @Produce json
// @Tags Parameters
// @Param scope path string true "Scope" Enums(template,workspace,import_job)
// @Param id path string true "ID" format(uuid)
// @Param name path string true "Name"
// @Success 200 {object} codersdk.Response
// @Router /parameters/{scope}/{id}/{name} [delete]
func (api *API) deleteParameter(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
scope, scopeID, valid := readScopeAndID(ctx, rw, r)
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (api *API) templateByOrganizationAndName(rw http.ResponseWriter, r *http.Re
// @Tags Templates
// @Param id path string true "Template ID" format(uuid)
// @Success 200 {object} codersdk.Template
// @Router /templates/{id} [get]
// @Router /templates/{id} [patch]
func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
Expand Down
4 changes: 2 additions & 2 deletions codersdk/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ type AuditLogResponse struct {
}

type CreateTestAuditLogRequest struct {
Action AuditAction `json:"action,omitempty"`
ResourceType ResourceType `json:"resource_type,omitempty"`
Action AuditAction `json:"action,omitempty" enums:"create,write,delete,start,stop"`
ResourceType ResourceType `json:"resource_type,omitempty" enums:"organization,template,template_version,user,workspace,workspace_build,git_ssh_key,api_key,group"`
ResourceID uuid.UUID `json:"resource_id,omitempty"`
Time time.Time `json:"time,omitempty"`
}
Expand Down
16 changes: 9 additions & 7 deletions codersdk/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ type ComputedParameter struct {
}

// Parameter represents a set value for the scope.
//
// @Description Parameter represents a set value for the scope.
type Parameter struct {
ID uuid.UUID `json:"id" table:"id"`
Scope ParameterScope `json:"scope" table:"scope"`
ScopeID uuid.UUID `json:"scope_id" table:"scope id"`
ID uuid.UUID `json:"id" table:"id" format:"uuid"`
Scope ParameterScope `json:"scope" table:"scope" enums:"template,workspace,import_job"`
ScopeID uuid.UUID `json:"scope_id" table:"scope id" format:"uuid"`
Name string `json:"name" table:"name"`
SourceScheme ParameterSourceScheme `json:"source_scheme" table:"source scheme" validate:"ne=none"`
DestinationScheme ParameterDestinationScheme `json:"destination_scheme" table:"destination scheme" validate:"ne=none"`
SourceScheme ParameterSourceScheme `json:"source_scheme" table:"source scheme" validate:"ne=none" enums:"none,data"`
DestinationScheme ParameterDestinationScheme `json:"destination_scheme" table:"destination scheme" validate:"ne=none" enums:"none,environment_variable,provisioner_variable"`
CreatedAt time.Time `json:"created_at" table:"created at"`
UpdatedAt time.Time `json:"updated_at" table:"updated at"`
}
Expand Down Expand Up @@ -96,8 +98,8 @@ type CreateParameterRequest struct {

Name string `json:"name" validate:"required"`
SourceValue string `json:"source_value" validate:"required"`
SourceScheme ParameterSourceScheme `json:"source_scheme" validate:"oneof=data,required"`
DestinationScheme ParameterDestinationScheme `json:"destination_scheme" validate:"oneof=environment_variable provisioner_variable,required"`
SourceScheme ParameterSourceScheme `json:"source_scheme" validate:"oneof=data,required" enums:"none,data"`
DestinationScheme ParameterDestinationScheme `json:"destination_scheme" validate:"oneof=environment_variable provisioner_variable,required" enums:"none,environment_variable,provisioner_variable"`
}

func (c *Client) CreateParameter(ctx context.Context, scope ParameterScope, id uuid.UUID, req CreateParameterRequest) (Parameter, error) {
Expand Down
2 changes: 1 addition & 1 deletion codersdk/workspacebuilds.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type WorkspaceBuild struct {
Job ProvisionerJob `json:"job"`
Reason BuildReason `db:"reason" json:"reason"`
Resources []WorkspaceResource `json:"resources"`
Deadline NullTime `json:"deadline,omitempty"`
Deadline NullTime `json:"deadline,omitempty" swaggertype:"string" format:"date-time"`
Status WorkspaceStatus `json:"status" enums:"pending,starting,running,stopping,stopped,failed,canceling,canceled,deleting,deleted"`
DailyCost int32 `json:"daily_cost"`
}
Expand Down
129 changes: 129 additions & 0 deletions docs/api/audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Audit

> This page is incomplete, stay tuned.

## Get audit logs

### Code samples

```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/audit?q=string \
-H 'Accept: application/json' \
-H 'Coder-Session-Token: API_KEY'
```

`GET /audit`

### Parameters

| Name | In | Type | Required | Description |
| ---------- | ----- | ------------ | -------- | ------------ |
| `q` | query | string | true | Search query |
| `after_id` | query | string(uuid) | false | After ID |
| `limit` | query | integer | false | Page limit |
| `offset` | query | integer | false | Page offset |

### Example responses

> 200 Response

```json
{
"audit_logs": [
{
"action": "string",
"additional_fields": [0],
"description": "string",
"diff": {
"property1": {
"new": null,
"old": null,
"secret": true
},
"property2": {
"new": null,
"old": null,
"secret": true
}
},
"id": "string",
"ip": {},
"is_deleted": true,
"organization_id": "string",
"request_id": "string",
"resource_icon": "string",
"resource_id": "string",
"resource_link": "string",
"resource_target": "string",
"resource_type": "string",
"status_code": 0,
"time": "string",
"user": {
"avatar_url": "string",
"created_at": "string",
"email": "string",
"id": "string",
"last_seen_at": "string",
"organization_ids": ["string"],
"roles": [
{
"display_name": "string",
"name": "string"
}
],
"status": "string",
"username": "string"
},
"user_agent": "string"
}
],
"count": 0
}
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ---------------------------------------------------------------- |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | [codersdk.AuditLogResponse](schemas.md#codersdkauditlogresponse) |

To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.

## Generate fake audit log

### Code samples

```shell
# Example request using curl
curl -X POST http://coder-server:8080/api/v2/audit/testgenerate \
-H 'Content-Type: application/json' \
-H 'Coder-Session-Token: API_KEY'
```

`POST /audit/testgenerate`

> Body parameter

```json
{
"action": "create",
"resource_id": "string",
"resource_type": "organization",
"time": "string"
}
```

### Parameters

| Name | In | Type | Required | Description |
| ------ | ---- | ---------------------------------------------------------------------------------- | -------- | ----------------- |
| `body` | body | [codersdk.CreateTestAuditLogRequest](schemas.md#codersdkcreatetestauditlogrequest) | true | Audit log request |

### Responses

| Status | Meaning | Description | Schema |
| ------ | --------------------------------------------------------------- | ----------- | ------ |
| 204 | [No Content](https://tools.ietf.org/html/rfc7231#section-6.3.5) | No Content | |

To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.
77 changes: 77 additions & 0 deletions docs/api/files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Files

> This page is incomplete, stay tuned.

## Upload file

### Code samples

```shell
# Example request using curl
curl -X POST http://coder-server:8080/api/v2/files \
-H 'Accept: application/json' \
-H 'Content-Type: application/x-tar' \
-H 'Coder-Session-Token: API_KEY'
```

`POST /files`

Notice: Swagger 2.0 doesn't support file upload with a `content-type` different than `application/x-www-form-urlencoded`.

> Body parameter

```yaml
file: string
```

### Parameters

| Name | In | Type | Required | Description |
| -------------- | ------ | -------------- | -------- | ---------------------------------------- |
| `Content-Type` | header | string | true | Content-Type must be `application/x-tar` |
| `body` | body | object | true | |
| `» file` | body | string(binary) | true | File to be uploaded |

### Example responses

> 201 Response

```json
{
"hash": "string"
}
```

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------------ | ----------- | ------------------------------------------------------------ |
| 201 | [Created](https://tools.ietf.org/html/rfc7231#section-6.3.2) | Created | [codersdk.UploadResponse](schemas.md#codersdkuploadresponse) |

To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.

## Get file by ID

### Code samples

```shell
# Example request using curl
curl -X GET http://coder-server:8080/api/v2/files/{fileID} \
-H 'Coder-Session-Token: API_KEY'
```

`GET /files/{fileID}`

### Parameters

| Name | In | Type | Required | Description |
| -------- | ---- | ------------ | -------- | ----------- |
| `fileID` | path | string(uuid) | true | File ID |

### Responses

| Status | Meaning | Description | Schema |
| ------ | ------------------------------------------------------- | ----------- | ------ |
| 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | OK | |

To perform this operation, you must be authenticated by means of one of the following methods: **CoderSessionToken**.
Loading
0