| 50 | } |
| 51 | |
| 52 | func 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 |