-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ipfs/feat/pluggable-keystore
pluggable keystores
- Loading branch information
Showing
6 changed files
with
120 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package plugin | ||
|
||
import ( | ||
keystore "github.com/ipfs/go-ipfs/keystore" | ||
prompt "github.com/ipfs/go-prompt" | ||
) | ||
|
||
// PluginKeystore is an interface that can be implemented to new keystore | ||
// backends. | ||
type PluginKeystore interface { | ||
Plugin | ||
|
||
// KeystoreTypeName returns the the keystore's type. In addition to | ||
// loading the keystore plugin, the user must configure their go-ipfs | ||
// node to use the specified keystore backend. | ||
KeystoreTypeName() string | ||
|
||
// Open opens the keystore. Prompter may be nil if non-interactive. | ||
Open( | ||
repoPath string, | ||
config map[string]interface{}, | ||
prompter prompt.Prompter, | ||
) (keystore.Keystore, error) | ||
} |
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,52 @@ | ||
package fsrepo | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
keystore "github.com/ipfs/go-ipfs/keystore" | ||
|
||
prompt "github.com/ipfs/go-prompt" | ||
) | ||
|
||
type KeystoreConstructor func( | ||
repoPath string, | ||
cfg map[string]interface{}, | ||
prompter prompt.Prompter, | ||
) (keystore.Keystore, error) | ||
|
||
var keystores = map[string]KeystoreConstructor{ | ||
"memory": MemKeystoreFromConfig, | ||
"files": FSKeystoreFromConfig, | ||
} | ||
|
||
func AddKeystore(name string, ctor KeystoreConstructor) error { | ||
_, ok := keystores[name] | ||
if ok { | ||
return fmt.Errorf("keystore %q registered more than once", name) | ||
} | ||
keystores[name] = ctor | ||
return nil | ||
} | ||
|
||
func FSKeystoreFromConfig( | ||
repo string, | ||
cfg map[string]interface{}, | ||
_ prompt.Prompter, | ||
) (keystore.Keystore, error) { | ||
path, ok := cfg["path"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'path' field is missing or not a string") | ||
} | ||
return keystore.NewFSKeystore(filepath.Join(repo, path)) | ||
} | ||
|
||
// MemKeystoreFromConfig opens an in-memory keystore based on the current | ||
// config. | ||
func MemKeystoreFromConfig( | ||
_ string, | ||
_ map[string]interface{}, | ||
_ prompt.Prompter, | ||
) (keystore.Keystore, error) { | ||
return keystore.NewMemKeystore(), nil | ||
} |