Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Add check selection api to the server #357

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
95 changes: 95 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,87 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/checks/{id}/selected": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get selected checks from resource",
"parameters": [
{
"type": "string",
"description": "Resource id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
},
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Create check selection for the resource",
"parameters": [
{
"type": "string",
"description": "Resource id",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Selected checks",
"name": "Body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/api/clusters/{cluster_id}/results": {
"get": {
"produces": [
Expand Down Expand Up @@ -491,6 +572,20 @@ var doc = `{
}
},
"definitions": {
"web.JSONSelectedChecks": {
"type": "object",
"required": [
"selected_checks"
],
"properties": {
"selected_checks": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"web.JSONTag": {
"type": "object",
"required": [
Expand Down
95 changes: 95 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,87 @@
"contact": {}
},
"paths": {
"/api/checks/{id}/selected": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Get selected checks from resource",
"parameters": [
{
"type": "string",
"description": "Resource id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
},
"404": {
"description": "Not Found",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
},
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Create check selection for the resource",
"parameters": [
{
"type": "string",
"description": "Resource id",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Selected checks",
"name": "Body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/web.JSONSelectedChecks"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
},
"/api/clusters/{cluster_id}/results": {
"get": {
"produces": [
Expand Down Expand Up @@ -471,6 +552,20 @@
}
},
"definitions": {
"web.JSONSelectedChecks": {
"type": "object",
"required": [
"selected_checks"
],
"properties": {
"selected_checks": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"web.JSONTag": {
"type": "object",
"required": [
Expand Down
62 changes: 62 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
definitions:
web.JSONSelectedChecks:
properties:
selected_checks:
items:
type: string
type: array
required:
- selected_checks
type: object
web.JSONTag:
properties:
tag:
Expand All @@ -9,6 +18,59 @@ definitions:
info:
contact: {}
paths:
/api/checks/{id}/selected:
get:
consumes:
- application/json
parameters:
- description: Resource id
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/web.JSONSelectedChecks'
"404":
description: Not Found
schema:
additionalProperties:
type: string
type: object
summary: Get selected checks from resource
post:
consumes:
- application/json
parameters:
- description: Resource id
in: path
name: id
required: true
type: string
- description: Selected checks
in: body
name: Body
required: true
schema:
$ref: '#/definitions/web.JSONSelectedChecks'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/web.JSONSelectedChecks'
"500":
description: Internal Server Error
schema:
additionalProperties:
type: string
type: object
summary: Create check selection for the resource
/api/clusters/{cluster_id}/results:
get:
parameters:
Expand Down
60 changes: 60 additions & 0 deletions web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type JSONTag struct {
Tag string `json:"tag" binding:"required"`
}

type JSONSelectedChecks struct {
SelectedChecks []string `json:"selected_checks" binding:"required"`
}

// ApiListTag godoc
// @Summary List all the tags in the system
// @Accept json
Expand Down Expand Up @@ -379,3 +383,59 @@ func ApiClusterCheckResultsHandler(client consul.Client, s services.ChecksServic
c.JSON(http.StatusOK, checkResults)
}
}

// ApiListTag godoc
// @Summary Get selected checks from resource
// @Accept json
// @Produce json
// @Param id path string true "Resource id"
// @Success 200 {object} JSONSelectedChecks
// @Failure 404 {object} map[string]string
// @Router /api/checks/{id}/selected [get]
func ApiCheckGetSelectedHandler(s services.ChecksService) gin.HandlerFunc {
return func(c *gin.Context) {
id := c.Param("id")

selectedChecks, err := s.GetSelectedChecksById(id)
if err != nil {
_ = c.Error(NotFoundError("could not find check selection"))
return
}

var jsonSelectedChecks JSONSelectedChecks
jsonSelectedChecks.SelectedChecks = selectedChecks.SelectedChecks

c.JSON(http.StatusOK, jsonSelectedChecks)
}
}

// ApiCheckCreateSelectedHandler godoc
// @Summary Create check selection for the resource
// @Accept json
// @Produce json
// @Param id path string true "Resource id"
// @Param Body body JSONSelectedChecks true "Selected checks"
// @Success 201 {object} JSONSelectedChecks
// @Failure 500 {object} map[string]string
// @Router /api/checks/{id}/selected [post]
func ApiCheckCreateSelectedHandler(s services.ChecksService) gin.HandlerFunc {
return func(c *gin.Context) {
id := c.Param("id")

var r JSONSelectedChecks

err := c.BindJSON(&r)
if err != nil {
_ = c.Error(BadRequestError("unable to parse JSON body"))
return
}

err = s.CreateSelectedChecks(id, r.SelectedChecks)
if err != nil {
_ = c.Error(err)
return
}

c.JSON(http.StatusCreated, &r)
}
}
Loading