Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 87f03b0

Browse files
committed
implement: ipfs key rename
Signed-off-by: Max Peng <[email protected]> (cherry picked from commit 2f50eed)
1 parent 32c19d8 commit 87f03b0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

key.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ type Key struct {
77
Name string
88
}
99

10+
type KeyRenameObject struct {
11+
Id string
12+
Now string
13+
Overwrite bool
14+
Was string
15+
}
16+
1017
type keyListOutput struct {
1118
Keys []*Key
1219
}
@@ -54,3 +61,14 @@ func (s *Shell) KeyList(ctx context.Context) ([]*Key, error) {
5461
}
5562
return out.Keys, nil
5663
}
64+
65+
// KeyRename Rename a keypair
66+
func (s *Shell) KeyRename(ctx context.Context, old string, new string, force bool) (*KeyRenameObject, error) {
67+
var out KeyRenameObject
68+
if err := s.Request("key/rename", old, new).
69+
Option("force", force).
70+
Exec(ctx, &out); err != nil {
71+
return nil, err
72+
}
73+
return &out, nil
74+
}

key_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ func TestKeyList(t *testing.T) {
2929
is.Equal(keys[0].Name, "self")
3030
is.NotNil(keys[0].Id)
3131
}
32+
33+
func TestKeyRename(t *testing.T) {
34+
is := is.New(t)
35+
s := NewShell(shellUrl)
36+
37+
key, err := s.KeyGen(context.Background(), "test1")
38+
is.Nil(err)
39+
40+
out, err := s.KeyRename(context.Background(), "test1", "test2", false)
41+
is.Nil(err)
42+
43+
is.Equal(out.Now, "test2")
44+
is.Equal(out.Was, "test1")
45+
is.Equal(out.Id, key.Id)
46+
is.False(out.Overwrite)
47+
}

0 commit comments

Comments
 (0)