Skip to content

Commit

Permalink
refactor on middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbITCybErSeC committed Dec 4, 2024
1 parent 766c9b1 commit 7c50d35
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 49 deletions.
27 changes: 0 additions & 27 deletions pkg/api/handlers/playbook/playbook_endpoints.go

This file was deleted.

16 changes: 0 additions & 16 deletions pkg/api/handlers/swagger/swagger_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
package swagger

import (
api "soarca/api"

"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
)

func Routes(route *gin.Engine) {
api.SwaggerInfo.BasePath = "/"
swagger := route.Group("/swagger")
{
swagger.GET("/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
}
}
File renamed without changes.
66 changes: 60 additions & 6 deletions pkg/api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
playbook_routes "soarca/pkg/api/playbook"

Check failure on line 7 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / Run ci-tests

package soarca/pkg/api/playbook is not in std (/opt/hostedtoolcache/go/1.22.2/x64/src/soarca/pkg/api/playbook)
reporter "soarca/pkg/api/reporter"

Check failure on line 8 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / Run ci-tests

package soarca/pkg/api/reporter is not in std (/opt/hostedtoolcache/go/1.22.2/x64/src/soarca/pkg/api/reporter)
status "soarca/pkg/api/status"

Check failure on line 9 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / Run ci-tests

package soarca/pkg/api/status is not in std (/opt/hostedtoolcache/go/1.22.2/x64/src/soarca/pkg/api/status)
swagger "soarca/pkg/api/swagger"
"soarca/pkg/api/trigger"

Check failure on line 10 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / Run ci-tests

package soarca/pkg/api/trigger is not in std (/opt/hostedtoolcache/go/1.22.2/x64/src/soarca/pkg/api/trigger)

"github.com/gin-contrib/cors"
gin "github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
)

// POST /operator/coa/coa-id
Expand Down Expand Up @@ -50,13 +50,67 @@ func Api(app *gin.Engine,
return nil
}

func Swagger(app *gin.Engine) {
swagger.Routes(app)
}

func Cors(app *gin.Engine, origins []string) {

config := cors.DefaultConfig()
config.AllowOrigins = origins
app.Use(cors.New(config))
}

func SwaggerRoutes(route *gin.Engine) {
api.SwaggerInfo.BasePath = "/"
swagger := route.Group("/swagger")
{
swagger.GET("/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
}
}

// Main Router for the following endpoints:
// GET /playbook
// POST /playbook
// GET /playbook/playbook-id
// PUT /playbook/playbook-id
// DELETE /playbook/playbook-id
func PlaybookRoutes(route *gin.Engine, controller database.IController) {
playbookController := NewPlaybookController(controller)
playbook := route.Group("/playbook")
{
playbook.GET("/", playbookController.getAllPlaybooks)
playbook.GET("/meta/", playbookController.getAllPlaybookMetas)
playbook.POST("/", playbookController.submitPlaybook)
playbook.GET("/:id", playbookController.getPlaybookByID)
playbook.PUT("/:id", playbookController.updatePlaybookByID)
playbook.DELETE("/:id", playbookController.deleteByPlaybookID)

}
}

// Main Router for the following endpoints:
// GET /reporter
// GET /reporter/{execution-id}
func ReporterRoutes(route *gin.Engine, informer informer.IExecutionInformer) {
executionInformer := NewExecutionInformer(informer)
report := route.Group("/reporter")
{
report.GET("/", executionInformer.getExecutions)
report.GET("/:id", executionInformer.getExecutionReport)
}
}

// GET /status
// GET /status/ping
func StepRoutes(route *gin.Engine) {
router := route.Group("/status")
{
router.GET("/", Api)
router.GET("/ping", Pong)

}
}

func TriggerRoutes(route *gin.Engine, trigger *TriggerApi) {
group := route.Group("/trigger")
{
group.POST("/playbook", trigger.Execute)
group.POST("/playbook/:id", trigger.ExecuteById)
}
}

0 comments on commit 7c50d35

Please sign in to comment.