@@ -39,14 +39,12 @@ import (
3939
4040const (
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
7868var (
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 {
133120func BooleanProperties () []string {
134121 return []string {
135122 skipUpdateCheck ,
136- TelemetryEnabledProperty ,
137123 }
138124}
139125
140126func 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-
221160func 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-
652576func LoadMongoCLIConfig () error { return Default ().LoadMongoCLIConfig (true ) }
653577func (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-
672585func (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.
751654func CLIConfigHome () (string , error ) {
752655 return MongoCLIConfigHome ()
0 commit comments