|
|
@@ -106,32 +106,9 @@ func New(ctx context.Context, store esv1beta1.GenericStore, kube client.Client,
|
|
|
config.WithRegion(prov.Region)
|
|
|
}
|
|
|
|
|
|
- var sess *session.Session
|
|
|
-
|
|
|
- // check if session can be reused
|
|
|
- tmpSession := SessionCache{
|
|
|
- Name: store.GetObjectMeta().Name,
|
|
|
- Namespace: namespace,
|
|
|
- Kind: store.GetTypeMeta().Kind,
|
|
|
- ResourceVersion: store.GetObjectMeta().ResourceVersion,
|
|
|
- }
|
|
|
-
|
|
|
- _, ok := sessions[tmpSession]
|
|
|
- if ok {
|
|
|
- log.Info("reusing aws session", "SecretStore", tmpSession.Name, "namespace", tmpSession.Namespace, "kind", tmpSession.Kind, "resourceversion", tmpSession.ResourceVersion)
|
|
|
- sess = sessions[tmpSession]
|
|
|
- } else {
|
|
|
- handlers := defaults.Handlers()
|
|
|
- handlers.Build.PushBack(request.WithAppendUserAgent("external-secrets"))
|
|
|
- sess, err = session.NewSessionWithOptions(session.Options{
|
|
|
- Config: *config,
|
|
|
- Handlers: handlers,
|
|
|
- SharedConfigState: session.SharedConfigDisable,
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- sessions[tmpSession] = sess
|
|
|
+ sess, err := getAWSSession(config, prov, store, namespace)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
}
|
|
|
|
|
|
if prov.Role != "" {
|
|
|
@@ -261,3 +238,55 @@ type STSProvider func(*session.Session) stsiface.STSAPI
|
|
|
func DefaultSTSProvider(sess *session.Session) stsiface.STSAPI {
|
|
|
return sts.New(sess)
|
|
|
}
|
|
|
+
|
|
|
+// getAWSSession check if an AWS session should be reused
|
|
|
+// it returns the aws session or an error.
|
|
|
+func getAWSSession(config *aws.Config, prov *esv1beta1.AWSProvider, store esv1beta1.GenericStore, namespace string) (*session.Session, error) {
|
|
|
+
|
|
|
+ sessionCache := prov.SessionCache
|
|
|
+
|
|
|
+ if sessionCache {
|
|
|
+
|
|
|
+ tmpSession := SessionCache{
|
|
|
+ Name: store.GetObjectMeta().Name,
|
|
|
+ Namespace: namespace,
|
|
|
+ Kind: store.GetTypeMeta().Kind,
|
|
|
+ ResourceVersion: store.GetObjectMeta().ResourceVersion,
|
|
|
+ }
|
|
|
+
|
|
|
+ _, ok := sessions[tmpSession]
|
|
|
+
|
|
|
+ if ok {
|
|
|
+ log.Info("reusing aws session", "SecretStore", tmpSession.Name, "namespace", tmpSession.Namespace, "kind", tmpSession.Kind, "resourceversion", tmpSession.ResourceVersion)
|
|
|
+ return sessions[tmpSession], nil
|
|
|
+ } else {
|
|
|
+ handlers := defaults.Handlers()
|
|
|
+ handlers.Build.PushBack(request.WithAppendUserAgent("external-secrets"))
|
|
|
+ sess, err := session.NewSessionWithOptions(session.Options{
|
|
|
+ Config: *config,
|
|
|
+ Handlers: handlers,
|
|
|
+ SharedConfigState: session.SharedConfigDisable,
|
|
|
+ })
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ sessions[tmpSession] = sess
|
|
|
+ return sess, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ handlers := defaults.Handlers()
|
|
|
+ handlers.Build.PushBack(request.WithAppendUserAgent("external-secrets"))
|
|
|
+ sess, err := session.NewSessionWithOptions(session.Options{
|
|
|
+ Config: *config,
|
|
|
+ Handlers: handlers,
|
|
|
+ SharedConfigState: session.SharedConfigDisable,
|
|
|
+ })
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return sess, nil
|
|
|
+ }
|
|
|
+}
|