Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/tanlang/rm perm chack falg / 移除兼容权限检查的 flag #171

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions auth/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ import (
)

// todo: rm checkPermission after v1.13.0
func InitRouter(app OAuthApp, checkPermission bool) http.Handler {
func InitRouter(app OAuthApp) http.Handler {
gin.SetMode(gin.ReleaseMode)

router := gin.New()
router.ContextWithFallback = true
router.Use(CorsMiddleWare())
router.Use(RewriteAddressInUrl())

if checkPermission {
router.Use(permMiddleWare(app))
} else {
router.Use(noPermMiddleWare())
}
router.Use(permMiddleWare(app))

headlerFunc := healthcheck.HandlerFunc()
router.GET("/healthcheck", func(c *gin.Context) {
Expand Down Expand Up @@ -210,11 +205,3 @@ func permMiddleWare(app OAuthApp) gin.HandlerFunc {
c.Next()
}
}

func noPermMiddleWare() gin.HandlerFunc {
return func(c *gin.Context) {
reqCtx := core.CtxWithPerm(c.Request.Context(), core.PermAdmin)
c.Request = c.Request.WithContext(reqCtx)
c.Next()
}
}
8 changes: 2 additions & 6 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ var runCommand = &cli.Command{
Name: "db-type",
Usage: "which db to use. sqlite/mysql",
},
// todo: rm flag disable-perm-check after v1.13.0
&cli.BoolFlag{
Name: "disable-perm-check",
Usage: "disable permission check for compatible with old version",
},
},
Action: run,
}
Expand Down Expand Up @@ -104,6 +99,7 @@ func run(cliCtx *cli.Context) error {
return fmt.Errorf("check deprecated repo exist: %w", err)
}
if deprecatedRepoPathExist {
fmt.Printf("[WARM]: repo path %s is deprecated, please transfer to %s instead\n", deprecatedRepoPath, repoPath)
repoPath = deprecatedRepoPath
}
}
Expand Down Expand Up @@ -140,7 +136,7 @@ func run(cliCtx *cli.Context) error {
return fmt.Errorf("save token: %s", err)
}

router := auth.InitRouter(app, !cliCtx.Bool("disable-perm-check"))
router := auth.InitRouter(app)

if cnf.Trace != nil && cnf.Trace.JaegerTracingEnabled {
log.Infof("register jaeger-tracing exporter to %s, with node-name:%s",
Expand Down
2 changes: 1 addition & 1 deletion cmd/mock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
if err != nil {
log.Fatalf("Failed to init sophon-auth: %s", err)
}
router := auth.InitRouter(app, true)
router := auth.InitRouter(app)
server := &http.Server{
Addr: "127.0.0.1:8989",
Handler: router,
Expand Down
2 changes: 1 addition & 1 deletion integrate_test/mock_deamon.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func setup(t *testing.T) (server *httptest.Server, dir string, token string) {
t.Fatalf("Failed to get default admin token: %s", err)
}

router := auth.InitRouter(app, true)
router := auth.InitRouter(app)
srv := httptest.NewServer(router)
return srv, tempDir, token
}
Expand Down
2 changes: 1 addition & 1 deletion jwtclient/auth_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
log.Fatalf("Failed to get default admin token : %s", err)
}

router := auth.InitRouter(app, true)
router := auth.InitRouter(app)
server := &http.Server{
Addr: cnf.Listen,
Handler: router,
Expand Down