Add support for inspect data v2 (#4185)
This commit is contained in:
@@ -1,414 +0,0 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
json "github.com/minio/colorjson"
|
||||
|
||||
"github.com/klauspost/compress/zip"
|
||||
"github.com/tinylib/msgp/msgp"
|
||||
)
|
||||
|
||||
func inspectToExportType(downloadPath string, datajson bool) error {
|
||||
decode := func(r io.Reader, file string) ([]byte, error) {
|
||||
b, e := ioutil.ReadAll(r)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
b, _, minor, e := checkXL2V1(b)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
var data xlMetaInlineData
|
||||
switch minor {
|
||||
case 0:
|
||||
_, e = msgp.CopyToJSON(buf, bytes.NewReader(b))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
case 1, 2:
|
||||
v, b, e := msgp.ReadBytesZC(b)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if _, nbuf, e := msgp.ReadUint32Bytes(b); e == nil {
|
||||
// Read metadata CRC (added in v2, ignore if not found)
|
||||
b = nbuf
|
||||
}
|
||||
|
||||
_, e = msgp.CopyToJSON(buf, bytes.NewReader(v))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
data = b
|
||||
case 3:
|
||||
v, b, e := msgp.ReadBytesZC(b)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if _, nbuf, e := msgp.ReadUint32Bytes(b); e == nil {
|
||||
// Read metadata CRC (added in v2, ignore if not found)
|
||||
b = nbuf
|
||||
}
|
||||
|
||||
nVers, v, e := decodeXLHeaders(v)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
type version struct {
|
||||
Idx int
|
||||
Header json.RawMessage
|
||||
Metadata json.RawMessage
|
||||
}
|
||||
versions := make([]version, nVers)
|
||||
e = decodeVersions(v, nVers, func(idx int, hdr, meta []byte) error {
|
||||
var header xlMetaV2VersionHeaderV2
|
||||
if _, e := header.UnmarshalMsg(hdr); e != nil {
|
||||
return e
|
||||
}
|
||||
b, e := header.MarshalJSON()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if _, e := msgp.UnmarshalAsJSON(&buf, meta); e != nil {
|
||||
return e
|
||||
}
|
||||
versions[idx] = version{
|
||||
Idx: idx,
|
||||
Header: b,
|
||||
Metadata: buf.Bytes(),
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
enc := json.NewEncoder(buf)
|
||||
if e := enc.Encode(struct {
|
||||
Versions []version
|
||||
}{Versions: versions}); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
data = b
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown metadata version %d", minor)
|
||||
}
|
||||
|
||||
if datajson {
|
||||
b, e := data.json()
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
buf = bytes.NewBuffer(b)
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
fmt.Println("{")
|
||||
|
||||
hasWritten := false
|
||||
var r io.Reader
|
||||
var sz int64
|
||||
f, e := os.Open(downloadPath)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if st, e := f.Stat(); e == nil {
|
||||
sz = st.Size()
|
||||
}
|
||||
defer f.Close()
|
||||
r = f
|
||||
|
||||
zr, e := zip.NewReader(r.(io.ReaderAt), sz)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
for _, file := range zr.File {
|
||||
if !file.FileInfo().IsDir() && strings.HasSuffix(file.Name, "xl.meta") {
|
||||
r, e := file.Open()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
// Quote string...
|
||||
b, _ := json.Marshal(file.Name)
|
||||
if hasWritten {
|
||||
fmt.Print(",\n")
|
||||
}
|
||||
fmt.Printf("\t%s: ", string(b))
|
||||
|
||||
b, e = decode(r, file.Name)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
fmt.Print(string(b))
|
||||
hasWritten = true
|
||||
}
|
||||
}
|
||||
fmt.Println("")
|
||||
fmt.Println("}")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
// XL header specifies the format
|
||||
xlHeader = [4]byte{'X', 'L', '2', ' '}
|
||||
|
||||
// Current version being written.
|
||||
xlVersionCurrent [4]byte
|
||||
)
|
||||
|
||||
const (
|
||||
// Breaking changes.
|
||||
// Newer versions cannot be read by older software.
|
||||
// This will prevent downgrades to incompatible versions.
|
||||
xlVersionMajor = 1
|
||||
|
||||
// Non breaking changes.
|
||||
// Bumping this is informational, but should be done
|
||||
// if any change is made to the data stored, bumping this
|
||||
// will allow to detect the exact version later.
|
||||
xlVersionMinor = 1
|
||||
)
|
||||
|
||||
func init() {
|
||||
binary.LittleEndian.PutUint16(xlVersionCurrent[0:2], xlVersionMajor)
|
||||
binary.LittleEndian.PutUint16(xlVersionCurrent[2:4], xlVersionMinor)
|
||||
}
|
||||
|
||||
// checkXL2V1 will check if the metadata has correct header and is a known major version.
|
||||
// The remaining payload and versions are returned.
|
||||
func checkXL2V1(buf []byte) (payload []byte, major, minor uint16, e error) {
|
||||
if len(buf) <= 8 {
|
||||
return payload, 0, 0, fmt.Errorf("xlMeta: no data")
|
||||
}
|
||||
|
||||
if !bytes.Equal(buf[:4], xlHeader[:]) {
|
||||
return payload, 0, 0, fmt.Errorf("xlMeta: unknown XLv2 header, expected %v, got %v", xlHeader[:4], buf[:4])
|
||||
}
|
||||
|
||||
if bytes.Equal(buf[4:8], []byte("1 ")) {
|
||||
// Set as 1,0.
|
||||
major, minor = 1, 0
|
||||
} else {
|
||||
major, minor = binary.LittleEndian.Uint16(buf[4:6]), binary.LittleEndian.Uint16(buf[6:8])
|
||||
}
|
||||
if major > xlVersionMajor {
|
||||
return buf[8:], major, minor, fmt.Errorf("xlMeta: unknown major version %d found", major)
|
||||
}
|
||||
|
||||
return buf[8:], major, minor, nil
|
||||
}
|
||||
|
||||
const xlMetaInlineDataVer = 1
|
||||
|
||||
type xlMetaInlineData []byte
|
||||
|
||||
// afterVersion returns the payload after the version, if any.
|
||||
func (x xlMetaInlineData) afterVersion() []byte {
|
||||
if len(x) == 0 {
|
||||
return x
|
||||
}
|
||||
return x[1:]
|
||||
}
|
||||
|
||||
// versionOK returns whether the version is ok.
|
||||
func (x xlMetaInlineData) versionOK() bool {
|
||||
if len(x) == 0 {
|
||||
return true
|
||||
}
|
||||
return x[0] > 0 && x[0] <= xlMetaInlineDataVer
|
||||
}
|
||||
|
||||
func (x xlMetaInlineData) json() ([]byte, error) {
|
||||
if len(x) == 0 {
|
||||
return []byte("{}"), nil
|
||||
}
|
||||
if !x.versionOK() {
|
||||
return nil, errors.New("xlMetaInlineData: unknown version")
|
||||
}
|
||||
|
||||
sz, buf, e := msgp.ReadMapHeaderBytes(x.afterVersion())
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
res := []byte("{")
|
||||
|
||||
for i := uint32(0); i < sz; i++ {
|
||||
var key, val []byte
|
||||
key, buf, e = msgp.ReadMapKeyZC(buf)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if len(key) == 0 {
|
||||
return nil, fmt.Errorf("xlMetaInlineData: key %d is length 0", i)
|
||||
}
|
||||
// Skip data...
|
||||
val, buf, e = msgp.ReadBytesZC(buf)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if i > 0 {
|
||||
res = append(res, ',')
|
||||
}
|
||||
s := fmt.Sprintf(`"%s":%d`, string(key), len(val))
|
||||
res = append(res, []byte(s)...)
|
||||
}
|
||||
res = append(res, '}')
|
||||
return res, nil
|
||||
}
|
||||
|
||||
const (
|
||||
xlHeaderVersion = 2
|
||||
xlMetaVersion = 2
|
||||
)
|
||||
|
||||
func decodeXLHeaders(buf []byte) (versions int, b []byte, e error) {
|
||||
hdrVer, buf, e := msgp.ReadUintBytes(buf)
|
||||
if e != nil {
|
||||
return 0, buf, e
|
||||
}
|
||||
metaVer, buf, e := msgp.ReadUintBytes(buf)
|
||||
if e != nil {
|
||||
return 0, buf, e
|
||||
}
|
||||
if hdrVer > xlHeaderVersion {
|
||||
return 0, buf, fmt.Errorf("decodeXLHeaders: Unknown xl header version %d", metaVer)
|
||||
}
|
||||
if metaVer > xlMetaVersion {
|
||||
return 0, buf, fmt.Errorf("decodeXLHeaders: Unknown xl meta version %d", metaVer)
|
||||
}
|
||||
versions, buf, e = msgp.ReadIntBytes(buf)
|
||||
if e != nil {
|
||||
return 0, buf, e
|
||||
}
|
||||
if versions < 0 {
|
||||
return 0, buf, fmt.Errorf("decodeXLHeaders: Negative version count %d", versions)
|
||||
}
|
||||
return versions, buf, nil
|
||||
}
|
||||
|
||||
// decodeVersions will decode a number of versions from a buffer
|
||||
// and perform a callback for each version in order, newest first.
|
||||
// Any non-nil error is returned.
|
||||
func decodeVersions(buf []byte, versions int, fn func(idx int, hdr, meta []byte) error) (e error) {
|
||||
var tHdr, tMeta []byte // Zero copy bytes
|
||||
for i := 0; i < versions; i++ {
|
||||
tHdr, buf, e = msgp.ReadBytesZC(buf)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
tMeta, buf, e = msgp.ReadBytesZC(buf)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if e = fn(i, tHdr, tMeta); e != nil {
|
||||
return e
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type xlMetaV2VersionHeaderV2 struct {
|
||||
VersionID [16]byte
|
||||
ModTime int64
|
||||
Signature [4]byte
|
||||
Type uint8
|
||||
Flags uint8
|
||||
}
|
||||
|
||||
// UnmarshalMsg implements msgp.Unmarshaler
|
||||
func (z *xlMetaV2VersionHeaderV2) UnmarshalMsg(bts []byte) (o []byte, e error) {
|
||||
var zb0001 uint32
|
||||
zb0001, bts, e = msgp.ReadArrayHeaderBytes(bts)
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e)
|
||||
return
|
||||
}
|
||||
if zb0001 != 5 {
|
||||
e = msgp.ArrayError{Wanted: 5, Got: zb0001}
|
||||
return
|
||||
}
|
||||
bts, e = msgp.ReadExactBytes(bts, (z.VersionID)[:])
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e, "VersionID")
|
||||
return
|
||||
}
|
||||
z.ModTime, bts, e = msgp.ReadInt64Bytes(bts)
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e, "ModTime")
|
||||
return
|
||||
}
|
||||
bts, e = msgp.ReadExactBytes(bts, (z.Signature)[:])
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e, "Signature")
|
||||
return
|
||||
}
|
||||
{
|
||||
var zb0002 uint8
|
||||
zb0002, bts, e = msgp.ReadUint8Bytes(bts)
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e, "Type")
|
||||
return
|
||||
}
|
||||
z.Type = zb0002
|
||||
}
|
||||
{
|
||||
var zb0003 uint8
|
||||
zb0003, bts, e = msgp.ReadUint8Bytes(bts)
|
||||
if e != nil {
|
||||
e = msgp.WrapError(e, "Flags")
|
||||
return
|
||||
}
|
||||
z.Flags = zb0003
|
||||
}
|
||||
o = bts
|
||||
return
|
||||
}
|
||||
|
||||
func (z xlMetaV2VersionHeaderV2) MarshalJSON() (o []byte, e error) {
|
||||
tmp := struct {
|
||||
VersionID string
|
||||
ModTime time.Time
|
||||
Signature string
|
||||
Type uint8
|
||||
Flags uint8
|
||||
}{
|
||||
VersionID: hex.EncodeToString(z.VersionID[:]),
|
||||
ModTime: time.Unix(0, z.ModTime),
|
||||
Signature: hex.EncodeToString(z.Signature[:]),
|
||||
Type: z.Type,
|
||||
Flags: z.Flags,
|
||||
}
|
||||
return json.Marshal(tmp)
|
||||
}
|
||||
+72
-86
@@ -19,12 +19,12 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -37,18 +37,14 @@ import (
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/secure-io/sio-go"
|
||||
)
|
||||
|
||||
const defaultPublicKey = "MIIBCgKCAQEAs/128UFS9A8YSJY1XqYKt06dLVQQCGDee69T+0Tip/1jGAB4z0/3QMpH0MiS8Wjs4BRWV51qvkfAHzwwdU7y6jxU05ctb/H/WzRj3FYdhhHKdzear9TLJftlTs+xwj2XaADjbLXCV1jGLS889A7f7z5DgABlVZMQd9BjVAR8ED3xRJ2/ZCNuQVJ+A8r7TYPGMY3wWvhhPgPk3Lx4WDZxDiDNlFs4GQSaESSsiVTb9vyGe/94CsCTM6Cw9QG6ifHKCa/rFszPYdKCabAfHcS3eTr0GM+TThSsxO7KfuscbmLJkfQev1srfL2Ii2RbnysqIJVWKEwdW05ID8ryPkuTuwIDAQAB"
|
||||
|
||||
var supportInspectFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "encrypt",
|
||||
Usage: "encrypt content with one time key for confidential data",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "export",
|
||||
Value: "json",
|
||||
Usage: "exports inspect data as JSON or data JSON from 'xl.meta', supported values are 'json' or 'djson'",
|
||||
Name: "legacy",
|
||||
Usage: "use the older inspect format",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -73,22 +69,42 @@ EXAMPLES:
|
||||
1. Download 'xl.meta' for a specific object from all the drives in a zip file.
|
||||
{{.Prompt}} {{.HelpName}} myminio/bucket/test*/xl.meta
|
||||
|
||||
2. Download all constituent parts for a specific object, and optionally encrypt the downloaded zip.
|
||||
{{.Prompt}} {{.HelpName}} --encrypt myminio/bucket/test*/*/part.*
|
||||
|
||||
3. Download recursively all objects at a prefix. NOTE: This can be an expensive operation use it with caution.
|
||||
2. Download recursively all objects at a prefix. NOTE: This can be an expensive operation use it with caution.
|
||||
{{.Prompt}} {{.HelpName}} myminio/bucket/test/**
|
||||
`,
|
||||
}
|
||||
|
||||
type inspectMessage struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}
|
||||
|
||||
// Colorized message for console printing.
|
||||
func (t inspectMessage) String() string {
|
||||
msg := ""
|
||||
if t.Key == "" {
|
||||
msg += fmt.Sprintf("File data successfully downloaded as %s\n", console.Colorize("File", t.File))
|
||||
} else {
|
||||
msg += fmt.Sprintf("Encrypted file data successfully downloaded as %s\n", console.Colorize("File", t.File))
|
||||
msg += fmt.Sprintf("Decryption key: %s\n\n", console.Colorize("Key", t.Key))
|
||||
|
||||
msg += fmt.Sprintf("The decryption key will ONLY be shown here. It cannot be recovered.\n")
|
||||
msg += fmt.Sprintf("The encrypted file can safely be shared without the decryption key.\n")
|
||||
msg += fmt.Sprintf("Even with the decryption key, data stored with encryption cannot be accessed.\n")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (t inspectMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.MarshalIndent(t, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
func checkSupportInspectSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, "inspect", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
if ctx.IsSet("export") && globalJSON {
|
||||
fatalIf(errInvalidArgument(), "--export=type cannot be specified with --json flag")
|
||||
}
|
||||
}
|
||||
|
||||
// mainSupportInspect - the entry function of inspect command
|
||||
@@ -99,7 +115,6 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
encrypt := ctx.Bool("encrypt")
|
||||
|
||||
alias, _ := url2Alias(aliasedURL)
|
||||
validateClusterRegistered(alias, false)
|
||||
@@ -124,36 +139,53 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
console.Infoln("Your shell is auto determined as '" + shellName + "', wildcard patterns are only supported with 'bash' SHELL.")
|
||||
}
|
||||
|
||||
var publicKey []byte
|
||||
if !ctx.Bool("legacy") {
|
||||
var e error
|
||||
publicKey, e = os.ReadFile(filepath.Join(mustGetMcConfigDir(), "support_public.pem"))
|
||||
if e != nil && !os.IsNotExist(e) {
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to inspect file.")
|
||||
} else if len(publicKey) > 0 {
|
||||
if !globalJSON && !globalQuiet {
|
||||
console.Infoln("Using public key from ", filepath.Join(mustGetMcConfigDir(), "support_public.pem"))
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to MinIO public key.
|
||||
if len(publicKey) == 0 {
|
||||
// Public key for MinIO confidential information.
|
||||
publicKey, _ = base64.StdEncoding.DecodeString(defaultPublicKey)
|
||||
}
|
||||
}
|
||||
|
||||
key, r, e := client.Inspect(context.Background(), madmin.InspectOptions{
|
||||
Volume: bucket,
|
||||
File: prefix,
|
||||
Volume: bucket,
|
||||
File: prefix,
|
||||
PublicKey: publicKey,
|
||||
})
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to inspect file.")
|
||||
|
||||
// Create profile zip file
|
||||
tmpFile, e := ioutil.TempFile("", "mc-inspect-")
|
||||
// Download the inspect data in a temporary file first
|
||||
tmpFile, e := os.CreateTemp("", "mc-inspect-")
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
ext := "enc"
|
||||
if !encrypt || ctx.IsSet("export") {
|
||||
ext = "zip"
|
||||
r = decryptInspect(key, r)
|
||||
}
|
||||
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, r)
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
// Close everything
|
||||
r.Close()
|
||||
tmpFile.Close()
|
||||
|
||||
// Create an id that is also crc.
|
||||
var id [4]byte
|
||||
binary.LittleEndian.PutUint32(id[:], crc32.ChecksumIEEE(key[:]))
|
||||
var keyHex string
|
||||
|
||||
// Choose a name and move the inspect data to its final destination
|
||||
downloadPath := fmt.Sprintf("inspect-data.enc")
|
||||
if key != nil {
|
||||
// Create an id that is also crc.
|
||||
var id [4]byte
|
||||
binary.LittleEndian.PutUint32(id[:], crc32.ChecksumIEEE(key[:]))
|
||||
// We use 4 bytes of the 32 bytes to identify they file.
|
||||
downloadPath = fmt.Sprintf("inspect-data.%s.enc", hex.EncodeToString(id[:]))
|
||||
keyHex = hex.EncodeToString(id[:]) + hex.EncodeToString(key[:])
|
||||
}
|
||||
|
||||
// We use 4 bytes of the 32 bytes to identify they file.
|
||||
downloadPath := fmt.Sprintf("inspect.%s.%s", hex.EncodeToString(id[:]), ext)
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
@@ -165,56 +197,10 @@ func mainSupportInspect(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to rename downloaded data, file exists at %s", tmpFile.Name())
|
||||
if ctx.IsSet("export") {
|
||||
switch v := ctx.String("export"); v {
|
||||
case "json":
|
||||
inspectToExportType(downloadPath, false)
|
||||
case "djson":
|
||||
inspectToExportType(downloadPath, true)
|
||||
default:
|
||||
os.Remove(downloadPath)
|
||||
fatalIf(errInvalidArgument().Trace("export="+v), "Unable to export inspect data")
|
||||
}
|
||||
os.Remove(downloadPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
hexKey := hex.EncodeToString(id[:]) + hex.EncodeToString(key[:])
|
||||
if !globalJSON {
|
||||
if !encrypt {
|
||||
console.Infof("File data successfully downloaded as %s\n", console.Colorize("File", downloadPath))
|
||||
return nil
|
||||
}
|
||||
console.Infof("Encrypted file data successfully downloaded as %s\n", console.Colorize("File", downloadPath))
|
||||
console.Infof("Decryption key: %s\n\n", console.Colorize("Key", hexKey))
|
||||
|
||||
console.Info("The decryption key will ONLY be shown here. It cannot be recovered.\n")
|
||||
console.Info("The encrypted file can safely be shared without the decryption key.\n")
|
||||
console.Info("Even with the decryption key, data stored with encryption cannot be accessed.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
v := struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}{
|
||||
printMsg(inspectMessage{
|
||||
File: downloadPath,
|
||||
Key: hexKey,
|
||||
}
|
||||
if !encrypt {
|
||||
v.Key = ""
|
||||
}
|
||||
b, e := json.Marshal(v)
|
||||
fatalIf(probe.NewError(e), "Unable to serialize data")
|
||||
console.Println(string(b))
|
||||
Key: keyHex,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func decryptInspect(key [32]byte, r io.Reader) io.ReadCloser {
|
||||
stream, err := sio.AES_256_GCM.Stream(key[:])
|
||||
fatalIf(probe.NewError(err), "Unable to initiate decryption")
|
||||
|
||||
// Zero nonce, we only use each key once, and 32 bytes is plenty.
|
||||
nonce := make([]byte, stream.NonceSize())
|
||||
return ioutil.NopCloser(stream.DecryptReader(r, nonce, nil))
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ require (
|
||||
github.com/minio/cli v1.24.0
|
||||
github.com/minio/colorjson v1.0.4
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go v1.6.6
|
||||
github.com/minio/madmin-go v1.7.1
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.41
|
||||
github.com/minio/pkg v1.5.4
|
||||
@@ -32,7 +32,6 @@ require (
|
||||
github.com/prometheus/prom2json v1.3.2
|
||||
github.com/rjeczalik/notify v0.9.2
|
||||
github.com/rs/xid v1.4.0
|
||||
github.com/secure-io/sio-go v0.3.1
|
||||
github.com/shirou/gopsutil/v3 v3.22.9
|
||||
github.com/tidwall/gjson v1.14.3
|
||||
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a
|
||||
@@ -52,8 +51,7 @@ require (
|
||||
github.com/navidys/tvxwidgets v0.1.1
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/prometheus/client_model v0.3.0
|
||||
github.com/rivo/tview v0.0.0-20220916081518-2e69b7385a37
|
||||
github.com/tinylib/msgp v1.1.7-0.20211026165309-e818a1881b0e
|
||||
github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b
|
||||
golang.org/x/term v0.0.0-20221017184919-83659145692c
|
||||
)
|
||||
|
||||
@@ -97,9 +95,11 @@ require (
|
||||
github.com/prometheus/common v0.37.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
github.com/rivo/uniseg v0.4.2 // indirect
|
||||
github.com/secure-io/sio-go v0.3.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tinylib/msgp v1.1.7-0.20211026165309-e818a1881b0e // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||
github.com/tklauser/numcpus v0.5.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
|
||||
@@ -265,6 +265,7 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
|
||||
github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0=
|
||||
github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
@@ -499,8 +500,9 @@ github.com/minio/colorjson v1.0.4 h1:sNJYTb2uNswdqmGARg9wrogCX8+GRZzEacYbJT86e00
|
||||
github.com/minio/colorjson v1.0.4/go.mod h1:ZgE8vYon4xC4yfBPclP/2gqMRYw+p+xRsBbLMDKdb9M=
|
||||
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
|
||||
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
|
||||
github.com/minio/madmin-go v1.6.6 h1:YwubKSJFeMXjW8RWOiXIhLaiTEC/rMJH2U0M57xsORA=
|
||||
github.com/minio/madmin-go v1.6.6/go.mod h1:ATvkBOLiP3av4D++2v1UEHC/QzsGtgXD5kYvvRYzdKs=
|
||||
github.com/minio/madmin-go v1.7.1 h1:4eMyMkLSVUFZmrrwxJrYnzRimy6eCoobqijaQxzYqak=
|
||||
github.com/minio/madmin-go v1.7.1/go.mod h1:3SO8SROxHN++tF6QxdTii2SSUaYSrr8lnE9EJWjvz0k=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.41 h1:Qhc82nDRep+VSuDEPSawKUHkARnZI5st7acEqgqVX+k=
|
||||
@@ -602,8 +604,8 @@ github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5
|
||||
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
|
||||
github.com/prometheus/prom2json v1.3.2 h1:heRKAGHWqm8N3IaRDDNBBJNVS6a9mLdsTlFhvOaNGb0=
|
||||
github.com/prometheus/prom2json v1.3.2/go.mod h1:TQ9o1OxW0eyhl4BBpVpGGsavyJfTDETna4/d0Kib+V0=
|
||||
github.com/rivo/tview v0.0.0-20220916081518-2e69b7385a37 h1:cTzFg1FfTXwXuODi7Doz70hsW+dAye1OBwAFWHCqmww=
|
||||
github.com/rivo/tview v0.0.0-20220916081518-2e69b7385a37/go.mod h1:YX2wUZOcJGOIycErz2s9KvDaP0jnWwRCirQMPLPpQ+Y=
|
||||
github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b h1:EMgbQ+bOHWkl0Ptano8M0yrzVZkxans+Vfv7ox/EtO8=
|
||||
github.com/rivo/tview v0.0.0-20211202162923-2a6de950f73b/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8=
|
||||
@@ -902,6 +904,7 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -945,6 +948,7 @@ golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20221017184919-83659145692c h1:dveknrit5futqEmXAvd2I1BbZIDhxRijsyWHM86NlcA=
|
||||
golang.org/x/term v0.0.0-20221017184919-83659145692c/go.mod h1:VTIZ7TEbF0BS9Sv9lPTvGbtW8i4z6GGbJBCM37uMCzY=
|
||||
|
||||
Reference in New Issue
Block a user