@@ -2,13 +2,14 @@ package plugin
22
33import (
44 "fmt"
5- "strings"
65
76 ddbds "github.com/Vanssh-k/go-ds-dynamodb"
87 "github.com/aws/aws-sdk-go/aws"
98 "github.com/aws/aws-sdk-go/aws/credentials"
109 "github.com/aws/aws-sdk-go/aws/session"
1110 "github.com/aws/aws-sdk-go/service/dynamodb"
11+ "github.com/ipfs/go-datastore"
12+ mount "github.com/ipfs/go-datastore/mount"
1213 "github.com/ipfs/kubo/plugin"
1314 "github.com/ipfs/kubo/repo"
1415 "github.com/ipfs/kubo/repo/fsrepo"
@@ -38,17 +39,11 @@ func (p *DDBPlugin) DatastoreTypeName() string {
3839
3940func (p * DDBPlugin ) DatastoreConfigParser () fsrepo.ConfigFromMap {
4041 return func (m map [string ]interface {}) (fsrepo.DatastoreConfig , error ) {
41- table , ok := m ["table" ].(string )
42- if ! ok || table == "" {
43- return nil , fmt .Errorf ("ddbds: no table specified" )
44- }
45-
4642 accessKey , _ := m ["accessKey" ].(string )
4743 secretKey , _ := m ["secretKey" ].(string )
4844 region , _ := m ["region" ].(string )
4945
5046 return & DDBConfig {
51- Table : table ,
5247 AccessKey : accessKey ,
5348 SecretKey : secretKey ,
5449 Region : region ,
@@ -57,30 +52,19 @@ func (p *DDBPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap {
5752}
5853
5954type DDBConfig struct {
60- Table string
6155 AccessKey string
6256 SecretKey string
6357 Region string
6458}
6559
6660func (c * DDBConfig ) DiskSpec () fsrepo.DiskSpec {
6761 return fsrepo.DiskSpec {
68- "table" : c .Table ,
6962 "accessKey" : c .AccessKey ,
7063 "secretKey" : c .SecretKey ,
7164 "region" : c .Region ,
7265 }
7366}
7467
75- // Extracts the Sort Key from DSKey
76- func extractSortKey (dsKey string ) (string , error ) {
77- parts := strings .SplitN (dsKey , "/" , 3 )
78- if len (parts ) < 3 {
79- return "" , fmt .Errorf ("invalid DSKey format: %s" , dsKey )
80- }
81- return parts [2 ], nil
82- }
83-
8468func (c * DDBConfig ) Create (path string ) (repo.Datastore , error ) {
8569 awsConfig := & aws.Config {
8670 Region : aws .String (c .Region ),
@@ -97,12 +81,26 @@ func (c *DDBConfig) Create(path string) (repo.Datastore, error) {
9781
9882 ddbClient := dynamodb .New (sess )
9983
100- ddbDS := ddbds .New (
101- ddbClient ,
102- c .Table ,
103- ddbds .WithPartitionkey ("PartitionKey" ),
104- ddbds .WithSortKey ("SortKey" ),
105- )
84+ // Mount different namespaces to different tables
85+ ddbDS := mount .New ([]mount.Mount {
86+ {
87+ // Providers datastore with partition & sort keys
88+ Prefix : datastore .NewKey ("/providers" ),
89+ Datastore : ddbds .New (ddbClient , "datastore-providers" ,
90+ ddbds .WithPartitionkey ("ContentHash" ), ddbds .WithSortKey ("ProviderID" )),
91+ },
92+ {
93+ // Pins datastore (without sort key)
94+ Prefix : datastore .NewKey ("/pins" ),
95+ Datastore : ddbds .New (ddbClient , "datastore-pins" ,
96+ ddbds .WithPartitionkey ("Hash" )),
97+ },
98+ {
99+ // Default datastore for everything else
100+ Prefix : datastore .NewKey ("/" ),
101+ Datastore : ddbds .New (ddbClient , "datastore-table" ),
102+ },
103+ })
106104
107105 return ddbDS , nil
108106}
0 commit comments