Skip to content
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
46 changes: 19 additions & 27 deletions common/log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@
// easy to build programs that use a consistent interface for logging. Here's an example
// of a simple Cobra-based program using this log package:
//
// func main() {
// // get the default logging options
// options := log.DefaultOptions()
// func main() {
// // get the default logging options
// options := log.DefaultOptions()
//
// rootCmd := &cobra.Command{
// Run: func(cmd *cobra.Command, args []string) {
// rootCmd := &cobra.Command{
// Run: func(cmd *cobra.Command, args []string) {
//
// // configure the logging system
// if err := log.Configure(options); err != nil {
// // print an error and quit
// }
// // configure the logging system
// if err := log.Configure(options); err != nil {
// // print an error and quit
// }
//
// // output some logs
// log.Info("Hello")
// log.Sync()
// },
// }
// // output some logs
// log.Info("Hello")
// log.Sync()
// },
// }
//
// // add logging-specific flags to the cobra command
// options.AttachCobraFlags(rootCmd)
// rootCmd.SetArgs(os.Args[1:])
// rootCmd.Execute()
// }
// // add logging-specific flags to the cobra command
// options.AttachCobraFlags(rootCmd)
// rootCmd.SetArgs(os.Args[1:])
// rootCmd.Execute()
// }
//
// Once configured, this package intercepts the output of the standard golang "log" package as well as anything
// sent to the global zap logger (zap.L()).
Expand All @@ -61,8 +61,6 @@ import (
"github.com/natefinch/lumberjack"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zapgrpc"
"google.golang.org/grpc/grpclog"
)

// none is used to disable logging output as well as to disable stack tracing.
Expand Down Expand Up @@ -323,12 +321,6 @@ func Configure(options *Options) error {

// capture standard golang "log" package output and force it through our logger
_ = zap.RedirectStdLog(captureLogger)

// capture gRPC logging
if options.LogGrpc {
grpclog.SetLogger(zapgrpc.NewLogger(captureLogger.WithOptions(zap.AddCallerSkip(2))))
}

return nil
}

Expand Down
6 changes: 0 additions & 6 deletions common/log/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ type Options struct {
// JSONEncoding controls whether the log is formatted as JSON.
JSONEncoding bool

// LogGrpc indicates that Grpc logs should be captured. The default is true.
// This is not exposed through the command-line flags, as this flag is mainly useful for testing: Grpc
// stack will hold on to the logger even though it gets closed. This causes data races.
LogGrpc bool

Level string

outputLevels string
Expand All @@ -131,7 +126,6 @@ func DefaultOptions() *Options {
RotationMaxBackups: defaultRotationMaxBackups,
outputLevels: DefaultScopeName + ":" + levelToString[defaultOutputLevel],
stackTraceLevels: DefaultScopeName + ":" + levelToString[defaultStackTraceLevel],
LogGrpc: false,
}
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/stretchr/testify v1.8.1
go.uber.org/zap v1.13.0
google.golang.org/grpc v1.50.1
google.golang.org/grpc v1.51.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -36,6 +36,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.5.3
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.4.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.5.3 h1:KUzOtjYlUCC5qjWrwW1kI0wHPvwnwPqUIa8eWh3TJro=
github.com/polarismesh/specification v1.5.3/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -217,6 +219,7 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY=
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
59 changes: 55 additions & 4 deletions handlers/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httputil"
"sync"
"time"

"github.com/gin-gonic/gin"
Expand All @@ -33,8 +34,54 @@ import (

"github.com/polarismesh/polaris-console/bootstrap"
"github.com/polarismesh/polaris-console/common/log"
"github.com/polarismesh/specification/source/go/api/v1/security"
)

func NewAdminGetter(conf *bootstrap.Config) {
_adminGetter.conf = conf
}

var _adminGetter = &AdminUserGetter{}

type AdminUserGetter struct {
conf *bootstrap.Config
lock sync.RWMutex
user *security.User
}

func (a *AdminUserGetter) GetAdminInfo() (*security.User, error) {
a.lock.Lock()
defer a.lock.Unlock()

if a.user != nil {
return a.user, nil
}

resp, err := http.Get(fmt.Sprintf("http://%s/maintain/v1/mainuser/exist", a.conf.PolarisServer.Address))
if err != nil {
log.Error("[Proxy][Login] get admin info fail", zap.Error(err))
return nil, err
}

if resp.StatusCode != http.StatusOK {
return nil, errors.New("get admin info fail")
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error("[Proxy][Login] get admin info fail", zap.Error(err))
return nil, err
}

user := &security.User{}
if err = json.Unmarshal(body, user); err != nil {
log.Error("[Proxy][Login] get admin info fail", zap.Error(err))
return nil, err
}
a.user = user
return a.user, nil
}

// ServiceOwner 服务(规则)负责人信息
type ServiceOwner struct {
Namespace string
Expand Down Expand Up @@ -63,12 +110,16 @@ func ReverseProxyForLogin(polarisServer *bootstrap.PolarisServer, conf *bootstra
log.Error("[Proxy][Login] modify login request fail", zap.Error(err))
return
}

admin, err := _adminGetter.GetAdminInfo()
if err != nil {
log.Error("[Proxy][Login] modify login request fail", zap.Error(err))
return
}

loginBody := &LoginRequest{}
_ = json.Unmarshal(body, loginBody)
loginBody.Owner = "polaris"
if len(conf.WebServer.MainUser) != 0 {
loginBody.Owner = conf.WebServer.MainUser
}
loginBody.Owner = admin.GetName().GetValue()
body, err = json.Marshal(loginBody)
if err != nil {
log.Error("[Proxy][Login] modify login request fail", zap.Error(err))
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"

"github.com/polarismesh/polaris-console/bootstrap"
"github.com/polarismesh/polaris-console/handlers"
"github.com/polarismesh/polaris-console/router"
)

Expand All @@ -32,6 +33,9 @@ func main() {
fmt.Printf("[ERROR] loadConfig fail\n")
return
}

handlers.NewAdminGetter(config)

// 初始化相关配置
bootstrap.Initialize(config)
// 设置模式
Expand Down
2 changes: 2 additions & 0 deletions router/admin_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ func AdminRouter(webSvr *gin.Engine, config *bootstrap.Config) {
// 后端server路由组
admin := webSvr.Group("/maintain/v1")
admin.GET("/server/functions", handlers.ReverseProxyNoAuthForServer(&config.PolarisServer, config))
admin.GET("/mainuser/exist", handlers.ReverseProxyNoAuthForServer(&config.PolarisServer, config))
admin.POST("/mainuser/create", handlers.ReverseProxyNoAuthForServer(&config.PolarisServer, config))
admin.GET("/bootstrap/config", handlers.ReverseProxyNoAuthForServer(&config.PolarisServer, config))
}
4 changes: 4 additions & 0 deletions web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ import App from './app'
import { Router, Switch, Route } from 'react-router-dom'
import LoginPage from '@src/polaris/auth/login/Page'
import LoginPageDuck from '@src/polaris/auth/login/PageDuck'
import InitPage from '@src/polaris/auth/init/Page'
import InitPageDuck from '@src/polaris/auth/init/PageDuck'
import { connectWithDuck } from './polaris/common/helpers'

const Login = connectWithDuck(LoginPage, LoginPageDuck as any)
const Init = connectWithDuck(InitPage, InitPageDuck as any)
export default function render() {
ReactDOM.unmountComponentAtNode(document.querySelector('#polaris-console'))
ReactDOM.render(
<Router history={history}>
<Switch>
<Route exact path='/init' component={Init} />
<Route exact path='/login' component={Login} />
<Route exact path='*'>
<App />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ export default (
},
},
]
}
}
124 changes: 124 additions & 0 deletions web/src/polaris/auth/init/Page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import * as React from 'react'
import { purify, DuckCmpProps } from 'saga-duck'

