s3.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package persistence
  2. import (
  3. "context"
  4. "github.com/aws/aws-sdk-go-v2/aws"
  5. "github.com/aws/aws-sdk-go-v2/config"
  6. "github.com/aws/aws-sdk-go-v2/credentials"
  7. "github.com/aws/aws-sdk-go-v2/service/s3"
  8. "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
  9. )
  10. type S3Wrapper struct {
  11. client *s3.Client
  12. bucket string
  13. }
  14. func NewS3Wrapper(region string, access_key string, secret_key string, bucket string) (*S3Wrapper, error) {
  15. c, err := config.LoadDefaultConfig(
  16. context.TODO(),
  17. config.WithRegion(region),
  18. config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
  19. access_key,
  20. secret_key,
  21. "",
  22. )),
  23. )
  24. if err != nil {
  25. log.Panic("Failed to load AWS S3 config: %v", err)
  26. }
  27. s3_client := s3.NewFromConfig(c)
  28. log.Info("AWS S3 config loaded")
  29. // check
  30. _, err = s3_client.HeadBucket(context.TODO(), &s3.HeadBucketInput{
  31. Bucket: aws.String(bucket),
  32. })
  33. if err != nil {
  34. log.Panic("Failed to head bucket: %v", err)
  35. }
  36. return &S3Wrapper{
  37. client: s3_client,
  38. bucket: bucket,
  39. }, nil
  40. }
  41. func (s *S3Wrapper) Save(tenant_id string, plugin_checksum string, key string, data []byte) error {
  42. return nil
  43. }
  44. func (s *S3Wrapper) Load(tenant_id string, plugin_checksum string, key string) ([]byte, error) {
  45. return nil, nil
  46. }
  47. func (s *S3Wrapper) Delete(tenant_id string, plugin_checksum string, key string) error {
  48. return nil
  49. }