Skip to content

Commit 84d1ea4

Browse files
authored
chore: update ci/cd env vars, tests, examples for v2 api keys (#617)
* chore: update github workflows * chore: update non-auth client examples to use v2 key * chore: update tests to use v1 token + separate v2 test suite
1 parent 488cbb9 commit 84d1ea4

35 files changed

+1837
-670
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ updates:
1111
interval: "daily"
1212
allow:
1313
- dependency-name: "Momento.Sdk"
14+
commit-message:
15+
# Prefix all commit messages with "chore: "
16+
- prefix: "chore"

.github/workflows/build.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on:
44
pull_request:
55
branches: [main]
66

7+
env:
8+
V1_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
9+
MOMENTO_API_KEY: ${{ secrets.ALPHA_API_KEY_V2 }}
10+
MOMENTO_ENDPOINT: "cell-alpha-dev.preprod.a.momentohq.com"
11+
712
jobs:
813
format-check:
914
runs-on: ubuntu-latest
@@ -20,8 +25,6 @@ jobs:
2025
os: [ubuntu-latest, windows-latest]
2126
grpc-web: [false, true]
2227
runs-on: ${{ matrix.os }}
23-
env:
24-
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
2528

2629
steps:
2730
- name: Get current time
@@ -58,10 +61,6 @@ jobs:
5861

5962
build_examples:
6063
runs-on: ubuntu-latest
61-
env:
62-
# TODO: remove token stored as secret in favor of using a
63-
# momento-local instance that can be spun up for testing
64-
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
6564

6665
steps:
6766
- name: Setup repo

.github/workflows/on-push-to-main-branch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
grpc-web: [false, true]
1313
runs-on: ${{ matrix.os }}
1414
env:
15-
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
15+
V1_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
16+
MOMENTO_API_KEY: ${{ secrets.ALPHA_API_KEY_V2 }}
17+
MOMENTO_ENDPOINT: "cell-alpha-dev.preprod.a.momentohq.com"
1618

1719
steps:
1820
- name: Get current time

examples/DictionaryExample/DictionaryExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
12-
<PackageReference Include="Momento.Sdk" Version="1.39.0" />
12+
<PackageReference Include="Momento.Sdk" Version="1.41.0" />
1313
</ItemGroup>
1414
</Project>

examples/DictionaryExample/Program.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
public class Driver
1010
{
11-
private static readonly string AUTH_TOKEN_ENV_VAR = "MOMENTO_API_KEY";
1211
private static readonly string CACHE_NAME_ENV_VAR = "MOMENTO_CACHE_NAME";
1312
private static readonly ILogger _logger;
1413
private static readonly ILoggerFactory _loggerFactory;
@@ -21,11 +20,12 @@ static Driver()
2120

2221
public async static Task Main()
2322
{
24-
var authToken = ReadAuthToken();
23+
// Looks for the environment variables MOMENTO_API_KEY and MOMENTO_ENDPOINT by default
24+
var creds = new EnvMomentoV2TokenProvider();
2525
var cacheName = ReadCacheName();
2626

2727
// Set up the client
28-
using ICacheClient client = new CacheClient(Configurations.Laptop.V1(), authToken, TimeSpan.FromSeconds(60));
28+
using ICacheClient client = new CacheClient(Configurations.Laptop.V1(), creds, TimeSpan.FromSeconds(60));
2929
await EnsureCacheExistsAsync(client, cacheName);
3030

3131
// Set a value
@@ -168,33 +168,6 @@ private static ILoggerFactory InitializeLogging()
168168
});
169169
}
170170

