Skip to content

Commit 6ede93f

Browse files
author
Gustavo Bazan
authored
task: delete Atlas dead code (#2764)
1 parent 468a07b commit 6ede93f

File tree

5 files changed

+2
-222
lines changed

5 files changed

+2
-222
lines changed

internal/cli/global_opts.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,3 @@ func DescriptionServiceName() string {
123123
}
124124
return "Atlas"
125125
}
126-
127-
// ReturnValueForSetting returns a boolean value that is useful when working with boolean flags to inform
128-
// whether the given option should be active or inactive.
129-
func ReturnValueForSetting(enableFlag, disableFlag bool) *bool {
130-
var valueToSet bool
131-
if enableFlag && disableFlag {
132-
return nil
133-
}
134-
if enableFlag {
135-
valueToSet = true
136-
return &valueToSet
137-
}
138-
if disableFlag {
139-
valueToSet = false
140-
return &valueToSet
141-
}
142-
return nil
143-
}

internal/cli/refresher_opts.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"go.mongodb.org/ops-manager/opsmngr"
2626
)
2727

28-
var TokenRefreshed bool
29-
3028
type RefresherOpts struct {
3129
flow Refresher
3230
}
@@ -60,7 +58,6 @@ func (opts *RefresherOpts) RefreshAccessToken(ctx context.Context) error {
6058
return err
6159
}
6260
if current.Valid() {
63-
TokenRefreshed = true
6461
return nil
6562
}
6663
t, _, err := opts.flow.RefreshToken(ctx, config.RefreshToken())
@@ -76,11 +73,7 @@ func (opts *RefresherOpts) RefreshAccessToken(ctx context.Context) error {
7673
}
7774
config.SetAccessToken(t.AccessToken)
7875
config.SetRefreshToken(t.RefreshToken)
79-
if err := config.Save(); err != nil {
80-
return err
81-
}
82-
TokenRefreshed = true
83-
return nil
76+
return config.Save()
8477
}
8578

