Skip to content

Commit

Permalink
add permission + regenerate docs swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricve committed Jun 11, 2024
1 parent a27e1a1 commit 2ac2988
Show file tree
Hide file tree
Showing 12 changed files with 344 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ml/data/face_inference.mp4
ml/data/test_images
node_modules
ui/out
__debug_bin*
__debug_bin*
api/__debug_bin*
Empty file removed api/__debug_bin141116329
Empty file.
Empty file removed api/__debug_bin383952432
Empty file.
Binary file removed api/__debug_bin783398833
Binary file not shown.
Empty file removed api/__debug_bin825136468
Empty file.
27 changes: 20 additions & 7 deletions api/controllers/locations.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (

// Locations godoc
// @Router /api/locations [get]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID getLocations
// @Tags locations
// @Summary Get all locations
Expand All @@ -20,11 +24,15 @@ func GetLocations(c *gin.Context) []models.Location {
c.JSON(200, gin.H{
"data": locations,
})
return nil;
return nil
}

// Location godoc
// @Router /api/locations/{id} [get]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID getLocation
// @Tags locations
// @Summary Get location by ID
Expand All @@ -50,9 +58,12 @@ func GetLocation(c *gin.Context) models.Location {
return location
}


// location godoc
// @Router /api/locations [post]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID addLocation
// @Tags locations
// @Summary Create location
Expand All @@ -74,18 +85,22 @@ func AddLocation(c *gin.Context) error {
c.JSON(500, gin.H{
"error": "Failed to add location",
})
return err
return err
}

c.JSON(201, gin.H{
"message": "Location added successfully",
"message": "Location added successfully",
"location": location,
})
return nil
return nil
}

// location godoc
// @Router /api/locations/{id} [delete]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID deleteLocation
// @Tags locations
// @Summary Delete location
Expand Down Expand Up @@ -115,5 +130,3 @@ func DeleteLocation(c *gin.Context) error {
})
return nil
}


34 changes: 27 additions & 7 deletions api/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ import (

// user godoc
// @Router /api/users [get]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID getUsers
// @Tags users
// @Summary Get all users
// @Description Get all users
// @Success 200 {array} models.User
func GetUsers(c *gin.Context) []models.User {
users := database.GetUsers()
c.JSON(200, gin.H{
"data": users,
})
return nil;
users := database.GetUsers()
c.JSON(200, gin.H{
"data": users,
})
return nil
}

// user godoc
// @Router /api/users/{id} [get]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID getUser
// @Tags users
// @Summary Get user
Expand Down Expand Up @@ -52,6 +60,10 @@ func GetUserById(c *gin.Context) models.User {

// user godoc
// @Router /api/users/{email} [get]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID getUserByEmail
// @Tags users
// @Summary Get user by email
Expand All @@ -71,6 +83,10 @@ func GetUserByEmail(c *gin.Context) models.User {

// user godoc
// @Router /api/users [post]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID addUser
// @Tags users
// @Summary Add user
Expand All @@ -92,18 +108,22 @@ func AddUser(c *gin.Context) error {
c.JSON(500, gin.H{
"error": "Failed to add user",
})
return err
return err
}

c.JSON(201, gin.H{
"message": "User added successfully",
"user": user,
"user": user,
})
return nil
}

// user godoc
// @Router /api/users/{id} [delete]
// @Security Bearer
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
// @ID deleteUser
// @Tags users
// @Summary Delete user
Expand Down
108 changes: 98 additions & 10 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ const docTemplate = `{
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"termsOfService": "https://kerberos.io",
"contact": {
"name": "API Support",
"url": "https://www.kerberos.io",
"email": "[email protected]"
},
"license": {
"name": "Apache 2.0 - Commons Clause",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/api/locations": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get all locations",
"tags": [
"locations"
Expand All @@ -36,6 +50,11 @@ const docTemplate = `{
}
},
"post": {
"security": [
{
"Bearer": []
}
],
"description": "Create location",
"consumes": [
"application/json"
Expand Down Expand Up @@ -71,6 +90,11 @@ const docTemplate = `{
},
"/api/locations/{id}": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get location by ID",
"tags": [
"locations"
Expand All @@ -96,6 +120,11 @@ const docTemplate = `{
}
},
"delete": {
"security": [
{
"Bearer": []
}
],
"description": "Delete location",
"tags": [
"locations"
Expand Down Expand Up @@ -149,6 +178,11 @@ const docTemplate = `{
},
"/api/users": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get all users",
"tags": [
"users"
Expand All @@ -168,7 +202,12 @@ const docTemplate = `{
}
},
"post": {
"description": "Create user",
"security": [
{
"Bearer": []
}
],
"description": "Add user",
"consumes": [
"application/json"
],
Expand All @@ -178,11 +217,11 @@ const docTemplate = `{
"tags": [
"users"
],
"summary": "Create user",
"summary": "Add user",
"operationId": "addUser",
"parameters": [
{
"description": "User",
"description": "User data",
"name": "user",
"in": "body",
"required": true,
Expand All @@ -191,6 +230,38 @@ const docTemplate = `{
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/models.User"
}
}
}
}
},
"/api/users/{email}": {
"get": {
"security": [
{
"Bearer": []
}
],
"description": "Get user by email",
"tags": [
"users"
],
"summary": "Get user by email",
"operationId": "getUserByEmail",
"parameters": [
{
"type": "string",
"description": "User email",
"name": "email",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
Expand All @@ -203,11 +274,16 @@ const docTemplate = `{
},
"/api/users/{id}": {
"get": {
"description": "Get user by id",
"security": [
{
"Bearer": []
}
],
"description": "Get user",
"tags": [
"users"
],
"summary": "Get user by id",
"summary": "Get user",
"operationId": "getUser",
"parameters": [
{
Expand All @@ -228,6 +304,11 @@ const docTemplate = `{
}
},
"delete": {
"security": [
{
"Bearer": []
}
],
"description": "Delete user",
"tags": [
"users"
Expand Down Expand Up @@ -329,17 +410,24 @@ const docTemplate = `{
}
}
}
},
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"name": "Authorization",
"in": "header"
}
}
}`

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Version: "1.0",
Host: "",
BasePath: "",
BasePath: "/",
Schemes: []string{},
Title: "",
Description: "",
Title: "Swagger Kerberos Agent API",
Description: "This is the API for using and configuring Kerberos Agent.",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
LeftDelim: "{{",
Expand Down
Loading

0 comments on commit 2ac2988

Please sign in to comment.