feat(ipfs diag profile): output version info only
sys diag includes private information (like the interface addresses)
Steven Allen committed
Jul 21, 2021 at 15:35 UTC
722fc4fa4c2fb501615825353d2c1dc10bbb832e
2 files changed
+19
-23
core/commands/profile.go
+8
-16
@@ -13,8 +13,6 @@ import (
13
"time"
14
15
cmds "github.com/ipfs/go-ipfs-cmds"
16
- "github.com/ipfs/go-ipfs/core"
17
- "github.com/ipfs/go-ipfs/core/commands/cmdenv"
16
"github.com/ipfs/go-ipfs/core/commands/e"
17
)
18
@@ -40,14 +38,9 @@ var sysProfileCmd = &cmds.Command{
38
return fmt.Errorf("failed to parse CPU profile duration %q: %w", cpuProfileTimeStr, err)
39
}
40
43
- nd, err := cmdenv.GetNode(env)
44
- if err != nil {
45
- return err
46
- }
47
-
41
r, w := io.Pipe()
42
go func() {
50
- _ = w.CloseWithError(writeProfiles(req.Context, nd, cpuProfileTime, w))
43
+ _ = w.CloseWithError(writeProfiles(req.Context, cpuProfileTime, w))
44
}()
45
return res.Emit(r)
46
},
@@ -88,7 +81,7 @@ var sysProfileCmd = &cmds.Command{
81
},
82
}
83
91
-func writeProfiles(ctx context.Context, nd *core.IpfsNode, cpuProfileTime time.Duration, w io.Writer) error {
84
+func writeProfiles(ctx context.Context, cpuProfileTime time.Duration, w io.Writer) error {
85
archive := zip.NewWriter(w)
86
87
// Take some profiles.
@@ -135,17 +128,16 @@ func writeProfiles(ctx context.Context, nd *core.IpfsNode, cpuProfileTime time.D
128
}
129
}
130
138
- // Collect info
131
+ // Collect version info
132
+ // I'd use diag sysinfo, but that includes some more sensitive information
133
+ // (GOPATH, etc.).
134
{
140
- out, err := archive.Create("sysinfo.json")
135
+ out, err := archive.Create("version.json")
136
if err != nil {
137
return err
138
}
144
- info, err := getInfo(nd)
145
- if err != nil {
146
- return err
147
- }
148
- err = json.NewEncoder(out).Encode(info)
139
+
140
+ err = json.NewEncoder(out).Encode(getVersionInfo())
141
if err != nil {
142
return err
143
}
core/commands/version.go
+11
-7
@@ -28,6 +28,16 @@ const (
28
versionAllOptionName = "all"
29
)
30
31
+func getVersionInfo() *VersionOutput {
32
+ return &VersionOutput{
33
+ Version: version.CurrentVersionNumber,
34
+ Commit: version.CurrentCommit,
35
+ Repo: fmt.Sprint(fsrepo.RepoVersion),
36
+ System: runtime.GOARCH + "/" + runtime.GOOS, //TODO: Precise version here
37
+ Golang: runtime.Version(),
38
+ }
39
+}
40
+
41
var VersionCmd = &cmds.Command{
42
Helptext: cmds.HelpText{
43
Tagline: "Show IPFS version information.",
@@ -46,13 +56,7 @@ var VersionCmd = &cmds.Command{
56
// must be permitted to run before init
57
Extra: CreateCmdExtras(SetDoesNotUseRepo(true), SetDoesNotUseConfigAsInput(true)),
58
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
49
- return cmds.EmitOnce(res, &VersionOutput{
50
- Version: version.CurrentVersionNumber,
51
- Commit: version.CurrentCommit,
52
- Repo: fmt.Sprint(fsrepo.RepoVersion),
53
- System: runtime.GOARCH + "/" + runtime.GOOS, //TODO: Precise version here
54
- Golang: runtime.Version(),
55
- })
59
+ return cmds.EmitOnce(res, getVersionInfo())
60
},
61
Encoders: cmds.EncoderMap{
62
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, version *VersionOutput) error {