Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents 7bb757d + fc5b1b6 commit 0d62d55
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 93 deletions.
15 changes: 9 additions & 6 deletions examples/DocExampleApis/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public static async Task Main(string[] args)
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN"),
TimeSpan.FromSeconds(10));
IAuthClient authClient = new AuthClient(
AuthConfigurations.Default.Latest(),
AuthConfigurations.Default.Latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
);
ITopicClient topicClient = new TopicClient(
TopicConfigurations.Laptop.latest(),
TopicConfigurations.Laptop.latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
);

Expand Down Expand Up @@ -196,7 +196,7 @@ public static async Task Example_API_GenerateDisposableToken(IAuthClient authCli
DisposableTokenScopes.TopicPublishOnly(CacheSelector.AllCaches, "acorn"),
ExpiresIn.Minutes(30)
);

if (oneTopicAllCachesToken is GenerateDisposableTokenResponse.Success token4)
{
// logging only a substring of the tokens, because logging security credentials is not advisable :)
Expand All @@ -210,17 +210,20 @@ public static async Task Example_API_GenerateDisposableToken(IAuthClient authCli

}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public static async Task Example_API_InstantiateTopicClient()
{
new TopicClient(
TopicConfigurations.Laptop.latest(),
TopicConfigurations.Laptop.latest(),
new EnvMomentoTokenProvider("MOMENTO_AUTH_TOKEN")
);
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

public static async Task Example_API_TopicPublish(ITopicClient topicClient)
{
var publishResponse =
await topicClient.PublishAsync("test-cache", "test-topic", "test-topic-value");
var publishResponse =
await topicClient.PublishAsync("test-cache", "test-topic", "test-topic-value");
switch (publishResponse)
{
case TopicPublishResponse.Success:
Expand Down
23 changes: 23 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/DisposableToken.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
namespace Momento.Sdk.Auth.AccessControl;

/// <summary>
/// Represents the permissions of a disposable token.
/// </summary>
public abstract record DisposableTokenPermission;

/// <summary>
/// A token that can be used to access a resource.
/// </summary>
public abstract record DisposableToken
{
/// <summary>
/// A cache permission.
/// </summary>
/// <param name="Role">The role.</param>
/// <param name="CacheSelector">The cache selector for the permissions.</param>
public record CachePermission(CacheRole Role, CacheSelector CacheSelector) : DisposableTokenPermission
{
// public virtual bool Equals(CachePermission? other)
Expand All @@ -12,9 +23,21 @@ public record CachePermission(CacheRole Role, CacheSelector CacheSelector) : Dis
// }
}

/// <summary>
/// A cache item permission.
/// </summary>
/// <param name="Role">The role.</param>
/// <param name="CacheSelector">The cache selector for the permissions.</param>
/// <param name="CacheItemSelector">A specific cache item selector for the permissions.</param>
public record CacheItemPermission
(CacheRole Role, CacheSelector CacheSelector, CacheItemSelector CacheItemSelector) : CachePermission(Role,
CacheSelector);

/// <summary>
/// A topic permission.
/// </summary>
/// <param name="Role">The role.</param>
/// <param name="CacheSelector">The cache selector for the permissions.</param>
/// <param name="TopicSelector">The topic selector for the permissions.</param>
public record TopicPermission(TopicRole Role, CacheSelector CacheSelector, TopicSelector TopicSelector) : DisposableTokenPermission;
}
10 changes: 10 additions & 0 deletions src/Momento.Sdk/Auth/AccessControl/DisposableTokenScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@

namespace Momento.Sdk.Auth.AccessControl;

/// <summary>
/// The permissions that can be granted.
/// </summary>
public class DisposableTokenScope
{
/// <summary>
/// The permissions that can be granted.
/// </summary>
public List<DisposableTokenPermission> Permissions { get; }

/// <summary>
/// Create a new <see cref="DisposableTokenScope"/> object.
/// </summary>
/// <param name="Permissions">The permissions that can be granted.</param>
public DisposableTokenScope(List<DisposableTokenPermission> Permissions)
{
this.Permissions = Permissions;
Expand Down
Loading

0 comments on commit 0d62d55

Please sign in to comment.