Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
blva committed Mar 20, 2024
1 parent 1bfb719 commit 88e00c4
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 20 deletions.
1 change: 1 addition & 0 deletions internal/cli/atlas/alerts/list.go
Expand Up @@ -92,6 +92,7 @@ func ListBuilder() *cobra.Command {
opts.ValidateProjectID,
opts.initStore(cmd.Context()),
opts.InitOutput(cmd.OutOrStdout(), listTemplate),
// opts.PreRun(),
)
},
RunE: func(_ *cobra.Command, _ []string) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/atlas/customdbroles/create.go
Expand Up @@ -61,7 +61,7 @@ func (opts *CreateOpts) Run() error {
}

func (opts *CreateOpts) newCustomDBRole() *atlasv2.UserCustomDBRole {
actions := convert.BuildAtlasActions(opts.action)
actions := joinActions(convert.BuildAtlasActions(opts.action))
inheritedRoles := convert.BuildAtlasInheritedRoles(opts.inheritedRoles)
return &atlasv2.UserCustomDBRole{
RoleName: opts.roleName,
Expand Down
4 changes: 0 additions & 4 deletions internal/cli/atlas/deployments/list.go
Expand Up @@ -70,10 +70,6 @@ func (opts *ListOpts) Run(ctx context.Context) error {
return nil
}

func (opts *ListOpts) PostRun() error {
return opts.PostRunMessages()
}

// ListBuilder atlas deployments list.
func ListBuilder() *cobra.Command {
opts := &ListOpts{}
Expand Down
3 changes: 0 additions & 3 deletions internal/cli/atlas/deployments/logs.go
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/search"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
"github.com/spf13/afero"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -67,12 +66,10 @@ func (opts *DownloadOpts) Run(ctx context.Context) error {
}

if opts.IsLocalDeploymentType() {
telemetry.AppendOption(telemetry.WithDeploymentType(options.LocalCluster))
return opts.RunLocal(ctx)
}

if opts.IsAtlasDeploymentType() {
telemetry.AppendOption(telemetry.WithDeploymentType(options.LocalCluster))
if err := opts.validateAtlasFlags(); err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/atlas/deployments/options/connect_opts.go
Expand Up @@ -53,15 +53,13 @@ func (opts *ConnectOpts) Connect(ctx context.Context) error {
}

if opts.IsAtlasDeploymentType() {
telemetry.AppendOption(telemetry.WithDeploymentType(AtlasCluster))
if err := opts.validateAndPromptAtlasOpts(); err != nil {
return err
}

return opts.connectToAtlas()
}

telemetry.AppendOption(telemetry.WithDeploymentType(LocalCluster))
return opts.connectToLocal(ctx)
}

Expand Down
22 changes: 12 additions & 10 deletions internal/cli/atlas/deployments/options/deployment_opts.go
Expand Up @@ -96,6 +96,7 @@ type DeploymentOpts struct {
DefaultSetter cli.DefaultSetterOpts
AtlasClusterListStore store.ClusterLister
Config setup.ProfileReader
DeploymentTelemetry DeploymentTypeTelemetry
}

type Deployment struct {
Expand All @@ -115,6 +116,7 @@ func (opts *DeploymentOpts) InitStore(ctx context.Context, writer io.Writer) fun
return err
}
opts.DefaultSetter.OutWriter = writer
opts.DeploymentTelemetry = NewDeploymentTypeTelemetry(opts)
return opts.DefaultSetter.InitStore(ctx)
}
}
Expand Down Expand Up @@ -242,19 +244,11 @@ func (opts *DeploymentOpts) ValidateAndPromptDeploymentType() error {
}

func (opts *DeploymentOpts) IsAtlasDeploymentType() bool {
if strings.EqualFold(opts.DeploymentType, AtlasCluster) {
telemetry.AppendOption(telemetry.WithDeploymentType(AtlasCluster))
return true
}
return false
return strings.EqualFold(opts.DeploymentType, AtlasCluster)
}

func (opts *DeploymentOpts) IsLocalDeploymentType() bool {
if strings.EqualFold(opts.DeploymentType, LocalCluster) {
telemetry.AppendOption(telemetry.WithDeploymentType(LocalCluster))
return true
}
return false
return strings.EqualFold(opts.DeploymentType, LocalCluster)
}

func (opts *DeploymentOpts) NoDeploymentTypeSet() bool {
Expand All @@ -264,3 +258,11 @@ func (opts *DeploymentOpts) NoDeploymentTypeSet() bool {
func (opts *DeploymentOpts) IsAuthEnabled() bool {
return opts.DBUsername != ""
}

func (opts *DeploymentOpts) PreRun() {
opts.DeploymentTelemetry.AppendDeploymentType()
}
func (opts *DeploymentOpts) PostRun() error {
opts.DeploymentTelemetry.AppendDeploymentType()
return opts.PostRunMessages()
}
@@ -0,0 +1,36 @@
// Copyright 2023 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package options

import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/telemetry"
)

//go:generate mockgen -destination=../../../../mocks/mock_deployment_opts_telemetry.go -package=mocks github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/atlas/deployments/options DeploymentTypeTelemetry
type DeploymentTypeTelemetry interface {
AppendDeploymentType()
}

func NewDeploymentTypeTelemetry(opts *DeploymentOpts) DeploymentTypeTelemetry {
return opts
}

func (opts *DeploymentOpts) AppendDeploymentType() {
if opts.IsLocalDeploymentType() {
telemetry.AppendOption(telemetry.WithDeploymentType(LocalCluster))
} else if opts.IsAtlasDeploymentType() {
telemetry.AppendOption(telemetry.WithDeploymentType(AtlasCluster))
}
}
46 changes: 46 additions & 0 deletions internal/mocks/mock_deployment_opts_telemetry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 88e00c4

Please sign in to comment.