diff --git a/internal/cli/global_opts.go b/internal/cli/global_opts.go index 5f2a45bf3f..a58f13d7a9 100644 --- a/internal/cli/global_opts.go +++ b/internal/cli/global_opts.go @@ -123,21 +123,3 @@ func DescriptionServiceName() string { } return "Atlas" } - -// ReturnValueForSetting returns a boolean value that is useful when working with boolean flags to inform -// whether the given option should be active or inactive. -func ReturnValueForSetting(enableFlag, disableFlag bool) *bool { - var valueToSet bool - if enableFlag && disableFlag { - return nil - } - if enableFlag { - valueToSet = true - return &valueToSet - } - if disableFlag { - valueToSet = false - return &valueToSet - } - return nil -} diff --git a/internal/cli/refresher_opts.go b/internal/cli/refresher_opts.go index 0cdb3c8e57..1f11cf46d4 100644 --- a/internal/cli/refresher_opts.go +++ b/internal/cli/refresher_opts.go @@ -25,8 +25,6 @@ import ( "go.mongodb.org/ops-manager/opsmngr" ) -var TokenRefreshed bool - type RefresherOpts struct { flow Refresher } @@ -60,7 +58,6 @@ func (opts *RefresherOpts) RefreshAccessToken(ctx context.Context) error { return err } if current.Valid() { - TokenRefreshed = true return nil } t, _, err := opts.flow.RefreshToken(ctx, config.RefreshToken()) @@ -76,11 +73,7 @@ func (opts *RefresherOpts) RefreshAccessToken(ctx context.Context) error { } config.SetAccessToken(t.AccessToken) config.SetRefreshToken(t.RefreshToken) - if err := config.Save(); err != nil { - return err - } - TokenRefreshed = true - return nil + return config.Save() } func (opts *RefresherOpts) PollToken(c context.Context, d *atlasauth.DeviceCode) (*atlasauth.Token, *opsmngr.Response, error) { diff --git a/internal/config/profile.go b/internal/config/profile.go index ceb5dd6cc4..34e0973d39 100644 --- a/internal/config/profile.go +++ b/internal/config/profile.go @@ -39,14 +39,12 @@ import ( const ( MongoCLIEnvPrefix = "MCLI" // MongoCLIEnvPrefix prefix for MongoCLI ENV variables - AtlasCLIEnvPrefix = "MONGODB_ATLAS" // AtlasCLIEnvPrefix prefix for AtlasCLI ENV variables DefaultProfile = "default" // DefaultProfile default CloudManagerService = "cloud-manager" // CloudManagerService settings when using CLoud Manager API OpsManagerService = "ops-manager" // OpsManagerService settings when using Ops Manager API JSON = "json" // JSON output format as json projectID = "project_id" orgID = "org_id" - mongoShellPath = "mongosh_path" configType = "toml" service = "service" publicAPIKey = "public_api_key" @@ -64,20 +62,11 @@ const ( configPerm = 0600 defaultPermissions = 0700 skipUpdateCheck = "skip_update_check" - TelemetryEnabledProperty = "telemetry_enabled" MongoCLI = "mongocli" - ContainerizedHostNameEnv = "MONGODB_ATLAS_IS_CONTAINERIZED" - GitHubActionsHostNameEnv = "GITHUB_ACTIONS" - AtlasActionHostNameEnv = "ATLAS_GITHUB_ACTION" - NativeHostName = "native" - DockerContainerHostName = "container" - GitHubActionsHostName = "all_github_actions" - AtlasActionHostName = "atlascli_github_action" ) var ( - HostName = getConfigHostnameFromEnvs() - UserAgent = fmt.Sprintf("%s/%s (%s;%s;%s)", MongoCLI, version.Version, runtime.GOOS, runtime.GOARCH, HostName) + UserAgent = fmt.Sprintf("%s/%s (%s;%s)", MongoCLI, version.Version, runtime.GOOS, runtime.GOARCH) defaultProfile = newProfile() ) @@ -122,9 +111,7 @@ func Properties() []string { baseURL, opsManagerCACertificate, opsManagerSkipVerify, - mongoShellPath, skipUpdateCheck, - TelemetryEnabledProperty, AccessTokenField, RefreshTokenField, } @@ -133,15 +120,12 @@ func Properties() []string { func BooleanProperties() []string { return []string{ skipUpdateCheck, - TelemetryEnabledProperty, } } func GlobalProperties() []string { return []string{ skipUpdateCheck, - TelemetryEnabledProperty, - mongoShellPath, } } @@ -173,51 +157,6 @@ func Exists(name string) bool { return search.StringInSlice(List(), name) } -// getConfigHostnameFromEnvs patches the agent hostname based on set env vars. -func getConfigHostnameFromEnvs() string { - var builder strings.Builder - - envVars := []struct { - envName string - hostName string - }{ - {AtlasActionHostNameEnv, AtlasActionHostName}, - {GitHubActionsHostNameEnv, GitHubActionsHostName}, - {ContainerizedHostNameEnv, DockerContainerHostName}, - } - - for _, envVar := range envVars { - if envIsTrue(envVar.envName) { - appendToHostName(&builder, envVar.hostName) - } else { - appendToHostName(&builder, "-") - } - } - configHostName := builder.String() - - if isDefaultHostName(configHostName) { - return NativeHostName - } - return configHostName -} - -func envIsTrue(env string) bool { - return IsTrue(os.Getenv(env)) -} - -func appendToHostName(builder *strings.Builder, configVal string) { - if builder.Len() > 0 { - builder.WriteString("|") - } - builder.WriteString(configVal) -} - -// isDefaultHostName checks if the hostname is the default placeholder. -func isDefaultHostName(hostname string) bool { - // Using strings.Count for a more dynamic approach. - return strings.Count(hostname, "-") == strings.Count(hostname, "|")+1 -} - func newProfile() *Profile { configDir, err := CLIConfigHome() np := &Profile{ @@ -634,21 +573,6 @@ func (p *Profile) Rename(newProfileName string) error { return nil } -func LoadAtlasCLIConfig() error { return Default().LoadAtlasCLIConfig(true) } -func (p *Profile) LoadAtlasCLIConfig(readEnvironmentVars bool) error { - if p.err != nil { - return p.err - } - - viper.SetConfigName("config") - - if hasMongoCLIEnvVars() { - viper.SetEnvKeyReplacer(strings.NewReplacer(AtlasCLIEnvPrefix, MongoCLIEnvPrefix)) - } - - return p.load(readEnvironmentVars, AtlasCLIEnvPrefix) -} - func LoadMongoCLIConfig() error { return Default().LoadMongoCLIConfig(true) } func (p *Profile) LoadMongoCLIConfig(readEnvironmentVars bool) error { if p.err != nil { @@ -658,17 +582,6 @@ func (p *Profile) LoadMongoCLIConfig(readEnvironmentVars bool) error { return p.load(readEnvironmentVars, MongoCLIEnvPrefix) } -func hasMongoCLIEnvVars() bool { - envVars := os.Environ() - for _, v := range envVars { - if strings.HasPrefix(v, MongoCLIEnvPrefix) { - return true - } - } - - return false -} - func (p *Profile) load(readEnvironmentVars bool, envPrefix string) error { viper.SetConfigType(configType) viper.SetConfigPermissions(configPerm) @@ -737,16 +650,6 @@ func MongoCLIConfigHome() (string, error) { return path.Join(home, "mongocli"), nil } -// AtlasCLIConfigHome retrieves configHome path based used by AtlasCLI. -func AtlasCLIConfigHome() (string, error) { - home, err := os.UserConfigDir() - if err != nil { - return "", err - } - - return path.Join(home, "atlascli"), nil -} - // CLIConfigHome retrieves configHome path. func CLIConfigHome() (string, error) { return MongoCLIConfigHome() diff --git a/internal/config/profile_test.go b/internal/config/profile_test.go index 5311767d55..2dd4fb476e 100644 --- a/internal/config/profile_test.go +++ b/internal/config/profile_test.go @@ -21,7 +21,6 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -68,24 +67,6 @@ func TestConfig_OldMongoCLIConfigHome(t *testing.T) { }) } -func TestConfig_AtlasCLIConfigHome(t *testing.T) { - t.Run("with env set", func(t *testing.T) { - expHome, err := os.UserConfigDir() - expected := fmt.Sprintf("%s/atlascli", expHome) - if err != nil { - t.Fatalf("os.UserConfigDir() unexpected error: %v", err) - } - - home, err := AtlasCLIConfigHome() - if err != nil { - t.Fatalf("AtlasCLIConfigHome() unexpected error: %v", err) - } - if home != expected { - t.Errorf("AtlasCLIConfigHome() = %s; want '%s'", home, expected) - } - }) -} - func TestConfig_IsTrue(t *testing.T) { tests := []struct { input string @@ -163,77 +144,6 @@ func TestConfig_IsTrue(t *testing.T) { } } -func Test_getConfigHostname(t *testing.T) { - type fields struct { - containerizedEnv string - atlasActionEnv string - ghActionsEnv string - } - tests := []struct { - name string - fields fields - expectedHostName string - }{ - { - name: "sets native hostname when no hostname env var is set", - fields: fields{ - containerizedEnv: "", - atlasActionEnv: "", - ghActionsEnv: "", - }, - expectedHostName: NativeHostName, - }, - { - name: "sets container hostname when containerized env var is set", - fields: fields{ - containerizedEnv: "true", - atlasActionEnv: "", - ghActionsEnv: "", - }, - expectedHostName: "-|-|" + DockerContainerHostName, - }, - { - name: "sets atlas action hostname when containerized env var is set", - fields: fields{ - containerizedEnv: "", - atlasActionEnv: "true", - ghActionsEnv: "", - }, - expectedHostName: AtlasActionHostName + "|-|-", - }, - { - name: "sets github actions hostname when action env var is set", - fields: fields{ - containerizedEnv: "", - atlasActionEnv: "", - ghActionsEnv: "true", - }, - expectedHostName: "-|" + GitHubActionsHostName + "|-", - }, - { - name: "sets actions and containerized hostnames when both env vars are set", - fields: fields{ - containerizedEnv: "true", - atlasActionEnv: "true", - ghActionsEnv: "true", - }, - expectedHostName: AtlasActionHostName + "|" + GitHubActionsHostName + "|" + DockerContainerHostName, - }, - } - for _, tt := range tests { - fields := tt.fields - expectedHostName := tt.expectedHostName - t.Run(tt.name, func(t *testing.T) { - t.Setenv(AtlasActionHostNameEnv, fields.atlasActionEnv) - t.Setenv(GitHubActionsHostNameEnv, fields.ghActionsEnv) - t.Setenv(ContainerizedHostNameEnv, fields.containerizedEnv) - actualHostName := getConfigHostnameFromEnvs() - - assert.Equal(t, expectedHostName, actualHostName) - }) - } -} - func TestConfig_SetName(t *testing.T) { t.Run("valid", func(t *testing.T) { require.NoError(t, SetName("default")) diff --git a/internal/store/store.go b/internal/store/store.go index 3b721d6b9e..a0ebdb20ce 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -47,7 +47,6 @@ const ( idleConnTimeout = 30 * time.Second expectContinueTimeout = 1 * time.Second versionManifestStaticPath = "https://opsmanager.mongodb.com/" - cloudGovServiceURL = "https://cloud.mongodbgov.com/" ) var errUnsupportedService = errors.New("unsupported service") @@ -227,13 +226,6 @@ func SkipVerify() Option { } } -func Telemetry() Option { - return func(s *Store) error { - s.telemetry = true - return nil - } -} - // CredentialsGetter interface for how to get credentials when Store must be authenticated. type CredentialsGetter interface { PublicAPIKey() string