diff --git a/plugin/plugins/Rules.mk b/plugin/plugins/Rules.mk index 450383be967e75bce1d65dbe2a91c221bf51344c..8041d16f6100194baffc5f55ed96d985e78e6e8d 100644 --- a/plugin/plugins/Rules.mk +++ b/plugin/plugins/Rules.mk @@ -1,6 +1,6 @@ include mk/header.mk -$(d)_plugins:=$(d)/git +$(d)_plugins:=$(d)/git $(d)/swiftds $(d)_plugins_so:=$(addsuffix .so,$($(d)_plugins)) $(d)_plugins_main:=$(addsuffix /main/main.go,$($(d)_plugins)) diff --git a/plugin/plugins/swiftds/swiftds.go b/plugin/plugins/swiftds/swiftds.go new file mode 100644 index 0000000000000000000000000000000000000000..4a674dcda9c225a2f35d5e2ff2c8c2116c3f2f5a --- /dev/null +++ b/plugin/plugins/swiftds/swiftds.go @@ -0,0 +1,92 @@ +package swiftds + +import ( + "github.com/ipfs/go-ipfs/plugin" + "github.com/ipfs/go-ipfs/repo" + "github.com/ipfs/go-ipfs/repo/fsrepo" + + "github.com/ipfs/go-ds-swift" +) + +// Plugins is exported list of plugins that will be loaded +var Plugins = []plugin.Plugin{ + &swiftPlugin{}, +} + +type swiftPlugin struct{} + +var _ plugin.PluginDatastore = (*swiftPlugin)(nil) + +func (*swiftPlugin) Name() string { + return "ds-swift" +} + +func (*swiftPlugin) Version() string { + return "0.0.1" +} + +func (*swiftPlugin) Init() error { + return nil +} + +func (*swiftPlugin) DatastoreTypeName() string { + return "swiftds" +} + +func (*swiftPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap { + return func(conf map[string]interface{}) (fsrepo.DatastoreConfig, error) { + // v2 only for now + + c := &swiftConfig{} + + c.AuthUrl = conf["AuthUrl"].(string) + c.TenantId = conf["TenantId"].(string) + c.Tenant = conf["Tenant"].(string) + c.UserName = conf["UserName"].(string) + c.ApiKey = conf["ApiKey"].(string) + c.Region = conf["Region"].(string) + c.Container = conf["Container"].(string) + + return c, nil + } +} + +type swiftConfig struct { + AuthUrl string + TenantId string + Tenant string + + UserName string + ApiKey string // password + + Region string + Container string +} + +func (c *swiftConfig) DiskSpec() fsrepo.DiskSpec { + // TODO: what else can we strip from here + return map[string]interface{}{ + "AuthUrl": c.AuthUrl, + "TenantId": c.TenantId, + "Tenant": c.Tenant, + "UserName": c.UserName, + "ApiKey": c.ApiKey, + "Region": c.Region, + "Container": c.Container, + } +} + +func (c *swiftConfig) Create(path string) (repo.Datastore, error) { + conf := swiftds.Config{} + + conf.AuthUrl = c.AuthUrl + conf.TenantId = c.TenantId + conf.Tenant = c.Tenant + conf.UserName = c.UserName + conf.ApiKey = c.ApiKey + conf.Region = c.Region + conf.Container = c.Container + conf.AuthVersion = 2 + + return swiftds.NewSwiftDatastore(conf) +}