Skip to content

Commit

Permalink
feat: support tenant (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
wklken authored Nov 27, 2024
1 parent 990dd37 commit 209ef14
Show file tree
Hide file tree
Showing 60 changed files with 1,351 additions and 816 deletions.
1 change: 1 addition & 0 deletions src/bkauth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/bkauth/environments/dev.bru
12 changes: 10 additions & 2 deletions src/bkauth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ note:
- depends on database only
- use cache, should be fast


## layers

> view(api/*/*.go) -> service -> cache -> dao -> database
Expand All @@ -20,7 +19,7 @@ note:

## develop

- `go 1.20` required
- `go 1.23` required

build and run

Expand Down Expand Up @@ -58,3 +57,12 @@ make lint
# build image
make docker-build
```

## api testing

we use [bruno](https://www.usebruno.com/) as the api testing tool.

1. import `src/bkauth/test/bkauth` into bruno
2. add `cp src/bkauth/test/dev.bru.tpl src/bkauth/test/dev.bru` and update the host
- the `x_bk_app_code: bk_paas3` and `x_bk_app_secret: G3dsdftR9nGQM8WnF1qwjGSVE0ScXrz1hKWM` should be the same in the config.yaml
3. switch the env into dev and test all apis
2 changes: 1 addition & 1 deletion src/bkauth/build/projects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
project_dir: bkauth
alias: bkauth
language: binary
version: 0.0.13
version: 1.1.0
version_type: ee
90 changes: 0 additions & 90 deletions src/bkauth/build/support-files/templates/#etc#bkauth_config.yaml

This file was deleted.

7 changes: 1 addition & 6 deletions src/bkauth/cmd/bkauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ package cmd
import (
"context"
"fmt"
"math/rand"
"os"
"os/signal"
"syscall"
"time"

_ "github.com/go-sql-driver/mysql"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -70,10 +68,6 @@ func Execute() {
func Start() {
fmt.Println("It's BKAuth")

// init rand
// nolint
rand.Seed(time.Now().UnixNano())

// 0. init config
if cfgFile != "" {
// Use config file from the flag.
Expand All @@ -85,6 +79,7 @@ func Start() {
if globalConfig.Debug {
fmt.Println(globalConfig)
}
fmt.Printf("enableMultiTenantMode: %v\n", globalConfig.EnableMultiTenantMode)

// 1. init
initLogger()
Expand Down
5 changes: 0 additions & 5 deletions src/bkauth/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package cmd

import (
"fmt"
"math/rand"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -96,9 +94,6 @@ func init() {

func cliStart() {
fmt.Println("cli start!")
// init rand
// nolint
rand.Seed(time.Now().UnixNano())

// 0. init config
if cfgFile != "" {
Expand Down
10 changes: 3 additions & 7 deletions src/bkauth/cmd/fixture_init.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TencentBlueKing is pleased to support the open source community by making
* 蓝鲸智云 - Auth服务(BlueKing - Auth) available.
* 蓝鲸智云 - Auth 服务 (BlueKing - Auth) available.
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -20,8 +20,6 @@ package cmd

import (
"fmt"
"math/rand"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -51,10 +49,6 @@ func init() {
}

func FixtureInitStart() {
// init rand
// nolint
rand.Seed(time.Now().UnixNano())

// 0. init config
if cfgFile != "" {
// Use config file from the flag.
Expand All @@ -66,13 +60,15 @@ func FixtureInitStart() {
if globalConfig.Debug {
fmt.Println(globalConfig)
}
fmt.Printf("enableMultiTenantMode: %v\n", globalConfig.EnableMultiTenantMode)

initLogger()
initDatabase()
initRedis()
initCaches()
initCryptos()

// 这里跟运维确认过,初始化的都是蓝鲸基础服务的数据,保持简单,由 bkauth 配置默认的 tenant_id
fixture.InitFixture(globalConfig)

// flush logger
Expand Down
115 changes: 0 additions & 115 deletions src/bkauth/cmd/sync.go

This file was deleted.

4 changes: 4 additions & 0 deletions src/bkauth/config.yaml.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
debug: true

# enableMultiTenantMode: false
enableMultiTenantMode: true

server:
host: 127.0.0.1
port: 9000
Expand All @@ -23,6 +26,7 @@ crypto:

accessKeys:
bkauth: "G3dsdftR9nGQM8WnF1qwjGSVE0ScXrz1hKWM"
bk_paas3: "G3dsdftR9nGQM8WnF1qwjGSVE0ScXrz1hKWM"

apiAllowLists:
- api: "manage_app"
Expand Down
Loading

0 comments on commit 209ef14

Please sign in to comment.