From b63d8f7c34efe77871a6f9d1f110513bb1d2b350 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Wed, 15 Nov 2023 13:20:02 +0100 Subject: [PATCH] feat: Add SDK id and version to requests (#33) --- README.md | 2 ++ pkg/provider/models.go | 6 ++++++ pkg/provider/provider.go | 8 +++++++- release-please-config.json | 5 ++++- 4 files changed, 19 insertions(+), 2 deletions(-) mode change 100644 => 100755 pkg/provider/provider.go diff --git a/README.md b/README.md index 140f680..aba4a4b 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,14 @@ Before starting to use the provider, it can be helpful to read through the gener and get familiar with the concepts. ## Adding the dependency + ``` require ( github.com/spotify/confidence-openfeature-provider-go v0.1.4 github.com/open-feature/go-sdk v1.7.0 ) ``` + ### Creating and using the flag provider diff --git a/pkg/provider/models.go b/pkg/provider/models.go index d0628f9..8d38648 100644 --- a/pkg/provider/models.go +++ b/pkg/provider/models.go @@ -52,6 +52,12 @@ type resolveRequest struct { Apply bool `json:"apply"` EvaluationContext map[string]interface{} `json:"evaluation_context"` Flags []string `json:"flags"` + Sdk sdk `json:"sdk"` +} + +type sdk struct { + Id string `json:"id"` + Version string `json:"version"` } type resolveResponse struct { diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go old mode 100644 new mode 100755 index 2f7ce72..76a6298 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -15,6 +15,11 @@ type FlagProvider struct { ResolveClient resolveClient } +var ( + SDK_ID = "SDK_ID_GO_PROVIDER" + SDK_VERSION = "0.1.4" // x-release-please-version +) + func NewFlagProvider(config APIConfig) (*FlagProvider, error) { validationError := config.validate() if validationError != nil { @@ -64,7 +69,8 @@ func (e FlagProvider) resolveFlag(ctx context.Context, flag string, defaultValue requestFlagName := fmt.Sprintf("flags/%s", flagName) resp, err := e.ResolveClient.sendResolveRequest(ctx, resolveRequest{ClientSecret: e.Config.APIKey, - Flags: []string{requestFlagName}, Apply: true, EvaluationContext: evalCtx}) + Flags: []string{requestFlagName}, Apply: true, EvaluationContext: evalCtx, + Sdk: sdk{Id: SDK_ID, Version: SDK_VERSION}}) if err != nil { return processResolveError(err, defaultValue) diff --git a/release-please-config.json b/release-please-config.json index 86cbac2..f1b7241 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -6,7 +6,10 @@ "prerelease": false, "bump-minor-pre-major": true, "bump-patch-for-minor-pre-major": true, - "extra-files": ["README.md"], + "extra-files": [ + "README.md", + "pkg/provider/provider.go" + ], "changelog-sections": [ { "type": "fix",