-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package persistence | ||
|
||
type Persistence struct { | ||
storage PersistenceStorage | ||
} | ||
|
||
func (c *Persistence) Save(tenant_id string, key string, data []byte) error { | ||
return nil | ||
} | ||
|
||
func (c *Persistence) Load(tenant_id string, key string) ([]byte, error) { | ||
return nil, nil | ||
} | ||
|
||
func (c *Persistence) Delete(tenant_id string, key string) error { | ||
return nil | ||
} | ||
|
||
func (c *Persistence) Scan(tenant_id string, prefix string, cursor int64) ([]string, error) { | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package persistence | ||
|
||
import ( | ||
"github.com/langgenius/dify-plugin-daemon/internal/types/app" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/log" | ||
) | ||
|
||
func InitPersistence(config *app.Config) *Persistence { | ||
if config.PersistenceStorageType == "s3" { | ||
s3, err := NewS3Wrapper( | ||
config.PersistenceStorageS3Region, | ||
config.PersistenceStorageS3AccessKey, | ||
config.PersistenceStorageS3SecretKey, | ||
config.PersistenceStorageS3Bucket, | ||
) | ||
if err != nil { | ||
log.Panic("Failed to initialize S3 wrapper: %v", err) | ||
} | ||
|
||
return &Persistence{ | ||
storage: s3, | ||
} | ||
} | ||
|
||
return &Persistence{ | ||
storage: NewLocalWrapper(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package persistence | ||
|
||
type LocalWrapper struct{} | ||
|
||
func NewLocalWrapper() *LocalWrapper { | ||
return &LocalWrapper{} | ||
} | ||
|
||
func (l *LocalWrapper) Save(tenant_id string, key string, data []byte) error { | ||
return nil | ||
} | ||
|
||
func (l *LocalWrapper) Load(tenant_id string, key string) ([]byte, error) { | ||
return nil, nil | ||
} | ||
|
||
func (l *LocalWrapper) Delete(tenant_id string, key string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package persistence | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/credentials" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
"github.com/langgenius/dify-plugin-daemon/internal/utils/log" | ||
) | ||
|
||
type S3Wrapper struct { | ||
client *s3.Client | ||
bucket string | ||
} | ||
|
||
func NewS3Wrapper(region string, access_key string, secret_key string, bucket string) (*S3Wrapper, error) { | ||
c, err := config.LoadDefaultConfig( | ||
context.TODO(), | ||
config.WithRegion(region), | ||
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( | ||
access_key, | ||
secret_key, | ||
"", | ||
)), | ||
) | ||
if err != nil { | ||
log.Panic("Failed to load AWS S3 config: %v", err) | ||
} | ||
|
||
s3_client := s3.NewFromConfig(c) | ||
log.Info("AWS S3 config loaded") | ||
|
||
// check | ||
_, err = s3_client.HeadBucket(context.TODO(), &s3.HeadBucketInput{ | ||
Bucket: aws.String(bucket), | ||
}) | ||
if err != nil { | ||
log.Panic("Failed to head bucket: %v", err) | ||
} | ||
|
||
return &S3Wrapper{ | ||
client: s3_client, | ||
bucket: bucket, | ||
}, nil | ||
} | ||
|
||
func (s *S3Wrapper) Save(tenant_id string, key string, data []byte) error { | ||
return nil | ||
} | ||
|
||
func (s *S3Wrapper) Load(tenant_id string, key string) ([]byte, error) { | ||
return nil, nil | ||
} | ||
|
||
func (s *S3Wrapper) Delete(tenant_id string, key string) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package persistence | ||
|
||
type PersistenceStorage interface { | ||
Save(tenant_id string, key string, data []byte) error | ||
Load(tenant_id string, key string) ([]byte, error) | ||
Delete(tenant_id string, key string) error | ||
} |
Oops, something went wrong.