document admin api endpoints

This commit is contained in:
gempir 2020-12-05 17:52:12 +01:00
parent a0b8de73c9
commit 8f76f05d2d
6 changed files with 371 additions and 122 deletions

View file

@ -1,8 +1,7 @@
# justlog [![Build Status](https://github.com/gempir/justlog/workflows/ci/badge.svg)](https://github.com/gempir/justlog/actions?query=workflow%3Aci)
### What is this?
justlog is a bot I maintain for a couple of channels. Its features differ from other bots in that it doesn't support
commands, etc. yet, it focuses on logging and providing an api for the logs.
Justlog is an twitch irc bot. It focuses on logging and providing an api for the logs.
### Docker
@ -39,75 +38,10 @@ docker run -p 8025:8025 --user $(id -u):$(id -g) -v $PWD/config.json:/etc/justlo
}
```
### Admin API
### Development
`POST` `/admin/channelConfigs/{channelID}`
Development requires [yarn](https://classic.yarnpkg.com/) and [go-swagger](https://goswagger.io/)
Will set the messageTypes logged for a channel
Run `go build && ./justlog` and `yarn start` in the web folder.
###### Headers
```
X-Api-Key: yourcoolapikey
```
###### Body
```
{
"messageTypes": [1]
}
```
---
`DELETE` `/admin/channelConfigs/{channelID}`
Will reset the messageTypes logged for a channel
###### Headers
```
X-Api-Key: yourcoolapikey
```
###### Body
```
{
"messageTypes": true
}
```
---
`POST` `/admin/channels`
Will add the channels to log
###### Headers
```
X-Api-Key: yourcoolapikey
```
###### Body
```
{
"channels": ["77829817"]
}
```
---
`DELETE` `/admin/channels`
Will remove the channels to log
###### Headers
```
X-Api-Key: yourcoolapikey
```
###### Body
```
{
"channels": ["77829817"]
}
```
Before committing make sure to run `make` to generate openAPI specs and bundle assets.

View file

@ -24,10 +24,53 @@ type channelConfigsDeleteRequest struct {
MessageTypes bool `json:"messageTypes,omitempty"`
}
// swagger:model
type channelConfigsRequest struct {
config.ChannelConfig
}
// swagger:route POST /admin/channelConfigs/{channelID} admin channelConfigs
//
// Will set the messageTypes logged for a channel
// https://github.com/gempir/go-twitch-irc/blob/master/message.go#L17
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// - text/plain
//
// Security:
// - api_key:
//
// Schemes: https
//
// Responses:
// 200:
// 400:
// 405:
// swagger:route DELETE /admin/channelConfigs/{channelID} admin deleteChannelConfigs
//
// Will reset the messageTypes logged for a channel
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// - text/plain
//
// Security:
// - api_key:
//
// Schemes: https
//
// Responses:
// 200:
// 400:
// 405:
func (s *Server) writeChannelConfigs(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost && r.Method != http.MethodDelete {
http.Error(w, "We'll see, we'll see. The winner gets tea.", http.StatusMethodNotAllowed)
@ -83,6 +126,49 @@ type channelConfigsJoinRequest struct {
Channels []string `json:"channels"`
}
// swagger:route POST /admin/channels admin addChannels
//
// Will add the channels to log
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// - text/plain
//
// Security:
// - api_key:
//
// Schemes: https
//
// Responses:
// 200:
// 400:
// 405:
// 500:
// swagger:route DELETE /admin/channels admin deleteChannels
//
// Will remove the channels to log
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// - text/plain
//
// Security:
// - api_key:
//
// Schemes: https
//
// Responses:
// 200:
// 400:
// 405:
// 500:
func (s *Server) writeChannels(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost && r.Method != http.MethodDelete {
http.Error(w, "We'll see, we'll see. The winner gets tea.", http.StatusMethodNotAllowed)

File diff suppressed because one or more lines are too long

View file

@ -1,3 +1,25 @@
// Package classification justlog API
//
// https://github.com/gempir/justlog
//
// Schemes: https
// BasePath: /
//
// Consumes:
// - application/json
// - application/xml
//
// Produces:
// - application/json
// - text/plain
//
// SecurityDefinitions:
// api_key:
// type: apiKey
// name: X-Api-Key
// in: header
//
// swagger:meta
package api
type LogParams struct {
@ -174,3 +196,27 @@ type ChannelUserIdLogsYearMonthParams struct {
Month string `json:"month"`
LogParams
}
// swagger:parameters channelConfigs
type ChannelConfigsParameters struct {
// in:body
Body channelConfigsRequest
}
// swagger:parameters deleteChannelConfigs
type DeleteChannelConfigsParameters struct {
// in:body
Body channelConfigsDeleteRequest
}
// swagger:parameters addChannels
type AddChannelsParameters struct {
// in:body
Body channelConfigsJoinRequest
}
// swagger:parameters deleteChannels
type DeleteChannelsParameters struct {
// in:body
Body channelsDeleteRequest
}

View file

@ -1,28 +1,3 @@
// Package classification justlog API
//
// https://github.com/gempir/justlog
//
// Schemes: https
// BasePath: /
//
// Consumes:
// - application/json
// - application/xml
//
// Produces:
// - application/json
// - text/plain
//
// Security:
// - api_key:
//
// SecurityDefinitions:
// api_key:
// type: apiKey
// name: X-Api-Key
// in: header
//
// swagger:meta
package api
import (

View file

@ -17,6 +17,156 @@
},
"basePath": "/",
"paths": {
"/admin/channelConfigs/{channelID}": {
"post": {
"security": [
{
"api_key": []
}
],
"description": "Will set the messageTypes logged for a channel\nhttps://github.com/gempir/go-twitch-irc/blob/master/message.go#L17",
"consumes": [
"application/json"
],
"produces": [
"application/json",
"text/plain"
],
"schemes": [
"https"
],
"tags": [
"admin"
],
"operationId": "channelConfigs",
"parameters": [
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/channelConfigsRequest"
}
}
],
"responses": {
"200": {},
"400": {},
"405": {}
}
},
"delete": {
"security": [
{
"api_key": []
}
],
"description": "Will reset the messageTypes logged for a channel",
"consumes": [
"application/json"
],
"produces": [
"application/json",
"text/plain"
],
"schemes": [
"https"
],
"tags": [
"admin"
],
"operationId": "deleteChannelConfigs",
"parameters": [
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/channelConfigsDeleteRequest"
}
}
],
"responses": {
"200": {},
"400": {},
"405": {}
}
}
},
"/admin/channels": {
"post": {
"security": [
{
"api_key": []
}
],
"description": "Will add the channels to log",
"consumes": [
"application/json"
],
"produces": [
"application/json",
"text/plain"
],
"schemes": [
"https"
],
"tags": [
"admin"
],
"operationId": "addChannels",
"parameters": [
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/channelConfigsJoinRequest"
}
}
],
"responses": {
"200": {},
"400": {},
"405": {},
"500": {}
}
},
"delete": {
"security": [
{
"api_key": []
}
],
"description": "Will remove the channels to log",
"consumes": [
"application/json"
],
"produces": [
"application/json",
"text/plain"
],
"schemes": [
"https"
],
"tags": [
"admin"
],
"operationId": "deleteChannels",
"parameters": [
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/channelsDeleteRequest"
}
}
],
"responses": {
"200": {},
"400": {},
"405": {},
"500": {}
}
}
},
"/channel/{channel}": {
"get": {
"description": "Get entire channel logs of current day",
@ -1025,6 +1175,20 @@
},
"x-go-package": "github.com/gempir/justlog/api"
},
"ChannelConfig": {
"description": "ChannelConfig config for individual channels",
"type": "object",
"properties": {
"messageTypes": {
"type": "array",
"items": {
"$ref": "#/definitions/MessageType"
},
"x-go-name": "MessageTypes"
}
},
"x-go-package": "github.com/gempir/justlog/config"
},
"MessageType": {
"description": "MessageType different message types possible to receive via IRC",
"type": "integer",
@ -1065,6 +1229,55 @@
},
"x-go-package": "github.com/gempir/justlog/api"
},
"channelConfigsDeleteRequest": {
"type": "object",
"properties": {
"messageTypes": {
"type": "boolean",
"x-go-name": "MessageTypes"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"channelConfigsJoinRequest": {
"type": "object",
"properties": {
"channels": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Channels"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"channelConfigsRequest": {
"type": "object",
"properties": {
"messageTypes": {
"type": "array",
"items": {
"$ref": "#/definitions/MessageType"
},
"x-go-name": "MessageTypes"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"channelsDeleteRequest": {
"type": "object",
"properties": {
"channels": {
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "Channels"
}
},
"x-go-package": "github.com/gempir/justlog/api"
},
"chatLog": {
"type": "object",
"properties": {
@ -1145,10 +1358,5 @@
"name": "X-Api-Key",
"in": "header"
}
},
"security": [
{
"api_key": []
}
]
}
}