forked from solo-io/unik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws_provider.go
57 lines (50 loc) · 1.36 KB
/
aws_provider.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
57
package aws
import (
"github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/emc-advanced-dev/unik/pkg/config"
"github.com/emc-advanced-dev/unik/pkg/state"
"os"
)
var AwsStateFile = os.Getenv("HOME") + "/.unik/aws/state.json"
type AwsProvider struct {
config config.Aws
state state.State
}
func NewAwsProvier(config config.Aws) *AwsProvider {
logrus.Infof("state file: %s", AwsStateFile)
return &AwsProvider{
config: config,
state: state.NewBasicState(AwsStateFile),
}
}
func (p *AwsProvider) WithState(state state.State) *AwsProvider {
p.state = state
return p
}
func (p *AwsProvider) newEC2() *ec2.EC2 {
sess := session.New(&aws.Config{
Region: aws.String(p.config.Region),
})
sess.Handlers.Send.PushFront(func(r *request.Request) {
if r != nil {
logrus.WithFields(logrus.Fields{"params": r.Params}).Debugf("request sent to ec2")
}
})
return ec2.New(sess)
}
func (p *AwsProvider) newS3() *s3.S3 {
sess := session.New(&aws.Config{
Region: aws.String(p.config.Region),
})
sess.Handlers.Send.PushFront(func(r *request.Request) {
if r != nil {
logrus.WithFields(logrus.Fields{"params": r.Params}).Debugf("request sent to s3")
}
})
return s3.New(sess)
}