MCPcopy Create free account
hub / github.com/asternic/wuzapi / InitializeS3Client

Method InitializeS3Client

s3manager.go:103–148  ·  view source on GitHub ↗

InitializeS3Client creates or updates S3 client for a user

(userID string, config *S3Config)

Source from the content-addressed store, hash-verified

101
102// InitializeS3Client creates or updates S3 client for a user
103func (m *S3Manager) InitializeS3Client(userID string, config *S3Config) error {
104 if !config.Enabled {
105 m.RemoveClient(userID)
106 return nil
107 }
108
109 m.mu.Lock()
110 defer m.mu.Unlock()
111
112 // Create custom credentials provider
113 credProvider := credentials.NewStaticCredentialsProvider(
114 config.AccessKey,
115 config.SecretKey,
116 "",
117 )
118
119 // Configure S3 client
120 cfg := aws.Config{
121 Region: config.Region,
122 Credentials: credProvider,
123 }
124
125 if config.Endpoint != "" {
126 customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
127 if service == s3.ServiceID {
128 return aws.Endpoint{
129 URL: config.Endpoint,
130 HostnameImmutable: config.PathStyle,
131 }, nil
132 }
133 return aws.Endpoint{}, &aws.EndpointNotFoundError{}
134 })
135 cfg.EndpointResolverWithOptions = customResolver
136 }
137
138 // Create S3 client
139 client := s3.NewFromConfig(cfg, func(o *s3.Options) {
140 o.UsePathStyle = config.PathStyle
141 })
142
143 m.clients[userID] = client
144 m.configs[userID] = config
145
146 log.Info().Str("userID", userID).Str("bucket", config.Bucket).Msg("S3 client initialized")
147 return nil
148}
149
150// RemoveClient removes S3 client for a user
151func (m *S3Manager) RemoveClient(userID string) {

Callers 5

EnsureClientFromDBMethod · 0.95
AddUserMethod · 0.80
EditUserMethod · 0.80
ConfigureS3Method · 0.80
TestS3ConnectionMethod · 0.80

Calls 1

RemoveClientMethod · 0.95

Tested by

no test coverage detected