-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: liran2000 <liran2000@gmail.com>
- Loading branch information
Showing
10 changed files
with
1,023 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Unofficial Harness OpenFeature GO Provider | ||
|
||
[Harness](https://developer.harness.io/docs/feature-flags) OpenFeature Provider can provide usage for Harness via OpenFeature GO SDK. | ||
|
||
# Installation | ||
|
||
To use the Harness provider, you'll need to install [Harness Go client](github.com/harness/ff-golang-server-sdk) and Harness provider. You can install the packages using the following command | ||
|
||
```shell | ||
go get github.com/harness/ff-golang-server-sdk | ||
go get github.com/open-feature/go-sdk-contrib/providers/harness | ||
``` | ||
|
||
## Concepts | ||
* Provider Object evaluation gets Harness JSON evaluation. | ||
* Other provider types evaluation gets Harness matching type evaluation. | ||
|
||
## Usage | ||
Harness OpenFeature Provider is using Harness GO SDK. | ||
|
||
### Evaluation Context | ||
Evaluation Context is mapped to Harness [target](https://developer.harness.io/docs/feature-flags/ff-sdks/server-sdks/feature-flag-sdks-go-application/#add-a-target). | ||
OpenFeature targetingKey is mapped to _Identifier_, _Name_ is mapped to _Name_ and other fields are mapped to Attributes | ||
fields. | ||
|
||
### Usage Example | ||
|
||
```go | ||
import ( | ||
harness "github.com/harness/ff-golang-server-sdk/client" | ||
harnessProvider "github.com/open-feature/go-sdk-contrib/providers/harness/pkg" | ||
) | ||
|
||
providerConfig := harnessProvider.ProviderConfig{ | ||
Options: []harness.ConfigOption{ | ||
harness.WithWaitForInitialized(true), | ||
harness.WithURL(URL), | ||
harness.WithStreamEnabled(false), | ||
harness.WithHTTPClient(http.DefaultClient), | ||
harness.WithStoreEnabled(false), | ||
}, | ||
SdkKey: ValidSDKKey, | ||
} | ||
|
||
provider, err := harnessProvider.NewProvider(providerConfig) | ||
if err != nil { | ||
t.Fail() | ||
} | ||
err = provider.Init(of.EvaluationContext{}) | ||
if err != nil { | ||
t.Fail() | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
of.SetProvider(provider) | ||
ofClient := of.NewClient("my-app") | ||
|
||
evalCtx := of.NewEvaluationContext( | ||
"john", | ||
map[string]interface{}{ | ||
"Firstname": "John", | ||
"Lastname": "Doe", | ||
"Email": "john@doe.com", | ||
}, | ||
) | ||
enabled, err := ofClient.BooleanValue(context.Background(), "TestTrueOn", false, evalCtx) | ||
if enabled == false { | ||
t.Fatalf("Expected feature to be enabled") | ||
} | ||
|
||
``` | ||
See [provider_test.go](./pkg/provider_test.go) for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module github.com/open-feature/go-sdk-contrib/providers/harness | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/harness/ff-golang-server-sdk v0.1.13 | ||
github.com/open-feature/go-sdk v1.7.0 | ||
github.com/stretchr/testify v1.8.4 | ||
github.com/jarcoal/httpmock v1.0.8 | ||
) | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.1.1 // indirect | ||
github.com/blang/semver/v4 v4.0.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/deepmap/oapi-codegen v1.11.0 // indirect | ||
github.com/getkin/kin-openapi v0.94.0 // indirect | ||
github.com/ghodss/yaml v1.0.0 // indirect | ||
github.com/go-logr/logr v1.2.4 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/swag v0.21.1 // indirect | ||
github.com/go-resty/resty/v2 v2.7.0 // indirect | ||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect | ||
github.com/hashicorp/go-retryablehttp v0.6.8 // indirect | ||
github.com/hashicorp/golang-lru v0.5.4 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 // indirect | ||
github.com/mitchellh/mapstructure v1.3.3 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/r3labs/sse v0.0.0-20201126193848-34e640891548 // indirect | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/twmb/murmur3 v1.1.5 // indirect | ||
go.uber.org/atomic v1.7.0 // indirect | ||
go.uber.org/multierr v1.6.0 // indirect | ||
go.uber.org/zap v1.16.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/net v0.12.0 // indirect | ||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.