summaryrefslogtreecommitdiff
path: root/cmd/commands.go
diff options
context:
space:
mode:
authorCass C <wcaplinger@gmail.com>2023-06-02 15:04:31 -0400
committerGitHub <noreply@github.com>2023-06-02 13:04:31 -0600
commit078f130a51b1546d63d770acdcbdec64cc7323a6 (patch)
tree0402f71cc005f1b97961cc03372b7ce82d6c254f /cmd/commands.go
parent9c180a59880160d775095f1f40650d8b8bc988a4 (diff)
cmd: Implement storage import/export (#5532)
* cmd: Implement 'storage import' and 'storage export' CLI commands. These commands use the certmagic.Storage interface. In particular, storage implementations should ensure that their List() functions correctly enumerate all keys when called with an empty prefix and recursive == true. Also, Stat() calls on keys holding values instead of nested keys are expected to set KeyInfo.IsTerminal = true. * remove errors.Join
Diffstat (limited to 'cmd/commands.go')
-rw-r--r--cmd/commands.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/cmd/commands.go b/cmd/commands.go
index a06336d..d1b76f4 100644
--- a/cmd/commands.go
+++ b/cmd/commands.go
@@ -306,6 +306,56 @@ the KEY=VALUE format will be loaded into the Caddy process.
})
RegisterCommand(Command{
+ Name: "storage",
+ Short: "Commands for working with Caddy's storage (EXPERIMENTAL)",
+ Long: `
+Allows exporting and importing Caddy's storage contents. The two commands can be
+combined in a pipeline to transfer directly from one storage to another:
+
+$ caddy storage export --config Caddyfile.old --output - |
+> caddy storage import --config Caddyfile.new --input -
+
+The - argument refers to stdout and stdin, respectively.
+
+NOTE: When importing to or exporting from file_system storage (the default), the command
+should be run as the user that owns the associated root path.
+
+EXPERIMENTAL: May be changed or removed.
+`,
+ CobraFunc: func(cmd *cobra.Command) {
+ exportCmd := &cobra.Command{
+ Use: "export --config <path> --output <path>",
+ Short: "Exports storage assets as a tarball",
+ Long: `
+The contents of the configured storage module (TLS certificates, etc)
+are exported via a tarball.
+
+--output is required, - can be given for stdout.
+`,
+ RunE: WrapCommandFuncForCobra(cmdExportStorage),
+ }
+ exportCmd.Flags().StringP("config", "c", "", "Input configuration file (required)")
+ exportCmd.Flags().StringP("output", "o", "", "Output path")
+ cmd.AddCommand(exportCmd)
+
+ importCmd := &cobra.Command{
+ Use: "import --config <path> --input <path>",
+ Short: "Imports storage assets from a tarball.",
+ Long: `
+Imports storage assets to the configured storage module. The import file must be
+a tar archive.
+
+--input is required, - can be given for stdin.
+`,
+ RunE: WrapCommandFuncForCobra(cmdImportStorage),
+ }
+ importCmd.Flags().StringP("config", "c", "", "Configuration file to load (required)")
+ importCmd.Flags().StringP("input", "i", "", "Tar of assets to load (required)")
+ cmd.AddCommand(importCmd)
+ },
+ })
+
+ RegisterCommand(Command{
Name: "fmt",
Usage: "[--overwrite] [--diff] [<path>]",
Short: "Formats a Caddyfile",