From 6c60de60df356d8ff90cfe730e8771e8b63ca044 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Thu, 23 May 2024 15:22:12 +0200 Subject: [PATCH] refactor: Rename repo and pointers to sdk-java (#127) * refactor: Rename repo and pointers to sdk-java * fix: repo URL * fix: Better snippet in README * fix: README errors * Update pom.xml Co-authored-by: Nicklas Lundin * Update pom.xml Co-authored-by: Nicklas Lundin --------- Co-authored-by: Nicklas Lundin --- .github/CONTRIBUTING.md | 2 +- .gitignore | 1 + README.md | 68 +++++++++++++++++--------------------- catalog-info.yaml | 2 +- pom.xml | 18 +++++----- release-please-config.json | 2 +- 6 files changed, 43 insertions(+), 50 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ed140c0f..c7101898 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -37,4 +37,4 @@ Github Actions are set up that are able to: In order to promote an uploaded version from **Staging** to **Release** (hence making it openly available on [Maven Central Search](https://central.sonatype.com/)) a user with the right credentials must login into the the [Sonatype UI](https://oss.sonatype.org/#welcome) and perform the release process manually. #### After realeasing -After a release PR is merged, the main branch will stay at the release version (non-snapshot) until updated. Release please will create a PR ([example](https://github.com/spotify/confidence-openfeature-provider-java/pull/55)) that does this "snapshot bump". The recommendation is to merge that PR directly when possible. +After a release PR is merged, the main branch will stay at the release version (non-snapshot) until updated. Release please will create a PR ([example](https://github.com/spotify/confidence-sdk-java/pull/55)) that does this "snapshot bump". The recommendation is to merge that PR directly when possible. diff --git a/.gitignore b/.gitignore index 3da0c7e1..2b610012 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ !.git* /target/ *.iml +**dependency-reduced-pom.xml \ No newline at end of file diff --git a/README.md b/README.md index b232a9e4..f7cb9a39 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,6 @@ -# Confidence OpenFeature Java Provider +# Java Confidence SDK -Java library for the [Confidence](https://confidence.spotify.com/) feature flag provider. - -The library includes a `Provider` for -the [OpenFeature Java SDK](https://openfeature.dev/docs/tutorials/getting-started/java), that can be -used to resolve feature flag values from the Confidence platform. - -To learn more about the basic concepts (flags, targeting key, evaluation contexts), -the [OpenFeature reference documentation](https://openfeature.dev/docs/reference/intro) can be -useful. +Java library for [Confidence](https://confidence.spotify.com/). ## Install @@ -18,14 +10,14 @@ useful. ```xml com.spotify.confidence - openfeature-provider + sdk-java 0.0.12-SNAPSHOT ``` #### Depending on a development snapshot -We deploy snapshots from the `main` branch to [Sonatype OSSRH](https://oss.sonatype.org/content/repositories/snapshots/com/spotify/confidence/openfeature-provider/). +We deploy snapshots from the `main` branch to [Sonatype OSSRH](https://oss.sonatype.org/content/repositories/snapshots/com/spotify/confidence/sdk-java/). To use a snapshot, add the following repository to your `pom.xml`: ```xml @@ -38,34 +30,34 @@ To use a snapshot, add the following repository to your `pom.xml`: ## Usage -The provider is instantiated using a client token that is configured in the Confidence UI or via the -management API. After that all interaction with the feature flags happens using the OpenFeature client APIs. +The SDK is instantiated using a client secret that is configured in the Confidence UI or via the +management console. +### Resolving flags +Flag values are evaluated remotely and returned to the application: ```java -package com.spotify.confidence.openfeature; - -import com.spotify.confidence.ConfidenceFeatureProvider; -import dev.openfeature.sdk.Client; -import dev.openfeature.sdk.MutableContext; -import dev.openfeature.sdk.OpenFeatureAPI; -import dev.openfeature.sdk.Value; -import java.util.Map; - -public final class ResolveFlags { +final Confidence confidence = Confidence.builder("").build(); +confidence.setContext(Map.of("country", ConfidenceValue.of("SE"))); +final String propertyValue = + confidence + .withContext( + Map.of( + "user_id", ConfidenceValue.of(""), + "country", ConfidenceValue.of("SE"))) + .getValue("flag-name.property-name", "defaultValue"); +``` - public static final String CLIENT_TOKEN = "<>"; +### Tracking events +Events are emitted to the Confidence backend: +```java +confidence.track("my-event", ConfidenceValue.of(Map.of("field", ConfidenceValue.of("data")))); +``` - public static void main(String[] args) { - final OpenFeatureAPI api = OpenFeatureAPI.getInstance(); - api.setProvider(new ConfidenceFeatureProvider(CLIENT_TOKEN)); - final Client client = api.getClient(); +## OpenFeature +The library includes a `Provider` for +the [OpenFeature Java SDK](https://openfeature.dev/docs/tutorials/getting-started/java), that can be +used to resolve feature flag values from the Confidence platform. - final String targetingKey = "userId"; - final Map context = Map.of("country", new Value("SE")); - final MutableContext ctx = new MutableContext(targetingKey, context); - final String propertyValue = client.getStringValue("flagName.propertyName", "defaultValue", - ctx); - System.out.println(propertyValue); - } -} -``` +To learn more about the basic concepts (flags, targeting key, evaluation contexts), +the [OpenFeature reference documentation](https://openfeature.dev/docs/reference/intro) can be +useful. \ No newline at end of file diff --git a/catalog-info.yaml b/catalog-info.yaml index 1ac371cd..5dfd1fe7 100644 --- a/catalog-info.yaml +++ b/catalog-info.yaml @@ -1,7 +1,7 @@ apiVersion: backstage.io/v1alpha1 kind: Component metadata: - name: confidence-openfeature-provider-java + name: sdk-java spec: type: library owner: hawkeye \ No newline at end of file diff --git a/pom.xml b/pom.xml index 676091bd..2745ef3d 100644 --- a/pom.xml +++ b/pom.xml @@ -14,11 +14,11 @@ com.spotify.confidence - openfeature-provider + sdk-java 0.0.12-SNAPSHOT - https://github.com/spotify/confidence-openfeature-provider-java - Confidence OpenFeature provider for Java + https://github.com/spotify/confidence-sdk-java + Confidence SDK for Java @@ -35,7 +35,7 @@ UTF-8 - Confidence OpenFeature Provider + Confidence SDK com.spotify https://github.com/spotify @@ -43,24 +43,24 @@ GitHub - https://github.com/spotify/confidence-openfeature-provider-java/issues + https://github.com/spotify/confidence-sdk-java/issues Apache License 2.0 - https://github.com/spotify/confidence-openfeature-provider-java/blob/main/LICENSE + https://github.com/spotify/confidence-sdk-java/blob/main/LICENSE repo - https://github.com/spotify/confidence-openfeature-provider-java + https://github.com/spotify/confidence-sdk-java - scm:git:git@github.com:spotify/confidence-openfeature-provider-java.git + scm:git:git@github.com:spotify/confidence-sdk-java.git - scm:git:git@github.com:spotify/confidence-openfeature-provider-java.git + scm:git:git@github.com:spotify/confidence-sdk-java.git diff --git a/release-please-config.json b/release-please-config.json index 7fb96d50..a7f82ebf 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -2,7 +2,7 @@ "bootstrap-sha": "188faf7e47b03bde3bf02c3521771301c77580d6", "packages": { ".": { - "package-name": "com.spotify.confidence.openfeature-provider", + "package-name": "com.spotify.confidence.java-sdk", "release-type": "maven", "monorepo-tags": false, "include-component-in-tag": false,