Repository navigation
add v3 feature flags API. Fix #1388 #1389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.x.x
Are you sure you want to change the base?
Changes from all commits
0718d10
285d449
f2c93fe
67fb15a
14154d2
88ba312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright 2026 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.cloudfoundry.reactor.client.v3.featureflags; | ||
|
|
||
| import java.util.Map; | ||
| import org.cloudfoundry.client.v3.featureflags.FeatureFlagsV3; | ||
| import org.cloudfoundry.client.v3.featureflags.GetFeatureFlagRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.GetFeatureFlagResponse; | ||
| import org.cloudfoundry.client.v3.featureflags.ListFeatureFlagsRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.ListFeatureFlagsResponse; | ||
| import org.cloudfoundry.client.v3.featureflags.UpdateFeatureFlagRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.UpdateFeatureFlagResponse; | ||
| import org.cloudfoundry.reactor.ConnectionContext; | ||
| import org.cloudfoundry.reactor.TokenProvider; | ||
| import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| /** | ||
| * The Reactor-based implementation of {@link FeatureFlagsV3} | ||
| */ | ||
| public final class ReactorFeatureFlagsV3 extends AbstractClientV3Operations | ||
| implements FeatureFlagsV3 { | ||
|
|
||
| /** | ||
| * Creates an instance | ||
| * | ||
| * @param connectionContext the {@link ConnectionContext} to use when communicating with the server | ||
| * @param root the root URI of the server. Typically something like {@code https://api.run.pivotal.io}. | ||
| * @param tokenProvider the {@link TokenProvider} to use when communicating with the server | ||
| * @param requestTags map with custom http headers which will be added to web request | ||
| */ | ||
| public ReactorFeatureFlagsV3( | ||
| ConnectionContext connectionContext, | ||
| Mono<String> root, | ||
| TokenProvider tokenProvider, | ||
| Map<String, String> requestTags) { | ||
| super(connectionContext, root, tokenProvider, requestTags); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<GetFeatureFlagResponse> get(GetFeatureFlagRequest request) { | ||
| return get( | ||
| request, | ||
| GetFeatureFlagResponse.class, | ||
| builder -> builder.pathSegment("feature_flags", request.getName())) | ||
| .checkpoint(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<ListFeatureFlagsResponse> list(ListFeatureFlagsRequest request) { | ||
| return get( | ||
| request, | ||
| ListFeatureFlagsResponse.class, | ||
| builder -> builder.pathSegment("feature_flags")) | ||
| .checkpoint(); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<UpdateFeatureFlagResponse> update(UpdateFeatureFlagRequest request) { | ||
| return patch( | ||
| request, | ||
| UpdateFeatureFlagResponse.class, | ||
| builder -> builder.pathSegment("feature_flags", request.getName())) | ||
| .checkpoint(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| /* | ||
| * Copyright 2026 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.cloudfoundry.reactor.client.v3.featureflags; | ||
|
|
||
| import static io.netty.handler.codec.http.HttpMethod.GET; | ||
| import static io.netty.handler.codec.http.HttpMethod.PATCH; | ||
| import static io.netty.handler.codec.http.HttpResponseStatus.OK; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.Collections; | ||
| import org.cloudfoundry.client.v3.Link; | ||
| import org.cloudfoundry.client.v3.Pagination; | ||
| import org.cloudfoundry.client.v3.featureflags.GetFeatureFlagRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.GetFeatureFlagResponse; | ||
| import org.cloudfoundry.client.v3.featureflags.ListFeatureFlagsRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.ListFeatureFlagsResponse; | ||
| import org.cloudfoundry.client.v3.featureflags.UpdateFeatureFlagRequest; | ||
| import org.cloudfoundry.client.v3.featureflags.UpdateFeatureFlagResponse; | ||
| import org.cloudfoundry.reactor.InteractionContext; | ||
| import org.cloudfoundry.reactor.TestRequest; | ||
| import org.cloudfoundry.reactor.TestResponse; | ||
| import org.cloudfoundry.reactor.client.AbstractClientApiTest; | ||
| import org.junit.jupiter.api.Test; | ||
| import reactor.test.StepVerifier; | ||
|
|
||
| final class ReactorFeatureFlagsV3Test extends AbstractClientApiTest { | ||
|
|
||
| private static final String BASE_URL = "https://api.example.org/v3/feature_flags/"; | ||
| private static final String UPDATED_AT = "2020-03-10T15:49:32Z"; | ||
|
|
||
| private final ReactorFeatureFlagsV3 featureFlags = | ||
| new ReactorFeatureFlagsV3( | ||
| CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap()); | ||
|
|
||
| @Test | ||
| void get() { | ||
| mockRequest( | ||
| InteractionContext.builder() | ||
| .request( | ||
| TestRequest.builder() | ||
| .method(GET) | ||
| .path("/feature_flags/app_scaling") | ||
| .build()) | ||
| .response( | ||
| TestResponse.builder() | ||
| .status(OK) | ||
| .payload( | ||
| "fixtures/client/v3/featureflags/GET_{feature_flag_name}_response.json") | ||
| .build()) | ||
| .build()); | ||
|
|
||
| this.featureFlags | ||
| .get(GetFeatureFlagRequest.builder().name("app_scaling").build()) | ||
| .as(StepVerifier::create) | ||
| .expectNext( | ||
| GetFeatureFlagResponse.builder() | ||
| .name("app_scaling") | ||
| .enabled(true) | ||
| .updatedAt(UPDATED_AT) | ||
| .link("self", selfLink("app_scaling")) | ||
| .build()) | ||
| .expectComplete() | ||
| .verify(Duration.ofSeconds(5)); | ||
| } | ||
|
|
||
| @Test | ||
| void list() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit tests only cover the happy path. It would be good to have:
The integration test also never sets |
||
| mockRequest( | ||
| InteractionContext.builder() | ||
| .request(TestRequest.builder().method(GET).path("/feature_flags").build()) | ||
| .response( | ||
| TestResponse.builder() | ||
| .status(OK) | ||
| .payload( | ||
| "fixtures/client/v3/featureflags/GET_response.json") | ||
| .build()) | ||
| .build()); | ||
|
|
||
| this.featureFlags | ||
| .list(ListFeatureFlagsRequest.builder().build()) | ||
| .as(StepVerifier::create) | ||
| .expectNext( | ||
| ListFeatureFlagsResponse.builder() | ||
| .pagination( | ||
| Pagination.builder() | ||
| .totalResults(2) | ||
| .first( | ||
| Link.builder() | ||
| .href( | ||
| "https://api.example.org/v3/feature_flags?page=1&per_page=50") | ||
| .build()) | ||
| .last( | ||
| Link.builder() | ||
| .href( | ||
| "https://api.example.org/v3/feature_flags?page=1&per_page=50") | ||
| .build()) | ||
| .build()) | ||
| .resource( | ||
| GetFeatureFlagResponse.builder() | ||
| .name("app_scaling") | ||
| .enabled(true) | ||
| .updatedAt(UPDATED_AT) | ||
| .link("self", selfLink("app_scaling")) | ||
| .build()) | ||
| .resource( | ||
| GetFeatureFlagResponse.builder() | ||
| .name("user_org_creation") | ||
| .enabled(false) | ||
| .customErrorMessage("This feature is disabled") | ||
| .updatedAt(UPDATED_AT) | ||
| .link("self", selfLink("user_org_creation")) | ||
| .build()) | ||
| .build()) | ||
| .expectComplete() | ||
| .verify(Duration.ofSeconds(5)); | ||
| } | ||
|
|
||
| @Test | ||
| void update() { | ||
| mockRequest( | ||
| InteractionContext.builder() | ||
| .request( | ||
| TestRequest.builder() | ||
| .method(PATCH) | ||
| .path("/feature_flags/app_scaling") | ||
| .payload( | ||
| "fixtures/client/v3/featureflags/PATCH_{feature_flag_name}_request.json") | ||
| .build()) | ||
| .response( | ||
| TestResponse.builder() | ||
| .status(OK) | ||
| .payload( | ||
| "fixtures/client/v3/featureflags/PATCH_{feature_flag_name}_response.json") | ||
| .build()) | ||
| .build()); | ||
|
|
||
| this.featureFlags | ||
| .update( | ||
| UpdateFeatureFlagRequest.builder() | ||
| .name("app_scaling") | ||
| .enabled(false) | ||
| .customErrorMessage("This feature is disabled") | ||
| .build()) | ||
| .as(StepVerifier::create) | ||
| .expectNext( | ||
| UpdateFeatureFlagResponse.builder() | ||
| .name("app_scaling") | ||
| .enabled(false) | ||
| .customErrorMessage("This feature is disabled") | ||
| .updatedAt(UPDATED_AT) | ||
| .link("self", selfLink("app_scaling")) | ||
| .build()) | ||
| .expectComplete() | ||
| .verify(Duration.ofSeconds(5)); | ||
| } | ||
|
|
||
| private static Link selfLink(String flagName) { | ||
| return Link.builder().href(BASE_URL + flagName).build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "pagination": { | ||
| "total_results": 2, | ||
| "first": { | ||
| "href": "https://api.example.org/v3/feature_flags?page=1&per_page=50" | ||
| }, | ||
| "last": { | ||
| "href": "https://api.example.org/v3/feature_flags?page=1&per_page=50" | ||
| }, | ||
| "next": null, | ||
| "previous": null | ||
| }, | ||
| "resources": [ | ||
| { | ||
| "name": "app_scaling", | ||
| "enabled": true, | ||
| "custom_error_message": null, | ||
| "updated_at": "2020-03-10T15:49:32Z", | ||
| "links": { | ||
| "self": { | ||
| "href": "https://api.example.org/v3/feature_flags/app_scaling" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "name": "user_org_creation", | ||
| "enabled": false, | ||
| "custom_error_message": "This feature is disabled", | ||
| "updated_at": "2020-03-10T15:49:32Z", | ||
| "links": { | ||
| "self": { | ||
| "href": "https://api.example.org/v3/feature_flags/user_org_creation" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "name": "app_scaling", | ||
| "enabled": true, | ||
| "custom_error_message": null, | ||
| "updated_at": "2020-03-10T15:49:32Z", | ||
| "links": { | ||
| "self": { | ||
| "href": "https://api.example.org/v3/feature_flags/app_scaling" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "enabled": false, | ||
| "custom_error_message": "This feature is disabled" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "name": "app_scaling", | ||
| "enabled": false, | ||
| "custom_error_message": "This feature is disabled", | ||
| "updated_at": "2020-03-10T15:49:32Z", | ||
| "links": { | ||
| "self": { | ||
| "href": "https://api.example.org/v3/feature_flags/app_scaling" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright 2013-2021 the original author or authors. | ||
| * Copyright 2013-2026 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -55,6 +55,7 @@ | |
| import org.cloudfoundry.client.v3.deployments.DeploymentsV3; | ||
| import org.cloudfoundry.client.v3.domains.DomainsV3; | ||
| import org.cloudfoundry.client.v3.droplets.Droplets; | ||
| import org.cloudfoundry.client.v3.featureflags.FeatureFlagsV3; | ||
| import org.cloudfoundry.client.v3.isolationsegments.IsolationSegments; | ||
| import org.cloudfoundry.client.v3.jobs.JobsV3; | ||
| import org.cloudfoundry.client.v3.organizations.OrganizationsV3; | ||
|
|
@@ -169,6 +170,11 @@ public interface CloudFoundryClient { | |
| */ | ||
| FeatureFlags featureFlags(); | ||
|
|
||
| /** | ||
| * Main entry point to the Cloud Foundry Feature Flags V3 Client API | ||
| */ | ||
| FeatureFlagsV3 featureFlagsV3(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a heads-up, no change needed: adding |
||
|
|
||
| /** | ||
| * Main entry point to the Cloud Foundry Info Client API | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This null check looks right to me, but it has nothing to do with feature flags. Could it go into its own PR, or at least get a small test (an upload with only resources and no bits) so it does not regress? Also the copyright year in the header is not updated for this file.