go-ddns-svc/module/apis/aws/aws.go

63 lines
1.2 KiB
Go
Raw Normal View History

2019-05-02 03:51:48 +00:00
package aws
import (
"errors"
"git.trj.tw/golang/go-ddns-svc/module/config"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/route53"
)
// AWSClient -
type AWSClient struct {
2019-05-02 10:08:39 +00:00
Session *session.Session
Config *aws.Config
R53 *route53.Route53
2019-05-02 03:51:48 +00:00
}
var client *AWSClient
2019-05-02 10:08:39 +00:00
// Error messages
var (
ErrNoClient = errors.New("client not init")
)
2019-05-02 03:51:48 +00:00
// NewAWS -
func NewAWS() error {
conf := config.GetConfig()
awsConf := &aws.Config{}
awsConf.Region = aws.String("us-east-1")
var sess *session.Session
if conf.AWS.SharedConfig {
if len(conf.AWS.SharedName) == 0 {
return errors.New("aws shared config name empty")
}
awsConf.Credentials = credentials.NewSharedCredentials("", conf.AWS.SharedName)
} else {
awsConf.Credentials = credentials.NewStaticCredentials(conf.AWS.AccessKey, conf.AWS.SecretKey, "")
}
sess = session.New(awsConf)
client = &AWSClient{}
client.Session = sess
client.Config = awsConf
2019-05-02 10:08:39 +00:00
client.R53 = route53.New(client.Session)
2019-05-02 03:51:48 +00:00
return nil
}
2019-05-02 10:08:39 +00:00
// ZoneData -
type ZoneData struct {
ID *string
Name string
}
// QueryDomain -
func QueryDomain() (*ZoneData, error) {
return nil, nil
}