diff options
| author | Stefan Boberg <[email protected]> | 2026-04-27 15:05:16 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-04-27 15:05:16 +0200 |
| commit | 6804dc6ff62c477399183dc85d2ad387298aa49d (patch) | |
| tree | f4153a901c758b9e385627b43f1606f8c2129a04 /src/zenserver | |
| parent | 5.8.9-pre3 (diff) | |
| download | archived-zen-6804dc6ff62c477399183dc85d2ad387298aa49d.tar.xz archived-zen-6804dc6ff62c477399183dc85d2ad387298aa49d.zip | |
GetEnvVariable: return std::optional<std::string> (#1017)
- `GetEnvVariable` now returns `std::optional<std::string>` so callers can distinguish an unset variable from one set to an empty value.
- Windows path uses `SetLastError(ERROR_SUCCESS)` + `ERROR_ENVVAR_NOT_FOUND` to detect "not found"; POSIX path returns `nullopt` when `getenv` returns `nullptr`.
- All call sites migrated. Most use `.value_or("")` to preserve current empty-or-unset behavior. The diagnostic helpers in `zen-test/artifactprovider-tests.cpp` now report `<unset>` vs `<empty>` distinctly.
- Added a check in the `ExpandEnvironmentVariables` test confirming `nullopt` for an unset variable; PATH/HOME lookups in that test use `REQUIRE(has_value())` so a missing var fails cleanly instead of throwing `bad_optional_access`.
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/hub/hydration.cpp | 10 | ||||
| -rw-r--r-- | src/zenserver/hub/zenhubserver.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/storage/projectstore/httpprojectstore.cpp | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/src/zenserver/hub/hydration.cpp b/src/zenserver/hub/hydration.cpp index 2730ba059..621af8a46 100644 --- a/src/zenserver/hub/hydration.cpp +++ b/src/zenserver/hub/hydration.cpp @@ -2303,11 +2303,11 @@ S3Hydration::S3Hydration(const Configuration& Config) : HydrationBase(Config) std::string Region = std::string(Settings["region"sv].AsString()); if (Region.empty()) { - Region = GetEnvVariable("AWS_DEFAULT_REGION"); + Region = GetEnvVariable("AWS_DEFAULT_REGION").value_or(""); } if (Region.empty()) { - Region = GetEnvVariable("AWS_REGION"); + Region = GetEnvVariable("AWS_REGION").value_or(""); } if (Region.empty()) { @@ -2322,7 +2322,7 @@ S3Hydration::S3Hydration(const Configuration& Config) : HydrationBase(Config) m_PathStyle = Settings["path-style"sv].AsBool(); } - std::string AccessKeyId = GetEnvVariable("AWS_ACCESS_KEY_ID"); + std::string AccessKeyId = GetEnvVariable("AWS_ACCESS_KEY_ID").value_or(""); if (AccessKeyId.empty()) { m_CredentialProvider = Ref<ImdsCredentialProvider>(new ImdsCredentialProvider({})); @@ -2330,8 +2330,8 @@ S3Hydration::S3Hydration(const Configuration& Config) : HydrationBase(Config) else { m_Credentials.AccessKeyId = std::move(AccessKeyId); - m_Credentials.SecretAccessKey = GetEnvVariable("AWS_SECRET_ACCESS_KEY"); - m_Credentials.SessionToken = GetEnvVariable("AWS_SESSION_TOKEN"); + m_Credentials.SecretAccessKey = GetEnvVariable("AWS_SECRET_ACCESS_KEY").value_or(""); + m_Credentials.SessionToken = GetEnvVariable("AWS_SESSION_TOKEN").value_or(""); } m_DefaultMultipartChunkSize = Settings["chunksize"sv].AsUInt64(DefaultMultipartChunkSize); diff --git a/src/zenserver/hub/zenhubserver.cpp b/src/zenserver/hub/zenhubserver.cpp index 27c1c9fc4..303b1f1b2 100644 --- a/src/zenserver/hub/zenhubserver.cpp +++ b/src/zenserver/hub/zenhubserver.cpp @@ -811,7 +811,7 @@ ZenHubServer::InitializeConsulRegistration(const ZenHubServerConfig& ServerConfi std::string ConsulAccessTokenEnvName = ServerConfig.ConsulTokenEnv.empty() ? GetDefaultConsulTokenEnvVariableName() : ServerConfig.ConsulTokenEnv; - std::string ConsulAccessToken = GetEnvVariable(ConsulAccessTokenEnvName); + std::string ConsulAccessToken = GetEnvVariable(ConsulAccessTokenEnvName).value_or(""); if (ConsulAccessToken.empty()) { if (!ServerConfig.ConsulTokenEnv.empty()) diff --git a/src/zenserver/storage/projectstore/httpprojectstore.cpp b/src/zenserver/storage/projectstore/httpprojectstore.cpp index 9844d02f0..c40690d5f 100644 --- a/src/zenserver/storage/projectstore/httpprojectstore.cpp +++ b/src/zenserver/storage/projectstore/httpprojectstore.cpp @@ -339,7 +339,7 @@ namespace { std::string_view AccessTokenEnvVariable = Cloud["access-token-env"].AsString(); if (!AccessTokenEnvVariable.empty()) { - AccessToken = GetEnvVariable(AccessTokenEnvVariable); + AccessToken = GetEnvVariable(AccessTokenEnvVariable).value_or(""); } } @@ -474,7 +474,7 @@ namespace { std::string_view AccessTokenEnvVariable = Builds["access-token-env"].AsString(); if (!AccessTokenEnvVariable.empty()) { - AccessToken = GetEnvVariable(AccessTokenEnvVariable); + AccessToken = GetEnvVariable(AccessTokenEnvVariable).value_or(""); } } |