Documentation
¶
Index ¶
- Constants
- Variables
- func APIVersion() string
- func AccessToken() string
- func AccessTokenSubject() (string, error)
- func AccountURL() string
- func AllProperties() []string
- func BooleanProperties() []string
- func CLIConfigHome() (string, error)
- func ClientID() string
- func ClientSecret() string
- func Delete() error
- func Exists(name string) bool
- func Get(name string) any
- func GetBool(name string) bool
- func GetInt64(name string) int64
- func GetLocalDeploymentImage() string
- func GetString(name string) string
- func GlobalProperties() []string
- func InitProfile(profile string) error
- func IsAccessSet() bool
- func IsCloud() bool
- func IsTelemetryEnabledSet() bool
- func IsTrue(s string) bool
- func List() []string
- func Name() string
- func OpsManagerURL() string
- func OrgID() string
- func Output() string
- func Path(f string) (string, error)
- func PrivateAPIKey() string
- func ProfileProperties() []string
- func ProjectID() string
- func PublicAPIKey() string
- func RefreshToken() string
- func Rename(newProfileName string) error
- func Save() error
- func Service() string
- func Set(name string, value any)
- func SetAPIVersion(v string)
- func SetAccessToken(v string)
- func SetAuthType(v AuthMechanism)
- func SetClientID(v string)
- func SetClientSecret(v string)
- func SetDefaultProfile(profile *Profile)
- func SetGlobal(name string, value any)
- func SetLocalDeploymentImage(v string)
- func SetName(name string) error
- func SetOpsManagerURL(v string)
- func SetOrgID(v string)
- func SetOutput(v string)
- func SetPrivateAPIKey(v string)
- func SetProfile(profile *Profile)
- func SetProjectID(v string)
- func SetPublicAPIKey(v string)
- func SetRefreshToken(v string)
- func SetService(v string)
- func SetSilenceStorageWarning(v bool)
- func SetSkipUpdateCheck(v bool)
- func SetTelemetryEnabled(v bool)
- func SilenceStorageWarning() bool
- func SkipUpdateCheck() bool
- func TelemetryEnabled() bool
- func Token() (*auth.Token, error)
- func UserAgent(version string) string
- func ViperConfigStoreFilename(configDir string) string
- func WithProfile(ctx context.Context, profile *Profile) context.Context
- type AuthMechanism
- type InMemoryStore
- func (*InMemoryStore) DeleteProfile(_ string) error
- func (s *InMemoryStore) GetGlobalValue(propertyName string) any
- func (s *InMemoryStore) GetHierarchicalValue(profileName string, propertyName string) any
- func (s *InMemoryStore) GetProfileNames() []string
- func (s *InMemoryStore) GetProfileStringMap(profileName string) map[string]string
- func (s *InMemoryStore) GetProfileValue(profileName string, propertyName string) any
- func (*InMemoryStore) IsSecure() bool
- func (s *InMemoryStore) IsSetGlobal(propertyName string) bool
- func (*InMemoryStore) RenameProfile(_, _ string) error
- func (*InMemoryStore) Save() error
- func (s *InMemoryStore) SetGlobalValue(propertyName string, value any)
- func (s *InMemoryStore) SetProfileValue(profileName string, propertyName string, value any)
- type Profile
- func (p *Profile) APIVersion() string
- func (p *Profile) AccessToken() string
- func (p *Profile) AccessTokenSubject() (string, error)
- func (p *Profile) AccountURL() string
- func (p *Profile) AuthType() AuthMechanism
- func (p *Profile) ClientID() string
- func (p *Profile) ClientSecret() string
- func (p *Profile) Delete() error
- func (p *Profile) Get(name string) any
- func (p *Profile) GetBool(name string) bool
- func (p *Profile) GetBoolWithDefault(name string, defaultValue bool) bool
- func (p *Profile) GetInt64(name string) int64
- func (p *Profile) GetLocalDeploymentImage() string
- func (p *Profile) GetString(name string) string
- func (p *Profile) IsAccessSet() bool
- func (p *Profile) IsTelemetryEnabledSet() bool
- func (p *Profile) List() []string
- func (p *Profile) Name() string
- func (p *Profile) OpsManagerURL() string
- func (p *Profile) OrgID() string
- func (p *Profile) Output() string
- func (p *Profile) PrivateAPIKey() string
- func (p *Profile) ProjectID() string
- func (p *Profile) PublicAPIKey() string
- func (p *Profile) RefreshToken() string
- func (p *Profile) Rename(newProfileName string) error
- func (p *Profile) Save() error
- func (p *Profile) Service() string
- func (p *Profile) Set(name string, value any)
- func (p *Profile) SetAPIVersion(v string)
- func (p *Profile) SetAccessToken(v string)
- func (p *Profile) SetAuthType(v AuthMechanism)
- func (p *Profile) SetClientID(v string)
- func (p *Profile) SetClientSecret(v string)
- func (p *Profile) SetGlobal(name string, value any)
- func (*Profile) SetLocalDeploymentImage(v string)
- func (p *Profile) SetName(name string) error
- func (p *Profile) SetOpsManagerURL(v string)
- func (p *Profile) SetOrgID(v string)
- func (p *Profile) SetOutput(v string)
- func (p *Profile) SetPrivateAPIKey(v string)
- func (p *Profile) SetProjectID(v string)
- func (p *Profile) SetPublicAPIKey(v string)
- func (p *Profile) SetRefreshToken(v string)
- func (p *Profile) SetService(v string)
- func (*Profile) SetSilenceStorageWarning(v bool)
- func (*Profile) SetSkipUpdateCheck(v bool)
- func (*Profile) SetTelemetryEnabled(v bool)
- func (p *Profile) SilenceStorageWarning() bool
- func (p *Profile) SkipUpdateCheck() bool
- func (p *Profile) TelemetryEnabled() bool
- func (p *Profile) Token() (*auth.Token, error)
- type ProxyStore
- func (p *ProxyStore) DeleteProfile(profileName string) error
- func (p *ProxyStore) GetGlobalValue(propertyName string) any
- func (p *ProxyStore) GetHierarchicalValue(profileName string, propertyName string) any
- func (p *ProxyStore) GetProfileNames() []string
- func (p *ProxyStore) GetProfileStringMap(profileName string) map[string]string
- func (p *ProxyStore) GetProfileValue(profileName string, propertyName string) any
- func (*ProxyStore) IsSecure() bool
- func (p *ProxyStore) IsSetGlobal(propertyName string) bool
- func (p *ProxyStore) RenameProfile(oldProfileName string, newProfileName string) error
- func (p *ProxyStore) Save() error
- func (p *ProxyStore) SetGlobalValue(propertyName string, value any)
- func (p *ProxyStore) SetProfileValue(profileName string, propertyName string, value any)
- type SecureStore
- type Store
- type ViperConfigStore
- func (s *ViperConfigStore) DeleteProfile(profileName string) error
- func (s *ViperConfigStore) Filename() string
- func (s *ViperConfigStore) GetGlobalValue(propertyName string) any
- func (s *ViperConfigStore) GetHierarchicalValue(profileName string, propertyName string) any
- func (s *ViperConfigStore) GetProfileNames() []string
- func (s *ViperConfigStore) GetProfileStringMap(profileName string) map[string]string
- func (s *ViperConfigStore) GetProfileValue(profileName string, propertyName string) any
- func (*ViperConfigStore) IsSecure() bool
- func (s *ViperConfigStore) IsSetGlobal(propertyName string) bool
- func (s *ViperConfigStore) RenameProfile(oldProfileName string, newProfileName string) error
- func (s *ViperConfigStore) Save() error
- func (s *ViperConfigStore) SetGlobalValue(propertyName string, value any)
- func (s *ViperConfigStore) SetProfileValue(profileName string, propertyName string, value any)
Constants ¶
const ( ProfileFlag = "profile" MongoCLIEnvPrefix = "MCLI" // MongoCLIEnvPrefix prefix for MongoCLI ENV variables AtlasCLIEnvPrefix = "MONGODB_ATLAS" // AtlasCLIEnvPrefix prefix for AtlasCLI ENV variables DefaultProfile = "default" // DefaultProfile default CloudService = "cloud" // CloudService setting when using Atlas API CloudGovService = "cloudgov" // CloudGovService setting when using Atlas API for Government AuthTypeField = "auth_type" AccessTokenField = "access_token" RefreshTokenField = "refresh_token" ClientIDField = "client_id" ClientSecretField = "client_secret" OpsManagerURLField = "ops_manager_url" AccountURLField = "account_url" TelemetryEnabledProperty = "telemetry_enabled" AtlasCLI = "atlascli" ContainerizedHostNameEnv = "MONGODB_ATLAS_IS_CONTAINERIZED" GitHubActionsHostNameEnv = "GITHUB_ACTIONS" AtlasActionHostNameEnv = "ATLAS_GITHUB_ACTION" CLIUserTypeEnv = "CLI_USER_TYPE" // CLIUserTypeEnv is used to separate MongoDB University users from default users DefaultUser = "default" // Users that do NOT use ATLAS CLI with MongoDB University UniversityUser = "university" // Users that uses ATLAS CLI with MongoDB University NativeHostName = "native" DockerContainerHostName = "container" GitHubActionsHostName = "all_github_actions" AtlasActionHostName = "atlascli_github_action" LocalDeploymentImage = "local_deployment_image" // LocalDeploymentImage is the config key for the MongoDB Local Dev Docker image Version = "version" // versionField is the key for the configuration version )
const (
MaxSupportedVersion = 2
)
MaxSupportedVersion is the maximum supported config version available in AtlasCLI.
Variables ¶
var ( CLIUserType = newCLIUserTypeFromEnvs() HostName = getConfigHostnameFromEnvs() )
var ErrProfileNameHasDots = errors.New("profile should not contain '.'")
var SecureProperties = []string{ publicAPIKey, privateAPIKey, AccessTokenField, RefreshTokenField, ClientIDField, ClientSecretField, }
SecureProperties defines which configuration properties require secure storage.
Functions ¶
func AccessTokenSubject ¶
AccessTokenSubject will return the encoded subject in a JWT. This method won't verify the token signature, it's only safe to use to get the token claims.
func AllProperties ¶
func AllProperties() []string
func BooleanProperties ¶
func BooleanProperties() []string
func Delete ¶
func Delete() error
Delete deletes an existing configuration. The profiles are reloaded afterwards, as this edits the file directly.
func GetLocalDeploymentImage ¶
func GetLocalDeploymentImage() string
GetLocalDeploymentImage returns the configured MongoDB Docker image URL.
func GlobalProperties ¶
func GlobalProperties() []string
func InitProfile ¶
func IsAccessSet ¶
func IsAccessSet() bool
IsAccessSet return true if Service Account or API Keys credentials have been set up.
func IsTelemetryEnabledSet ¶
func IsTelemetryEnabledSet() bool
IsTelemetryEnabledSet return true if telemetry_enabled has been set.
func ProfileProperties ¶
func ProfileProperties() []string
func Rename ¶
Rename replaces the Profile to a new Profile name, overwriting any Profile that existed before.
func SetDefaultProfile ¶
func SetDefaultProfile(profile *Profile)
func SetLocalDeploymentImage ¶
func SetLocalDeploymentImage(v string)
SetLocalDeploymentImage sets the MongoDB Docker image URL.
func SetOpsManagerURL ¶
func SetOpsManagerURL(v string)
SetOpsManagerURL set configured ops manager base url.
func SetPrivateAPIKey ¶
func SetPrivateAPIKey(v string)
SetPrivateAPIKey set configured private api key.
func SetProfile ¶
func SetProfile(profile *Profile)
Workaround to keep existing code working We cannot set the profile immediately because of a race condition which breaks all the unit tests
The goal is to get rid of this, but we will need to do this gradually, since it's a large change that affects almost every command
func SetSilenceStorageWarning ¶
func SetSilenceStorageWarning(v bool)
SetSilenceStorageWarning sets the global silence storage warning.
func SetSkipUpdateCheck ¶
func SetSkipUpdateCheck(v bool)
SetSkipUpdateCheck sets the global skip update check.
func SetTelemetryEnabled ¶
func SetTelemetryEnabled(v bool)
SetTelemetryEnabled sets the telemetry enabled value.
func SilenceStorageWarning ¶
func SilenceStorageWarning() bool
SilenceStorageWarning get the global silence storage warning.
func SkipUpdateCheck ¶
func SkipUpdateCheck() bool
SkipUpdateCheck get the global skip update check.
func TelemetryEnabled ¶
func TelemetryEnabled() bool
TelemetryEnabled get the configured telemetry enabled value.
func ViperConfigStoreFilename ¶
ViperConfigStoreFilename returns the full path to the configuration file.
Types ¶
type AuthMechanism ¶
type AuthMechanism string
const ( APIKeys AuthMechanism = "api_keys" UserAccount AuthMechanism = "user_account" ServiceAccount AuthMechanism = "service_account" NoAuth AuthMechanism = "no_auth" )
func AuthType ¶
func AuthType() AuthMechanism
AuthType determines the auth type, prioritizing credentials set via environment variables. It first retrieves the auth type configured in the profile. If programmatic credentials that do not match the profile's auth type are detected, AuthType infers that these credentials were set via environment variables and returns the corresponding auth type. This assumes users will not explicitly export the auth type variable.
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
Temporary InMemoryStore to mimick legacy behavior Will be removed by CLOUDP-339855 when we get rid of static references in the profile
func NewInMemoryStore ¶
func NewInMemoryStore() *InMemoryStore
NewInMemoryStore creates a new InMemoryStore instance with an initialized Viper configuration. This store is used as a temporary workaround for unit tests that expect profiles to be available before they are actually configured, preventing nil pointer references.
func (*InMemoryStore) DeleteProfile ¶
func (*InMemoryStore) DeleteProfile(_ string) error
DeleteProfile is not implemented for InMemoryStore and will panic if called. This functionality is intended for persistent existing tests.
func (*InMemoryStore) GetGlobalValue ¶
func (s *InMemoryStore) GetGlobalValue(propertyName string) any
GetGlobalValue retrieves a global configuration property value.
func (*InMemoryStore) GetHierarchicalValue ¶
func (s *InMemoryStore) GetHierarchicalValue(profileName string, propertyName string) any
GetHierarchicalValue retrieves a property value with hierarchical precedence. It first checks for global properties, then falls back to profile-specific settings.
func (*InMemoryStore) GetProfileNames ¶
func (s *InMemoryStore) GetProfileNames() []string
GetProfileNames returns a sorted list of all profile names stored in the configuration.
func (*InMemoryStore) GetProfileStringMap ¶
func (s *InMemoryStore) GetProfileStringMap(profileName string) map[string]string
GetProfileStringMap returns all configuration properties for a profile as a string map.
func (*InMemoryStore) GetProfileValue ¶
func (s *InMemoryStore) GetProfileValue(profileName string, propertyName string) any
GetProfileValue retrieves a property value from a specific profile's configuration.
func (*InMemoryStore) IsSecure ¶
func (*InMemoryStore) IsSecure() bool
IsSecure returns true to indicate this store treats data as secure, even though it's stored in memory. This maintains compatibility with the Store interface.
func (*InMemoryStore) IsSetGlobal ¶
func (s *InMemoryStore) IsSetGlobal(propertyName string) bool
IsSetGlobal checks whether a global configuration property has been set.
func (*InMemoryStore) RenameProfile ¶
func (*InMemoryStore) RenameProfile(_, _ string) error
RenameProfile is not implemented for InMemoryStore and will panic if called. This functionality is intended for persistent existing tests.
func (*InMemoryStore) Save ¶
func (*InMemoryStore) Save() error
Save is a no-op for InMemoryStore since data is only stored in memory and doesn't need to be persisted to disk.
func (*InMemoryStore) SetGlobalValue ¶
func (s *InMemoryStore) SetGlobalValue(propertyName string, value any)
SetGlobalValue sets a global configuration property that applies across all profiles.
func (*InMemoryStore) SetProfileValue ¶
func (s *InMemoryStore) SetProfileValue(profileName string, propertyName string, value any)
SetProfileValue sets a property value for a specific profile, creating or updating the profile's configuration map as needed.
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
func LoadAtlasCLIConfig ¶
LoadAtlasCLIConfig loads configuration using the maximum supported version, ensuring plugins always use the latest AtlasCLI configuration schema.
func LoadAtlasCLIConfigWithVersion ¶
LoadAtlasCLIConfigWithVersion loads configuration with validation for specified version. The expectedVersion parameter enforces compatibility by rejecting configs that are newer or older than expected.
func NewProfile ¶
func ProfileFromContext ¶
Getting a value
func (*Profile) APIVersion ¶
func (*Profile) AccessToken ¶
func (*Profile) AccessTokenSubject ¶
func (*Profile) AccountURL ¶
func (*Profile) AuthType ¶
func (p *Profile) AuthType() AuthMechanism
func (*Profile) ClientSecret ¶
func (*Profile) GetBoolWithDefault ¶
func (*Profile) GetLocalDeploymentImage ¶
func (*Profile) IsAccessSet ¶
func (*Profile) IsTelemetryEnabledSet ¶
func (*Profile) OpsManagerURL ¶
func (*Profile) PrivateAPIKey ¶
func (*Profile) PublicAPIKey ¶
func (*Profile) RefreshToken ¶
func (*Profile) SetAPIVersion ¶
func (*Profile) SetAccessToken ¶
func (*Profile) SetAuthType ¶
func (p *Profile) SetAuthType(v AuthMechanism)
func (*Profile) SetClientID ¶
func (*Profile) SetClientSecret ¶
func (*Profile) SetLocalDeploymentImage ¶
func (*Profile) SetOpsManagerURL ¶
func (*Profile) SetPrivateAPIKey ¶
func (*Profile) SetProjectID ¶
func (*Profile) SetPublicAPIKey ¶
func (*Profile) SetRefreshToken ¶
func (*Profile) SetService ¶
func (*Profile) SetSilenceStorageWarning ¶
func (*Profile) SetSkipUpdateCheck ¶
func (*Profile) SetTelemetryEnabled ¶
func (*Profile) SilenceStorageWarning ¶
func (*Profile) SkipUpdateCheck ¶
func (*Profile) TelemetryEnabled ¶
type ProxyStore ¶
type ProxyStore struct {
// contains filtered or unexported fields
}
ProxyStore routes properties between secure and insecure stores based on property type.
func (*ProxyStore) DeleteProfile ¶
func (p *ProxyStore) DeleteProfile(profileName string) error
DeleteProfile delegates to the insecure store for profile management.
func (*ProxyStore) GetGlobalValue ¶
func (p *ProxyStore) GetGlobalValue(propertyName string) any
GetGlobalValue routes to secure or insecure store based on property type.
func (*ProxyStore) GetHierarchicalValue ¶
func (p *ProxyStore) GetHierarchicalValue(profileName string, propertyName string) any
GetHierarchicalValue routes to secure or insecure store based on property type. For secure properties, it first checks the insecure store for a value, in the case that environment variables are used. If no value is found, it will proceed with secure store.
func (*ProxyStore) GetProfileNames ¶
func (p *ProxyStore) GetProfileNames() []string
GetProfileNames returns profile names from the insecure store.
func (*ProxyStore) GetProfileStringMap ¶
func (p *ProxyStore) GetProfileStringMap(profileName string) map[string]string
GetProfileStringMap returns insecure properties only, excluding secure values.
func (*ProxyStore) GetProfileValue ¶
func (p *ProxyStore) GetProfileValue(profileName string, propertyName string) any
GetProfileValue routes to secure or insecure store based on property type.
func (*ProxyStore) IsSecure ¶
func (*ProxyStore) IsSecure() bool
IsSecure returns true as ProxyStore provides secure storage capabilities.
func (*ProxyStore) IsSetGlobal ¶
func (p *ProxyStore) IsSetGlobal(propertyName string) bool
IsSetGlobal checks only insecure store for global property existence as no secure properties are global
func (*ProxyStore) RenameProfile ¶
func (p *ProxyStore) RenameProfile(oldProfileName string, newProfileName string) error
RenameProfile delegates to the insecure store for profile management.
func (*ProxyStore) Save ¶
func (p *ProxyStore) Save() error
Save persists both secure and insecure stores, collecting any errors.
func (*ProxyStore) SetGlobalValue ¶
func (p *ProxyStore) SetGlobalValue(propertyName string, value any)
SetGlobalValue routes to secure or insecure store based on property type.
func (*ProxyStore) SetProfileValue ¶
func (p *ProxyStore) SetProfileValue(profileName string, propertyName string, value any)
SetProfileValue routes to secure or insecure store based on property type.
type SecureStore ¶
type Store ¶
type Store interface {
IsSecure() bool
Save() error
GetProfileNames() []string
RenameProfile(oldProfileName string, newProfileName string) error
DeleteProfile(profileName string) error
GetHierarchicalValue(profileName string, propertyName string) any
SetProfileValue(profileName string, propertyName string, value any)
GetProfileValue(profileName string, propertyName string) any
GetProfileStringMap(profileName string) map[string]string
SetGlobalValue(propertyName string, value any)
GetGlobalValue(propertyName string) any
IsSetGlobal(propertyName string) bool
}
func NewDefaultStore ¶
NewDefaultStore creates a store with default filesystem and secure storage if available.
func NewStore ¶
func NewStore(insecureStore Store, secureStore SecureStore) Store
NewStore creates a ProxyStore if secure storage is available, otherwise returns insecure store.
func NewStoreWithEnvOption ¶
NewStoreWithEnvOption creates a store with default filesystem and secure storage if available. It will load environment variables according to the loadEnvVars input.
type ViperConfigStore ¶
type ViperConfigStore struct {
// contains filtered or unexported fields
}
ViperConfigStore implements the config.Store interface
func NewViperStore ¶
func NewViperStore(fs afero.Fs, loadEnvVars bool) (*ViperConfigStore, error)
ViperConfigStore specific methods NewViperStore creates a ViperConfigStore with filesystem, config paths, and optional environment variable loading.
func (*ViperConfigStore) DeleteProfile ¶
func (s *ViperConfigStore) DeleteProfile(profileName string) error
DeleteProfile removes profile from configuration using direct TOML manipulation.
func (*ViperConfigStore) Filename ¶
func (s *ViperConfigStore) Filename() string
Filename returns this store's configuration file path.
func (*ViperConfigStore) GetGlobalValue ¶
func (s *ViperConfigStore) GetGlobalValue(propertyName string) any
GetGlobalValue retrieves global configuration property.
func (*ViperConfigStore) GetHierarchicalValue ¶
func (s *ViperConfigStore) GetHierarchicalValue(profileName string, propertyName string) any
GetHierarchicalValue checks global settings first, then profile-specific values.
func (*ViperConfigStore) GetProfileNames ¶
func (s *ViperConfigStore) GetProfileNames() []string
GetProfileNames returns all profile names in the configuration file.
func (*ViperConfigStore) GetProfileStringMap ¶
func (s *ViperConfigStore) GetProfileStringMap(profileName string) map[string]string
GetProfileStringMap returns all profile properties as string map.
func (*ViperConfigStore) GetProfileValue ¶
func (s *ViperConfigStore) GetProfileValue(profileName string, propertyName string) any
GetProfileValue retrieves property value from profile configuration.
func (*ViperConfigStore) IsSecure ¶
func (*ViperConfigStore) IsSecure() bool
IsSecure returns false as this store uses plaintext TOML files.
func (*ViperConfigStore) IsSetGlobal ¶
func (s *ViperConfigStore) IsSetGlobal(propertyName string) bool
IsSetGlobal checks if global property is set.
func (*ViperConfigStore) RenameProfile ¶
func (s *ViperConfigStore) RenameProfile(oldProfileName string, newProfileName string) error
RenameProfile copies profile configuration to new name and deletes old one.
func (*ViperConfigStore) Save ¶
func (s *ViperConfigStore) Save() error
Save persists configuration to disk, creating directories if needed.
func (*ViperConfigStore) SetGlobalValue ¶
func (s *ViperConfigStore) SetGlobalValue(propertyName string, value any)
SetGlobalValue sets global configuration property.
func (*ViperConfigStore) SetProfileValue ¶
func (s *ViperConfigStore) SetProfileValue(profileName string, propertyName string, value any)
SetProfileValue sets profile property.