Skip to content

Commit cd564a0

Browse files
authored
feat:企业级鉴权功能实现
1 parent 5d98a1d commit cd564a0

File tree

192 files changed

+7595
-10432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+7595
-10432
lines changed

Diff for: .github/workflows/codecov.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,25 @@ jobs:
6161
with:
6262
fetch-depth: 2
6363

64+
- uses: shogo82148/actions-setup-mysql@v1
65+
with:
66+
mysql-version: "5.7"
67+
auto-start: true
68+
my-cnf: |
69+
innodb_log_file_size=256MB
70+
innodb_buffer_pool_size=512MB
71+
max_allowed_packet=16MB
72+
max_connections=50
73+
local_infile=1
74+
root-password: root
75+
76+
6477
- name: Initialize database
6578
env:
6679
MYSQL_DB_USER: root
6780
MYSQL_DB_PWD: root
6881
MYSQL_DATABASE: polaris_server
6982
run: |
70-
sudo systemctl start mysql.service
7183
mysql -e 'CREATE DATABASE ${{ env.MYSQL_DATABASE }};' -u${{ env.MYSQL_DB_USER }} -p${{ env.MYSQL_DB_PWD }}
7284
mysql -e "ALTER USER '${{ env.MYSQL_DB_USER }}'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" -u${{ env.MYSQL_DB_USER }} -p${{ env.MYSQL_DB_PWD }}
7385

Diff for: .golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ linters-settings:
167167
disabled: false
168168
- name: max-public-structs
169169
severity: warning
170-
disabled: false
170+
disabled: true
171171
arguments: [35]
172172
- name: indent-error-flow
173173
severity: warning
@@ -281,7 +281,7 @@ linters-settings:
281281
govet:
282282
# Report about shadowed variables.
283283
# Default: false
284-
check-shadowing: true
284+
shadow: false
285285
# Settings per analyzer.
286286
settings:
287287
# Analyzer name, run `go tool vet help` to see all analyzers.

Diff for: admin/api.go

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/polarismesh/polaris/common/model"
2727
"github.com/polarismesh/polaris/common/model/admin"
28+
authcommon "github.com/polarismesh/polaris/common/model/auth"
2829
)
2930

3031
// AdminOperateServer Maintain related operation
@@ -55,4 +56,6 @@ type AdminOperateServer interface {
5556
GetCMDBInfo(ctx context.Context) ([]model.LocationView, error)
5657
// InitMainUser
5758
InitMainUser(ctx context.Context, user apisecurity.User) error
59+
// GetServerFunctions Get server functions
60+
GetServerFunctions(ctx context.Context) []authcommon.ServerFunctionGroup
5861
}

Diff for: admin/config.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323

2424
// Config maintain configuration
2525
type Config struct {
26-
Jobs []job.JobConfig `yaml:"jobs"`
26+
Jobs []job.JobConfig `yaml:"jobs"`
27+
Interceptors []string `yaml:"-"`
2728
}
2829

2930
func DefaultConfig() *Config {

Diff for: admin/default.go

+43-23
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,32 @@ package admin
2020
import (
2121
"context"
2222
"errors"
23+
"fmt"
2324

2425
"github.com/polarismesh/polaris/admin/job"
25-
"github.com/polarismesh/polaris/auth"
2626
"github.com/polarismesh/polaris/cache"
2727
"github.com/polarismesh/polaris/service"
2828
"github.com/polarismesh/polaris/service/healthcheck"
2929
"github.com/polarismesh/polaris/store"
3030
)
3131

3232
var (
33-
server AdminOperateServer
34-
maintainServer = &Server{}
35-
finishInit bool
33+
server AdminOperateServer
34+
maintainServer = &Server{}
35+
finishInit bool
36+
serverProxyFactories = map[string]ServerProxyFactory{}
3637
)
3738

39+
type ServerProxyFactory func(ctx context.Context, pre AdminOperateServer) (AdminOperateServer, error)
40+
41+
func RegisterServerProxy(name string, factor ServerProxyFactory) error {
42+
if _, ok := serverProxyFactories[name]; ok {
43+
return fmt.Errorf("duplicate ServerProxyFactory, name(%s)", name)
44+
}
45+
serverProxyFactories[name] = factor
46+
return nil
47+
}
48+
3849
// Initialize 初始化
3950
func Initialize(ctx context.Context, cfg *Config, namingService service.DiscoverServer,
4051
healthCheckServer *healthcheck.Server, cacheMgn *cache.CacheManager, storage store.Store) error {
@@ -43,40 +54,49 @@ func Initialize(ctx context.Context, cfg *Config, namingService service.Discover
4354
return nil
4455
}
4556

46-
err := initialize(ctx, cfg, namingService, healthCheckServer, cacheMgn, storage)
57+
proxySvr, actualSvr, err := InitServer(ctx, cfg, namingService, healthCheckServer, cacheMgn, storage)
4758
if err != nil {
4859
return err
4960
}
5061

62+
server = proxySvr
63+
maintainServer = actualSvr
5164
finishInit = true
5265
return nil
5366
}
5467

55-
func initialize(_ context.Context, cfg *Config, namingService service.DiscoverServer,
56-
healthCheckServer *healthcheck.Server, cacheMgn *cache.CacheManager, storage store.Store) error {
68+
func InitServer(ctx context.Context, cfg *Config, namingService service.DiscoverServer,
69+
healthCheckServer *healthcheck.Server, cacheMgn *cache.CacheManager, storage store.Store) (AdminOperateServer, *Server, error) {
5770

58-
userMgn, err := auth.GetUserServer()
59-
if err != nil {
60-
return err
61-
}
71+
actualSvr := new(Server)
6272

63-
strategyMgn, err := auth.GetStrategyServer()
64-
if err != nil {
65-
return err
66-
}
67-
68-
maintainServer.namingServer = namingService
69-
maintainServer.healthCheckServer = healthCheckServer
70-
maintainServer.cacheMgn = cacheMgn
71-
maintainServer.storage = storage
73+
actualSvr.namingServer = namingService
74+
actualSvr.healthCheckServer = healthCheckServer
75+
actualSvr.cacheMgn = cacheMgn
76+
actualSvr.storage = storage
7277

7378
maintainJobs := job.NewMaintainJobs(namingService, cacheMgn, storage)
7479
if err := maintainJobs.StartMaintianJobs(cfg.Jobs); err != nil {
75-
return err
80+
return nil, nil, err
7681
}
7782

78-
server = newServerAuthAbility(maintainServer, userMgn, strategyMgn)
79-
return nil
83+
var proxySvr AdminOperateServer
84+
proxySvr = actualSvr
85+
order := GetChainOrder()
86+
for i := range order {
87+
factory, exist := serverProxyFactories[order[i]]
88+
if !exist {
89+
return nil, nil, fmt.Errorf("name(%s) not exist in serverProxyFactories", order[i])
90+
}
91+
92+
afterSvr, err := factory(ctx, proxySvr)
93+
if err != nil {
94+
return nil, nil, err
95+
}
96+
proxySvr = afterSvr
97+
}
98+
99+
return proxySvr, actualSvr, nil
80100
}
81101

82102
// GetServer 获取已经初始化好的Server

Diff for: admin/interceptor/auth/log.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package auth
19+
20+
import (
21+
commonlog "github.com/polarismesh/polaris/common/log"
22+
)
23+
24+
var log = commonlog.GetScopeOrDefaultByName(commonlog.AuthLoggerName)

0 commit comments

Comments
 (0)