Skip to content

Commit

Permalink
feat: Adding OpenFeature provider for Schematic
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Papillon <[email protected]>
  • Loading branch information
bpapillon committed Feb 11, 2025
1 parent 9ae74e6 commit 66f1bd8
Show file tree
Hide file tree
Showing 9 changed files with 606 additions and 0 deletions.
14 changes: 14 additions & 0 deletions DotnetSdkContrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Provide
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Flipt.Test", "test\OpenFeature.Contrib.Providers.Flipt.Test\OpenFeature.Contrib.Providers.Flipt.Test.csproj", "{B446D481-B5A3-4509-8933-C4CF6DA9B147}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Schematic", "src\OpenFeature.Contrib.Providers.Schematic\OpenFeature.Contrib.Providers.Schematic.csproj", "{CF1AB517-1D51-455F-80C0-56B4856E6A6B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenFeature.Contrib.Providers.Schematic.Test", "test\OpenFeature.Contrib.Providers.Schematic.Test\OpenFeature.Contrib.Providers.Schematic.Test.csproj", "{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -127,6 +131,14 @@ Global
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B446D481-B5A3-4509-8933-C4CF6DA9B147}.Release|Any CPU.Build.0 = Release|Any CPU
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF1AB517-1D51-455F-80C0-56B4856E6A6B}.Release|Any CPU.Build.0 = Release|Any CPU
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -151,5 +163,7 @@ Global
{F3080350-B0AB-4D59-B416-50CC38C99087} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
{5ECF7DBF-FE64-40A2-BF39-239DE173DA4B} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
{B446D481-B5A3-4509-8933-C4CF6DA9B147} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
{CF1AB517-1D51-455F-80C0-56B4856E6A6B} = {0E563821-BD08-4B7F-BF9D-395CAD80F026}
{08BD26A8-0C14-40F1-BFAF-7D413B76EF6B} = {B6D3230B-5E4D-4FF1-868E-2F4E325C84FE}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@
"extra-files": [
"OpenFeature.Contrib.Providers.Flipt.csproj"
]
},
"src/OpenFeature.Contrib.Providers.Schematic": {
"package-name": "OpenFeature.Contrib.Providers.Schematic",
"release-type": "simple",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"versioning": "default",
"extra-files": [
"OpenFeature.Contrib.Providers.Schematic.csproj"
]
}
},
"changelog-sections": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>OpenFeature.Contrib.Providers.Schematic</PackageId>
<VersionNumber>0.1.0</VersionNumber> <!--x-release-please-version -->
<VersionPrefix>$(VersionNumber)</VersionPrefix>
<AssemblyVersion>$(VersionNumber)</AssemblyVersion>
<FileVersion>$(VersionNumber)</FileVersion>
<Description>Schematic provider for .NET</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Authors>Benjamin Papillon</Authors>
</PropertyGroup>
<ItemGroup>
<!-- make the internal methods visble to our test project -->
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="SchematicHQ.Client" Version="1.0.6" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

</Project>

124 changes: 124 additions & 0 deletions src/OpenFeature.Contrib.Providers.Schematic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Schematic .NET Provider

The Schematic provider allows you to connect to your Schematic instance through the OpenFeature SDK

# .Net SDK usage

## Requirements

- open-feature/dotnet-sdk v1.5.0 > v2.0.0

## Install dependencies

The first things we will do is install the **Open Feature SDK** and the **Schematic OpenFeature provider**.

### .NET Cli
```shell
dotnet add package OpenFeature.Contrib.Providers.Schematic
```
### Package Manager

```shell
NuGet\Install-Package OpenFeature.Contrib.Providers.Schematic
```
### Package Reference

```xml
<PackageReference Include="OpenFeature.Contrib.Providers.Schematic" />
```
### Paket cli

```shell
paket add OpenFeature.Contrib.Providers.Schematic
```

### Cake

```shell
// Install OpenFeature.Contrib.Providers.Schematic as a Cake Addin
#addin nuget:?package=OpenFeature.Contrib.Providers.Schematic

// Install OpenFeature.Contrib.Providers.Schematic as a Cake Tool
#tool nuget:?package=OpenFeature.Contrib.Providers.Schematic
```

## Using the Schematic Provider with the OpenFeature SDK

To use Schematic as an OpenFeature provider, define your provider and Schematic settings.

```csharp
using OpenFeature;
using OpenFeature.Contrib.Providers.Schematic;
using System;

var schematicProvider = new SchematicFeatureProvider("your-api-key");

// Set the schematicProvider as the provider for the OpenFeature SDK
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider);

// Get an OpenFeature client
var client = OpenFeature.Api.Instance.GetClient("my-app");

// Set company and/or user context
var context = EvaluationContext.Builder()
.Set("company", new Dictionary<string, string> {
{ "id", "your-company-id" },
})
.Set("user", new Dictionary<string, string> {
{ "id", "your-user-id" },
})
.Build();

// Evaluate a flag
var val = await client.GetBooleanValueAsync("your-flag-key", false, context);

// Print the value of the 'your-flag-key' feature flag
Console.WriteLine(val);
```

You can also provide additional configuration options to the provider to manage caching behavior, offline mode, and other capabilities:

```csharp
using OpenFeature;
using OpenFeature.Contrib.Providers.Schematic;
using SchematicHQ.Client;
using System;

var options = new ClientOptions
{
Offline = true, // Run in offline mode
FlagDefaults = new Dictionary<string, bool> // Default values for offline mode
{
{ "some-flag-key", true }
},
Logger = new ConsoleLogger(), // Optional custom logger
CacheProviders = new List<ICacheProvider<bool?>> // Optional cache configuration
{
new LocalCache<bool?>(1000, TimeSpan.FromSeconds(30))
}
};

var schematicProvider = new SchematicFeatureProvider("your-api-key", options);

// Set the schematicProvider as the provider for the OpenFeature SDK
await OpenFeature.Api.Instance.SetProviderAsync(schematicProvider);

// Get an OpenFeature client
var client = OpenFeature.Api.Instance.GetClient("my-app");

// Set company and/or user context
var context = EvaluationContext.Builder()
.Set("company", new Dictionary<string, string> {
{ "id", "your-company-id" },
})
.Set("user", new Dictionary<string, string> {
{ "id", "your-user-id" },
})
.Build();

// Evaluate a flag
var val = await client.GetBooleanValueAsync("your-flag-key", false, context);

// Print the value of the 'your-flag-key' feature flag
Console.WriteLine(val);
```
Loading

0 comments on commit 66f1bd8

Please sign in to comment.