提交 97e1c953 作者: Juan Batiz-Benet

Merge pull request #1063 from AtnNn/publish-path

Publish by path
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
core "github.com/ipfs/go-ipfs/core" core "github.com/ipfs/go-ipfs/core"
nsys "github.com/ipfs/go-ipfs/namesys" nsys "github.com/ipfs/go-ipfs/namesys"
crypto "github.com/ipfs/go-ipfs/p2p/crypto" crypto "github.com/ipfs/go-ipfs/p2p/crypto"
path "github.com/ipfs/go-ipfs/path"
u "github.com/ipfs/go-ipfs/util" u "github.com/ipfs/go-ipfs/util"
) )
...@@ -32,12 +33,12 @@ default value of <name> is your own identity public key. ...@@ -32,12 +33,12 @@ default value of <name> is your own identity public key.
Examples: Examples:
Publish a <ref> to your identity name: Publish an <ipfs-path> to your identity name:
> ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy > ipfs name publish /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
Publish a <ref> to another public key: Publish an <ipfs-path> to another public key (not implemented):
> ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
...@@ -71,21 +72,32 @@ Publish a <ref> to another public key: ...@@ -71,21 +72,32 @@ Publish a <ref> to another public key:
return return
} }
// name := "" var pstr string
ref := ""
switch len(args) { switch len(args) {
case 2: case 2:
// name = args[0] // name = args[0]
ref = args[1] pstr = args[1]
res.SetError(errors.New("keychains not yet implemented"), cmds.ErrNormal) res.SetError(errors.New("keychains not yet implemented"), cmds.ErrNormal)
case 1: case 1:
// name = n.Identity.ID.String() // name = n.Identity.ID.String()
ref = args[0] pstr = args[0]
}
node, err := n.Resolver.ResolvePath(path.FromString(pstr))
if err != nil {
res.SetError(fmt.Errorf("failed to resolve path: %v", err), cmds.ErrNormal)
return
}
key, err := node.Key()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
} }
// TODO n.Keychain.Get(name).PrivKey // TODO n.Keychain.Get(name).PrivKey
output, err := publish(n, n.PrivateKey, ref) output, err := publish(n, n.PrivateKey, key.Pretty())
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# thus they can be defined + changed in one place # thus they can be defined + changed in one place
HASH_WELCOME_DOCS="Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj" HASH_WELCOME_DOCS="Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj"
HASH_HELP_PAGE="QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7"
HASH_EMPTY_DIR="QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" HASH_EMPTY_DIR="QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
...@@ -10,24 +10,46 @@ test_description="Test ipfs repo operations" ...@@ -10,24 +10,46 @@ test_description="Test ipfs repo operations"
test_init_ipfs test_init_ipfs
# test publishing a hash
test_expect_success "'ipfs name publish' succeeds" ' test_expect_success "'ipfs name publish' succeeds" '
PEERID=`ipfs id -format="<id>"` && PEERID=`ipfs id -format="<id>"` &&
HASH=QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB && ipfs name publish "$HASH_WELCOME_DOCS" >publish_out
ipfs name publish $HASH > publish_out
' '
test_expect_success "publish output looks good" ' test_expect_success "publish output looks good" '
echo Published name $PEERID to $HASH > expected1 && echo "Published name $PEERID to $HASH_WELCOME_DOCS" >expected1 &&
test_cmp publish_out expected1 test_cmp publish_out expected1
' '
test_expect_success "'ipfs name resolve' succeeds" ' test_expect_success "'ipfs name resolve' succeeds" '
ipfs name resolve $PEERID > output ipfs name resolve "$PEERID" >output
' '
test_expect_success "resolve output looks good" ' test_expect_success "resolve output looks good" '
printf "%s" $HASH > expected2 && printf "%s" "$HASH_WELCOME_DOCS" >expected2 &&
test_cmp output expected2 test_cmp output expected2
' '
# now test with a path
test_expect_success "'ipfs name publish' succeeds" '
PEERID=`ipfs id -format="<id>"` &&
ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
'
test_expect_success "publish a path looks good" '
echo "Published name $PEERID to $HASH_HELP_PAGE" >expected3 &&
test_cmp publish_out expected3
'
test_expect_success "'ipfs name resolve' succeeds" '
ipfs name resolve "$PEERID" >output
'
test_expect_success "resolve output looks good" '
printf "%s" "$HASH_HELP_PAGE" >expected4 &&
test_cmp output expected4
'
test_done test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论