Skip to content

Commit

Permalink
feat(http): add labels endpoints to telegraf config (#1824)
Browse files Browse the repository at this point in the history
  • Loading branch information
imogenkinsman authored Dec 11, 2018
1 parent c9ec2dd commit e0fc798
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 5 deletions.
1 change: 1 addition & 0 deletions http/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func NewAPIHandler(b *APIBackend) *APIHandler {
h.TelegrafHandler = NewTelegrafHandler(
b.Logger.With(zap.String("handler", "telegraf")),
b.UserResourceMappingService,
b.LabelService,
b.TelegrafService,
)

Expand Down
106 changes: 106 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,112 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Error"
'/telegrafs/{telegrafID}/labels':
get:
tags:
- Telegrafs
summary: list all labels for a telegraf config
parameters:
- in: path
name: telegrafID
schema:
type: string
required: true
description: ID of the telegraf config
responses:
'200':
description: a list of all labels for a telegraf config
content:
application/json:
schema:
type: object
properties:
labels:
type: array
items:
type: string
links:
$ref: "#/components/schemas/Links"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
tags:
- Telegrafs
summary: add a label to a telegraf config
parameters:
- in: path
name: telegrafID
schema:
type: string
required: true
description: ID of the telegraf config
requestBody:
description: label to add
required: true
content:
application/json:
schema:
type: object
properties:
label:
type: string
responses:
'200':
description: a list of all labels for a telegraf config
content:
application/json:
schema:
type: object
properties:
labels:
type: array
items:
type: string
links:
$ref: "#/components/schemas/Links"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
'/telegrafs/{telegrafID}/labels/{label}':
delete:
tags:
- Telegrafs
summary: delete a label from a telegraf config
parameters:
- in: path
name: telegrafID
schema:
type: string
required: true
description: ID of the telegraf config
- in: path
name: label
schema:
type: string
required: true
description: the label name
responses:
'204':
description: delete has been accepted
'404':
description: telegraf config not found
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
'/telegrafs/{telegrafID}/members':
get:
tags:
Expand Down
19 changes: 14 additions & 5 deletions http/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,31 @@ type TelegrafHandler struct {

TelegrafService platform.TelegrafConfigStore
UserResourceMappingService platform.UserResourceMappingService
LabelService platform.LabelService
}

const (
telegrafsPath = "/api/v2/telegrafs"
telegrafsIDPath = "/api/v2/telegrafs/:id"
telegrafsIDMembersIDPath = "/api/v2/telegrafs/:id/members/:userID"
telegrafsIDOwnersPath = "/api/v2/telegrafs/:id/owners"
telegrafsIDOwnersIDPath = "/api/v2/telegrafs/:id/owners/:userID"
telegrafsPath = "/api/v2/telegrafs"
telegrafsIDPath = "/api/v2/telegrafs/:id"
telegrafsIDMembersIDPath = "/api/v2/telegrafs/:id/members/:userID"
telegrafsIDOwnersPath = "/api/v2/telegrafs/:id/owners"
telegrafsIDOwnersIDPath = "/api/v2/telegrafs/:id/owners/:userID"
telegrafsIDLabelsPath = "/api/v2/telegrafs/:id/labels"
telegrafsIDLabelsNamePath = "/api/v2/telegrafs/:id/labels/:name"
)

// NewTelegrafHandler returns a new instance of TelegrafHandler.
func NewTelegrafHandler(
logger *zap.Logger,
mappingService platform.UserResourceMappingService,
labelService platform.LabelService,
telegrafSvc platform.TelegrafConfigStore,
) *TelegrafHandler {
h := &TelegrafHandler{
Router: httprouter.New(),

UserResourceMappingService: mappingService,
LabelService: labelService,
TelegrafService: telegrafSvc,
Logger: logger,
}
Expand All @@ -59,6 +64,10 @@ func NewTelegrafHandler(
h.HandlerFunc("GET", telegrafsIDOwnersPath, newGetMembersHandler(h.UserResourceMappingService, platform.Owner))
h.HandlerFunc("DELETE", telegrafsIDOwnersIDPath, newDeleteMemberHandler(h.UserResourceMappingService, platform.Owner))

h.HandlerFunc("GET", telegrafsIDLabelsPath, newGetLabelsHandler(h.LabelService))
h.HandlerFunc("POST", telegrafsIDLabelsPath, newPostLabelHandler(h.LabelService))
h.HandlerFunc("DELETE", telegrafsIDLabelsNamePath, newDeleteLabelHandler(h.LabelService))

return h
}

Expand Down

0 comments on commit e0fc798

Please sign in to comment.