MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / New

Function New

plugins/destination/s3/client/client.go:52–187  ·  view source on GitHub ↗
(ctx context.Context, logger zerolog.Logger, s []byte, opts plugin.NewClientOptions)

Source from the content-addressed store, hash-verified

50}
51
52func New(ctx context.Context, logger zerolog.Logger, s []byte, opts plugin.NewClientOptions) (plugin.Client, error) {
53 c := &Client{
54 logger: logger.With().Str("module", "s3").Logger(),
55 syncID: opts.InvocationID,
56 initializedTables: make(map[string]string),
57 spec: &spec.Spec{},
58 }
59 if opts.NoConnection {
60 return c, nil
61 }
62
63 if err := json.Unmarshal(s, &c.spec); err != nil {
64 return nil, fmt.Errorf("failed to unmarshal s3 spec: %w", err)
65 }
66 if err := c.spec.Validate(); err != nil {
67 return nil, err
68 }
69 c.spec.SetDefaults()
70
71 if c.syncID == "" && c.spec.PathContainsSyncID() {
72 return nil, errors.New("path contains {{SYNC_ID}}. Upgrade your CLI to use this path variable")
73 }
74
75 filetypesClient, err := filetypes.NewClient(&c.spec.FileSpec)
76 if err != nil {
77 return nil, fmt.Errorf("failed to create filetypes client: %w", err)
78 }
79 c.Client = filetypesClient
80
81 configFns := []func(*config.LoadOptions) error{
82 config.WithDefaultRegion("us-east-1"),
83 config.WithRetryer(func() aws.Retryer {
84 return retry.NewStandard(func(so *retry.StandardOptions) {
85 so.MaxAttempts = *c.spec.MaxRetries
86 so.MaxBackoff = time.Duration(*c.spec.MaxBackoff) * time.Second
87 so.RateLimiter = ratelimit.None
88 })
89 }),
90 }
91
92 if c.spec.Credentials != nil && c.spec.Credentials.LocalProfile != "" {
93 configFns = append(configFns, config.WithSharedConfigProfile(c.spec.Credentials.LocalProfile))
94 }
95
96 cfg, err := config.LoadDefaultConfig(ctx, configFns...)
97 if err != nil {
98 return nil, fmt.Errorf("unable to load AWS SDK config: %w", err)
99 }
100
101 cfg.Region = c.spec.Region
102 if c.spec.AWSDebug {
103 cfg.ClientLogMode |= aws.LogRequestWithBody | aws.LogResponseWithBody
104 }
105
106 if c.spec.Credentials != nil && c.spec.Credentials.RoleARN != "" {
107 opts := make([]func(*stscreds.AssumeRoleOptions), 0, 1)
108
109 // default is 15 minutes. All roles allow for a minimum of 1 hour, some can be configured for up to 12 hours

Callers 1

testPluginCustomFunction · 0.70

Calls 8

ErrorfMethod · 0.80
PathContainsSyncIDMethod · 0.80
LoggerMethod · 0.45
ValidateMethod · 0.45
SetDefaultsMethod · 0.45
ErrorMethod · 0.45
StringMethod · 0.45
ReplacePathVariablesMethod · 0.45

Tested by 1

testPluginCustomFunction · 0.56