about summary refs log tree commit diff
path: root/src/nm-cloud-setup/nmcs-provider-aliyun.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nm-cloud-setup/nmcs-provider-aliyun.c')
-rw-r--r--src/nm-cloud-setup/nmcs-provider-aliyun.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/src/nm-cloud-setup/nmcs-provider-aliyun.c b/src/nm-cloud-setup/nmcs-provider-aliyun.c
index 7f51f431..20010a2c 100644
--- a/src/nm-cloud-setup/nmcs-provider-aliyun.c
+++ b/src/nm-cloud-setup/nmcs-provider-aliyun.c
@@ -18,27 +18,7 @@
 #define NM_ALIYUN_METADATA_URL_BASE /* $NM_ALIYUN_BASE/$NM_ALIYUN_API_VERSION */ \
     "/meta-data/network/interfaces/macs/"
 
-static const char *
-_aliyun_base(void)
-{
-    static const char *base_cached = NULL;
-    const char        *base;
-
-again:
-    base = g_atomic_pointer_get(&base_cached);
-    if (G_UNLIKELY(!base)) {
-        /* 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 = nmcs_utils_uri_complete_interned(base) ?: ("" NM_ALIYUN_HOST);
-
-        if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base))
-            goto again;
-    }
-
-    return base;
-}
+NMCS_DEFINE_HOST_BASE(_aliyun_base, NMCS_ENV_NM_CLOUD_SETUP_ALIYUN_HOST, NM_ALIYUN_HOST);
 
 #define _aliyun_uri_concat(...) nmcs_utils_uri_build_concat(_aliyun_base(), __VA_ARGS__)
 #define _aliyun_uri_interfaces(...) \
@@ -558,7 +538,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;
 }