Skip to content

Commit

Permalink
feat: Add Harness provider (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: liran2000 <liran2000@gmail.com>
  • Loading branch information
liran2000 authored Oct 31, 2023
1 parent d14883e commit a6940bc
Show file tree
Hide file tree
Showing 10 changed files with 1,023 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ components:
providers/unleash:
- liran2000
- sighphyre
providers/harness:
- liran2000
- davejohnston

ignored-authors:
- renovate-bot
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"providers/flagsmith": "0.1.4",
"providers/launchdarkly": "0.1.3",
"providers/unleash": "0.0.2-alpha",
"providers/harness": "0.0.1-alpha",
"tests/flagd": "1.3.1"
}
Empty file added providers/harness/CHANGELOG.md
Empty file.
74 changes: 74 additions & 0 deletions providers/harness/README.md
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.

50 changes: 50 additions & 0 deletions providers/harness/go.mod
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
)
Loading

0 comments on commit a6940bc

Please sign in to comment.