-
Notifications
You must be signed in to change notification settings - Fork 35
/
client.go
32 lines (28 loc) · 884 Bytes
/
client.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
package ses
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/viant/endly"
"github.com/viant/endly/system/cloud/aws"
)
var clientKey = (*ses.SES)(nil)
func setClient(context *endly.Context, rawRequest map[string]interface{}) error {
config, err := aws.InitCredentials(context, rawRequest, clientKey)
if err != nil || config == nil {
return err
}
sess := session.Must(session.NewSession())
client := ses.New(sess, config)
return context.Put(clientKey, client)
}
func getClient(context *endly.Context) (interface{}, error) {
client := &ses.SES{}
if !context.Contains(clientKey) {
_ = setClient(context, map[string]interface{}{"client": 1})
}
if !context.GetInto(clientKey, &client) {
return nil, fmt.Errorf("unable to locate client %T, please add Credentials atribute ", client)
}
return client, nil
}