ipfs key export output keys with .key extension by default
Adin Schmahmann committed
Aug 3, 2020 at 17:28 UTC
fab3a3578d8f5f9b9de4a262a6015d0bf210429b
2 files changed
+19
-12
core/commands/keystore.go
+9
-2
@@ -6,6 +6,8 @@ import (
6
"io"
7
"io/ioutil"
8
"os"
9
+ "path/filepath"
10
+ "strings"
11
"text/tabwriter"
12
13
cmds "github.com/ipfs/go-ipfs-cmds"
@@ -157,7 +159,7 @@ var keyExportCmd = &cmds.Command{
159
ShortDescription: `
160
Exports a named libp2p key to disk.
161
160
-By default, the output will be stored at './<key-name>', but an alternate
162
+By default, the output will be stored at './<key-name>.key', but an alternate
163
path can be specified with '--output=<path>' or '-o=<path>'.
164
`,
165
},
@@ -211,7 +213,12 @@ path can be specified with '--output=<path>' or '-o=<path>'.
213
return e.New(e.TypeErr(outReader, v))
214
}
215
214
- outPath := getOutPath(req)
216
+ outPath, _ := req.Options[outputOptionName].(string)
217
+ if outPath == "" {
218
+ trimmed := strings.TrimRight(fmt.Sprintf("%s.key", req.Arguments[0]), "/")
219
+ _, outPath = filepath.Split(trimmed)
220
+ outPath = filepath.Clean(outPath)
221
+ }
222
223
// create file
224
file, err := os.Create(outPath)
test/sharness/t0165-keystore.sh
+10
-10
@@ -19,8 +19,8 @@ test_check_rsa2048_b58mh_peerid $PEERID
19
20
test_expect_success "test RSA key sk export format" '
21
ipfs key export key_rsa &&
22
-test_check_rsa2048_sk key_rsa &&
23
-rm key_rsa
22
+test_check_rsa2048_sk key_rsa.key &&
23
+rm key_rsa.key
24
'
25
26
test_expect_success "test RSA key B36CID multihash format" '
@@ -36,8 +36,8 @@ test_check_ed25519_b36cid_peerid $PEERID
36
37
test_expect_success "test ED25519 key sk export format" '
38
ipfs key export key_ed25519 &&
39
-test_check_ed25519_sk key_ed25519 &&
40
-rm key_ed25519
39
+test_check_ed25519_sk key_ed25519.key &&
40
+rm key_ed25519.key
41
'
42
43
test_expect_success "test ED25519 key B36CID multihash format" '
@@ -61,22 +61,22 @@ ipfs key rm key_ed25519
61
test_expect_success "export and import rsa key" '
62
ipfs key export generated_rsa_key &&
63
ipfs key rm generated_rsa_key &&
64
- ipfs key import generated_rsa_key generated_rsa_key > roundtrip_rsa_key_id &&
64
+ ipfs key import generated_rsa_key generated_rsa_key.key > roundtrip_rsa_key_id &&
65
test_cmp rsa_key_id roundtrip_rsa_key_id
66
'
67
68
test_expect_success "export and import ed25519 key" '
69
ipfs key export generated_ed25519_key &&
70
ipfs key rm generated_ed25519_key &&
71
- ipfs key import generated_ed25519_key generated_ed25519_key > roundtrip_ed25519_key_id &&
71
+ ipfs key import generated_ed25519_key generated_ed25519_key.key > roundtrip_ed25519_key_id &&
72
test_cmp ed25519_key_id roundtrip_ed25519_key_id
73
'
74
75
test_expect_success "test export file option" '
76
ipfs key export generated_rsa_key -o=named_rsa_export_file &&
77
- test_cmp generated_rsa_key named_rsa_export_file &&
77
+ test_cmp generated_rsa_key.key named_rsa_export_file &&
78
ipfs key export generated_ed25519_key -o=named_ed25519_export_file &&
79
- test_cmp generated_ed25519_key named_ed25519_export_file
79
+ test_cmp generated_ed25519_key.key named_ed25519_export_file
80
'
81
82
test_expect_success "key export can't export self" '
@@ -89,10 +89,10 @@ ipfs key rm key_ed25519
89
test_expect_success "key import can't import self" '
90
ipfs key gen overwrite_self_import &&
91
ipfs key export overwrite_self_import &&
92
- test_must_fail ipfs key import self overwrite_self_import 2>&1 | tee key_imp_out &&
92
+ test_must_fail ipfs key import self overwrite_self_import.key 2>&1 | tee key_imp_out &&
93
grep -q "Error: cannot import key with name" key_imp_out &&
94
ipfs key rm overwrite_self_import &&
95
- rm overwrite_self_import
95
+ rm overwrite_self_import.key
96
'
97
98
test_expect_success "add a default key" '