mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 11:50:14 +01:00
cloud-setup: refactor handling of environment variables
Previously, there was NMCS_ENV_VARIABLE() macro. That macro did nothing, it merely acted as something to grep for, when searching the source for which environment variables nm-cloud-setup honors. That is an interesting thing to know, because nm-cloud-setup is configured via environment variables. Change that. Instead add a define for each environment variable. You can now instead grep for "NMCS_ENV_" to find them all.
This commit is contained in:
parent
62104477c3
commit
eaa2188119
6 changed files with 22 additions and 12 deletions
|
|
@ -633,7 +633,7 @@ main(int argc, const char *const *argv)
|
|||
nm_auto_free_nmcs_provider_get_config_result NMCSProviderGetConfigResult *result = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
_nm_logging_enabled_init(g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_LOG")));
|
||||
_nm_logging_enabled_init(g_getenv(NMCS_ENV_NM_CLOUD_SETUP_LOG));
|
||||
|
||||
_LOGD("nm-cloud-setup %s starting...", NM_DIST_VERSION);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,19 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* mark names for variables that can be used as configuration. Search
|
||||
* for NMCS_ENV_VARIABLE() to find all honored environment variables. */
|
||||
#define NMCS_ENV_VARIABLE(var) "" var ""
|
||||
/* Environment variables for configuring nm-cloud-setup */
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_ALIYUN "NM_CLOUD_SETUP_ALIYUN"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_AZURE "NM_CLOUD_SETUP_AZURE"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_EC2 "NM_CLOUD_SETUP_EC2"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_GCP "NM_CLOUD_SETUP_GCP"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_LOG "NM_CLOUD_SETUP_LOG"
|
||||
|
||||
/* Undocumented/internal environment variables for configuring nm-cloud-setup.
|
||||
* These are mainly for testing/debugging. */
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_ALIYUN_HOST "NM_CLOUD_SETUP_ALIYUN_HOST"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_AZURE_HOST "NM_CLOUD_SETUP_AZURE_HOST"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_EC2_HOST "NM_CLOUD_SETUP_EC2_HOST"
|
||||
#define NMCS_ENV_NM_CLOUD_SETUP_GCP_HOST "NM_CLOUD_SETUP_GCP_HOST"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ again:
|
|||
/* The base URI can be set via environment variable.
|
||||
* This is mainly for testing, it's not usually supposed to be configured.
|
||||
* Consider this private API! */
|
||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_ALIYUN_HOST"));
|
||||
base = g_getenv(NMCS_ENV_NM_CLOUD_SETUP_ALIYUN_HOST);
|
||||
base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_ALIYUN_HOST);
|
||||
|
||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||
|
|
@ -558,7 +558,7 @@ nmcs_provider_aliyun_class_init(NMCSProviderAliyunClass *klass)
|
|||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "aliyun";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_ALIYUN");
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_NM_CLOUD_SETUP_ALIYUN;
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ again:
|
|||
/* The base URI can be set via environment variable.
|
||||
* This is mainly for testing, it's not usually supposed to be configured.
|
||||
* Consider this private API! */
|
||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_AZURE_HOST"));
|
||||
base = g_getenv(NMCS_ENV_NM_CLOUD_SETUP_AZURE_HOST);
|
||||
base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_AZURE_BASE);
|
||||
|
||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||
|
|
@ -586,7 +586,7 @@ nmcs_provider_azure_class_init(NMCSProviderAzureClass *klass)
|
|||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "azure";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_AZURE");
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_NM_CLOUD_SETUP_AZURE;
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ again:
|
|||
/* The base URI can be set via environment variable.
|
||||
* This is mainly for testing, it's not usually supposed to be configured.
|
||||
* Consider this private API! */
|
||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2_HOST"));
|
||||
base = g_getenv(NMCS_ENV_NM_CLOUD_SETUP_EC2_HOST);
|
||||
base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_EC2_BASE);
|
||||
|
||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||
|
|
@ -435,7 +435,7 @@ nmcs_provider_ec2_class_init(NMCSProviderEC2Class *klass)
|
|||
object_class->dispose = dispose;
|
||||
|
||||
provider_class->_name = "ec2";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_EC2");
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_NM_CLOUD_SETUP_EC2;
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ again:
|
|||
/* The base URI can be set via environment variable.
|
||||
* This is mainly for testing, it's not usually supposed to be configured.
|
||||
* Consider this private API! */
|
||||
base = g_getenv(NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_GCP_HOST"));
|
||||
base = g_getenv(NMCS_ENV_NM_CLOUD_SETUP_GCP_HOST);
|
||||
base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_GCP_BASE);
|
||||
|
||||
if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
|
||||
|
|
@ -482,7 +482,7 @@ nmcs_provider_gcp_class_init(NMCSProviderGCPClass *klass)
|
|||
NMCSProviderClass *provider_class = NMCS_PROVIDER_CLASS(klass);
|
||||
|
||||
provider_class->_name = "GCP";
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_VARIABLE("NM_CLOUD_SETUP_GCP");
|
||||
provider_class->_env_provider_enabled = NMCS_ENV_NM_CLOUD_SETUP_GCP;
|
||||
provider_class->detect = detect;
|
||||
provider_class->get_config = get_config;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue