diff --git a/machinery/main.go b/machinery/main.go index 20f869e..d5a1ef3 100644 --- a/machinery/main.go +++ b/machinery/main.go @@ -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 } diff --git a/machinery/src/components/Config.go b/machinery/src/components/Config.go index b90cdf5..2acda49 100644 --- a/machinery/src/components/Config.go +++ b/machinery/src/components/Config.go @@ -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. diff --git a/machinery/src/models/ApiResponse.go b/machinery/src/models/ApiResponse.go index 43bc111..bb3d1b0 100644 --- a/machinery/src/models/ApiResponse.go +++ b/machinery/src/models/ApiResponse.go @@ -1,5 +1,5 @@ package models type APIResponse struct { - Data interface{} `json:"data" bson:"data"` + Data interface{} `json:"data" bson:"data"` } diff --git a/machinery/src/models/Config.go b/machinery/src/models/Config.go index 16abfee..f376e41 100644 --- a/machinery/src/models/Config.go +++ b/machinery/src/models/Config.go @@ -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"` } diff --git a/machinery/src/models/User.go b/machinery/src/models/User.go index d0dfba7..f33fbbe 100644 --- a/machinery/src/models/User.go +++ b/machinery/src/models/User.go @@ -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"` } diff --git a/machinery/src/routers/http/Cors.go b/machinery/src/routers/http/Cors.go index 0698b76..6e63dd7 100644 --- a/machinery/src/routers/http/Cors.go +++ b/machinery/src/routers/http/Cors.go @@ -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 -} \ No newline at end of file +} diff --git a/machinery/src/routers/http/JWTMiddleware.go b/machinery/src/routers/http/JWTMiddleware.go index 4e92add..92114d2 100644 --- a/machinery/src/routers/http/JWTMiddleware.go +++ b/machinery/src/routers/http/JWTMiddleware.go @@ -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 diff --git a/machinery/src/routers/http/Routes.go b/machinery/src/routers/http/Routes.go index 56db5aa..6423731 100644 --- a/machinery/src/routers/http/Routes.go +++ b/machinery/src/routers/http/Routes.go @@ -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, }) -} \ No newline at end of file +} diff --git a/machinery/src/routers/http/Server.go b/machinery/src/routers/http/Server.go index 90aedb8..d3601c6 100644 --- a/machinery/src/routers/http/Server.go +++ b/machinery/src/routers/http/Server.go @@ -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) -} \ No newline at end of file +} diff --git a/machinery/src/routers/main.go b/machinery/src/routers/main.go index 7e6203a..fdb0dbd 100644 --- a/machinery/src/routers/main.go +++ b/machinery/src/routers/main.go @@ -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) -} \ No newline at end of file +} diff --git a/machinery/src/routers/mqtt/Listener.go b/machinery/src/routers/mqtt/Listener.go index 690e022..f0deb9d 100644 --- a/machinery/src/routers/mqtt/Listener.go +++ b/machinery/src/routers/mqtt/Listener.go @@ -1,5 +1,5 @@ package mqtt -func StartListener(name string){ +func StartListener(name string) { -} \ No newline at end of file +}