package beego

import (
	"github.com/astaxie/beego"
	"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/middleware"
	_ "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/port/beego/routers"
)

func init() {
	beego.InsertFilter("*", beego.BeforeRouter, middleware.AllowCors())
	//beego.InsertFilter("*", beego.BeforeRouter, middleware.OpenTracingAdapter)

	beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequestLogFilter())
	beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(), false)

	beego.InsertFilter("/v1/auth/profile", beego.BeforeExec, middleware.CheckAuthorization)
	beego.InsertFilter("/v1/user/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
	beego.InsertFilter("/v1/role/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
	beego.InsertFilter("/v1/project_module/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
	beego.InsertFilter("/v1/client_version/*", beego.BeforeExec, middleware.InspectRoleAccess(""))
	beego.InsertFilter("/v1/project_module_version/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
	beego.InsertFilter("/v1/project_module_files/*", beego.BeforeExec, middleware.InspectRoleAccess("/project_module/*"))
	beego.InsertFilter("/v1/rbac/*", beego.BeforeExec, middleware.InspectRoleAccess("/role/*"))

	beego.InsertFilter("/log", beego.BeforeStatic, middleware.BasicAuth())
}