Skip to content

Commit 1ebf748

Browse files
author
Nicola Strappazzon C
committed
feat - aws/rds: allow yaml and json, verify env var, perform session.
1 parent 65cda7a commit 1ebf748

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

aws/rds/main.go

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package rds
22

33
import (
4+
"errors"
5+
6+
"github.com/debeando/go-common/env"
47
"github.com/debeando/go-common/retry"
58

69
"github.com/aws/aws-sdk-go/aws"
@@ -9,28 +12,35 @@ import (
912
)
1013

1114
type RDS struct {
12-
Client *rds.RDS `json:"-"` // AWS RDS connection.
13-
Instance string `json:"instance"` // New instance (replica).
14-
Class string `json:"class"` // New instance class.
15-
Region string `json:"region"` // AWS region account.
16-
Primary string `json:"primary"` // Source instance (primary).
17-
Status string `json:"status"` // New instance status.
18-
Endpoint string `json:"endpoint"` // New instance endpoint.
19-
Protection bool `json:"protection"` // New instance is set to deletion protection.
20-
Port uint16 `json:"port"` // New instance port of endpoint.
21-
Zone string `json:"zone"` // New instance Availability Zone.
15+
Client *rds.RDS `json:"-" yaml:"-"` // AWS RDS connection.
16+
Instance string `json:"instance" yaml:"instance"` // New instance (replica).
17+
Class string `json:"class" yaml:"class"` // New instance class.
18+
Region string `json:"region" yaml:"region"` // AWS region account.
19+
Primary string `json:"primary" yaml:"primary"` // Source instance (primary).
20+
Status string `json:"status" yaml:"status"` // New instance status.
21+
Endpoint string `json:"endpoint" yaml:"endpoint"` // New instance endpoint.
22+
Protection bool `json:"protection" yaml:"protection"` // New instance is set to deletion protection.
23+
Port uint16 `json:"port" yaml:"port"` // New instance port of endpoint.
24+
Zone string `json:"zone" yaml:"zone"` // New instance Availability Zone.
25+
Session *session.Session
2226
}
2327

2428
func (r *RDS) Init() (err error) {
25-
sess, err := session.NewSession(&aws.Config{
26-
Region: aws.String(r.Region),
27-
})
29+
if !env.Exist("AWS_REGION") {
30+
return errors.New("You must specify a region. Define value of environment variable AWS_REGION.")
31+
}
2832

29-
r.Client = rds.New(sess)
33+
r.Session = session.Must(session.NewSession())
34+
35+
r.Client = rds.New(r.Session)
3036

3137
return
3238
}
3339

40+
func (r *RDS) GetSessionRegion() string {
41+
return aws.StringValue(r.Session.Config.Region)
42+
}
43+
3444
func (r *RDS) List() Instances {
3545
instances := Instances{}
3646
instance := Instance{}

0 commit comments

Comments
 (0)