171-
private static ICredentialProvider ReadAuthToken()
172-
{
173-
try
174-
{
175-
return new EnvMomentoTokenProvider(AUTH_TOKEN_ENV_VAR);
176-
}
177-
catch (InvalidArgumentException)
178-
{
179-
}
180-
181-
Console.Write($"Auth token not detected in environment variable {AUTH_TOKEN_ENV_VAR}. Enter auth token here: ");
182-
var authToken = Console.ReadLine()!.Trim();
183-
184-
StringMomentoTokenProvider? authProvider = null;
185-
try
186-
{
187-
authProvider = new StringMomentoTokenProvider(authToken);
188-
}
189-
catch (InvalidArgumentException e)
190-
{
191-
_logger.LogInformation("{}", e);
192-
_loggerFactory.Dispose();
193-
Environment.Exit(1);
194-
}
195-
return authProvider!;
196-
}
197-
198171
private static string ReadCacheName()
199172
{
200173
var cacheName = System.Environment.GetEnvironmentVariable(CACHE_NAME_ENV_VAR);

examples/DictionaryExample/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@
22

33
This example program demonstrates usage of the dictionary data type.
44

5-
# Usage
6-
7-
The program assumes the auth token and cache names are available in environment variables. The auth token is assumed to be in the variable `MOMENTO_API_KEY` and the cache name in `MOMENTO_CACHE_NAME`. If either of these is missing, you will be prompted to enter the values on the terminal.
5+
## Prerequisites
86

9-
To run the program, run either:
7+
* [`dotnet`](https://dotnet.microsoft.com/en-us/download) 6.0 or higher is required
8+
* A Momento API key is required. You can generate one using the [Momento Console](https://console.gomomento.com/api-keys).
9+
* A Momento service endpoint is required. Choose the one for the [region](https://docs.momentohq.com/platform/regions) you'll be using, e.g. `cache.cell-1-ap-southeast-1-1.prod.a.momentohq.com` for ap-southeast-1.
1010

11-
```bash
12-
MOMENTO_API_KEY=<YOUR_API_KEY_HERE> MOMENTO_CACHE_NAME=<YOUR_CACHE_NAME_HERE> dotnet run
13-
```
11+
# Usage
1412

15-
or
13+
To run the program, run either:
1614

1715
```bash
18-
dotnet run
16+
MOMENTO_API_KEY=<YOUR_API_KEY_HERE> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> MOMENTO_CACHE_NAME=<YOUR_CACHE_NAME_HERE> dotnet run
1917
```
2018

21-
and you will be prompted to enter the auth token and cache name.
22-
2319
If the cache name entered does not exist, the program will create it.

examples/DisposableTokens/DisposableTokens.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>
19-
<PackageReference Include="Momento.Sdk" Version="1.39.0" />
19+
<PackageReference Include="Momento.Sdk" Version="1.41.0" />
2020
</ItemGroup>
2121
</Project>

examples/DisposableTokens/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ static class Program
1111

1212
private static readonly ICredentialProvider authProvider;
1313
private static readonly IAuthClient client;
14-
14+
1515
static Program()
1616
{
17-
authProvider = new EnvMomentoTokenProvider("MOMENTO_API_KEY");
17+
authProvider = new EnvMomentoTokenProvider("V1_API_KEY");
1818
client = new AuthClient(AuthConfigurations.Default.Latest(), authProvider);
1919
}
2020

@@ -71,9 +71,9 @@ private static GenerateDisposableTokenResponse.Success ProcessResponse(GenerateD
7171
private static void PrintTokenInfo(GenerateDisposableTokenResponse.Success token)
7272
{
7373
Console.WriteLine(
74-
"The generated disposable token (truncated): "
75-
+ token.AuthToken.Substring(0, 10)
76-
+ "..."
74+
"The generated disposable token (truncated): "
75+
+ token.AuthToken.Substring(0, 10)
76+
+ "..."
7777
+ token.AuthToken.Substring((token.AuthToken.Length - 10), 10)
7878
);
7979
Console.WriteLine("The token expires at (epoch timestamp): " + token.ExpiresAt.Epoch() + "\n");

examples/DocExampleApis/DocExampleApis.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Momento.Sdk" Version="1.39.0" />
11+
<PackageReference Include="Momento.Sdk" Version="1.41.0" />
1212
</ItemGroup>
1313

1414
</Project>

0 commit comments

Comments
 (0)