Skip to content
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

Youtube Bee (#25) #248

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6a4b478
initial verson done
Mark-Jung Apr 30, 2019
bd37889
error messages
Mark-Jung Apr 30, 2019
0529378
done with youtube bee;
Mark-Jung May 14, 2019
6904446
Added logs API end-point, which lets you retrieve Beehive's logs
muesli Apr 29, 2019
095472f
Reverse ordering in LogSorter
muesli Apr 29, 2019
022293f
Sideload Hives in API requests to /bees
muesli Apr 29, 2019
6511f38
Bees can now expose their state
muesli Apr 29, 2019
2d82826
Support states in IRCBee
muesli Apr 29, 2019
a896302
Fixed converting strong to float64 in ConvertValue
muesli Apr 30, 2019
20081f0
Go mod tidy our module deps
muesli May 1, 2019
d9e2b63
Bumped dependencies to latest compatible releases
muesli May 1, 2019
ac93554
Added Prometheus Bee (#231)
CalmBit May 1, 2019
7960d01
Updated Go module definitions
muesli May 1, 2019
7d52298
fix handling of boolean config values
mkrauser May 2, 2019
1c9af59
Cronbee fix
CalmBit May 3, 2019
714db01
LogDebugF
CalmBit May 3, 2019
f15c349
TravisCI Bee (#234)
CalmBit May 4, 2019
fc99c8f
added email server bee
mkrauser May 2, 2019
6184238
Bumped smolder dependency to @master
muesli May 5, 2019
9032dea
Add timestamp to telegram events (#153)
rubiojr May 6, 2019
abc4184
Added missing event name
mkrauser May 6, 2019
f0a1a85
Add JSON-Function for Templates (#242)
mkrauser May 7, 2019
9137dbb
Added Docker example with CANONICAL_URL env var
muesli May 7, 2019
7715804
Discord Bee (#239)
CalmBit May 8, 2019
d28e8b2
Disable notification & serial hives on non-Linux unices
muesli May 9, 2019
7b75d90
Fixed typos in a few bees
muesli May 13, 2019
4398116
fixed comments
Mark-Jung May 15, 2019
def2f42
forgot to fix indentation. oops.
Mark-Jung May 15, 2019
92b4601
Merge branch 'youtube-bee' of github.com:Mark-Jung/beehive into youtu…
Mark-Jung May 23, 2019
e1a471f
debugging
Mark-Jung May 26, 2019
2e70d41
Merge branch 'master' into youtube-bee
Mark-Jung May 26, 2019
a5a1018
specified incoming events to two
Mark-Jung May 28, 2019
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ beehive.conf

# Embedded assets
api/bindata.go

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ the `-bind` and `-canonicalurl` parameters. For example:

beehive -bind "192.168.0.1:8181" -canonicalurl "http://192.168.0.1:8181"

or

docker run --name beehive -d -e CANONICAL_URL="http://192.168.0.1:8181" -p 8181:8181 fribbledom/beehive

## Development

Need help? Want to hack on your own Hives? Join us on IRC (irc://freenode.net/#beehive) or [Gitter](https://gitter.im/the_beehive/Lobby).
Expand Down
2 changes: 2 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/muesli/beehive/api/resources/bees"
"github.com/muesli/beehive/api/resources/chains"
"github.com/muesli/beehive/api/resources/hives"
"github.com/muesli/beehive/api/resources/logs"
"github.com/muesli/beehive/app"
)

Expand Down Expand Up @@ -191,6 +192,7 @@ func Run() {
&bees.BeeResource{},
&chains.ChainResource{},
&actions.ActionResource{},
&logs.LogResource{},
)

server := &http.Server{Addr: bind, Handler: wsContainer}
Expand Down
17 changes: 15 additions & 2 deletions api/resources/bees/bees_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
"time"

restful "github.com/emicklei/go-restful"
"github.com/muesli/beehive/bees"

"github.com/muesli/smolder"

"github.com/muesli/beehive/api/resources/hives"
"github.com/muesli/beehive/bees"
)

// BeeResponse is the common response to 'bee' requests
Expand All @@ -36,6 +37,9 @@ type BeeResponse struct {

Bees []beeInfoResponse `json:"bees,omitempty"`
bees map[string]*bees.BeeInterface

Hives []hives.HiveInfoResponse `json:"hives,omitempty"`
hives map[string]*bees.BeeFactoryInterface
}

type beeInfoResponse struct {
Expand All @@ -55,11 +59,20 @@ func (r *BeeResponse) Init(context smolder.APIContext) {
r.Context = context

r.bees = make(map[string]*bees.BeeInterface)
r.hives = make(map[string]*bees.BeeFactoryInterface)
}

// AddBee adds a bee to the response
func (r *BeeResponse) AddBee(bee *bees.BeeInterface) {
r.bees[(*bee).Name()] = bee

hive := bees.GetFactory((*bee).Namespace())
if hive == nil {
panic("Hive for Bee not found")
}

r.hives[(*hive).Name()] = hive
r.Hives = append(r.Hives, hives.PrepareHiveResponse(r.Context, hive))
}

// Send responds to a request with http.StatusOK
Expand Down
14 changes: 8 additions & 6 deletions api/resources/hives/hives_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ import (
type HiveResponse struct {
smolder.Response

Hives []hiveInfoResponse `json:"hives,omitempty"`
Hives []HiveInfoResponse `json:"hives,omitempty"`
hives map[string]*bees.BeeFactoryInterface
}

type hiveInfoResponse struct {
type HiveInfoResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Image string `json:"image"`
LogoColor string `json:"logocolor"`
Options []bees.BeeOptionDescriptor `json:"options"`
States []bees.StateDescriptor `json:"states"`
Events []bees.EventDescriptor `json:"events"`
Actions []bees.ActionDescriptor `json:"actions"`
}
Expand All @@ -73,7 +74,7 @@ func (r *HiveResponse) Send(response *restful.Response) {
sort.Strings(keys)

for _, k := range keys {
r.Hives = append(r.Hives, prepareHiveResponse(r.Context, r.hives[k]))
r.Hives = append(r.Hives, PrepareHiveResponse(r.Context, r.hives[k]))
}

r.Response.Send(response)
Expand All @@ -85,23 +86,24 @@ func (r *HiveResponse) EmptyResponse() interface{} {
var out struct {
Hives interface{} `json:"hives"`
}
out.Hives = []hiveInfoResponse{}
out.Hives = []HiveInfoResponse{}
return out
}
return nil
}

func prepareHiveResponse(ctx smolder.APIContext, hive *bees.BeeFactoryInterface) hiveInfoResponse {
func PrepareHiveResponse(ctx smolder.APIContext, hive *bees.BeeFactoryInterface) HiveInfoResponse {
u, _ := url.Parse(ctx.(*context.APIContext).Config.BaseURL)
u.Path = path.Join(u.Path, "images", (*hive).Image())

resp := hiveInfoResponse{
resp := HiveInfoResponse{
ID: (*hive).ID(),
Name: (*hive).Name(),
Description: (*hive).Description(),
Image: u.String(),
LogoColor: (*hive).LogoColor(),
Options: (*hive).Options(),
States: (*hive).States(),
Events: (*hive).Events(),
Actions: (*hive).Actions(),
}
Expand Down
54 changes: 54 additions & 0 deletions api/resources/logs/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2017-2019 Christian Muehlhaeuser
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
*/

package logs

import (
"github.com/emicklei/go-restful"
"github.com/muesli/smolder"
)

// LogResource is the resource responsible for /logs
type LogResource struct {
smolder.Resource
}

var (
// _ smolder.GetIDSupported = &LogResource{}
_ smolder.GetSupported = &LogResource{}
)

// Register this resource with the container to setup all the routes
func (r *LogResource) Register(container *restful.Container, config smolder.APIConfig, context smolder.APIContextFactory) {
r.Name = "LogResource"
r.TypeName = "log"
r.Endpoint = "logs"
r.Doc = "Manage logs"

r.Config = config
r.Context = context

r.Init(container, r)
}

// Returns returns the model that will be returned
func (r *LogResource) Returns() interface{} {
return LogResponse{}
}
77 changes: 77 additions & 0 deletions api/resources/logs/logs_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2017-2019 Christian Muehlhaeuser
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
*/

package logs

import (
"github.com/muesli/beehive/bees"

"github.com/emicklei/go-restful"
"github.com/muesli/smolder"
)

// GetAuthRequired returns true because all requests need authentication
func (r *LogResource) GetAuthRequired() bool {
return false
}

// GetByIDsAuthRequired returns true because all requests need authentication
func (r *LogResource) GetByIDsAuthRequired() bool {
return false
}

// GetDoc returns the description of this API endpoint
func (r *LogResource) GetDoc() string {
return "retrieve logs"
}

// GetParams returns the parameters supported by this API endpoint
func (r *LogResource) GetParams() []*restful.Parameter {
params := []*restful.Parameter{}
params = append(params, restful.QueryParameter("bee", "id of a bee").DataType("string"))

return params
}

// GetByIDs sends out all items matching a set of IDs
/*
func (r *LogResource) GetByIDs(ctx smolder.APIContext, request *restful.Request, response *restful.Response, ids []string) {
resp := LogResponse{}
resp.Init(ctx)

resp.Send(response)
}
*/

// Get sends out items matching the query parameters
func (r *LogResource) Get(ctx smolder.APIContext, request *restful.Request, response *restful.Response, params map[string][]string) {
// ctxapi := ctx.(*context.APIContext)
bee := request.QueryParameter("bee")

resp := LogResponse{}
resp.Init(ctx)

logs := bees.GetLogs(bee)
for _, log := range logs {
resp.AddLog(&log)
}

resp.Send(response)
}
84 changes: 84 additions & 0 deletions api/resources/logs/logs_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (C) 2015-2019 Christian Muehlhaeuser
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
*/

package logs

import (
"time"

"github.com/muesli/beehive/bees"

"github.com/muesli/smolder"
)

// LogResponse is the common response to 'log' requests
type LogResponse struct {
smolder.Response

Logs []logInfoResponse `json:"logs,omitempty"`
logs []*bees.LogMessage
}

type logInfoResponse struct {
ID string `json:"id"`
Bee string `json:"bee"`
Level int64 `json:"level"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
}

// Init a new response
func (r *LogResponse) Init(context smolder.APIContext) {
r.Parent = r
r.Context = context

r.Logs = []logInfoResponse{}
}

// AddLog adds a log to the response
func (r *LogResponse) AddLog(log *bees.LogMessage) {
r.logs = append(r.logs, log)
r.Logs = append(r.Logs, prepareLogResponse(r.Context, log))
}

// EmptyResponse returns an empty API response for this endpoint if there's no data to respond with
func (r *LogResponse) EmptyResponse() interface{} {
if len(r.logs) == 0 {
var out struct {
Logs interface{} `json:"logs"`
}
out.Logs = []logInfoResponse{}
return out
}
return nil
}

func prepareLogResponse(context smolder.APIContext, log *bees.LogMessage) logInfoResponse {
// ctx := context.(*context.APIContext)
resp := logInfoResponse{
ID: (*log).ID,
Bee: (*log).Bee,
Level: int64((*log).MessageType),
Message: (*log).Message,
Timestamp: (*log).Timestamp,
}

return resp
}
Binary file added assets/bees/discordbee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bees/emailserverbee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bees/prometheusbee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bees/travisbee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions beehive.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ func main() {

api.Run()

log.SetLevel(log.InfoLevel)

log.Println()
log.Println("Beehive is buzzing...")

Expand Down
Loading