forked from stelligent/mu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds.go
56 lines (44 loc) · 1.46 KB
/
rds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package aws
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/aws/aws-sdk-go/service/rds/rdsiface"
"github.com/stelligent/mu/common"
)
type rdsManager struct {
rdsAPI rdsiface.RDSAPI
}
func newRdsManager(sess *session.Session) (common.RdsManager, error) {
log.Debug("Connecting to RDS service")
rdsAPI := rds.New(sess)
return &rdsManager{
rdsAPI: rdsAPI,
}, nil
}
// SetIamAuthentication set value of RDS IAM authentication
func (rdsMgr *rdsManager) SetIamAuthentication(dbInstanceIdentifier string, enabled bool, dbEngine string) error {
rdsAPI := rdsMgr.rdsAPI
var err error
if dbEngine == "aurora" || dbEngine == "" {
params := &rds.ModifyDBClusterInput{
DBClusterIdentifier: aws.String(dbInstanceIdentifier),
EnableIAMDatabaseAuthentication: aws.Bool(enabled),
ApplyImmediately: aws.Bool(true),
}
log.Debugf("Setting IAM Authentication to '%s' for '%s'", enabled, dbInstanceIdentifier)
_, err = rdsAPI.ModifyDBCluster(params)
} else {
params := &rds.ModifyDBInstanceInput{
DBInstanceIdentifier: aws.String(dbInstanceIdentifier),
EnableIAMDatabaseAuthentication: aws.Bool(enabled),
ApplyImmediately: aws.Bool(true),
}
log.Debugf("Setting IAM Authentication to '%s' for '%s'", enabled, dbInstanceIdentifier)
_, err = rdsAPI.ModifyDBInstance(params)
}
if err != nil {
return err
}
return nil
}