Commit 2fa43ce4 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

ipfs name cmd improvements

- cleaned up cmd help
- ipfs name publish [<name>] <ref>
- ipfs name resolve [<name>]
- publish validates <ref>
- both validate n args
parent 6ac11702
......@@ -8,11 +8,43 @@ import (
)
var cmdIpfsName = &commander.Command{
UsageLine: "name",
Short: "Ipfs namespace manipulation tools.",
Long: `ipfs name [publish|resolve] <ref/hash>`,
Run: addCmd,
Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
UsageLine: "name [publish | resolve]",
Short: "ipfs namespace (ipns) tool",
Long: `ipfs name - Get/Set ipfs config values.
ipfs name publish [<name>] <ref> - Assign the <ref> to <name>
ipfs name resolve [<name>] - Resolve the <ref> value of <name>
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In both publish
and resolve, the default value of <name> is your own identity public key.
Examples:
Publish a <ref> to your identity name:
> ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Publish a <ref> to another public key:
> ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve the value of your identity:
> ipfs name resolve
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve te value of another name:
> ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`,
Run: addCmd,
Flag: *flag.NewFlagSet("ipfs-name", flag.ExitOnError),
Subcommands: []*commander.Command{
cmdIpfsPub,
cmdIpfsResolve,
......
......@@ -8,22 +8,34 @@ import (
var cmdIpfsPub = &commander.Command{
UsageLine: "publish",
Short: "Publish an object to ipns under your key.",
Long: `ipfs publish <path> - Publish object to ipns.
Short: "publish a <ref> to ipns.",
Long: `ipfs publish [<name>] <ref> - publish a <ref> to ipns.
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In publish, the
default value of <name> is your own identity public key.
Examples:
Publish a <ref> to your identity name:
> ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Publish a <ref> to another public key:
> ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`,
Run: pubCmd,
Flag: *flag.NewFlagSet("ipfs-publish", flag.ExitOnError),
}
func init() {
cmdIpfsPub.Flag.String("k", "", "Specify key to use for publishing.")
}
var pubCmd = makeCommand(command{
name: "publish",
args: 1,
flags: []string{"k"},
flags: nil,
online: true,
cmdFn: commands.Publish,
})
......@@ -8,8 +8,25 @@ import (
var cmdIpfsResolve = &commander.Command{
UsageLine: "resolve",
Short: "resolve an ipns link to a hash",
Long: `ipfs resolve <hash>... - Resolve hash.
Short: "resolve an ipns name to a <ref>",
Long: `ipfs resolve [<name>] - Resolve an ipns name to a <ref>.
IPNS is a PKI namespace, where names are the hashes of public keys, and
the private key enables publishing new (signed) values. In resolve, the
default value of <name> is your own identity public key.
Examples:
Resolve the value of your identity:
> ipfs name resolve
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Resolve te value of another name:
> ipfs name resolve QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n
QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
`,
Run: resolveCmd,
......@@ -18,7 +35,7 @@ var cmdIpfsResolve = &commander.Command{
var resolveCmd = makeCommand(command{
name: "resolve",
args: 1,
args: 0,
flags: nil,
online: true,
cmdFn: commands.Resolve,
......
......@@ -13,14 +13,32 @@ import (
func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
log.Debug("Begin Publish")
if n.Identity == nil {
return errors.New("Identity not loaded!")
}
// name := ""
ref := ""
switch len(args) {
case 2:
// name = args[0]
ref = args[1]
return errors.New("keychains not yet implemented")
case 1:
// name = n.Identity.ID.String()
ref = args[0]
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
// later, n.Keychain.Get(name).PrivKey
k := n.Identity.PrivKey
pub := nsys.NewRoutingPublisher(n.Routing)
err := pub.Publish(k, args[0])
err := pub.Publish(k, ref)
if err != nil {
return err
}
......@@ -29,7 +47,7 @@ func Publish(n *core.IpfsNode, args []string, opts map[string]interface{}, out i
if err != nil {
return err
}
fmt.Fprintf(out, "published mapping %s to %s\n", u.Key(hash), args[0])
fmt.Fprintf(out, "published name %s to %s\n", u.Key(hash), ref)
return nil
}
package commands
import (
"errors"
"fmt"
"io"
......@@ -8,7 +9,23 @@ import (
)
func Resolve(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
res, err := n.Namesys.Resolve(args[0])
name := ""
switch len(args) {
case 1:
name = args[0]
case 0:
if n.Identity == nil {
return errors.New("Identity not loaded!")
}
name = n.Identity.ID.String()
default:
return fmt.Errorf("Publish expects 1 or 2 args; got %d.", len(args))
}
res, err := n.Namesys.Resolve(name)
if err != nil {
return err
}
......
package namesys
import (
"fmt"
"time"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
ci "github.com/jbenet/go-ipfs/crypto"
routing "github.com/jbenet/go-ipfs/routing"
......@@ -25,6 +27,13 @@ func NewRoutingPublisher(route routing.IpfsRouting) Publisher {
// Publish implements Publisher. Accepts a keypair and a value,
func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error {
log.Debug("namesys: Publish %s", value)
// validate `value` is a ref (multihash)
_, err := mh.FromB58String(value)
if err != nil {
return fmt.Errorf("publish value must be str multihash. %v", err)
}
ctx := context.TODO()
data, err := createRoutingEntryData(k, value)
if err != nil {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment