1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-04 13:27:14 +08:00

publish by path

This commit is contained in:
Etienne Laurin
2015-04-12 16:16:10 +00:00
parent 78bb5f4937
commit 233c39ff62
3 changed files with 48 additions and 13 deletions

View File

@ -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.
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:
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

View File

@ -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"

View File

@ -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