Skip to content

Commit

Permalink
chore: Cleanup of download command
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjee committed Mar 18, 2024
1 parent d1442ef commit f5871ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 34 deletions.
10 changes: 3 additions & 7 deletions docs/command/atlas-streams-instances-download.txt
Expand Up @@ -22,7 +22,7 @@ Syntax
.. code-block::
:caption: Command Syntax

atlas streams instances download <tenantName> <auditLogs.gz> [options]
atlas streams instances download <tenantName> [options]

.. Code end marker, please don't delete this comment

Expand All @@ -41,10 +41,6 @@ Arguments
- string
- true
- Label that identifies the tenant that stores the log files that you want to download.
* - auditLogs.gz
- string
- true
- Log file that you want to return.

Options
-------
Expand All @@ -71,7 +67,7 @@ Options
- help for download
* - --out
- string
- false
- true
- Output file name. This value defaults to the log name.
* - --projectId
- string
Expand Down Expand Up @@ -114,4 +110,4 @@ Examples
.. code-block::

# Download the audit log file from the instance myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
atlas streams instance logs myProcessor auditLogs.gz --projectId 5e2211c17a3e5a48f5497de3
atlas streams instance download myProcessor --projectId 5e2211c17a3e5a48f5497de3
34 changes: 8 additions & 26 deletions internal/cli/atlas/streams/instance/download.go
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
"slices"

"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
Expand All @@ -37,7 +36,6 @@ type DownloadOpts struct {
cli.GlobalOpts
cli.DownloaderOpts
tenantName string
fileName string
start int64
end int64
store store.StreamsDownloader
Expand All @@ -51,13 +49,6 @@ func (opts *DownloadOpts) initStore(ctx context.Context) func() error {
}
}

func (opts *DownloadOpts) initDefaultOut() error {
if opts.Out == "" {
opts.Out = opts.fileName
}
return nil
}

func (opts *DownloadOpts) Run() error {
params := atlasv2.DownloadStreamTenantAuditLogsApiParams{
GroupId: opts.ProjectID,
Expand Down Expand Up @@ -90,41 +81,31 @@ func (opts *DownloadOpts) Run() error {
}

// DownloadBuilder
// atlas streams download [tenantName] audit.gz --projectId [projectID].
// atlas streams download [tenantName] --projectId [projectID].
func DownloadBuilder() *cobra.Command {
const argsN = 2
const argsN = 1
opts := &DownloadOpts{}
opts.Fs = afero.NewOsFs()
cmd := &cobra.Command{
Use: "download <tenantName> <auditLogs.gz>",
Use: "download <tenantName>",
Short: "Download a compressed file that contains the logs for the specified Atlas Stream Processing instance.",
Long: `This command downloads a file with a .gz extension.` + fmt.Sprintf(usage.RequiredRole, "Project Data Access Read/Write"),
Args: cobra.MatchAll(
require.ExactArgs(argsN),
func(cmd *cobra.Command, args []string) error {
if !slices.Contains(cmd.ValidArgs, args[1]) {
return fmt.Errorf("<logname> must be one of %s", cmd.ValidArgs)
}
return nil
},
),
Example: ` # Download the audit log file from the instance myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
atlas streams instance logs myProcessor auditLogs.gz --projectId 5e2211c17a3e5a48f5497de3`,
atlas streams instance download myProcessor --projectId 5e2211c17a3e5a48f5497de3`,
Annotations: map[string]string{
"tenantNameDesc": "Label that identifies the tenant that stores the log files that you want to download.",
"auditLogs.gzDesc": "Log file that you want to return.",
"output": downloadMessage,
"tenantNameDesc": "Label that identifies the tenant that stores the log files that you want to download.",
"output": downloadMessage,
},
PreRunE: func(cmd *cobra.Command, args []string) error {
opts.tenantName = args[0]
opts.fileName = args[1]
return opts.PreRunE(opts.ValidateProjectID, opts.initStore(cmd.Context()), opts.initDefaultOut)
return opts.PreRunE(opts.ValidateProjectID, opts.initStore(cmd.Context()))
},
RunE: func(_ *cobra.Command, _ []string) error {
return opts.Run()
},

ValidArgs: []string{"auditLogs.gz"},
}

cmd.Flags().StringVar(&opts.Out, flag.Out, "", usage.LogOut)
Expand All @@ -134,6 +115,7 @@ func DownloadBuilder() *cobra.Command {

cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)

_ = cmd.MarkFlagRequired(flag.Out)
_ = cmd.MarkFlagFilename(flag.Out)

return cmd
Expand Down
1 change: 0 additions & 1 deletion test/e2e/atlas/streams_test.go
Expand Up @@ -100,7 +100,6 @@ func TestStreams(t *testing.T) {
"instance",
"download",
instanceName,
"auditLogs.gz",
"--out",
"-",
"--start",
Expand Down

0 comments on commit f5871ec

Please sign in to comment.