This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
factory.go
94 lines (84 loc) · 3.12 KB
/
factory.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package data
import (
"context"
"time"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/stow"
"github.com/flyteorg/stow/s3"
"github.com/flyteorg/flytestdlib/storage"
"github.com/aws/aws-sdk-go/aws"
"github.com/flyteorg/flyteadmin/pkg/common"
"github.com/flyteorg/flyteadmin/pkg/data/implementations"
"github.com/flyteorg/flyteadmin/pkg/data/interfaces"
)
type RemoteDataHandlerConfig struct {
CloudProvider common.CloudProvider
Retries int // Number of times to attempt to initialize a new config on failure.
Region string
SignedURLDurationMinutes int
SigningPrincipal string
RemoteDataStoreClient *storage.DataStore
}
type RemoteDataHandler interface {
GetRemoteURLInterface() interfaces.RemoteURLInterface
}
type remoteDataHandler struct {
remoteURL interfaces.RemoteURLInterface
}
func (r *remoteDataHandler) GetRemoteURLInterface() interfaces.RemoteURLInterface {
return r.remoteURL
}
func GetRemoteDataHandler(cfg RemoteDataHandlerConfig) RemoteDataHandler {
switch cfg.CloudProvider {
case common.AWS:
awsConfig := aws.NewConfig().WithRegion(cfg.Region).WithMaxRetries(cfg.Retries)
presignedURLDuration := time.Minute * time.Duration(cfg.SignedURLDurationMinutes)
return &remoteDataHandler{
remoteURL: implementations.NewAWSRemoteURL(awsConfig, presignedURLDuration),
}
case common.GCP:
signedURLDuration := time.Minute * time.Duration(cfg.SignedURLDurationMinutes)
return &remoteDataHandler{
remoteURL: implementations.NewGCPRemoteURL(cfg.SigningPrincipal, signedURLDuration),
}
case common.Local:
logger.Infof(context.TODO(), "setting up local signer ----- ")
// Since minio = aws s3, we are creating the same client but using the config primitives from aws
storageCfg := storage.GetConfig()
accessKeyID := ""
secret := ""
endpoint := ""
if len(storageCfg.Stow.Config) > 0 {
stowCfg := stow.ConfigMap(storageCfg.Stow.Config)
accessKeyID, _ = stowCfg.Config(s3.ConfigAccessKeyID)
secret, _ = stowCfg.Config(s3.ConfigSecretKey)
endpoint, _ = stowCfg.Config(s3.ConfigEndpoint)
} else {
accessKeyID = storageCfg.Connection.AccessKey
secret = storageCfg.Connection.SecretKey
endpoint = storageCfg.Connection.Endpoint.String()
}
logger.Infof(context.TODO(), "setting up local signer - %s, %s, %s", accessKeyID, secret, endpoint)
creds := credentials.NewStaticCredentials(accessKeyID, secret, "")
awsConfig := aws.NewConfig().
WithRegion(cfg.Region).
WithMaxRetries(cfg.Retries).
WithCredentials(creds).
WithEndpoint(endpoint).
WithDisableSSL(true).
WithS3ForcePathStyle(true)
presignedURLDuration := time.Minute * time.Duration(cfg.SignedURLDurationMinutes)
return &remoteDataHandler{
remoteURL: implementations.NewAWSRemoteURL(awsConfig, presignedURLDuration),
}
case common.None:
fallthrough
default:
logger.Infof(context.Background(),
"Using default noop remote url implementation for cloud provider type [%s]", cfg.CloudProvider)
return &remoteDataHandler{
remoteURL: implementations.NewNoopRemoteURL(*cfg.RemoteDataStoreClient),
}
}
}