From 8f8bbf46cd62ca26552e4222a8f4686ac2230326 Mon Sep 17 00:00:00 2001 From: Pete Gautier Date: Mon, 11 Sep 2023 13:05:37 -0700 Subject: [PATCH] chore: add preprocessor directoves for unity build --- .github/workflows/on-push-to-release-branch.yaml | 2 +- src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs | 2 ++ .../Auth/AccessControl/DisposableTokenScope.cs | 2 ++ .../Auth/AccessControl/DisposableTokenScopes.cs | 2 ++ src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs | 2 ++ src/Momento.Sdk/Auth/AccessControl/Permissions.cs | 2 ++ src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs | 5 +++++ src/Momento.Sdk/Auth/ICredentialProvider.cs | 3 +++ src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs | 5 +++++ src/Momento.Sdk/Auth/Utils.cs | 9 +++++++++ src/Momento.Sdk/AuthClient.cs | 2 ++ src/Momento.Sdk/Config/AuthConfiguration.cs | 2 ++ src/Momento.Sdk/Config/AuthConfigurations.cs | 2 ++ src/Momento.Sdk/Config/IAuthConfiguration.cs | 2 ++ .../Config/Transport/IAuthTransportStrategy.cs | 2 ++ .../Config/Transport/StaticAuthTransportStrategy.cs | 2 ++ src/Momento.Sdk/IAuthClient.cs | 2 ++ src/Momento.Sdk/Internal/AuthGrpcManager.cs | 2 ++ src/Momento.Sdk/Internal/LoggingUtils.cs | 3 ++- .../Internal/OldDotNetVersionsRecordWorkaround.cs | 2 +- src/Momento.Sdk/Internal/ScsTokenClient.cs | 2 ++ src/Momento.Sdk/Internal/Utils.cs | 5 +++++ .../Responses/GenerateDisposableTokenResponse.cs | 2 ++ tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs | 2 ++ tests/Integration/Momento.Sdk.Tests/Fixtures.cs | 2 ++ .../Auth/AccessControl/DisposableTokenScopeTest.cs | 2 ++ 26 files changed, 67 insertions(+), 3 deletions(-) diff --git a/.github/workflows/on-push-to-release-branch.yaml b/.github/workflows/on-push-to-release-branch.yaml index 7eee2692..93768b0e 100644 --- a/.github/workflows/on-push-to-release-branch.yaml +++ b/.github/workflows/on-push-to-release-branch.yaml @@ -65,7 +65,7 @@ jobs: rm -rf bin VERSION="${{ needs.release.outputs.version }}" echo "version: ${VERSION}" - dotnet build --configuration Release -f netstandard2.0 -p:DefineConstants=USE_GRPC_WEB + dotnet build --configuration Release -f netstandard2.0 -p:DefineConstants=USE_GRPC_WEB;BUILD_FOR_UNITY DLL_FILE=./bin/Release/netstandard2.0/Momento.Sdk.dll ARCHIVE_FILE_NAME=Momento.Sdk.Unity.${VERSION}.dll AUTH="Authorization: token ${{ secrets.MOMENTO_MACHINE_USER_GITHUB_TOKEN }}" diff --git a/src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs b/src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs index f563b22d..38951140 100644 --- a/src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs +++ b/src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY namespace Momento.Sdk.Auth.AccessControl; public abstract record DisposableTokenPermission; @@ -18,3 +19,4 @@ public record CacheItemPermission public record TopicPermission(TopicRole Role, CacheSelector CacheSelector, TopicSelector TopicSelector) : DisposableTokenPermission; } +#endif diff --git a/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs b/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs index 728e7572..55ed8067 100644 --- a/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs +++ b/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System.Collections.Generic; namespace Momento.Sdk.Auth.AccessControl; @@ -11,3 +12,4 @@ public DisposableTokenScope(List Permissions) this.Permissions = Permissions; } } +#endif diff --git a/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScopes.cs b/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScopes.cs index c4020520..ebeb9ecc 100644 --- a/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScopes.cs +++ b/src/Momento.Sdk/Auth/AccessControl/DisposableTokenScopes.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System.Collections.Generic; namespace Momento.Sdk.Auth.AccessControl; @@ -258,3 +259,4 @@ public static DisposableTokenScope TopicPublishOnly(CacheSelector cacheSelector, }); } } +#endif diff --git a/src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs b/src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs index 5c8ed2ea..c19f0430 100644 --- a/src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs +++ b/src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; @@ -90,3 +91,4 @@ public static ExpiresAt FromEpoch(int? epoch) return new ExpiresAt(epoch); } } +#endif diff --git a/src/Momento.Sdk/Auth/AccessControl/Permissions.cs b/src/Momento.Sdk/Auth/AccessControl/Permissions.cs index db0f08f4..d87fc8b1 100644 --- a/src/Momento.Sdk/Auth/AccessControl/Permissions.cs +++ b/src/Momento.Sdk/Auth/AccessControl/Permissions.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY namespace Momento.Sdk.Auth.AccessControl; public enum CacheRole @@ -65,3 +66,4 @@ public static SelectByTopicName ByName(string topicName) return new SelectByTopicName(topicName); } } +#endif diff --git a/src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs b/src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs index 599df506..01ea7789 100644 --- a/src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs +++ b/src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs @@ -17,8 +17,11 @@ public class EnvMomentoTokenProvider : ICredentialProvider public string ControlEndpoint { get; private set; } /// public string CacheEndpoint { get; private set; } + + #if !BUILD_FOR_UNITY /// public string TokenEndpoint { get; private set; } + #endif /// /// Reads and parses a JWT token stored as an environment variable. @@ -41,7 +44,9 @@ public EnvMomentoTokenProvider(string name) var tokenData = AuthUtils.TryDecodeAuthToken(AuthToken); ControlEndpoint = tokenData.ControlEndpoint; CacheEndpoint = tokenData.CacheEndpoint; + #if !BUILD_FOR_UNITY TokenEndpoint = tokenData.TokenEndpoint; + #endif AuthToken = tokenData.AuthToken; } diff --git a/src/Momento.Sdk/Auth/ICredentialProvider.cs b/src/Momento.Sdk/Auth/ICredentialProvider.cs index 08ae30e7..6315d3ea 100644 --- a/src/Momento.Sdk/Auth/ICredentialProvider.cs +++ b/src/Momento.Sdk/Auth/ICredentialProvider.cs @@ -17,10 +17,13 @@ public interface ICredentialProvider /// The host which the Momento client will connect to the Momento data plane /// string CacheEndpoint { get; } + + #if !BUILD_FOR_UNITY /// /// The host which the Momento client will connect to the token endpoint /// string TokenEndpoint { get; } + #endif /// /// Copy constructor to override the CacheEndpoint diff --git a/src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs b/src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs index d3d335c0..80cab0bb 100644 --- a/src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs +++ b/src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs @@ -17,8 +17,11 @@ public class StringMomentoTokenProvider : ICredentialProvider public string ControlEndpoint { get; private set; } /// public string CacheEndpoint { get; private set; } + + #if !BUILD_FOR_UNITY /// public string TokenEndpoint { get; private set; } + #endif /// /// Reads and parses a JWT token from a string. @@ -36,7 +39,9 @@ public StringMomentoTokenProvider(string token) var tokenData = AuthUtils.TryDecodeAuthToken(AuthToken); ControlEndpoint = tokenData.ControlEndpoint; CacheEndpoint = tokenData.CacheEndpoint; + #if !BUILD_FOR_UNITY TokenEndpoint = tokenData.TokenEndpoint; + #endif AuthToken = tokenData.AuthToken; } diff --git a/src/Momento.Sdk/Auth/Utils.cs b/src/Momento.Sdk/Auth/Utils.cs index 49e3fda4..778bd18d 100644 --- a/src/Momento.Sdk/Auth/Utils.cs +++ b/src/Momento.Sdk/Auth/Utils.cs @@ -10,14 +10,19 @@ internal class TokenAndEndpoints public string AuthToken { get; } public string ControlEndpoint { get; } public string CacheEndpoint { get; } + + #if !BUILD_FOR_UNITY public string TokenEndpoint { get; } + #endif public TokenAndEndpoints(string authToken, string controlEndpoint, string cacheEndpoint, string tokenEndpoint) { AuthToken = authToken; ControlEndpoint = controlEndpoint; CacheEndpoint = cacheEndpoint; + #if !BUILD_FOR_UNITY TokenEndpoint = tokenEndpoint; + #endif } } @@ -59,7 +64,9 @@ public static TokenAndEndpoints TryDecodeAuthToken(string authToken) decodedToken.api_key!, "control." + decodedToken.endpoint, "cache." + decodedToken.endpoint, + #if !BUILD_FOR_UNITY "token." + decodedToken.endpoint + #endif ); } else @@ -69,7 +76,9 @@ public static TokenAndEndpoints TryDecodeAuthToken(string authToken) authToken, claims.ControlEndpoint, claims.CacheEndpoint, + #if !BUILD_FOR_UNITY claims.CacheEndpoint + #endif ); } } diff --git a/src/Momento.Sdk/AuthClient.cs b/src/Momento.Sdk/AuthClient.cs index f871fdcb..5c249fca 100644 --- a/src/Momento.Sdk/AuthClient.cs +++ b/src/Momento.Sdk/AuthClient.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using System.Threading.Tasks; using Momento.Sdk.Auth; @@ -37,3 +38,4 @@ public void Dispose() scsTokenClient.Dispose(); } } +#endif diff --git a/src/Momento.Sdk/Config/AuthConfiguration.cs b/src/Momento.Sdk/Config/AuthConfiguration.cs index 5cc289bf..d44a1a54 100644 --- a/src/Momento.Sdk/Config/AuthConfiguration.cs +++ b/src/Momento.Sdk/Config/AuthConfiguration.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using Microsoft.Extensions.Logging; using Momento.Sdk.Config.Transport; @@ -49,3 +50,4 @@ public override int GetHashCode() } } +#endif diff --git a/src/Momento.Sdk/Config/AuthConfigurations.cs b/src/Momento.Sdk/Config/AuthConfigurations.cs index e560a0a9..018fa2bf 100644 --- a/src/Momento.Sdk/Config/AuthConfigurations.cs +++ b/src/Momento.Sdk/Config/AuthConfigurations.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -54,3 +55,4 @@ public static IAuthConfiguration Latest(ILoggerFactory? loggerFactory = null) } } } +#endif diff --git a/src/Momento.Sdk/Config/IAuthConfiguration.cs b/src/Momento.Sdk/Config/IAuthConfiguration.cs index cde50a80..8e0c82d2 100644 --- a/src/Momento.Sdk/Config/IAuthConfiguration.cs +++ b/src/Momento.Sdk/Config/IAuthConfiguration.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using Microsoft.Extensions.Logging; using Momento.Sdk.Config.Transport; @@ -20,3 +21,4 @@ public interface IAuthConfiguration /// AuthConfiguration object with custom transport strategy provided public IAuthConfiguration WithTransportStrategy(IAuthTransportStrategy transportStrategy); } +#endif diff --git a/src/Momento.Sdk/Config/Transport/IAuthTransportStrategy.cs b/src/Momento.Sdk/Config/Transport/IAuthTransportStrategy.cs index acbcacae..a512ca2f 100644 --- a/src/Momento.Sdk/Config/Transport/IAuthTransportStrategy.cs +++ b/src/Momento.Sdk/Config/Transport/IAuthTransportStrategy.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; namespace Momento.Sdk.Config.Transport; @@ -27,3 +28,4 @@ public interface IAuthTransportStrategy /// A new IAuthTransportStrategy with the specified client timeout public IAuthTransportStrategy WithClientTimeout(TimeSpan clientTimeout); } +#endif diff --git a/src/Momento.Sdk/Config/Transport/StaticAuthTransportStrategy.cs b/src/Momento.Sdk/Config/Transport/StaticAuthTransportStrategy.cs index fcf56941..01e30108 100644 --- a/src/Momento.Sdk/Config/Transport/StaticAuthTransportStrategy.cs +++ b/src/Momento.Sdk/Config/Transport/StaticAuthTransportStrategy.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using Microsoft.Extensions.Logging; @@ -62,3 +63,4 @@ public override int GetHashCode() return base.GetHashCode(); } } +#endif diff --git a/src/Momento.Sdk/IAuthClient.cs b/src/Momento.Sdk/IAuthClient.cs index d0e63339..ad87228d 100644 --- a/src/Momento.Sdk/IAuthClient.cs +++ b/src/Momento.Sdk/IAuthClient.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using System.Threading.Tasks; using Momento.Sdk.Auth.AccessControl; @@ -10,3 +11,4 @@ public interface IAuthClient : IDisposable public Task GenerateDisposableTokenAsync(DisposableTokenScope scope, ExpiresIn expiresIn); } +#endif diff --git a/src/Momento.Sdk/Internal/AuthGrpcManager.cs b/src/Momento.Sdk/Internal/AuthGrpcManager.cs index d8d79887..c9d9e87c 100644 --- a/src/Momento.Sdk/Internal/AuthGrpcManager.cs +++ b/src/Momento.Sdk/Internal/AuthGrpcManager.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using System.Collections.Generic; using System.Linq; @@ -103,3 +104,4 @@ public void Dispose() GC.SuppressFinalize(this); } } +#endif diff --git a/src/Momento.Sdk/Internal/LoggingUtils.cs b/src/Momento.Sdk/Internal/LoggingUtils.cs index 27bed456..81a72db7 100644 --- a/src/Momento.Sdk/Internal/LoggingUtils.cs +++ b/src/Momento.Sdk/Internal/LoggingUtils.cs @@ -486,6 +486,7 @@ public static TError LogTraceTopicSubscriptionError(this ILogger logger, } #endif +#if !BUILD_FOR_UNITY /// /// Logs a message at TRACE level that indicates that an auth request is about to be executed. /// @@ -533,7 +534,7 @@ public static TSuccess LogTraceAuthRequestSuccess(this ILogger logger, } return success; } - +#endif private static string ReadableByteString(ByteString? input) { diff --git a/src/Momento.Sdk/Internal/OldDotNetVersionsRecordWorkaround.cs b/src/Momento.Sdk/Internal/OldDotNetVersionsRecordWorkaround.cs index 9e8769b9..b39e14d0 100644 --- a/src/Momento.Sdk/Internal/OldDotNetVersionsRecordWorkaround.cs +++ b/src/Momento.Sdk/Internal/OldDotNetVersionsRecordWorkaround.cs @@ -1,4 +1,4 @@ -#if !NET5_0_OR_GREATER +#if !NET5_0_OR_GREATER || !BUILD_FOR_UNITY using System.ComponentModel; diff --git a/src/Momento.Sdk/Internal/ScsTokenClient.cs b/src/Momento.Sdk/Internal/ScsTokenClient.cs index 75ea11e5..07a0fbe2 100644 --- a/src/Momento.Sdk/Internal/ScsTokenClient.cs +++ b/src/Momento.Sdk/Internal/ScsTokenClient.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System; using System.Threading.Tasks; using Grpc.Core; @@ -235,3 +236,4 @@ public void Dispose() } } +#endif diff --git a/src/Momento.Sdk/Internal/Utils.cs b/src/Momento.Sdk/Internal/Utils.cs index 8bf57116..d5aee2c9 100644 --- a/src/Momento.Sdk/Internal/Utils.cs +++ b/src/Momento.Sdk/Internal/Utils.cs @@ -3,7 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; + +#if !BUILD_FOR_UNITY using Momento.Sdk.Exceptions; +#endif namespace Momento.Sdk.Internal; @@ -102,6 +105,7 @@ public static void ArgumentStrictlyPositive(int? argument, string paramName) } } + #if !BUILD_FOR_UNITY /// /// Throw an exception if the supplied ExpiresIn object is invalid. /// @@ -122,6 +126,7 @@ public static void CheckValidDisposableTokenExpiry(ExpiresIn expiresIn) throw new InvalidArgumentException("Disposable token must expire within 1 hour"); } } + #endif /// /// Defines methods to support comparing containers of reference items by their diff --git a/src/Momento.Sdk/Responses/GenerateDisposableTokenResponse.cs b/src/Momento.Sdk/Responses/GenerateDisposableTokenResponse.cs index 37cb0e30..2689f157 100644 --- a/src/Momento.Sdk/Responses/GenerateDisposableTokenResponse.cs +++ b/src/Momento.Sdk/Responses/GenerateDisposableTokenResponse.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using Momento.Sdk.Exceptions; using Momento.Protos.TokenClient; using System; @@ -94,3 +95,4 @@ public override string ToString() } } } +#endif diff --git a/tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs b/tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs index 76c470d7..bfc935ab 100644 --- a/tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs +++ b/tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System.Threading.Tasks; using Momento.Sdk.Auth.AccessControl; @@ -23,3 +24,4 @@ public async Task GenerateDisposableAuthToken_HappyPath() } } +#endif diff --git a/tests/Integration/Momento.Sdk.Tests/Fixtures.cs b/tests/Integration/Momento.Sdk.Tests/Fixtures.cs index c856acb9..f8e90908 100644 --- a/tests/Integration/Momento.Sdk.Tests/Fixtures.cs +++ b/tests/Integration/Momento.Sdk.Tests/Fixtures.cs @@ -91,6 +91,7 @@ public class TopicClientCollection : ICollectionFixture } #endif +#if !BUILD_FOR_UNITY public class AuthClientFixture : IDisposable { public IAuthClient Client { get; private set; } @@ -117,6 +118,7 @@ public void Dispose() Client.Dispose(); } } +#endif /// /// Register the fixture in xUnit. diff --git a/tests/Unit/Momento.Sdk.Tests/Auth/AccessControl/DisposableTokenScopeTest.cs b/tests/Unit/Momento.Sdk.Tests/Auth/AccessControl/DisposableTokenScopeTest.cs index cbb0f045..c23fb98d 100644 --- a/tests/Unit/Momento.Sdk.Tests/Auth/AccessControl/DisposableTokenScopeTest.cs +++ b/tests/Unit/Momento.Sdk.Tests/Auth/AccessControl/DisposableTokenScopeTest.cs @@ -1,3 +1,4 @@ +#if !BUILD_FOR_UNITY using System.Collections.Generic; using FluentAssertions; using Momento.Sdk.Auth.AccessControl; @@ -407,3 +408,4 @@ public void DisposableTokenScopes_TopicPublishOnly() })); } } +#endif