8000 docs: audit, deploymentconfig, files, parameters by mtojek · Pull Request #5506 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

docs: audit, deploymentconfig, files, parameters #5506

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 7 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
< 8000 tbody>
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
E85D 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
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 delet F438 e-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