import Duck from './PageDuck'
import insertCSS from '@src/polaris/common/helpers/insertCSS'
import { Row, Col, Card, H2, Text, Form, Button, Input as TeaInput, Copy, Bubble } from 'tea-component'
import FormField from '@src/polaris/common/duckComponents/form/Field'
import Input from '@src/polaris/common/duckComponents/form/Input'
insertCSS(
'login',
`.login-background{
height:100vh;
width:100vw;
overflow:hidden;

}`,
)
export default purify(function (props: DuckCmpProps<Duck>) {
const { duck, store, dispatch } = props
const { ducks, creators, selector } = duck
const { userName, password } = ducks.form.getAPI(store, dispatch).getFields(['userName', 'password'])
const { preError } = selector(store)
return (
<div
style={{ background: 'url(static/img/login-background.png)', backgroundSize: '100% 100%' }}
className={'login-background'}
>
<img
src={'static/img/logo-polaris.png'}
style={{ width: '200px', position: 'absolute', top: 0, left: 0, padding: '15px' }}
/>
<Row style={{ margin: '30vh 0 30vh 0', height: '40vh' }}>
<Col span={4}></Col>

<Col span={16}>
<Row style={{ maxWidth: '1000px', margin: 'auto' }}>
<Col span={15}>
<Card
style={{
backgroundColor: 'transparent',
border: 'none',
padding: '5vh 0',
}}
bordered
>
<Card.Body>
<Text parent={'div'} style={{ color: '#fff', fontSize: '24px', width: '550px' }}>
北极星服务治理中心
</Text>
<Text parent={'div'} style={{ color: 'rgba(255, 255, 255, 0.6)', width: '450px' }}>
一个支持多语言、多框架和异构基础设施的服务治理中心,提供服务发现、流量调度、熔断降级、限流鉴权和可观测性等服务治理功能。北极星治理中心默认提供服务注册功能,也可以搭配其他服务注册中心使用。
</Text>
</Card.Body>
</Card>
</Col>
<Col span={9}>
<Card>
<Card.Body>
<Row>
<Col>
<H2>
<Text align={'center'} parent={'div'} style={{ width: '100%' }}>
初始化主账户
</Text>
</H2>
</Col>
</Row>
<Row>
<Col>
<Text theme={'weak'} parent={'div'} style={{ width: '100%' }} align={'center'}>
外网访问建议设置访问控制策略
</Text>
</Col>
</Row>
<Form style={{ padding: '20px 0px' }}>
<FormField field={userName} label={'用户名'}>
<Input field={userName} size={'full'} />
</FormField>
<FormField field={password} label={'密码'}>
<TeaInput.Password
value={password.getValue() || ''}
size={'full'}
onChange={(v) => {
password.setValue(v)
password.setTouched(true)
password.setError('')
}}
onPressEnter={() => {
password.setError('')
dispatch(creators.submit())
}}
rules={false}
disabled={preError}
/>
</FormField>
</Form>
<Row>
<Col span={8}></Col>
<Bubble>
<Col span={8}>
<Button
type={'primary'}
style={{ width: '100%', margin: 'auto' }}
onClick={() => {
password.setError('')
dispatch(creators.submit())
}}
disabled={preError}
>
初始化
</Button>
</Col>
</Bubble>
</Row>
</Card.Body>
</Card>
</Col>
</Row>
</Col>
<Col span={4}></Col>
</Row>
</div>
)
})
Loading
Loading