Use a default data directory.
This commit is contained in:
parent
63226afd23
commit
83a6194b7c
28
README.md
28
README.md
|
@ -6,34 +6,38 @@ A single executable to manage a Pigeon node.
|
||||||
|
|
||||||
Don't use the Go version yet. If you want something stable, there is a [Ruby version that is feature complete](https://tildegit.org/PigeonProtocolConsortium/Pigeon-Ruby).
|
Don't use the Go version yet. If you want something stable, there is a [Ruby version that is feature complete](https://tildegit.org/PigeonProtocolConsortium/Pigeon-Ruby).
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
|
||||||
|
By default, data is stored in `~/.pigeon`.
|
||||||
|
You can override this value by specifying a `PIGEON_PATH` ENV var.
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- [ ] Finish http://go-database-sql.org/nulls.html
|
|
||||||
- [ ] Fix go module nonsense. Read a tut or sth https://thenewstack.io/understanding-golang-packages/
|
|
||||||
- [ ] Add a real testing lib to DRY things up.
|
- [ ] Add a real testing lib to DRY things up.
|
||||||
|
- [ ] Figure out a system for where to place the default data storage directory
|
||||||
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
|
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
|
||||||
- [ ] Finish all the things below:
|
- [ ] Finish all the things below:
|
||||||
|
|
||||||
|Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|
|Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|
||||||
|-----|------------|--------|---------------|-----------|
|
|-----|------------|--------|---------------|-----------|
|
||||||
| |show |peers | | |
|
|
||||||
| |show |peers | --blocked | |
|
|
||||||
| |unfollow |peer | | |
|
|
||||||
| |follow |peer | user mhash | |
|
|
||||||
| |unblock |peer | user mhash | |
|
|
||||||
| |block |peer | user mhash | |
|
| |block |peer | user mhash | |
|
||||||
| |show |blob | | |
|
|
||||||
| |create |blob | file path | |
|
| |create |blob | file path | |
|
||||||
| |create |blob | pipe | |
|
| |create |blob | pipe | |
|
||||||
| |create |draft | | |
|
|
||||||
| |update |draft | --key=? | --value=? |
|
|
||||||
| |show |draft | | |
|
|
||||||
| |publish |draft | | |
|
|
||||||
| |create |bundle | | |
|
| |create |bundle | | |
|
||||||
|
| |create |draft | | |
|
||||||
|
| |find |blob | | |
|
||||||
| |find |message | --all | |
|
| |find |message | --all | |
|
||||||
| |find |message | --last | |
|
| |find |message | --last | |
|
||||||
|
| |follow |peer | user mhash | |
|
||||||
| |ingest |bundle | | |
|
| |ingest |bundle | | |
|
||||||
|
| |publish |draft | | |
|
||||||
|
| |show |draft | | |
|
||||||
| |show |message | message mhash | |
|
| |show |message | message mhash | |
|
||||||
|
| |show |peers | | |
|
||||||
|
| |show |peers | --blocked | |
|
||||||
|
| |unblock |peer | user mhash | |
|
||||||
|
| |unfollow |peer | | |
|
||||||
|
| |update |draft | --key=? | --value=? |
|
||||||
| X |show |identity| | |
|
| X |show |identity| | |
|
||||||
| X |create |identity| | |
|
| X |create |identity| | |
|
||||||
| X |help | | | |
|
| X |help | | | |
|
||||||
|
|
3
build.sh
3
build.sh
|
@ -3,3 +3,6 @@
|
||||||
cd project
|
cd project
|
||||||
go build --o=../pigeon-cli
|
go build --o=../pigeon-cli
|
||||||
cd -
|
cd -
|
||||||
|
PIGEON_PATH="."
|
||||||
|
./pigeon-cli version
|
||||||
|
./pigeon-cli show identity
|
||||||
|
|
|
@ -7,15 +7,18 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ======== LEVEL ZERO =====================================
|
// CLI: `pigeon`
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "pigeon",
|
Use: "pigeon",
|
||||||
Short: "Pigeon is a peer-to-peer database for offline systems.",
|
Short: "Pigeon is a peer-to-peer database for offline systems.",
|
||||||
Long: `Pigeon is an off-grid, serverless, peer-to-peer
|
Long: `Pigeon is an off-grid, serverless, peer-to-peer
|
||||||
database for building software that works on poor internet
|
database for building software that works on poor internet
|
||||||
connections, or entirely offline.`,
|
connections, or entirely offline.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CLI: `pigeon version`
|
||||||
var versionCmd = &cobra.Command{
|
var versionCmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the software version.",
|
Short: "Print the software version.",
|
||||||
|
@ -24,20 +27,21 @@ var versionCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======== LEVEL ONE ======================================
|
// CLI: `pigeon show [resource]`
|
||||||
var showCmd = &cobra.Command{
|
var showCmd = &cobra.Command{
|
||||||
Use: "show [resource]",
|
Use: "show [resource]",
|
||||||
Short: "Show various resources",
|
Short: "Show various resources",
|
||||||
Long: `Shows resources such as blobs, drafts, identities, messages, peers, etc..`,
|
Long: `Shows resources such as blobs, drafts, identities, messages, peers, etc..`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CLI: `pigeon create [resource]`
|
||||||
var createCmd = &cobra.Command{
|
var createCmd = &cobra.Command{
|
||||||
Use: "create [resource]",
|
Use: "create [resource]",
|
||||||
Short: "Create various resources",
|
Short: "Create various resources",
|
||||||
Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`,
|
Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======== LEVEL TWO ======================================
|
// CLI: `pigeon create identity`
|
||||||
var createIdentityCmd = &cobra.Command{
|
var createIdentityCmd = &cobra.Command{
|
||||||
Use: "identity",
|
Use: "identity",
|
||||||
Short: "Create a new identity.",
|
Short: "Create a new identity.",
|
||||||
|
@ -47,6 +51,7 @@ var createIdentityCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CLI: `pigeon show identity`
|
||||||
var showIdentityCmd = &cobra.Command{
|
var showIdentityCmd = &cobra.Command{
|
||||||
Use: "identity",
|
Use: "identity",
|
||||||
Short: "Show current user identity.",
|
Short: "Show current user identity.",
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"log"
|
"log"
|
||||||
|
"path"
|
||||||
|
|
||||||
"modernc.org/ql"
|
"modernc.org/ql"
|
||||||
)
|
)
|
||||||
|
@ -26,8 +27,9 @@ var migrations = []migration{
|
||||||
|
|
||||||
func openDB() *sql.DB {
|
func openDB() *sql.DB {
|
||||||
ql.RegisterDriver()
|
ql.RegisterDriver()
|
||||||
|
pigeonPath := maybeSetupPigeonDir()
|
||||||
db, err0 := sql.Open("ql", "file://testdata/secret.db")
|
dbPath := path.Join(pigeonPath, "db")
|
||||||
|
db, err0 := sql.Open("ql", dbPath)
|
||||||
|
|
||||||
if err0 != nil {
|
if err0 != nil {
|
||||||
log.Fatalf("failed to open db: %s", err0)
|
log.Fatalf("failed to open db: %s", err0)
|
||||||
|
|
|
@ -11,3 +11,7 @@ var encoder = base32.NewEncoding(alphabet).WithPadding(base32.NoPadding)
|
||||||
func B32Encode(data []byte) string {
|
func B32Encode(data []byte) string {
|
||||||
return encoder.EncodeToString(data)
|
return encoder.EncodeToString(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func encodeUserMhash(pubKey []byte) string {
|
||||||
|
return UserSigil + B32Encode(pubKey)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/mitchellh/go-homedir"
|
||||||
|
)
|
||||||
|
|
||||||
|
func maybeSetupPigeonDir() string {
|
||||||
|
var pigeonDataDir string
|
||||||
|
customPath, hasCustomPath := os.LookupEnv("PIGEON_PATH")
|
||||||
|
if hasCustomPath {
|
||||||
|
pigeonDataDir = customPath
|
||||||
|
} else {
|
||||||
|
home, err := homedir.Dir()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Home directory resolution error %s", err)
|
||||||
|
}
|
||||||
|
pigeonDataDir = path.Join(home, ".pigeon")
|
||||||
|
}
|
||||||
|
os.MkdirAll(pigeonDataDir, 0700)
|
||||||
|
return pigeonDataDir
|
||||||
|
}
|
|
@ -37,8 +37,3 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
|
||||||
SetConfig("private_key", priv)
|
SetConfig("private_key", priv)
|
||||||
return pub, priv
|
return pub, priv
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeUserMhash(pubKey []byte) string {
|
|
||||||
sigil := "USER."
|
|
||||||
return sigil + B32Encode(pubKey)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue