Skip to content

Commit

Permalink
feat:add auto create database
Browse files Browse the repository at this point in the history
  • Loading branch information
geebytes committed Jun 17, 2024
1 parent 446bdd8 commit 1ccb002
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 41 deletions.
17 changes: 9 additions & 8 deletions cmd/begonia/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ var accessKey string
var secret string
var addr string

func readInitAPP() {
func readInitAPP(env string) {
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatalf(err.Error())
return
}

path := filepath.Join(homeDir, ".begonia")
path = filepath.Join(path, "admin-app.json")
path = filepath.Join(path, fmt.Sprintf("admin-app.%s.json", env))
file, err := os.Open(path)
if err != nil {
log.Fatalf(err.Error())
Expand Down Expand Up @@ -66,8 +67,8 @@ func readInitAPP() {
addr = gw.Addr

}
func RegisterEndpoint(name string, endpoints []string, pbFile string, opts ...client.EndpointOption) {
readInitAPP()
func RegisterEndpoint(env,name string, endpoints []string, pbFile string, opts ...client.EndpointOption) {
readInitAPP(env)
pb, err := os.ReadFile(pbFile)
if err != nil {
panic(err)
Expand Down Expand Up @@ -102,8 +103,8 @@ func RegisterEndpoint(name string, endpoints []string, pbFile string, opts ...cl
log.Printf("#####################Add Endpoint Success#####################")
log.Printf("#####################ID:%s####################################", rsp.Id)
}
func UpdateEndpoint(id string, mask []string, opts ...client.EndpointOption) {
readInitAPP()
func UpdateEndpoint(env,id string, mask []string, opts ...client.EndpointOption) {
readInitAPP(env)
apiClient := client.NewEndpointAPI(addr, accessKey, secret)
log.Printf("#####################Update Endpoint###########################")
patch := &endpoint.EndpointSrvUpdateRequest{}
Expand All @@ -119,8 +120,8 @@ func UpdateEndpoint(id string, mask []string, opts ...client.EndpointOption) {
log.Printf("#####################Update Endpoint %s Success#####################", id)

}
func DeleteEndpoint(id string) {
readInitAPP()
func DeleteEndpoint(env,id string) {
readInitAPP(env)
apiClient := client.NewEndpointAPI(addr, accessKey, secret)
log.Printf("#####################Delete Endpoint:%s#####################", id)
_, err := apiClient.DeleteEndpointConfig(context.Background(), id)
Expand Down
11 changes: 7 additions & 4 deletions cmd/begonia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func NewEndpointDelCmd() *cobra.Command {

Run: func(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id")
env, _ := cmd.Flags().GetString("env")

DeleteEndpoint(id)
DeleteEndpoint(env,id)
},
}
cmd.Flags().StringP("id", "i", "", "ID Of Your Service")
Expand All @@ -95,8 +96,9 @@ func NewEndpointAddCmd() *cobra.Command {
tags, _ := cmd.Flags().GetStringArray("tags")
balance, _ := cmd.Flags().GetString("balance")
endpoints, _ := cmd.Flags().GetStringArray("endpoint")
env,_:=cmd.Flags().GetString("env")

RegisterEndpoint(name, endpoints, desc, client.WithBalance(strings.ToUpper(balance)), client.WithTags(tags))
RegisterEndpoint(env,name, endpoints, desc, client.WithBalance(strings.ToUpper(balance)), client.WithTags(tags))
},
}
cmd = newWriteEndpointCmd(cmd)
Expand Down Expand Up @@ -156,7 +158,8 @@ func NewEndpointUpdateCmd() *cobra.Command {
options = append(options, client.WithEndpoints(meta))
mask = append(mask, "endpoints")
}
UpdateEndpoint(id, mask, options...)
env,_:=cmd.Flags().GetString("env")
UpdateEndpoint(env,id, mask, options...)
},
}
cmd = newWriteEndpointCmd(cmd)
Expand Down Expand Up @@ -198,7 +201,7 @@ func main() {
rootCmd.AddCommand(cmd)
rootCmd.AddCommand(NewBegoniaInfoCmd())
rootCmd.AddCommand(addCommonCommand(NewInitCmd()))
rootCmd.AddCommand(NewEndpointCmd())
rootCmd.AddCommand(addCommonCommand(NewEndpointCmd()))
if err := cmd.Execute(); err != nil {
log.Fatalf("failed to start begonia: %v", err)
}
Expand Down
9 changes: 8 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mysql:
port: 3306
user: "test"
password: "test"
database: "begonia-test"
database: "begonia-dev"
table_prefix: "begonia_"
admin:
name: "admin"
Expand Down Expand Up @@ -110,6 +110,13 @@ test:
secretKey: "begoniabegonia"
- name: "FILE_ENGINE_LOCAL"
endpoint: "/tmp/upload"
mysql:
host: "127.0.0.1"
port: 3306
user: "test"
password: "test"
database: "begonia-test"
table_prefix: "begonia_"
etcd:
endpoint:
prefix: "/begonia/endpoints"
Expand Down
7 changes: 1 addition & 6 deletions gateway/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ func TestRequest(t *testing.T) {
go example.Run(":12148")
time.Sleep(time.Second * 3)
c.Convey("test request", t, func() {
// request := GrpcRequestImpl{
// FullMethodName: "helloworld.Greeter/SayHello",
// In: &v1.HelloRequest{Msg: "begonia"},
// Out: &v1.HelloReply{},
// Ctx: context.Background(),
// }

request := NewGrpcRequest(context.Background(), nil, nil, "helloworld.Greeter/SayHello", WithIn(&v1.HelloRequest{Msg: "begonia"}), WithOut(&v1.HelloReply{}))
pool := NewGrpcConnPool("127.0.0.1:12148")
endpoint := NewEndpoint(pool)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cockroachdb/errors v1.11.1
github.com/google/wire v0.6.0
github.com/smartystreets/goconvey v1.8.1
github.com/spark-lence/tiga v0.0.0-20240617015203-a7e022d3fac4
github.com/spark-lence/tiga v0.0.0-20240617161215-fd493c5e06ac
github.com/spf13/cobra v1.8.0
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3
google.golang.org/grpc v1.64.0
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoa
github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk=
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
Expand Down Expand Up @@ -118,6 +119,7 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down Expand Up @@ -161,6 +163,7 @@ github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ib
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
Expand Down Expand Up @@ -202,6 +205,7 @@ github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0=
github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I=
github.com/redis/go-redis/v9 v9.5.3 h1:fOAp1/uJG+ZtcITgZOfYFmTKPE7n4Vclj1wZFgRciUU=
github.com/redis/go-redis/v9 v9.5.3/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
Expand Down Expand Up @@ -231,6 +235,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spark-lence/tiga v0.0.0-20240617015203-a7e022d3fac4 h1:HmuGbn+mhKpi5tM8iM5vpUUx4K+XZZdrPecNu8IeO8c=
github.com/spark-lence/tiga v0.0.0-20240617015203-a7e022d3fac4/go.mod h1:MSL8X9t+qvpQ4Tq3vVPKncq9RJcCzF2XGEWkCuNhm6Q=
github.com/spark-lence/tiga v0.0.0-20240617161215-fd493c5e06ac h1:qGLujl2jYtkIeQYa2JEzQIQ5W3grnNcqVc2uuPV3uco=
github.com/spark-lence/tiga v0.0.0-20240617161215-fd493c5e06ac/go.mod h1:MSL8X9t+qvpQ4Tq3vVPKncq9RJcCzF2XGEWkCuNhm6Q=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
Expand Down Expand Up @@ -406,6 +412,7 @@ gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UD
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
Expand Down
7 changes: 6 additions & 1 deletion internal/middleware/auth/aksk.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ func (a *AccessKeyAuthMiddleware) RequestBefore(ctx context.Context, info *grpc.
if !ok {
md = metadata.MD{}
}
md.Set(gosdk.HeaderXIdentity, owner)
// md.Set(gosdk.HeaderXIdentity, owner)
md = metadata.Join(md, metadata.Pairs(gosdk.HeaderXIdentity, owner))

ctx = metadata.NewIncomingContext(ctx, md)
// md2, _ := metadata.FromIncomingContext(ctx)


return ctx, nil

}
Expand Down
11 changes: 8 additions & 3 deletions internal/middleware/auth/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func (a *ApiKeyAuthImpl) UnaryInterceptor(ctx context.Context, req any, info *gr
if err != nil {
return nil, gosdk.NewError(fmt.Errorf("query uid base on apikey get error:%w", err), int32(api.UserSvrCode_USER_APIKEY_NOT_MATCH_ERR), codes.Unauthenticated, "authorization_check")
}
ctx = metadata.NewIncomingContext(ctx, metadata.Pairs(gosdk.HeaderXIdentity, identity))
md,_:=metadata.FromIncomingContext(ctx)

md = metadata.Join(md, metadata.Pairs(gosdk.HeaderXIdentity, identity))
ctx = metadata.NewIncomingContext(ctx, md)
return handler(ctx, req)
}
return nil, err
Expand Down Expand Up @@ -86,9 +89,11 @@ func (a *ApiKeyAuthImpl) ValidateStream(ctx context.Context, req interface{}, fu
if err != nil {
return ctx, gosdk.NewError(fmt.Errorf("query user id base on apikey err:%w", err), int32(api.UserSvrCode_USER_APIKEY_NOT_MATCH_ERR), codes.Unauthenticated, "authorization_check")
}
ctx = metadata.NewIncomingContext(ctx, metadata.Pairs(gosdk.HeaderXIdentity, identity))
md,_:=metadata.FromIncomingContext(ctx)

md = metadata.Join(md, metadata.Pairs(gosdk.HeaderXIdentity, identity))
headers.Set(strings.ToLower(gosdk.HeaderXIdentity), identity)
return ctx, err
return metadata.NewIncomingContext(ctx,md), err
}
return ctx, err
}
Expand Down
36 changes: 33 additions & 3 deletions internal/middleware/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ func readInitAPP() (string, string, string) {
log.Fatalf(err.Error())
return "", "", ""
}
env := "dev"
if begonia.Env != "" {
env = begonia.Env
}
path := filepath.Join(homeDir, ".begonia")
path = filepath.Join(path, "admin-app.json")
path = filepath.Join(path, fmt.Sprintf("admin-app.%s.json", env))
file, err := os.Open(path)
if err != nil {
log.Fatalf(err.Error())
Expand Down Expand Up @@ -241,6 +245,12 @@ func TestUnaryInterceptor(t *testing.T) {
if identify:=md.Get(gosdk.HeaderXIdentity);len(identify)==0||identify[0]==""{
return nil,fmt.Errorf("no app identity")
}
XAccessKey:=md.Get(gosdk.HeaderXAccessKey)
XApiKey:=md.Get(gosdk.HeaderXApiKey)
XAuthz:=md.Get("authorization")
if len(XAccessKey)==0 && len(XApiKey)==0 && len(XAuthz)==0{
return nil,fmt.Errorf("no app auth key")
}
return nil, nil
}
R := routers.Get()
Expand Down Expand Up @@ -342,7 +352,15 @@ func TestStreamInterceptor(t *testing.T) {

ctx = metadata.NewIncomingContext(ctx, metadata.Pairs(gosdk.HeaderXApiKey, cnf.GetAdminAPIKey()))
err = mid.StreamInterceptor(&v1.Users{}, &greeterSayHelloWebsocketServer{ServerStream: &testStream{ctx: ctx}}, &grpc.StreamServerInfo{FullMethod: "/INTEGRATION.TESTSERVICE/GET"}, func(srv interface{}, ss grpc.ServerStream) error {
return nil
err:= ss.RecvMsg(srv)
md,_:=metadata.FromIncomingContext(ss.Context())
if identify:=md.Get(gosdk.HeaderXIdentity);len(identify)==0||identify[0]==""{
return fmt.Errorf("no app identity")
}
if xAppKey:=md.Get(gosdk.HeaderXApiKey);len(xAppKey)==0||xAppKey[0]==""{
return fmt.Errorf("no app key")
}
return err
})
c.So(err, c.ShouldBeNil)
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs(gosdk.HeaderXApiKey, "cnf.GetAdminAPIKey()"))
Expand All @@ -356,7 +374,15 @@ func TestStreamInterceptor(t *testing.T) {
jwt := getJWT()
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs("authorization", "Bearer "+jwt))
err = mid.StreamInterceptor(&v1.Users{}, &greeterSayHelloWebsocketServer{ServerStream: &testStream{ctx: ctx}}, &grpc.StreamServerInfo{FullMethod: "/INTEGRATION.TESTSERVICE/GET"}, func(srv interface{}, ss grpc.ServerStream) error {
return ss.RecvMsg(srv)
err:= ss.RecvMsg(srv)
md,_:=metadata.FromIncomingContext(ss.Context())
if identify:=md.Get(gosdk.HeaderXIdentity);len(identify)==0||identify[0]==""{
return fmt.Errorf("no app identity")
}
if xAuthorization:=md.Get("authorization");len(xAuthorization)==0||xAuthorization[0]==""{
return fmt.Errorf("no jwt key")
}
return err
})
c.So(err, c.ShouldBeNil)
ctx = metadata.NewIncomingContext(context.Background(), metadata.Pairs("authorization", "Bearer 123"))
Expand Down Expand Up @@ -399,6 +425,10 @@ func TestStreamInterceptor(t *testing.T) {
if identify:=md.Get(gosdk.HeaderXIdentity);len(identify)==0||identify[0]==""{
return fmt.Errorf("no app identity")
}
if xAccessKey:=md.Get(gosdk.HeaderXAccessKey);len(xAccessKey)==0||xAccessKey[0]==""{
t.Logf("error metadata:%v",md)
return fmt.Errorf("no app access key")
}
return err
})
c.So(err, c.ShouldBeNil)
Expand Down
5 changes: 3 additions & 2 deletions internal/middleware/auth/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ func (g *GrpcHeader) Release() {
}
func (g *GrpcHeader) Set(key, value string) {
g.in.Set(key, value)
newCtx := metadata.NewIncomingContext(g.ctx, g.in)
g.ctx = newCtx
md, _ := metadata.FromIncomingContext(g.ctx)
newMd := metadata.Join(md, g.in)
g.ctx = metadata.NewIncomingContext(g.ctx, newMd)

}
func (g *GrpcHeader) SendHeader(key, value string) {
Expand Down
3 changes: 1 addition & 2 deletions internal/middleware/auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ func (a *JWTAuth) checkJWT(ctx context.Context, authorization string, rspHeader

}
func (a *JWTAuth) jwtValidator(ctx context.Context, headers Header) (context.Context, error) {
// 获取请求的方法名
// 获取路由


md, _ := metadata.FromIncomingContext(ctx)

Expand Down
2 changes: 0 additions & 2 deletions internal/middleware/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package middleware
import (
"context"
"fmt"
"log"
"strings"

"github.com/begonia-org/begonia/internal/pkg/routers"
Expand Down Expand Up @@ -58,7 +57,6 @@ func (s *HttpStream) SendMsg(m interface{}) error {
router := routersList.GetRouteByGrpcMethod(s.FullMethod)
// 对内置服务的http响应进行格式化
if routersList.IsLocalSrv(s.FullMethod) || router.UseJsonResponse {
log.Printf("转换fullMethod:%v", s.FullMethod)
rsp, _ := grpcToHttpResponse(m, nil)
return s.ServerStream.SendMsg(rsp)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/migrate/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type APPOperator struct {
func NewAPPOperator(mysql *tiga.MySQLDao) *APPOperator {
return &APPOperator{mysql: mysql}
}
func dumpInitApp(app *api.Apps) error {
func dumpInitApp(app *api.Apps,env string) error {
log.Print("########################################admin-app###############################")
log.Printf("Init appid:%s", app.Appid)
log.Printf("Init accessKey:%s", app.AccessKey)
Expand All @@ -36,7 +36,7 @@ func dumpInitApp(app *api.Apps) error {
if err := os.MkdirAll(path, os.ModePerm); err != nil {
return err
}
file, err := os.Create(filepath.Join(path, "admin-app.json"))
file, err := os.Create(filepath.Join(path, fmt.Sprintf("admin-app.%s.json",env)))
if err != nil {
return err
}
Expand All @@ -49,11 +49,11 @@ func dumpInitApp(app *api.Apps) error {
log.Print("#################################################################################")
return nil
}
func (m *APPOperator) InitAdminAPP(owner string) (err error) {
func (m *APPOperator) InitAdminAPP(owner,env string) (err error) {
app := &api.Apps{}
defer func() {
if app.Appid != "" {
if errInit := dumpInitApp(app); errInit != nil {
if errInit := dumpInitApp(app,env); errInit != nil {
err = errInit
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/migrate/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ func (m *InitOperator) Init() error {
phone := m.config.GetDefaultAdminPhone()
aseKey := m.config.GetAesKey()
ivKey := m.config.GetAesIv()
env:=m.config.GetEnv()
uid, err := m.user.InitAdminUser(adminPasswd, aseKey, ivKey, name, email, phone)
if err != nil {
log.Printf("failed to init admin user: %v", err)
return err
}

return m.app.InitAdminAPP(uid)
return m.app.InitAdminAPP(uid,env)
}
Loading

0 comments on commit 1ccb002

Please sign in to comment.