diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..59e1e49a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "nuget" # See documentation for possible values + directory: "/examples" # Location of package manifests + schedule: + interval: "daily" + allow: + - dependency-name: "Momento.Sdk" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3855dbc0..5a8475de 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -46,3 +46,41 @@ jobs: run: | dotnet test tests/Integration/Momento.Sdk.Incubating.Tests shell: bash + + build_examples: + runs-on: ubuntu-latest + env: + # TODO: remove token stored as secret in favor of using a + # momento-local instance that can be spun up for testing + MOMENTO_AUTH_TOKEN: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }} + + steps: + - name: Setup repo + uses: actions/checkout@v2 + + - name: Set up dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: "6.0.x" + + - name: Run samples + id: validation + continue-on-error: true + run: | + pushd dotnet/MomentoExamples + dotnet build MomentoApplication + dotnet run --project MomentoApplication + dotnet build MomentoApplicationPresignedUrl + popd + shell: bash + + - name: Send CI failure mail + if: ${{ steps.validation.outcome == 'failure' }} + uses: ./.github/actions/error-email-action + with: + username: ${{secrets.MAIL_USERNAME}} + password: ${{secrets.MAIL_PASSWORD}} + + - name: Flag Job Failure + if: ${{ steps.validation.outcome == 'failure' }} + run: exit 1 diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..92275dbc --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,405 @@ +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# content below from: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ \ No newline at end of file diff --git a/examples/MomentoApplication/MomentoApplication.csproj b/examples/MomentoApplication/MomentoApplication.csproj new file mode 100644 index 00000000..4b042904 --- /dev/null +++ b/examples/MomentoApplication/MomentoApplication.csproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + PackageReference + + + + + + diff --git a/examples/MomentoApplication/Program.cs b/examples/MomentoApplication/Program.cs new file mode 100644 index 00000000..b7bfbe37 --- /dev/null +++ b/examples/MomentoApplication/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Threading.Tasks; +using Momento.Sdk; +using Momento.Sdk.Exceptions; +using Momento.Sdk.Responses; + +namespace MomentoApplication +{ + class Program + { + static readonly String MOMENTO_AUTH_TOKEN = Environment.GetEnvironmentVariable("MOMENTO_AUTH_TOKEN"); + static readonly String CACHE_NAME = "cache"; + static readonly String KEY = "MyKey"; + static readonly String VALUE = "MyData"; + static readonly uint DEFAULT_TTL_SECONDS = 60; + + async static Task Main(string[] args) + { + using SimpleCacheClient client = new SimpleCacheClient(MOMENTO_AUTH_TOKEN, DEFAULT_TTL_SECONDS); + try + { + client.CreateCache(CACHE_NAME); + } + catch (AlreadyExistsException) + { + Console.WriteLine($"Cache with name {CACHE_NAME} already exists.\n"); + } + Console.WriteLine("Listing caches:"); + String token = null; + do + { + ListCachesResponse resp = client.ListCaches(token); + foreach (CacheInfo cacheInfo in resp.Caches) + { + Console.WriteLine(cacheInfo.Name); + } + token = resp.NextPageToken; + } while (!String.IsNullOrEmpty(token)); + Console.WriteLine($"\nSetting key: {KEY} with value: {VALUE}"); + await client.SetAsync(CACHE_NAME, KEY, VALUE); + Console.WriteLine($"\nGet value for key: {KEY}"); + CacheGetResponse getResponse = await client.GetAsync(CACHE_NAME, KEY); + Console.WriteLine($"\nLookedup value: {getResponse.String()}, Stored value: {VALUE}"); + } + } +} diff --git a/examples/MomentoApplicationPresignedUrl/MomentoApplicationPresignedUrl.csproj b/examples/MomentoApplicationPresignedUrl/MomentoApplicationPresignedUrl.csproj new file mode 100644 index 00000000..43e7e0fa --- /dev/null +++ b/examples/MomentoApplicationPresignedUrl/MomentoApplicationPresignedUrl.csproj @@ -0,0 +1,12 @@ + + + + Exe + net6.0 + + + + + + + diff --git a/examples/MomentoApplicationPresignedUrl/Program.cs b/examples/MomentoApplicationPresignedUrl/Program.cs new file mode 100644 index 00000000..3b6618c9 --- /dev/null +++ b/examples/MomentoApplicationPresignedUrl/Program.cs @@ -0,0 +1,75 @@ +using System; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Momento.Sdk; +using Momento.Sdk.Requests; + +namespace MomentoApplicationPresignedUrl +{ + class Program + { + private static readonly string SIGNING_KEY = Environment.GetEnvironmentVariable("SIGNING_KEY"); + private static readonly string ENDPOINT = Environment.GetEnvironmentVariable("ENDPOINT"); + + private static readonly uint URL_TTL_MINUTES = 10; + private static readonly string CACHE_NAME = Environment.GetEnvironmentVariable("CACHE_NAME"); + private static readonly string OBJECT_KEY = "MyKey"; + private static readonly string OBJECT_VALUE = "MyData"; + private static readonly uint OBJECT_TTL_SECONDS = 60 * 60 * 24 * 14; // 14 days + + private static readonly HttpClient client = new HttpClient(); + + private static async Task RunPresignedUrlExample(Uri setUri, Uri getUri) + { + Console.WriteLine($"Posting value with signed URL for {CacheOperation.SET}: {OBJECT_VALUE}"); + var data = new StringContent(OBJECT_VALUE, Encoding.UTF8, "application/json"); + var setResponse = await client.PostAsync(setUri, data); + setResponse.EnsureSuccessStatusCode(); + + var getResponse = await client.GetStringAsync(getUri); + Console.WriteLine($"Retrieved value with signed URL for {CacheOperation.GET}: {getResponse}"); + } + + static async Task Main(string[] args) + { + if (String.IsNullOrEmpty(SIGNING_KEY)) + { + Console.WriteLine($"Enviroment variable SIGNING_KEY not set"); + Environment.Exit(1); + } + if (String.IsNullOrEmpty(ENDPOINT)) + { + Console.WriteLine($"Enviroment variable ENDPOINT not set"); + Environment.Exit(1); + } + + var cacheName = CACHE_NAME; + if (String.IsNullOrEmpty(CACHE_NAME)) + { + cacheName = "default-cache"; + Console.WriteLine($"Enviroment variable CACHE_NAME not set. Using cache name {cacheName}."); + } + + // prepare requests + uint expiryEpochSeconds = (uint)DateTimeOffset.UtcNow.AddMinutes(URL_TTL_MINUTES).ToUnixTimeSeconds(); + var setReq = new SigningRequest(cacheName, OBJECT_KEY, CacheOperation.SET, expiryEpochSeconds) { TtlSeconds = OBJECT_TTL_SECONDS }; + var getReq = new SigningRequest(cacheName, OBJECT_KEY, CacheOperation.GET, expiryEpochSeconds); + Console.WriteLine($"Request claims: exp = {expiryEpochSeconds}, cache = {cacheName}, key = {OBJECT_KEY}, ttl (for set) = {OBJECT_TTL_SECONDS}"); + + // create presigned urls + MomentoSigner signer = new MomentoSigner(SIGNING_KEY); + var setUrl = signer.CreatePresignedUrl(ENDPOINT, setReq); + var getUrl = signer.CreatePresignedUrl(ENDPOINT, getReq); + + Uri setUri, getUri; + Uri.TryCreate(setUrl, UriKind.Absolute, out setUri); + Console.WriteLine($"Signed URL for {CacheOperation.SET}:\n{setUri}"); + Uri.TryCreate(getUrl, UriKind.Absolute, out getUri); + Console.WriteLine($"Signed URL for {CacheOperation.GET}:\n{getUri}"); + + // set and get using presigned urls + await RunPresignedUrlExample(setUri, getUri); + } + } +} \ No newline at end of file diff --git a/examples/MomentoApplicationPresignedUrlNet45/Program.cs b/examples/MomentoApplicationPresignedUrlNet45/Program.cs new file mode 100644 index 00000000..0d92b1b1 --- /dev/null +++ b/examples/MomentoApplicationPresignedUrlNet45/Program.cs @@ -0,0 +1,74 @@ +using System; +using System.Text; +using System.Net.Http; +using System.Threading.Tasks; +using MomentoSdkDotnet45; + +namespace MomentoApplicationPresignedUrl +{ + class Program + { + private static readonly string SIGNING_KEY = Environment.GetEnvironmentVariable("SIGNING_KEY"); + private static readonly string ENDPOINT = Environment.GetEnvironmentVariable("ENDPOINT"); + + private static readonly uint URL_TTL_MINUTES = 10; + private static readonly string CACHE_NAME = Environment.GetEnvironmentVariable("CACHE_NAME"); + private static readonly string OBJECT_KEY = "MyKey"; + private static readonly string OBJECT_VALUE = "MyData"; + private static readonly uint OBJECT_TTL_SECONDS = 60 * 60 * 24 * 14; // 14 days + + private static readonly HttpClient client = new HttpClient(); + + private static async Task RunPresignedUrlExample(Uri setUri, Uri getUri) + { + Console.WriteLine($"Posting value with signed URL for {CacheOperation.SET}: {OBJECT_VALUE}"); + var data = new StringContent(OBJECT_VALUE, Encoding.UTF8, "application/json"); + var setResponse = await client.PostAsync(setUri, data); + setResponse.EnsureSuccessStatusCode(); + + var getResponse = await client.GetStringAsync(getUri); + Console.WriteLine($"Retrieved value with signed URL for {CacheOperation.GET}: {getResponse}"); + } + + static async Task Main(string[] args) + { + if (String.IsNullOrEmpty(SIGNING_KEY)) + { + Console.WriteLine($"Enviroment variable SIGNING_KEY not set"); + Environment.Exit(1); + } + if (String.IsNullOrEmpty(ENDPOINT)) + { + Console.WriteLine($"Enviroment variable ENDPOINT not set"); + Environment.Exit(1); + } + + var cacheName = CACHE_NAME; + if (String.IsNullOrEmpty(CACHE_NAME)) + { + cacheName = "default-cache"; + Console.WriteLine($"Enviroment variable CACHE_NAME not set. Using cache name {cacheName}."); + } + + // prepare requests + uint expiryEpochSeconds = (uint) DateTimeOffset.UtcNow.AddMinutes(URL_TTL_MINUTES).Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + var setReq = new SigningRequest(cacheName, OBJECT_KEY, CacheOperation.SET, expiryEpochSeconds) { TtlSeconds = OBJECT_TTL_SECONDS }; + var getReq = new SigningRequest(cacheName, OBJECT_KEY, CacheOperation.GET, expiryEpochSeconds); + Console.WriteLine($"Request claims: exp = {expiryEpochSeconds}, cache = {cacheName}, key = {OBJECT_KEY}, ttl (for set) = {OBJECT_TTL_SECONDS}"); + + // create presigned urls + MomentoSigner signer = new MomentoSigner(SIGNING_KEY); + var setUrl = signer.CreatePresignedUrl(ENDPOINT, setReq); + var getUrl = signer.CreatePresignedUrl(ENDPOINT, getReq); + + Uri setUri, getUri; + Uri.TryCreate(setUrl, UriKind.Absolute, out setUri); + Console.WriteLine($"Signed URL for {CacheOperation.SET}:\n{setUri}"); + Uri.TryCreate(getUrl, UriKind.Absolute, out getUri); + Console.WriteLine($"Signed URL for {CacheOperation.GET}:\n{getUri}"); + + // set and get using presigned urls + await RunPresignedUrlExample(setUri, getUri); + } + } +} \ No newline at end of file diff --git a/examples/MomentoApplicationPresignedUrlNet45/README.md b/examples/MomentoApplicationPresignedUrlNet45/README.md new file mode 100644 index 00000000..637d27d2 --- /dev/null +++ b/examples/MomentoApplicationPresignedUrlNet45/README.md @@ -0,0 +1,15 @@ +## MomentoSdkDotnet45 + +SDK is built for target framework .NET Framework 4.5 or above. Only MomentoSigner is supported. + +## To add to your project + +In Visual Studio project, open the NuGet Package Manager. + +Add package source https://momento.jfrog.io/artifactory/api/nuget/nuget-public. + +Install the package MomentoSdkDotnet45. + +## Example Code for Presigned URL Creation + +[Program.cs](Program.cs) diff --git a/examples/MomentoExamples.sln b/examples/MomentoExamples.sln new file mode 100644 index 00000000..22c3ba9f --- /dev/null +++ b/examples/MomentoExamples.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.810.11 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MomentoApplication", "MomentoApplication\MomentoApplication.csproj", "{269830D5-AD7E-4527-A625-38C6464659D4}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MomentoFSharpApplication", "MomentoFSharpApplication\MomentoFSharpApplication.fsproj", "{68EAA822-06A9-45CE-BCE0-9A1754F5450C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {269830D5-AD7E-4527-A625-38C6464659D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {269830D5-AD7E-4527-A625-38C6464659D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {269830D5-AD7E-4527-A625-38C6464659D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {269830D5-AD7E-4527-A625-38C6464659D4}.Release|Any CPU.Build.0 = Release|Any CPU + {68EAA822-06A9-45CE-BCE0-9A1754F5450C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {68EAA822-06A9-45CE-BCE0-9A1754F5450C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {68EAA822-06A9-45CE-BCE0-9A1754F5450C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {68EAA822-06A9-45CE-BCE0-9A1754F5450C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {000D04D9-1F52-4312-9B6D-B8F04A77A155} + EndGlobalSection +EndGlobal diff --git a/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj b/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj new file mode 100644 index 00000000..48f7df92 --- /dev/null +++ b/examples/MomentoFSharpApplication/MomentoFSharpApplication.fsproj @@ -0,0 +1,17 @@ + + + + Exe + net6.0 + + + + + + + + + + + + diff --git a/examples/MomentoFSharpApplication/Program.fs b/examples/MomentoFSharpApplication/Program.fs new file mode 100644 index 00000000..8529a921 --- /dev/null +++ b/examples/MomentoFSharpApplication/Program.fs @@ -0,0 +1,34 @@ +open Momento.Sdk +open Momento.Sdk.Exceptions +open System + + +let MOMENTO_AUTH_TOKEN = Environment.GetEnvironmentVariable("MOMENTO_AUTH_TOKEN") +let CACHE_NAME = "cache" +let DEFAULT_TTL_SECONDS = 60u + +let exerciseCache() = ( + printfn "Howdy" + using(new SimpleCacheClient(MOMENTO_AUTH_TOKEN, DEFAULT_TTL_SECONDS)) (fun client -> + try + client.CreateCache(CACHE_NAME) + with + | :? AlreadyExistsException -> printfn $"Cache with name {CACHE_NAME} already exists\n"; null + |> ignore + + + printfn("Listing caches:") + let resp = client.ListCaches() + for cacheInfo in resp.Caches do + printfn $"{cacheInfo.Name}" + + + null + ) + +) + +[] +let main(argv :string[]) = + exerciseCache() + 0