Skip to content

Commit

Permalink
chore: add preprocessor directoves for unity build
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Sep 11, 2023
1 parent 056c33a commit 8f8bbf4
Show file tree
Hide file tree
Showing 26 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-push-to-release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
namespace Momento.Sdk.Auth.AccessControl;

public abstract record DisposableTokenPermission;
Expand All @@ -18,3 +19,4 @@ public record CacheItemPermission

public record TopicPermission(TopicRole Role, CacheSelector CacheSelector, TopicSelector TopicSelector) : DisposableTokenPermission;
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System.Collections.Generic;

namespace Momento.Sdk.Auth.AccessControl;
Expand All @@ -11,3 +12,4 @@ public DisposableTokenScope(List<DisposableTokenPermission> Permissions)
this.Permissions = Permissions;
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/DisposableTokenScopes.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System.Collections.Generic;

namespace Momento.Sdk.Auth.AccessControl;
Expand Down Expand Up @@ -258,3 +259,4 @@ public static DisposableTokenScope TopicPublishOnly(CacheSelector cacheSelector,
});
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/ExpiresIn.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;


Expand Down Expand Up @@ -90,3 +91,4 @@ public static ExpiresAt FromEpoch(int? epoch)
return new ExpiresAt(epoch);
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/Permissions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
namespace Momento.Sdk.Auth.AccessControl;

public enum CacheRole
Expand Down Expand Up @@ -65,3 +66,4 @@ public static SelectByTopicName ByName(string topicName)
return new SelectByTopicName(topicName);
}
}
#endif
5 changes: 5 additions & 0 deletions src/Momento.Sdk/Auth/EnvMomentoTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public class EnvMomentoTokenProvider : ICredentialProvider
public string ControlEndpoint { get; private set; }
/// <inheritdoc />
public string CacheEndpoint { get; private set; }

#if !BUILD_FOR_UNITY
/// <inheritdoc />
public string TokenEndpoint { get; private set; }
#endif

/// <summary>
/// Reads and parses a JWT token stored as an environment variable.
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Momento.Sdk/Auth/ICredentialProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public interface ICredentialProvider
/// The host which the Momento client will connect to the Momento data plane
/// </summary>
string CacheEndpoint { get; }

#if !BUILD_FOR_UNITY
/// <summary>
/// The host which the Momento client will connect to the token endpoint
/// </summary>
string TokenEndpoint { get; }
#endif

/// <summary>
/// Copy constructor to override the CacheEndpoint
Expand Down
5 changes: 5 additions & 0 deletions src/Momento.Sdk/Auth/StringMomentoTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public class StringMomentoTokenProvider : ICredentialProvider
public string ControlEndpoint { get; private set; }
/// <inheritdoc />
public string CacheEndpoint { get; private set; }

#if !BUILD_FOR_UNITY
/// <inheritdoc />
public string TokenEndpoint { get; private set; }
#endif

/// <summary>
/// Reads and parses a JWT token from a string.
Expand All @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Momento.Sdk/Auth/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -69,7 +76,9 @@ public static TokenAndEndpoints TryDecodeAuthToken(string authToken)
authToken,
claims.ControlEndpoint,
claims.CacheEndpoint,
#if !BUILD_FOR_UNITY
claims.CacheEndpoint
#endif
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Momento.Sdk/AuthClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using System.Threading.Tasks;
using Momento.Sdk.Auth;
Expand Down Expand Up @@ -37,3 +38,4 @@ public void Dispose()
scsTokenClient.Dispose();
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Config/AuthConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using Microsoft.Extensions.Logging;
using Momento.Sdk.Config.Transport;

Expand Down Expand Up @@ -49,3 +50,4 @@ public override int GetHashCode()
}

}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Config/AuthConfigurations.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down Expand Up @@ -54,3 +55,4 @@ public static IAuthConfiguration Latest(ILoggerFactory? loggerFactory = null)
}
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Config/IAuthConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using Microsoft.Extensions.Logging;
using Momento.Sdk.Config.Transport;

Expand All @@ -20,3 +21,4 @@ public interface IAuthConfiguration
/// <returns>AuthConfiguration object with custom transport strategy provided</returns>
public IAuthConfiguration WithTransportStrategy(IAuthTransportStrategy transportStrategy);
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Config/Transport/IAuthTransportStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;

