This commit is contained in:
cedricve
2021-01-02 20:12:20 +01:00
parent 55cc2b1be1
commit e0168fe86b
11 changed files with 84 additions and 86 deletions
+17 -16
View File
@@ -2,36 +2,37 @@ package main
import (
"fmt"
"github.com/kerberos-io/opensource/machinery/src/routers"
"log"
"os"
"github.com/kerberos-io/opensource/machinery/src/routers"
)
func main(){
func main() {
const VERSION = 3.0
action := os.Args[1]
switch action {
case "version":
log.Printf("%s: %0.1f\n", "You are currrently running Kerberos Open Source", VERSION)
case "pending-upload":
name := os.Args[2]
fmt.Println(name)
//cloud.PendingUpload(log, name)
case "discover":
timeout := os.Args[2]
fmt.Println(timeout)
//duration, _ := strconv.Atoi(timeout)
//capture.Discover(log, time.Duration(duration))
case "run": {
case "version":
log.Printf("%s: %0.1f\n", "You are currrently running Kerberos Open Source", VERSION)
case "pending-upload":
name := os.Args[2]
fmt.Println(name)
//cloud.PendingUpload(log, name)
case "discover":
timeout := os.Args[2]
fmt.Println(timeout)
//duration, _ := strconv.Atoi(timeout)
//capture.Discover(log, time.Duration(duration))
case "run":
{
name := os.Args[2]
port := os.Args[3]
routers.StartMqttListener(name)
routers.StartWebserver(name, port)
}
default:
fmt.Println("Sorry I don't understand :(")
default:
fmt.Println("Sorry I don't understand :(")
}
return
}
-1
View File
@@ -9,7 +9,6 @@ import (
"time"
)
// ReadUserConfig Reads the user configuration of the Kerberos Open Source instance.
// This will return a models.User struct including the username, password,
// selected language, and if the installation was completed or not.
+1 -1
View File
@@ -1,5 +1,5 @@
package models
type APIResponse struct {
Data interface{} `json:"data" bson:"data"`
Data interface{} `json:"data" bson:"data"`
}
+43 -44
View File
@@ -1,96 +1,95 @@
package models
//Config is the highlevel struct which contains all the configuration of
//your Kerberos Open Source instance.
type Config struct {
Type string `json:"type" binding:"required"`
Key string `json:"key"`
Name string `json:"name"`
Timezone string `json:"timezone,omitempty" bson:"timezone,omitempty"`
Capture Capture `json:"capture"`
Timetable []*Timetable `json:"timetable"`
Region *Region `json:"region"`
Cloud string `json:"cloud,omitempty" bson:"cloud,omitempty"`
KStorage *KStorage `json:"kstorage,omitempty" bson:"kstorage,omitempty"`
MQTTURI string `json:"mqtturi,omitempty" bson:"mqtturi,omitempty"`
Type string `json:"type" binding:"required"`
Key string `json:"key"`
Name string `json:"name"`
Timezone string `json:"timezone,omitempty" bson:"timezone,omitempty"`
Capture Capture `json:"capture"`
Timetable []*Timetable `json:"timetable"`
Region *Region `json:"region"`
Cloud string `json:"cloud,omitempty" bson:"cloud,omitempty"`
KStorage *KStorage `json:"kstorage,omitempty" bson:"kstorage,omitempty"`
MQTTURI string `json:"mqtturi,omitempty" bson:"mqtturi,omitempty"`
}
//Capture defines which camera type (Id) you are using (IP, USB or Raspberry Pi camera),
//and also contains recording specific parameters.
type Capture struct {
Name string `json:"name"`
IPCamera IPCamera `json:"ipcamera"`
USBCamera USBCamera `json:"usbcamera"`
RaspiCamera RaspiCamera `json:"raspicamera"`
Continuous string `json:"continuous,omitempty"`
PostRecording int64 `json:"postrecording"`
PreRecording int `json:"prerecording"`
MaxLengthRecording int64 `json:"maxlengthrecording"`
Name string `json:"name"`
IPCamera IPCamera `json:"ipcamera"`
USBCamera USBCamera `json:"usbcamera"`
RaspiCamera RaspiCamera `json:"raspicamera"`
Continuous string `json:"continuous,omitempty"`
PostRecording int64 `json:"postrecording"`
PreRecording int `json:"prerecording"`
MaxLengthRecording int64 `json:"maxlengthrecording"`
}
//IPCamera configuration, such as the RTSP url of the IPCamera and the FPS.
type IPCamera struct {
RTSP string `json:"rtsp"`
FPS string `json:"fps"`
RTSP string `json:"rtsp"`
FPS string `json:"fps"`
}
//USBCamera configuration, such as the device path (/dev/video*)
type USBCamera struct {
Device string `json:"device"`
Device string `json:"device"`
}
//RaspiCamera configuration, such as the device path (/dev/video*)
type RaspiCamera struct {
Device string `json:"device"`
Device string `json:"device"`
}
//Region specifies the type (Id) of Region Of Interest (ROI), you
//would like to use.
type Region struct {
Name string `json:"name"`
Rectangle Rectangle `json:"rectangle"`
Polygon []Polygon `json:"polygon"`
Name string `json:"name"`
Rectangle Rectangle `json:"rectangle"`
Polygon []Polygon `json:"polygon"`
}
//Rectangle is defined by a starting point, left top (x1,y1) and end point (x2,y2).
type Rectangle struct {
X1 int `json:"x1"`
Y1 int `json:"y1"`
X2 int `json:"x2"`
Y2 int `json:"y2"`
X1 int `json:"x1"`
Y1 int `json:"y1"`
X2 int `json:"x2"`
Y2 int `json:"y2"`
}
//Polygon is a sequence of coordinates (x,y). The ID specifies an unique identifier,
//as multiple polygons can be defined.
type Polygon struct {
ID string `json:"id"`
Coordinates []Coordinate `json:"coordinates"`
ID string `json:"id"`
Coordinates []Coordinate `json:"coordinates"`
}
//Coordinate belongs to a Polygon.
type Coordinate struct {
X float64 `json:"x"`
Y float64 `json:"y"`
X float64 `json:"x"`
Y float64 `json:"y"`
}
//Timetable allows you to set a Time Of Intterest (TOI), which limits recording or
//detection to a predefined time interval. Two tracks can be set, which allows you
//to give some flexibility.
type Timetable struct {
Start1 int `json:"start1"`
End1 int `json:"end1"`
Start2 int `json:"start2"`
End2 int `json:"end2"`
Start1 int `json:"start1"`
End1 int `json:"end1"`
Start2 int `json:"start2"`
End2 int `json:"end2"`
}
//KStorage contains the credentials of the Kerberos Storage/Kerberos Cloud instance.
//By defining KStorage you can make your recordings available in the cloud, at a centrel place.
type KStorage struct {
URI string `json:"uri,omitempty" bson:"uri,omitempty"`
CloudKey string `json:"cloud_key,omitempty" bson:"cloud_key,omitempty"`
AccessKey string `json:"access_key,omitempty" bson:"access_key,omitempty"`
SecretAccessKey string `json:"secret_access_key,omitempty" bson:"secret_access_key,omitempty"`
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
Directory string `json:"directory,omitempty" bson:"directory,omitempty"`
URI string `json:"uri,omitempty" bson:"uri,omitempty"`
CloudKey string `json:"cloud_key,omitempty" bson:"cloud_key,omitempty"`
AccessKey string `json:"access_key,omitempty" bson:"access_key,omitempty"`
SecretAccessKey string `json:"secret_access_key,omitempty" bson:"secret_access_key,omitempty"`
Provider string `json:"provider,omitempty" bson:"provider,omitempty"`
Directory string `json:"directory,omitempty" bson:"directory,omitempty"`
}
+5 -5
View File
@@ -1,9 +1,9 @@
package models
type User struct {
Installed bool `json:"installed" bson:"installed"`
Username string `json:"username" bson:"username"`
Password string `json:"password" bson:"password"`
Role string `json:"role" bson:"role"`
Language string `json:"language" bson:"language"`
Installed bool `json:"installed" bson:"installed"`
Username string `json:"username" bson:"username"`
Password string `json:"password" bson:"password"`
Role string `json:"role" bson:"role"`
Language string `json:"language" bson:"language"`
}
+2 -2
View File
@@ -13,7 +13,7 @@ func CORS() gin.HandlerFunc {
AllowHeaders: []string{"Origin", "Content-Type", "authorization", "multipart/form-data", "x-requested-with"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
MaxAge: 12 * time.Hour,
})
return c
}
}
+3 -3
View File
@@ -28,14 +28,14 @@ func JWTMiddleWare() jwt.GinJWTMiddleware {
},
IdentityHandler: func(c *gin.Context) interface{} {
claims := jwt.ExtractClaims(c)
user := claims["id"].(map[string]interface {})
user := claims["id"].(map[string]interface{})
return &models.User{
Username: user["username"].(string),
Role: user["role"].(string),
Role: user["role"].(string),
}
},
Authorizator: func(data interface{}, c *gin.Context) bool {
if _, ok := data.(*models.User); ok { //&& v.Username == "admin" {
if _, ok := data.(*models.User); ok { //&& v.Username == "admin" {
return true
}
return false
+5 -5
View File
@@ -7,7 +7,7 @@ import (
"github.com/kerberos-io/opensource/machinery/src/models"
)
func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware ) {
func AddRoutes(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) {
api := r.Group("/api")
{
@@ -32,7 +32,7 @@ func GetInstallation(c *gin.Context) {
// Get the user configuration
userConfig := components.ReadUserConfig()
c.JSON(200, models.APIResponse {
c.JSON(200, models.APIResponse{
Data: userConfig.Installed,
})
}
@@ -44,11 +44,11 @@ func GetInstallation(c *gin.Context) {
// @Produce json
// @Success 200 {object} models.APIResponse
// @Router /api/install [post]
func UpdateInstallation (c *gin.Context) {
func UpdateInstallation(c *gin.Context) {
// TODO update user config and update global object.
// userConfig = ...
userConfig := components.ReadUserConfig()
c.JSON(200, models.APIResponse {
c.JSON(200, models.APIResponse{
Data: userConfig,
})
}
}
+3 -4
View File
@@ -11,7 +11,6 @@ import (
"log"
)
// @title Swagger Kerberos Open Source API
// @version 1.0
// @description This is the API for using and configure Kerberos Open source.
@@ -30,7 +29,7 @@ import (
// @in header
// @name Authorization
func StartServer(name string, port string){
func StartServer(name string, port string) {
// Initialize REST API
r := gin.Default()
@@ -48,7 +47,7 @@ func StartServer(name string, port string){
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
// The JWT middleware
middleWare :=JWTMiddleWare()
middleWare := JWTMiddleWare()
authMiddleware, err := jwt.New(&middleWare)
if err != nil {
log.Fatal("JWT Error:" + err.Error())
@@ -59,4 +58,4 @@ func StartServer(name string, port string){
// Run the api on port
r.Run(":" + port)
}
}
+3 -3
View File
@@ -5,10 +5,10 @@ import (
"github.com/kerberos-io/opensource/machinery/src/routers/mqtt"
)
func StartWebserver(name string, port string){
func StartWebserver(name string, port string) {
http.StartServer(name, port)
}
func StartMqttListener(name string){
func StartMqttListener(name string) {
mqtt.StartListener(name)
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
package mqtt
func StartListener(name string){
func StartListener(name string) {
}
}