Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
4d4d7b8e
Commit
4d4d7b8e
authored
May 01, 2017
by
Michael Muré
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ipfs key rm
License: MIT Signed-off-by:
Michael Muré
<
batolettre@gmail.com
>
parent
f44ff30e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
core/commands/keystore.go
core/commands/keystore.go
+56
-0
test/sharness/t0165-keystore.sh
test/sharness/t0165-keystore.sh
+8
-0
No files found.
core/commands/keystore.go
View file @
4d4d7b8e
...
...
@@ -35,6 +35,7 @@ var KeyCmd = &cmds.Command{
Subcommands
:
map
[
string
]
*
cmds
.
Command
{
"gen"
:
KeyGenCmd
,
"list"
:
KeyListCmd
,
"rm"
:
KeyRmCmd
,
},
}
...
...
@@ -202,6 +203,61 @@ var KeyListCmd = &cmds.Command{
Type
:
KeyOutputList
{},
}
var
KeyRmCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Remove a keypair"
,
},
Arguments
:
[]
cmds
.
Argument
{
cmds
.
StringArg
(
"name"
,
true
,
false
,
"name of key to remove"
),
},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
n
,
err
:=
req
.
InvocContext
()
.
GetNode
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
name
:=
req
.
Arguments
()[
0
]
if
name
==
"self"
{
res
.
SetError
(
fmt
.
Errorf
(
"cannot remove key with name 'self'"
),
cmds
.
ErrNormal
)
return
}
removed
,
err
:=
n
.
Repo
.
Keystore
()
.
Get
(
name
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
err
=
n
.
Repo
.
Keystore
()
.
Delete
(
name
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
pubKey
:=
removed
.
GetPublic
()
pid
,
err
:=
peer
.
IDFromPublicKey
(
pubKey
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
&
KeyOutput
{
Name
:
name
,
Id
:
pid
.
Pretty
(),
})
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
v
:=
res
.
Output
()
.
(
*
KeyOutput
)
s
:=
fmt
.
Sprintf
(
"Removed key %s with Id: %s
\n
"
,
v
.
Name
,
v
.
Id
)
return
strings
.
NewReader
(
s
),
nil
},
},
Type
:
KeyOutput
{},
}
func
keyOutputListMarshaler
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
withId
,
_
,
_
:=
res
.
Request
()
.
Option
(
"l"
)
.
Bool
()
...
...
test/sharness/t0165-keystore.sh
View file @
4d4d7b8e
...
...
@@ -36,6 +36,14 @@ test_key_cmd() {
PeerID="$(ipfs config Identity.PeerID)"
ipfs key list -l | grep "$PeerID self"
'
test_expect_success
"key rm remove a key"
'
ipfs key rm foobarsa
echo bazed > list_exp &&
echo self >> list_exp
ipfs key list | sort > list_out &&
test_cmp list_exp list_out
'
}
test_key_cmd
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment