forked from openfga/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistStores-name-filter.patch
More file actions
234 lines (224 loc) · 11.3 KB
/
listStores-name-filter.patch
File metadata and controls
234 lines (224 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
diff --git a/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java b/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
index 6a88c8a..3ecb618 100644
--- a/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
+++ b/src/main/java/dev/openfga/sdk/api/OpenFgaApi.java
@@ -480,7 +480,21 @@ public class OpenFgaApi {
*/
public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(Integer pageSize, String continuationToken)
throws ApiException, FgaInvalidParameterException {
- return listStores(pageSize, continuationToken, this.configuration);
+ return listStores(pageSize, continuationToken, null, this.configuration);
+ }
+
+ /**
+ * List all stores
+ * Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
+ * @param pageSize (optional)
+ * @param continuationToken (optional)
+ * @param name (optional)
+ * @return CompletableFuture<ApiResponse<ListStoresResponse>>
+ * @throws ApiException if fails to make API call
+ */
+ public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
+ Integer pageSize, String continuationToken, String name) throws ApiException, FgaInvalidParameterException {
+ return listStores(pageSize, continuationToken, name, this.configuration);
}
/**
@@ -495,15 +509,31 @@ public class OpenFgaApi {
public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
Integer pageSize, String continuationToken, ConfigurationOverride configurationOverride)
throws ApiException, FgaInvalidParameterException {
- return listStores(pageSize, continuationToken, this.configuration.override(configurationOverride));
+ return listStores(pageSize, continuationToken, null, this.configuration.override(configurationOverride));
+ }
+
+ /**
+ * List all stores
+ * Returns a paginated list of OpenFGA stores and a continuation token to get additional stores. The continuation token will be empty if there are no more stores.
+ * @param pageSize (optional)
+ * @param continuationToken (optional)
+ * @param name (optional)
+ * @param configurationOverride Override the {@link Configuration} this OpenFgaApi was constructed with
+ * @return CompletableFuture<ApiResponse<ListStoresResponse>>
+ * @throws ApiException if fails to make API call
+ */
+ public CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
+ Integer pageSize, String continuationToken, String name, ConfigurationOverride configurationOverride)
+ throws ApiException, FgaInvalidParameterException {
+ return listStores(pageSize, continuationToken, name, this.configuration.override(configurationOverride));
}
private CompletableFuture<ApiResponse<ListStoresResponse>> listStores(
- Integer pageSize, String continuationToken, Configuration configuration)
+ Integer pageSize, String continuationToken, String name, Configuration configuration)
throws ApiException, FgaInvalidParameterException {
String path = "/stores";
- path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken);
+ path = pathWithParams(path, "page_size", pageSize, "continuation_token", continuationToken, "name", name);
Map<String, Object> methodParameters = new HashMap<>();
diff --git a/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java b/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
index 540cf7e..5095ce7 100644
--- a/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
+++ b/src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
@@ -94,7 +94,8 @@ public class OpenFgaClient {
throws FgaInvalidParameterException {
configuration.assertValid();
var overrides = new ConfigurationOverride().addHeaders(options);
- return call(() -> api.listStores(options.getPageSize(), options.getContinuationToken(), overrides))
+ return call(() -> api.listStores(
+ options.getPageSize(), options.getContinuationToken(), options.getName(), overrides))
.thenApply(ClientListStoresResponse::new);
}
diff --git a/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java b/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java
index 81f6c37..c1ffdea 100644
--- a/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java
+++ b/src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java
@@ -18,6 +18,7 @@ public class ClientListStoresOptions implements AdditionalHeadersSupplier {
private Map<String, String> additionalHeaders;
private Integer pageSize;
private String continuationToken;
+ private String name;
public ClientListStoresOptions additionalHeaders(Map<String, String> additionalHeaders) {
this.additionalHeaders = additionalHeaders;
@@ -46,4 +47,13 @@ public class ClientListStoresOptions implements AdditionalHeadersSupplier {
public String getContinuationToken() {
return continuationToken;
}
+
+ public ClientListStoresOptions name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
}
diff --git a/src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java b/src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java
index 6182a5f..c8f1a76 100644
--- a/src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java
+++ b/src/test-integration/java/dev/openfga/sdk/api/OpenFgaApiIntegrationTest.java
@@ -124,6 +124,30 @@ public class OpenFgaApiIntegrationTest {
}
}
+ @Test
+ public void listStoresWithNameFilter() throws Exception {
+ // Given
+ String testName = thisTestName();
+ String targetStore = testName + "-target-store";
+ String otherStore1 = testName + "-other-store-1";
+ String otherStore2 = testName + "-other-store-2";
+
+ // Create multiple stores
+ createStore(targetStore);
+ createStore(otherStore1);
+ createStore(otherStore2);
+
+ // When - Filter by name
+ ListStoresResponse response =
+ api.listStores(100, null, targetStore).get().getData();
+
+ // Then - Should only return the target store
+ List<String> storeNames =
+ response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList());
+ assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response");
+ assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name");
+ }
+
@Test
public void readAuthModel() throws Exception {
// Given
diff --git a/src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java b/src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java
index 76e93b1..ec177cc 100644
--- a/src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java
+++ b/src/test-integration/java/dev/openfga/sdk/api/client/OpenFgaClientIntegrationTest.java
@@ -141,6 +141,32 @@ public class OpenFgaClientIntegrationTest {
}
}
+ @Test
+ public void listStoresWithNameFilter() throws Exception {
+ // Given
+ String testName = thisTestName();
+ String targetStore = testName + "-target-store";
+ String otherStore1 = testName + "-other-store-1";
+ String otherStore2 = testName + "-other-store-2";
+
+ // Create multiple stores
+ createStore(targetStore);
+ createStore(otherStore1);
+ createStore(otherStore2);
+
+ ClientListStoresOptions options = new ClientListStoresOptions().name(targetStore);
+
+ // When - Filter by name using client options
+ ClientListStoresResponse response = fga.listStores(options).get();
+
+ // Then - Should only return the target store
+ assertNotNull(response.getStores());
+ List<String> storeNames =
+ response.getStores().stream().map(Store::getName).collect(java.util.stream.Collectors.toList());
+ assertTrue(storeNames.contains(targetStore), "Target store should be in the filtered response");
+ assertEquals(1, storeNames.size(), "Should return only one store when filtering by exact name");
+ }
+
@Test
public void readAuthModel() throws Exception {
// Given
diff --git a/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java b/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
index f111ac0..1f4991c 100644
--- a/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
+++ b/src/test/java/dev/openfga/sdk/api/client/OpenFgaClientTest.java
@@ -294,6 +294,55 @@ public class OpenFgaClientTest {
assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName());
}
+ @Test
+ public void listStoresTest_withNameFilter() throws Exception {
+ // Given
+ String responseBody =
+ String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
+ String storeName = "test-store";
+ String getUrl = String.format("https://api.fga.example/stores?name=%s", storeName);
+ mockHttpClient.onGet(getUrl).doReturn(200, responseBody);
+ ClientListStoresOptions options = new ClientListStoresOptions().name(storeName);
+
+ // When
+ ClientListStoresResponse response = fga.listStores(options).get();
+
+ // Then
+ mockHttpClient.verify().get(getUrl).called(1);
+ assertNotNull(response.getStores());
+ assertEquals(1, response.getStores().size());
+ assertEquals(DEFAULT_STORE_ID, response.getStores().get(0).getId());
+ assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName());
+ }
+
+ @Test
+ public void listStoresTest_withAllParameters() throws Exception {
+ // Given
+ String responseBody =
+ String.format("{\"stores\":[{\"id\":\"%s\",\"name\":\"%s\"}]}", DEFAULT_STORE_ID, DEFAULT_STORE_NAME);
+ int pageSize = 10;
+ String continuationToken = "continuationToken";
+ String storeName = "test-store";
+ String getUrl = String.format(
+ "https://api.fga.example/stores?page_size=%d&continuation_token=%s&name=%s",
+ pageSize, continuationToken, storeName);
+ mockHttpClient.onGet(getUrl).doReturn(200, responseBody);
+ ClientListStoresOptions options = new ClientListStoresOptions()
+ .pageSize(pageSize)
+ .continuationToken(continuationToken)
+ .name(storeName);
+
+ // When
+ ClientListStoresResponse response = fga.listStores(options).get();
+
+ // Then
+ mockHttpClient.verify().get(getUrl).called(1);
+ assertNotNull(response.getStores());
+ assertEquals(1, response.getStores().size());
+ assertEquals(DEFAULT_STORE_ID, response.getStores().get(0).getId());
+ assertEquals(DEFAULT_STORE_NAME, response.getStores().get(0).getName());
+ }
+
/**
* Create a store.
*/