namespace Momento.Sdk.Config.Transport;
Expand Down Expand Up @@ -27,3 +28,4 @@ public interface IAuthTransportStrategy
/// <returns>A new IAuthTransportStrategy with the specified client timeout</returns>
public IAuthTransportStrategy WithClientTimeout(TimeSpan clientTimeout);
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -62,3 +63,4 @@ public override int GetHashCode()
return base.GetHashCode();
}
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/IAuthClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using System.Threading.Tasks;
using Momento.Sdk.Auth.AccessControl;
Expand All @@ -10,3 +11,4 @@ public interface IAuthClient : IDisposable
public Task<GenerateDisposableTokenResponse> GenerateDisposableTokenAsync(DisposableTokenScope scope,
ExpiresIn expiresIn);
}
#endif
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Internal/AuthGrpcManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -103,3 +104,4 @@ public void Dispose()
GC.SuppressFinalize(this);
}
}
#endif
3 changes: 2 additions & 1 deletion src/Momento.Sdk/Internal/LoggingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ public static TError LogTraceTopicSubscriptionError<TError>(this ILogger logger,
}
#endif

#if !BUILD_FOR_UNITY
/// <summary>
/// Logs a message at TRACE level that indicates that an auth request is about to be executed.
/// </summary>
Expand Down Expand Up @@ -533,7 +534,7 @@ public static TSuccess LogTraceAuthRequestSuccess<TSuccess>(this ILogger logger,
}
return success;
}

#endif

private static string ReadableByteString(ByteString? input)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NET5_0_OR_GREATER
#if !NET5_0_OR_GREATER || !BUILD_FOR_UNITY

using System.ComponentModel;

Expand Down
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Internal/ScsTokenClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System;
using System.Threading.Tasks;
using Grpc.Core;
Expand Down Expand Up @@ -235,3 +236,4 @@ public void Dispose()
}

}
#endif
5 changes: 5 additions & 0 deletions src/Momento.Sdk/Internal/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -102,6 +105,7 @@ public static void ArgumentStrictlyPositive(int? argument, string paramName)
}
}

#if !BUILD_FOR_UNITY
/// <summary>
/// Throw an exception if the supplied ExpiresIn object is invalid.
/// </summary>
Expand All @@ -122,6 +126,7 @@ public static void CheckValidDisposableTokenExpiry(ExpiresIn expiresIn)
throw new InvalidArgumentException("Disposable token must expire within 1 hour");
}
}
#endif

/// <summary>
/// Defines methods to support comparing containers of reference items by their
Expand Down
2 changes: 2 additions & 0 deletions src/Momento.Sdk/Responses/GenerateDisposableTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using Momento.Sdk.Exceptions;
using Momento.Protos.TokenClient;
using System;
Expand Down Expand Up @@ -94,3 +95,4 @@ public override string ToString()
}
}
}
#endif
2 changes: 2 additions & 0 deletions tests/Integration/Momento.Sdk.Tests/AuthClientTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System.Threading.Tasks;
using Momento.Sdk.Auth.AccessControl;

Expand All @@ -23,3 +24,4 @@ public async Task GenerateDisposableAuthToken_HappyPath()
}

}
#endif
2 changes: 2 additions & 0 deletions tests/Integration/Momento.Sdk.Tests/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class TopicClientCollection : ICollectionFixture<TopicClientFixture>
}
#endif

#if !BUILD_FOR_UNITY
public class AuthClientFixture : IDisposable
{
public IAuthClient Client { get; private set; }
Expand All @@ -117,6 +118,7 @@ public void Dispose()
Client.Dispose();
}
}
#endif

/// <summary>
/// Register the fixture in xUnit.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !BUILD_FOR_UNITY
using System.Collections.Generic;
using FluentAssertions;
using Momento.Sdk.Auth.AccessControl;
Expand Down Expand Up @@ -407,3 +408,4 @@ public void DisposableTokenScopes_TopicPublishOnly()
}));
}
}
#endif

0 comments on commit 8f8bbf4

Please sign in to comment.