8679
func (opts *RefresherOpts) PollToken(c context.Context, d *atlasauth.DeviceCode) (*atlasauth.Token, *opsmngr.Response, error) {

internal/config/profile.go

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ import (
3939

4040
const (
4141
MongoCLIEnvPrefix = "MCLI" // MongoCLIEnvPrefix prefix for MongoCLI ENV variables
42-
AtlasCLIEnvPrefix = "MONGODB_ATLAS" // AtlasCLIEnvPrefix prefix for AtlasCLI ENV variables
4342
DefaultProfile = "default" // DefaultProfile default
4443
CloudManagerService = "cloud-manager" // CloudManagerService settings when using CLoud Manager API
4544
OpsManagerService = "ops-manager" // OpsManagerService settings when using Ops Manager API
4645
JSON = "json" // JSON output format as json
4746
projectID = "project_id"
4847
orgID = "org_id"
49-
mongoShellPath = "mongosh_path"
5048
configType = "toml"
5149
service = "service"
5250
publicAPIKey = "public_api_key"
@@ -64,20 +62,11 @@ const (
6462
configPerm = 0600
6563
defaultPermissions = 0700
6664
skipUpdateCheck = "skip_update_check"
67-
TelemetryEnabledProperty = "telemetry_enabled"
6865
MongoCLI = "mongocli"
69-
ContainerizedHostNameEnv = "MONGODB_ATLAS_IS_CONTAINERIZED"
70-
GitHubActionsHostNameEnv = "GITHUB_ACTIONS"
71-
AtlasActionHostNameEnv = "ATLAS_GITHUB_ACTION"
72-
NativeHostName = "native"
73-
DockerContainerHostName = "container"
74-
GitHubActionsHostName = "all_github_actions"
75-
AtlasActionHostName = "atlascli_github_action"
7666
)
7767

7868
var (
79-
HostName = getConfigHostnameFromEnvs()
80-
UserAgent = fmt.Sprintf("%s/%s (%s;%s;%s)", MongoCLI, version.Version, runtime.GOOS, runtime.GOARCH, HostName)
69+
UserAgent = fmt.Sprintf("%s/%s (%s;%s)", MongoCLI, version.Version, runtime.GOOS, runtime.GOARCH)
8170
defaultProfile = newProfile()
8271
)
8372

@@ -122,9 +111,7 @@ func Properties() []string {
122111
baseURL,
123112
opsManagerCACertificate,
124113
opsManagerSkipVerify,
125-
mongoShellPath,
126114
skipUpdateCheck,
127-
TelemetryEnabledProperty,
128115
AccessTokenField,
129116
RefreshTokenField,
130117
}
@@ -133,15 +120,12 @@ func Properties() []string {
133120
func BooleanProperties() []string {
134121
return []string{
135122
skipUpdateCheck,
136-
TelemetryEnabledProperty,
137123
}
138124
}
139125

140126
func GlobalProperties() []string {
141127
return []string{
142128
skipUpdateCheck,
143-
TelemetryEnabledProperty,
144-
mongoShellPath,
145129
}
146130
}
147131

@@ -173,51 +157,6 @@ func Exists(name string) bool {
173157
return search.StringInSlice(List(), name)
174158
}
175159

176-
// getConfigHostnameFromEnvs patches the agent hostname based on set env vars.
177-
func getConfigHostnameFromEnvs() string {
178-
var builder strings.Builder
179-
180-
envVars := []struct {
181-
envName string
182-
hostName string
183-
}{
184-
{AtlasActionHostNameEnv, AtlasActionHostName},
185-
{GitHubActionsHostNameEnv, GitHubActionsHostName},
186-
{ContainerizedHostNameEnv, DockerContainerHostName},
187-
}
188-
189-
for _, envVar := range envVars {
190-
if envIsTrue(envVar.envName) {
191-
appendToHostName(&builder, envVar.hostName)
192-
} else {
193-
appendToHostName(&builder, "-")
194-
}
195-
}
196-
configHostName := builder.String()
197-
198-
if isDefaultHostName(configHostName) {
199-
return NativeHostName
200-
}
201-
return configHostName
202-
}
203-
204-
func envIsTrue(env string) bool {
205-
return IsTrue(os.Getenv(env))
206-
}
207-
208-
func appendToHostName(builder *strings.Builder, configVal string) {
209-
if builder.Len() > 0 {
210-
builder.WriteString("|")
211-
}
212-
builder.WriteString(configVal)
213-
}
214-
215-
// isDefaultHostName checks if the hostname is the default placeholder.
216-
func isDefaultHostName(hostname string) bool {
217-
// Using strings.Count for a more dynamic approach.
218-
return strings.Count(hostname, "-") == strings.Count(hostname, "|")+1
219-
}
220-
221160
func newProfile() *Profile {
222161
configDir, err := CLIConfigHome()
223162
np := &Profile{
@@ -634,21 +573,6 @@ func (p *Profile) Rename(newProfileName string) error {
634573
return nil
635574
}
636575

637-
func LoadAtlasCLIConfig() error { return Default().LoadAtlasCLIConfig(true) }
638-
func (p *Profile) LoadAtlasCLIConfig(readEnvironmentVars bool) error {
639-
if p.err != nil {
640-
return p.err
641-
}
642-
643-
viper.SetConfigName("config")
644-
645-
if hasMongoCLIEnvVars() {
646-
viper.SetEnvKeyReplacer(strings.NewReplacer(AtlasCLIEnvPrefix, MongoCLIEnvPrefix))
647-
}
648-
649-
return p.load(readEnvironmentVars, AtlasCLIEnvPrefix)
650-
}
651-
652576
func LoadMongoCLIConfig() error { return Default().LoadMongoCLIConfig(true) }
653577
func (p *Profile) LoadMongoCLIConfig(readEnvironmentVars bool) error {
654578
if p.err != nil {
@@ -658,17 +582,6 @@ func (p *Profile) LoadMongoCLIConfig(readEnvironmentVars bool) error {
658582
return p.load(readEnvironmentVars, MongoCLIEnvPrefix)
659583
}
660584

661-
func hasMongoCLIEnvVars() bool {
662-
envVars := os.Environ()
663-
for _, v := range envVars {
664-
if strings.HasPrefix(v, MongoCLIEnvPrefix) {
665-
return true
666-
}
667-
}
668-
669-
return false
670-
}
671-
672585
func (p *Profile) load(readEnvironmentVars bool, envPrefix string) error {
673586
viper.SetConfigType(configType)
674587
viper.SetConfigPermissions(configPerm)
@@ -737,16 +650,6 @@ func MongoCLIConfigHome() (string, error) {
737650
return path.Join(home, "mongocli"), nil
738651
}
739652

740-
// AtlasCLIConfigHome retrieves configHome path based used by AtlasCLI.
741-
func AtlasCLIConfigHome() (string, error) {
742-
home, err := os.UserConfigDir()
743-
if err != nil {
744-
return "", err
745-
}
746-
747-
return path.Join(home, "atlascli"), nil
748-
}
749-
750653
// CLIConfigHome retrieves configHome path.
751654
func CLIConfigHome() (string, error) {
752655
return MongoCLIConfigHome()

internal/config/profile_test.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222
"testing"
2323

24-
"github.com/stretchr/testify/assert"
2524
"github.com/stretchr/testify/require"
2625
)
2726

@@ -68,24 +67,6 @@ func TestConfig_OldMongoCLIConfigHome(t *testing.T) {
6867
})
6968
}
7069

71-
func TestConfig_AtlasCLIConfigHome(t *testing.T) {
72-
t.Run("with env set", func(t *testing.T) {
73-
expHome, err := os.UserConfigDir()
74-
expected := fmt.Sprintf("%s/atlascli", expHome)
75-
if err != nil {
76-
t.Fatalf("os.UserConfigDir() unexpected error: %v", err)
77-
}
78-
79-
home, err := AtlasCLIConfigHome()
80-
if err != nil {
81-
t.Fatalf("AtlasCLIConfigHome() unexpected error: %v", err)
82-
}
83-
if home != expected {
84-
t.Errorf("AtlasCLIConfigHome() = %s; want '%s'", home, expected)
85-
}
86-
})
87-
}
88-
8970
func TestConfig_IsTrue(t *testing.T) {
9071
tests := []struct {
9172
input string
@@ -163,77 +144,6 @@ func TestConfig_IsTrue(t *testing.T) {
163144
}
164145
}
165146

166-
func Test_getConfigHostname(t *testing.T) {
167-
type fields struct {
168-
containerizedEnv string
169-
atlasActionEnv string
170-
ghActionsEnv string
171-
}
172-
tests := []struct {
173-
name string
174-
fields fields
175-
expectedHostName string
176-
}{
177-
{
178-
name: "sets native hostname when no hostname env var is set",
179-
fields: fields{
180-
containerizedEnv: "",
181-
atlasActionEnv: "",
182-
ghActionsEnv: "",
183-
},
184-
expectedHostName: NativeHostName,
185-
},
186-
{
187-
name: "sets container hostname when containerized env var is set",
188-
fields: fields{
189-
containerizedEnv: "true",
190-
atlasActionEnv: "",
191-
ghActionsEnv: "",
192-
},
193-
expectedHostName: "-|-|" + DockerContainerHostName,
194-
},
195-
{
196-
name: "sets atlas action hostname when containerized env var is set",
197-
fields: fields{
198-
containerizedEnv: "",
199-
atlasActionEnv: "true",
200-
ghActionsEnv: "",
201-
},
202-
expectedHostName: AtlasActionHostName + "|-|-",
203-
},
204-
{
205-
name: "sets github actions hostname when action env var is set",
206-
fields: fields{
207-
containerizedEnv: "",
208-
atlasActionEnv: "",
209-
ghActionsEnv: "true",
210-
},
211-
expectedHostName: "-|" + GitHubActionsHostName + "|-",
212-
},
213-
{
214-
name: "sets actions and containerized hostnames when both env vars are set",
215-
fields: fields{
216-
containerizedEnv: "true",
217-
atlasActionEnv: "true",
218-
ghActionsEnv: "true",
219-
},
220-
expectedHostName: AtlasActionHostName + "|" + GitHubActionsHostName + "|" + DockerContainerHostName,
221-
},
222-
}
223-
for _, tt := range tests {
224-
fields := tt.fields
225-
expectedHostName := tt.expectedHostName
226-
t.Run(tt.name, func(t *testing.T) {
227-
t.Setenv(AtlasActionHostNameEnv, fields.atlasActionEnv)
228-
t.Setenv(GitHubActionsHostNameEnv, fields.ghActionsEnv)
229-
t.Setenv(ContainerizedHostNameEnv, fields.containerizedEnv)
230-
actualHostName := getConfigHostnameFromEnvs()
231-
232-
assert.Equal(t, expectedHostName, actualHostName)
233-
})
234-
}
235-
}
236-
237147
func TestConfig_SetName(t *testing.T) {
238148
t.Run("valid", func(t *testing.T) {
239149
require.NoError(t, SetName("default"))

internal/store/store.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const (
4747
idleConnTimeout = 30 * time.Second
4848
expectContinueTimeout = 1 * time.Second
4949
versionManifestStaticPath = "https://opsmanager.mongodb.com/"
50-
cloudGovServiceURL = "https://cloud.mongodbgov.com/"
5150
)
5251

5352
var errUnsupportedService = errors.New("unsupported service")
@@ -227,13 +226,6 @@ func SkipVerify() Option {
227226
}
228227
}
229228

230-
func Telemetry() Option {
231-
return func(s *Store) error {
232-
s.telemetry = true
233-
return nil
234-
}
235-
}
236-
237229
// CredentialsGetter interface for how to get credentials when Store must be authenticated.
238230
type CredentialsGetter interface {
239231
PublicAPIKey() string

0 commit comments

Comments
 (0)