Skip to content

Commit 21dfc6d

Browse files
committed
Improve addDatabaseUser()
1 parent 6242c14 commit 21dfc6d

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func main() {
3636
object.InitRuleMap()
3737
object.InitActionMap()
3838
run.InitAppMap()
39+
run.InitRdsClient()
3940
run.InitSelfStart()
4041
object.StartMonitorSitesLoop()
4142

run/database_cloud.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,32 @@ package run
1616

1717
import (
1818
"fmt"
19-
"github.com/beego/beego"
2019

2120
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
2221
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
2322
"github.com/aliyun/alibaba-cloud-sdk-go/services/rds"
23+
"github.com/beego/beego"
2424
)
2525

2626
var rdsClient *rds.Client
2727

28-
func InitRdsClient() *rds.Client {
28+
func InitRdsClient() {
2929
dbRegionId := beego.AppConfig.String("dbRegionId")
3030
dbAccessKeyId := beego.AppConfig.String("dbAccessKeyId")
3131
dbAccessKeySecret := beego.AppConfig.String("dbAccessKeySecret")
3232

33+
if dbRegionId == "" || dbAccessKeyId == "" || dbAccessKeySecret == "" {
34+
return
35+
}
36+
3337
config := sdk.NewConfig()
3438
credential := credentials.NewAccessKeyCredential(dbAccessKeyId, dbAccessKeySecret)
39+
3540
var err error
3641
rdsClient, err = rds.NewClientWithOptions(dbRegionId, config, credential)
3742
if err != nil {
3843
panic(err)
3944
}
40-
41-
return rdsClient
4245
}
4346

4447
func gitCreateDatabaseCloud(name string) (bool, error) {
@@ -57,6 +60,11 @@ func gitCreateDatabaseCloud(name string) (bool, error) {
5760
return false, err
5861
}
5962

63+
err = addDatabaseUser(name)
64+
if err != nil {
65+
return false, err
66+
}
67+
6068
return true, err
6169
}
6270

run/database_cloud_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,4 @@ func TestCreateDatabaseCloud(t *testing.T) {
2424
if err != nil {
2525
panic(err)
2626
}
27-
28-
err = addDatabaseUser(dbName)
29-
if err != nil {
30-
panic(err)
31-
}
3227
}

0 commit comments

Comments
 (0)