Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage tools cat command to easily cat sentinels and other jsons #1164

Merged
merged 3 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmd/common/st/cat_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package st

import (
"github.com/spf13/cobra"
"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/internal"
"github.com/wal-g/wal-g/internal/storagetools"
)

const (
catObjectShortDescription = "Cat the specified storage object to STDOUT"

decryptFlag = "decrypt"
decompressFlag = "decompress"
)

// catObjectCmd represents the catObject command
var catObjectCmd = &cobra.Command{
Use: "cat relative_object_path",
Short: catObjectShortDescription,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
objectPath := args[0]

folder, err := internal.ConfigureFolder()
tracelog.ErrorLogger.FatalOnError(err)

storagetools.HandleCatObject(objectPath, folder, decrypt, decompress)
},
}

var decrypt bool
var decompress bool

func init() {
StorageToolsCmd.AddCommand(catObjectCmd)
getObjectCmd.Flags().BoolVar(&decrypt, decryptFlag, false, "decrypt the object")
getObjectCmd.Flags().BoolVar(&decompress, decompressFlag, false, "decompress the object")
}
13 changes: 13 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ Examples:

``wal-g st get path/to/remote_file path/to/local_file --no-decrypt`` download the file from storage without decryption.

### ``cat``
Show the specified storage object to STDOUT.
By default, the command will NOT try to decompress and decrypt it.
Useful for getting sentinels and other meta-information files.

Flags:
1. Add `--decompress` to decompress source file
2. Add `--decrypt` to decrypt source file

Examples:

``wal-g st cat path/to/remote_file.json`` show `remote_file.json`

### ``rm``
Remove the specified storage object.

Expand Down
14 changes: 14 additions & 0 deletions internal/storagetools/cat_object_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package storagetools

import (
"os"

"github.com/wal-g/tracelog"
"github.com/wal-g/wal-g/pkg/storages/storage"
)

func HandleCatObject(objectPath string, folder storage.Folder, decrypt, decompress bool) {
dstFile := os.Stdout
err := downloadObject(objectPath, folder, dstFile, decrypt, decompress)
tracelog.ErrorLogger.FatalfOnError("Failed to download the file: %v", err)
}