diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2023-04-17 07:08:12 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-05-12 12:42:55 +0200 |
commit | 515e69df3a549aa5a23052f3d68a04e1ed1e6b99 (patch) | |
tree | 2fd62db082007c83f45d8138179a77b6a05bc602 | |
parent | 1f310abfd81f8f4fac8a2e761fe6aa6ae5e755d5 (diff) | |
download | NetworkManager-515e69df3a549aa5a23052f3d68a04e1ed1e6b99.tar.gz |
cloud-setup/azure: add ability to redirect metadata API requests
A different host can be specified with (undocumented, private)
NM_CLOUD_SETUP_AZURE_HOST environment variable.
-rw-r--r-- | src/nm-cloud-setup/nmcs-provider-azure.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/nm-cloud-setup/nmcs-provider-azure.c b/src/nm-cloud-setup/nmcs-provider-azure.c index 69946f5c53..418d380a5d 100644 --- a/src/nm-cloud-setup/nmcs-provider-azure.c +++ b/src/nm-cloud-setup/nmcs-provider-azure.c @@ -17,8 +17,30 @@ #define NM_AZURE_METADATA_URL_BASE /* $NM_AZURE_BASE/$NM_AZURE_API_VERSION */ \ "/metadata/instance/network/interface/" +static const char * +_azure_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_AZURE_HOST")); + base = nmcs_utils_uri_complete_interned(base) ?: ("" NM_AZURE_BASE); + + if (!g_atomic_pointer_compare_and_exchange(&base_cached, NULL, base)) + goto again; + } + + return base; +} + #define _azure_uri_concat(...) \ - nmcs_utils_uri_build_concat(NM_AZURE_BASE, __VA_ARGS__, NM_AZURE_API_VERSION) + nmcs_utils_uri_build_concat(_azure_base(), __VA_ARGS__, NM_AZURE_API_VERSION) #define _azure_uri_interfaces(...) _azure_uri_concat(NM_AZURE_METADATA_URL_BASE, ##__VA_ARGS__) /*****************************************************************************/ |