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

task: remove config.BinName #2801

Merged
merged 1 commit into from Mar 25, 2024
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
4 changes: 2 additions & 2 deletions internal/cli/atlas/backup/exports/buckets/create.go
Expand Up @@ -75,8 +75,8 @@ func CreateBuilder() *cobra.Command {
Use: "create <bucketName>",
Short: "Create an export destination for Atlas backups using an existing AWS S3 bucket.",
Long: fmt.Sprintf(usage.RequiredRole, "Project Owner"),
Example: fmt.Sprintf(` # The following command creates an export destination for Atlas backups using the existing AWS S3 bucket named test-bucket:
%s backup export buckets create test-bucket --cloudProvider AWS --iamRoleId 12345678f901a234dbdb00ca`, config.BinName()),
Example: ` # The following command creates an export destination for Atlas backups using the existing AWS S3 bucket named test-bucket:
atlas backup export buckets create test-bucket --cloudProvider AWS --iamRoleId 12345678f901a234dbdb00ca`,
Args: require.ExactArgs(1),
Annotations: map[string]string{
"bucketNameDesc": "Name of the existing S3 bucket that the provided role ID is authorized to access.",
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/atlas/backup/exports/jobs/create.go
Expand Up @@ -86,8 +86,8 @@ func CreateBuilder() *cobra.Command {
Use: "create",
Short: "Export one backup snapshot for an M10 or higher Atlas cluster to an existing AWS S3 bucket.",
Long: fmt.Sprintf(usage.RequiredRole, "Project Owner"),
Example: fmt.Sprintf(` # The following command exports one backup snapshot of the ExampleCluster cluster to an existing AWS S3 bucket:
%s backup export jobs create --clusterName ExampleCluster --bucketId 62c569f85b7a381c093cc539 --snapshotId 62c808ceeb4e021d850dfe1b --customData name=test,info=test`, config.BinName()),
Example: ` # The following command exports one backup snapshot of the ExampleCluster cluster to an existing AWS S3 bucket:
atlas backup export jobs create --clusterName ExampleCluster --bucketId 62c569f85b7a381c093cc539 --snapshotId 62c808ceeb4e021d850dfe1b --customData name=test,info=test`,
Annotations: map[string]string{
"output": createTemplate,
},
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/auth/login.go
Expand Up @@ -185,10 +185,10 @@ func (opts *LoginOpts) setUpProfile(ctx context.Context) error {
return ErrOrgIDNotFound
}

_, _ = fmt.Fprintf(opts.OutWriter, `
_, _ = fmt.Fprint(opts.OutWriter, `
You have successfully configured your profile.
You can use [%s config set] to change your profile settings later.
`, config.BinName())
You can use [atlas config set] to change your profile settings later.
`)
}

return opts.config.Save()
Expand Down Expand Up @@ -289,9 +289,9 @@ func LoginBuilder() *cobra.Command {
cmd := &cobra.Command{
Use: "login",
Short: "Authenticate with MongoDB Atlas.",
Example: fmt.Sprintf(` # Log in to your MongoDB Atlas account in interactive mode:
%s auth login
`, config.BinName()),
Example: ` # Log in to your MongoDB Atlas account in interactive mode:
atlas auth login
`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
opts.OutWriter = cmd.OutOrStdout()
defaultProfile := config.Default()
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/auth/whoami.go
Expand Up @@ -50,9 +50,9 @@ func WhoAmIBuilder() *cobra.Command {
cmd := &cobra.Command{
Use: "whoami",
Short: "Verifies and displays information about your authentication state.",
Example: fmt.Sprintf(` # See the logged account:
%s auth whoami
`, config.BinName()),
Example: ` # See the logged account:
atlas auth whoami
`,
PreRun: func(cmd *cobra.Command, _ []string) {
opts.OutWriter = cmd.OutOrStdout()
},
Expand Down
7 changes: 3 additions & 4 deletions internal/cli/config/edit.go
Expand Up @@ -15,7 +15,6 @@
package config

import (
"fmt"
"os"
"os/exec"

Expand Down Expand Up @@ -48,9 +47,9 @@ func EditBuilder() *cobra.Command {
Use: "edit",
Short: "Opens the config file with the default text editor.",
Long: `Uses the default editor to open the config file. You can use EDITOR or VISUAL envs to change the default.`,
Example: fmt.Sprintf(` # To open the config
%s config edit
`, config.BinName()),
Example: ` # To open the config
atlas config edit
`,
RunE: func(_ *cobra.Command, _ []string) error {
return opt.Run()
},
Expand Down
4 changes: 1 addition & 3 deletions internal/cli/config/list.go
Expand Up @@ -15,8 +15,6 @@
package config

import (
"fmt"

"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
Expand Down Expand Up @@ -44,7 +42,7 @@ func ListBuilder() *cobra.Command {
Aliases: []string{"ls"},
Short: "Return a list of available profiles by name.",
Long: `If you did not specify a name for your profile, it displays as the default profile.`,
Example: fmt.Sprintf(" %s config ls", config.BinName()),
Example: " atlas config ls",
PreRun: func(cmd *cobra.Command, _ []string) {
o.OutWriter = cmd.OutOrStdout()
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/config/rename.go
Expand Up @@ -66,8 +66,8 @@ func RenameBuilder() *cobra.Command {
Use: "rename <oldProfileName> <newProfileName>",
Aliases: []string{"mv"},
Short: "Rename a profile.",
Example: fmt.Sprintf(` # Rename a profile called myProfile to testProfile:
%s config rename myProfile testProfile`, config.BinName()),
Example: ` # Rename a profile called myProfile to testProfile:
atlas config rename myProfile testProfile`,
Annotations: map[string]string{
"oldProfileNameDesc": "Name of the profile to rename.",
"newProfileNameDesc": "New name of the profile.",
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/config/set.go
Expand Up @@ -83,9 +83,9 @@ func SetBuilder() *cobra.Command {
}
return nil
},
Example: fmt.Sprintf(`
Example: `
Set the organization ID in the default profile to 5dd5aaef7a3e5a6c5bd12de4:
%s config set org_id 5dd5aaef7a3e5a6c5bd12de4`, config.BinName()),
atlas config set org_id 5dd5aaef7a3e5a6c5bd12de4`,
Annotations: map[string]string{
"propertyNameDesc": "Property to set in the profile. Valid values for Atlas CLI and MongoDB CLI are project_id, org_id, service, public_api_key, private_api_key, output, mongosh_path, skip_update_check, telemetry_enabled, access_token, and refresh_token. Additionally, values that are only valid for MongoDB CLI include ops_manager_url base_url, ops_manager_ca_certificate, and ops_manager_skip_verify.",
"valueDesc": "Value for the property to set in the profile.",
Expand Down
9 changes: 6 additions & 3 deletions internal/cli/refresher_opts.go
Expand Up @@ -68,9 +68,12 @@ func (opts *RefresherOpts) RefreshAccessToken(ctx context.Context) error {
var target *atlas.ErrorResponse
if errors.As(err, &target) && target.ErrorCode == "INVALID_REFRESH_TOKEN" {
return fmt.Errorf(
"%w\n\nPlease note that your session expires periodically. If you use Atlas CLI for automation, see https://www.mongodb.com/docs/atlas/cli/stable/atlas-cli-automate/ for best practices.\nTo login, run: %s auth login",
ErrInvalidRefreshToken,
config.BinName())
`%w

Please note that your session expires periodically.
If you use Atlas CLI for automation, see https://www.mongodb.com/docs/atlas/cli/stable/atlas-cli-automate/ for best practices.
To login, run: atlas auth login`,
ErrInvalidRefreshToken)
}
return err
}
Expand Down
10 changes: 4 additions & 6 deletions internal/cli/root/atlas/builder.go
Expand Up @@ -348,14 +348,12 @@ func (n *Notifier) notifyIfApplicable(isHb bool) error {
} else {
upgradeInstructions = "To upgrade, see: https://dochub.mongodb.org/core/install-atlas-cli"
}

newVersionTemplate := `
A new version of atlascli is available '%s'!
_, err = fmt.Fprintf(n.writer, `
A new version of atlascli is available %q!
%s

To disable this alert, run "%s config set skip_update_check true"
`
_, err = fmt.Fprintf(n.writer, newVersionTemplate, release.Version, upgradeInstructions, config.BinName())
To disable this alert, run "atlas config set skip_update_check true"
`, release.Version, upgradeInstructions)
return err
}

Expand Down
87 changes: 37 additions & 50 deletions internal/cli/root/atlas/builder_test.go
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/golang/mock/gomock"
"github.com/google/go-github/v50/github"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/config"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/latestrelease"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/mocks"
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/test"
Expand All @@ -41,8 +40,41 @@ func TestBuilder(t *testing.T) {
}

func TestOutputOpts_notifyIfApplicable(t *testing.T) {
tests := testCases()
f := false
atlasV := "atlascli/v2.0.0"
tests := []struct {
currentVersion string
expectNewVersion bool
release *github.RepositoryRelease
}{
{
currentVersion: "atlascli/v1.0.0",
expectNewVersion: true,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v3.0.0",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v2.0.0",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v2.0.0-123",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v3.0.0-123",
expectNewVersion: false,
release: nil,
},
}
for _, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("%v/%v", tt.currentVersion, tt.release), func(t *testing.T) {
prevVersion := version.Version
version.Version = tt.currentVersion
Expand Down Expand Up @@ -82,11 +114,11 @@ func TestOutputOpts_notifyIfApplicable(t *testing.T) {
want := ""
if tt.expectNewVersion {
want = fmt.Sprintf(`
A new version of atlascli is available '%v'!
A new version of atlascli is available %q!
To upgrade, see: https://dochub.mongodb.org/core/install-atlas-cli

To disable this alert, run "%s config set skip_update_check true"
`, v, config.BinName())
To disable this alert, run "atlas config set skip_update_check true"
`, v)
}

if got := bufOut.String(); got != want {
Expand All @@ -95,48 +127,3 @@ To disable this alert, run "%s config set skip_update_check true"
})
}
}

type testCase struct {
currentVersion string
expectNewVersion bool
release *github.RepositoryRelease
}

func testCases() []testCase {
f := false
atlasV := "atlascli/v2.0.0"

tests := []testCase{
{
currentVersion: "v1.0.0",
expectNewVersion: true,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "atlascli/v1.0.0",
expectNewVersion: true,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v3.0.0",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v2.0.0",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v2.0.0-123",
expectNewVersion: false,
release: &github.RepositoryRelease{TagName: &atlasV, Prerelease: &f, Draft: &f},
},
{
currentVersion: "v3.0.0-123",
expectNewVersion: false,
release: nil,
},
}
return tests
}
4 changes: 0 additions & 4 deletions internal/config/profile.go
Expand Up @@ -77,10 +77,6 @@ var (
defaultProfile = newProfile()
)

func BinName() string {
return "atlas"
}

type Setter interface {
Set(string, interface{})
}
Expand Down
18 changes: 6 additions & 12 deletions internal/validate/validate.go
Expand Up @@ -104,16 +104,12 @@ func Credentials() error {
return nil
}

configCMD := "config"
if config.BinName() == "atlas" {
configCMD += " init"
}
return fmt.Errorf(
"%w\n\nTo log in using your Atlas username and password, run: %s auth login\nTo set credentials using API keys, run: %s %s",
`%w

To log in using your Atlas username and password, run: atlas auth login
To set credentials using API keys, run: atlas config init`,
ErrMissingCredentials,
config.BinName(),
config.BinName(),
configCMD,
)
}

Expand All @@ -126,10 +122,9 @@ func NoAPIKeys() error {
}
return fmt.Errorf(`%w (%s)

To authenticate using your Atlas username and password on a new profile, run: %s auth login --profile <profile_name>`,
To authenticate using your Atlas username and password on a new profile, run: atlas auth login --profile <profile_name>`,
ErrAlreadyAuthenticatedAPIKeys,
config.PublicAPIKey(),
config.BinName(),
)
}

Expand All @@ -143,10 +138,9 @@ func NoAccessToken() error {
subject, _ := config.AccessTokenSubject()
return fmt.Errorf(`%w (%s)

To log out, run: %s auth logout`,
To log out, run: atlas auth logout`,
ErrAlreadyAuthenticatedToken,
subject,
config.BinName(),
)
}

Expand Down