diff options
| author | Dan Engelbrecht <[email protected]> | 2023-02-13 13:02:06 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-13 05:02:06 -0800 |
| commit | 1639507f8d3831322d7da5cfa0c63cd374695ddf (patch) | |
| tree | 3760a70cdf9fdf749fc38db55ae754e21b050f95 | |
| parent | no sentry report on port conflict (#228) (diff) | |
| download | zen-1639507f8d3831322d7da5cfa0c63cd374695ddf.tar.xz zen-1639507f8d3831322d7da5cfa0c63cd374695ddf.zip | |
Move knowledge of UE env variable from zenserver to zen command line tool (#227)
* move knowledge of UE env variable from zenserver to zen command line tool
* move env-fetching code to GetEnvVariable
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rw-r--r-- | zen/cmds/projectstore.cpp | 35 | ||||
| -rw-r--r-- | zen/cmds/projectstore.h | 2 | ||||
| -rw-r--r-- | zencore/filesystem.cpp | 23 | ||||
| -rw-r--r-- | zencore/include/zencore/filesystem.h | 2 | ||||
| -rw-r--r-- | zenserver/projectstore/projectstore.cpp | 17 |
6 files changed, 71 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ebde92b4a..6dc1c15df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ "key" : "<iohash>", "openid-provider" : "<provider-id>", "access-token" : "<access-token>", + "access-token-env": <envvariablename>", "disableblocks" : "<disableblocks>", "disabletempblocks" : "<disabletempblocks>" }, @@ -63,7 +64,8 @@ - `"bucket"` - Name of bucket to store data to - `"key"` - IoHash key to the stored oplog container - `"openid-provider"` - Optional. Name of openid provider used to authenticate with, requires that the zen server instance has been provided with a oids refresh token for <provider-id> - - `"access-token"` - Optional. JWS access token to authenticate with + - `"access-token"` - Optional. JWT access token to authenticate with + - `"access-token-env"` - Optional. Name of environment variable that holds an JWT access token to authenticate with - `"disableblocks"` - Optional. Disable creation of attachments blocks - "true"/"false" (export only) - `"disabletempblocks"` - Optional. Disable creation of attachments temp blocks forcing upload before oplog container - "true"/"false" (export only) - `"zen"` - Optional. Indicates remote location is a Zen server instance @@ -102,6 +104,7 @@ - `key` Key to the stored oplog container (If omitted a default key will be generated based on project/oplog/namespace/bucket) - `openid-provider` Optional name of openid provider used to authenticate with, requires that the zen server instance has been provided with a oids refresh token for the provider name - `access-token` Optional JWT access token to authenticate with + - `access-token-env` - Optional name of environment variable that holds an JWT access token to authenticate with - `disableblocks` Disable block creation and save all attachments individually - `disabletempblocks` Disable temp block creation and upload blocks without waiting for oplog container to be uploaded - `--zen` Zen server instance url to export to / import from @@ -119,7 +122,8 @@ - `bucket` Name of bucket to store data to - `key` Key to the stored oplog container (If omitted a default key will be generated based on project/oplog/namespace/bucket) - `openid-provider` Optional name of openid provider used to authenticate with, requires that the zen server instance has been provided with a oids refresh token for the provider name - - `access-token` Optional JWS access token to authenticate with + - `access-token` Optional JWT access token to authenticate with + - `access-token-env` - Optional name of environment variable that holds an JWT access token to authenticate with - `--zen` Zen server instance url to export to / import from - `--source-project` The remote project name (id) (optional, defaults to same as `project`) - `--source-oplog` The remote oplog name (id) (optional, defaults to same as `olplog`) diff --git a/zen/cmds/projectstore.cpp b/zen/cmds/projectstore.cpp index 8ecdecaaa..e12b85edc 100644 --- a/zen/cmds/projectstore.cpp +++ b/zen/cmds/projectstore.cpp @@ -11,6 +11,21 @@ ZEN_THIRD_PARTY_INCLUDES_START #include <cpr/cpr.h> ZEN_THIRD_PARTY_INCLUDES_END +namespace { + +using namespace std::literals; + +const std::string DefaultCloudAccessTokenEnvVariableName( +#if ZEN_PLATFORM_WINDOWS + "UE-CloudDataCacheAccessToken"sv +#endif +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC + "UE_CloudDataCacheAccessToken"sv +#endif +); + +} // namespace + /////////////////////////////////////// DropProjectCommand::DropProjectCommand() @@ -297,6 +312,12 @@ ExportOplogCommand::ExportOplogCommand() m_Options.add_option("cloud", "", "access-token", "Cloud Storage access token", cxxopts::value(m_CloudAccessToken), "<accesstoken>"); m_Options.add_option("cloud", "", + "access-token-env", + "Name of environment variable that holds the cloud Storage access token", + cxxopts::value(m_CloudAccessTokenEnv)->default_value(DefaultCloudAccessTokenEnvVariableName), + "<envvariable>"); + m_Options.add_option("cloud", + "", "disabletempblocks", "Disable temp block creation and upload blocks without waiting for oplog container to be uploaded", cxxopts::value(m_CloudDisableTempBlocks), @@ -493,6 +514,10 @@ ExportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg { Writer.AddString("access-token"sv, m_CloudAccessToken); } + if (!m_CloudAccessTokenEnv.empty()) + { + Writer.AddString("access-token-env"sv, m_CloudAccessTokenEnv); + } if (m_DisableBlocks) { Writer.AddBool("disableblocks"sv, true); @@ -554,6 +579,12 @@ ImportOplogCommand::ImportOplogCommand() m_Options .add_option("cloud", "", "openid-provider", "Cloud Storage openid provider", cxxopts::value(m_CloudOpenIdProvider), "<provider>"); m_Options.add_option("cloud", "", "access-token", "Cloud Storage access token", cxxopts::value(m_CloudAccessToken), "<accesstoken>"); + m_Options.add_option("cloud", + "", + "access-token-env", + "Name of environment variable that holds the cloud Storage access token", + cxxopts::value(m_CloudAccessTokenEnv)->default_value(DefaultCloudAccessTokenEnvVariableName), + "<envvariable>"); m_Options.add_option("", "", "zen", "Zen service upload address", cxxopts::value(m_ZenUrl), "<url>"); m_Options.add_option("zen", "", "source-project", "Zen source project name", cxxopts::value(m_ZenProjectName), "<sourceprojectid>"); @@ -718,6 +749,10 @@ ImportOplogCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** arg { Writer.AddString("access-token"sv, m_CloudAccessToken); } + if (!m_CloudAccessTokenEnv.empty()) + { + Writer.AddString("access-token-env"sv, m_CloudAccessTokenEnv); + } } Writer.EndObject(); // "cloud" SourceDescription = fmt::format("[cloud] '{}/{}/{}/{}'", m_CloudUrl, m_CloudNamespace, m_CloudBucket, m_CloudKey); diff --git a/zen/cmds/projectstore.h b/zen/cmds/projectstore.h index af4da548f..53ba14825 100644 --- a/zen/cmds/projectstore.h +++ b/zen/cmds/projectstore.h @@ -97,6 +97,7 @@ private: std::string m_CloudKey; std::string m_CloudOpenIdProvider; std::string m_CloudAccessToken; + std::string m_CloudAccessTokenEnv; bool m_CloudDisableTempBlocks = false; std::string m_ZenUrl; @@ -134,6 +135,7 @@ private: std::string m_CloudKey; std::string m_CloudOpenIdProvider; std::string m_CloudAccessToken; + std::string m_CloudAccessTokenEnv; std::string m_ZenUrl; std::string m_ZenProjectName; diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index a2442a134..a17773024 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -1117,6 +1117,29 @@ GetDirectoryContent(const std::filesystem::path& RootDir, uint8_t Flags, Directo Traversal.TraverseFileSystem(RootDir, Visit); } +std::string +GetEnvVariable(std::string_view VariableName) +{ + ZEN_ASSERT(!VariableName.empty()); +#if ZEN_PLATFORM_WINDOWS + + CHAR EnvVariableBuffer[1023 + 1]; + DWORD RESULT = GetEnvironmentVariableA(std::string(VariableName).c_str(), EnvVariableBuffer, sizeof(EnvVariableBuffer)); + if (RESULT > 0 && RESULT < sizeof(EnvVariableBuffer)) + { + return std::string(EnvVariableBuffer); + } +#endif +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC + char* EnvVariable = getenv(std::string(VariableName).c_str()); + if (EnvVariable) + { + return std::string(EnvVariable); + } +#endif + return ""; +} + ////////////////////////////////////////////////////////////////////////// // // Testing related code follows... diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h index f49135687..fa5f94170 100644 --- a/zencore/include/zencore/filesystem.h +++ b/zencore/include/zencore/filesystem.h @@ -181,6 +181,8 @@ struct DirectoryContent void GetDirectoryContent(const std::filesystem::path& RootDir, uint8_t Flags, DirectoryContent& OutContent); +std::string GetEnvVariable(std::string_view VariableName); + ////////////////////////////////////////////////////////////////////////// void filesystem_forcelink(); // internal diff --git a/zenserver/projectstore/projectstore.cpp b/zenserver/projectstore/projectstore.cpp index 82aac1605..57b24c63d 100644 --- a/zenserver/projectstore/projectstore.cpp +++ b/zenserver/projectstore/projectstore.cpp @@ -124,22 +124,11 @@ namespace { std::string AccessToken = std::string(Cloud["access-token"sv].AsString()); if (AccessToken.empty()) { -#if PLATFORM_WINDOWS - - CHAR EnvVariableBuffer[1023 + 1]; - DWORD RESULT = GetEnvironmentVariableA("UE-CloudDataCacheAccessToken", EnvVariableBuffer, sizeof(EnvVariableBuffer)); - if (RESULT > 0 && RESULT < sizeof(EnvVariableBuffer)) + std::string_view AccessTokenEnvVariable = Cloud["access-token-env"].AsString(); + if (!AccessTokenEnvVariable.empty()) { - AccessToken = std::string(EnvVariableBuffer); + AccessToken = GetEnvVariable(AccessTokenEnvVariable); } -#endif -#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - char* EnvVariable = getenv("UE_CloudDataCacheAccessToken"); - if (EnvVariable) - { - AccessToken = std::string(EnvVariable); - } -#endif } std::string_view KeyParam = Cloud["key"sv].AsString(); if (KeyParam.empty()) |