-
-
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.
move postgres to plugins; test in head context with updated dependenc…
…ies; undo gx releases; address feedback; gx hashes will need to be updated once go-ipfs-config PR is merged and gx released"
- Loading branch information
Showing
7 changed files
with
155 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,3 @@ bin/tmp | |
vendor | ||
.tarball | ||
go-ipfs-source.tar.gz | ||
|
||
.idea |
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 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] | ||
then | ||
echo "Env variables not provided" | ||
echo "Usage: ./ipfs_postgres.sh <IPFS_PGHOST> <IPFS_PGUSER> <IPFS_PGDATABASE>" | ||
exit 1 | ||
fi | ||
|
||
export IPFS_PGHOST=$1 | ||
export IPFS_PGUSER=$2 | ||
export IPFS_PGDATABASE=$3 | ||
printf "${IPFS_PGUSER}@${IPFS_PGHOST} password:" | ||
stty -echo | ||
read IPFS_PGPASSWORD | ||
stty echo | ||
export IPFS_PGPASSWORD | ||
|
||
ipfs init --profile=postgresds |
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
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,126 @@ | ||
package postgresds | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/ipfs/go-ipfs/plugin" | ||
"github.com/ipfs/go-ipfs/repo" | ||
"github.com/ipfs/go-ipfs/repo/fsrepo" | ||
|
||
postgresdb "gx/ipfs/QmZmPKg1RKY2Cy5czKEBJTfDYzenbGww2pFNQKxLSKrPRB/sql-datastore/postgres" | ||
"gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir" | ||
) | ||
|
||
// Plugins is exported list of plugins that will be loaded | ||
var Plugins = []plugin.Plugin{ | ||
&postgresdsPlugin{}, | ||
} | ||
|
||
type postgresdsPlugin struct{} | ||
|
||
var _ plugin.PluginDatastore = (*postgresdsPlugin)(nil) | ||
|
||
func (*postgresdsPlugin) Name() string { | ||
return "ds-postgresds" | ||
} | ||
|
||
func (*postgresdsPlugin) Version() string { | ||
return "0.1.0" | ||
} | ||
|
||
func (*postgresdsPlugin) Init() error { | ||
return nil | ||
} | ||
|
||
func (*postgresdsPlugin) DatastoreTypeName() string { | ||
return "postgres" | ||
} | ||
|
||
type datastoreConfig struct { | ||
host string | ||
port string | ||
user string | ||
passfile string | ||
password string | ||
dbname string | ||
} | ||
|
||
// Returns a configuration stub for a postgres datastore from the given parameters | ||
func (*postgresdsPlugin) DatastoreConfigParser() fsrepo.ConfigFromMap { | ||
return func(params map[string]interface{}) (fsrepo.DatastoreConfig, error) { | ||
var c datastoreConfig | ||
var ok bool | ||
c.passfile, ok = params["passfile"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'passfile' field was not a string") | ||
} | ||
if c.passfile != "" { | ||
path, err := homedir.Expand(filepath.Clean(c.passfile)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
info, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
envVars := strings.Split(string(info), ":") | ||
if len(envVars) != 5 { | ||
return nil, fmt.Errorf("passfile at %s not of format: <IPFS_PGHOST>:<IPFS_PGPORT>:<IPFS_PGDATABASE>:<IPFS_PGUSER>:<IPFS_PGPASSWORD>", c.passfile) | ||
} | ||
c.host = envVars[0] | ||
c.port = envVars[1] | ||
c.dbname = envVars[2] | ||
c.user = envVars[3] | ||
c.password = envVars[4] | ||
return &c, nil | ||
} | ||
c.host, ok = params["host"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'path' field was not a string") | ||
} | ||
c.port, ok = params["port"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'port' field was not a string") | ||
} | ||
c.user, ok = params["user"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'user' field was not a string") | ||
} | ||
c.dbname, ok = params["dbname"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'dbname' field was not a string") | ||
} | ||
c.password, ok = params["password"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("'password' field was not a string") | ||
} | ||
return &c, nil | ||
} | ||
} | ||
|
||
func (c *datastoreConfig) DiskSpec() fsrepo.DiskSpec { | ||
return map[string]interface{}{ | ||
"type": "postgres", | ||
"user": c.user, | ||
"database": c.dbname, | ||
} | ||
} | ||
|
||
func (c *datastoreConfig) Create(path string) (repo.Datastore, error) { | ||
pg := postgresdb.Options{ | ||
Host: c.host, | ||
User: c.user, | ||
Database: c.dbname, | ||
Password: c.password, | ||
Port: c.port, | ||
} | ||
ds, err := pg.Create() | ||
if err != nil { | ||
fmt.Println("error loading pg: ", err) | ||
return ds, err | ||
} | ||
return ds, nil | ||
} |
d8f9c3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were the following issues with your Pull Request
We ask for a few features in the commit message for Open Source licensing hygiene and commit message clarity.
git commit --amend
can often help you quickly improve the commit message.Guidelines and a script are available to help in the long run.
Your feedback on GitCop is welcome on this issue.
This message was auto-generated by https://gitcop.com