use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.
the class CoreAnalyticsLinkManager method sendLink.
private CompletableFuture<Void> sendLink(HttpMethod method, Map<String, String> link, CoreCommonOptions options, String tracingId) {
// ensure mutability, and don't modify caller's map
link = new HashMap<>(link);
CoreHttpPath path = getLinkPathAndAdjustMap(link);
UrlQueryStringBuilder form = newForm();
link.forEach(form::set);
return httpClient.newRequest(method, path, options).trace(tracingId).form(form).exec(core).exceptionally(t -> {
throw translateCompilationFailureToInvalidArgument(t);
}).thenApply(result -> null);
}
use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.
the class CoreBucketManager method convertSettingsToParams.
private UrlQueryStringBuilder convertSettingsToParams(Map<String, String> settings, boolean update) {
Map<String, String> params = new HashMap<>(settings);
// The following values must not be changed on update
if (update) {
params.remove("name");
params.remove("bucketType");
params.remove("conflictResolutionType");
params.remove("replicaIndex");
params.remove("storageBackend");
}
UrlQueryStringBuilder form = UrlQueryStringBuilder.createForUrlSafeNames();
params.forEach(form::set);
return form;
}
use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.
the class AsyncUserManager method upsertUser.
public CompletableFuture<Void> upsertUser(User user, UpsertUserOptions options) {
String username = user.username();
UrlQueryStringBuilder params = newForm().add("name", user.displayName()).add("roles", user.roles().stream().map(Role::format).collect(Collectors.joining(",")));
// Versions >= 6.5 treat the absent parameter just like an empty list.
if (!user.groups().isEmpty()) {
params.add("groups", String.join(",", user.groups()));
}
// Password is required when creating user, but optional when updating existing user.
user.password().ifPresent(pwd -> params.add("password", pwd));
return httpClient.put(pathForUser(AuthDomain.LOCAL, username), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MU_UPSERT_USER).form(params).exec(core).thenApply(response -> null);
}
use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method createLimitedScope.
static void createLimitedScope(String name, String bucket, ScopeRateLimits limits) throws Exception {
Map<String, Object> jsonLimits = new HashMap<>();
if (limits.kv != null) {
jsonLimits.put("kv", mapOf("data_size", limits.kv.dataSize));
}
if (limits.fts != null) {
jsonLimits.put("fts", mapOf("num_fts_indexes", limits.fts.numFtsIndexes));
}
if (limits.index != null) {
jsonLimits.put("index", mapOf("num_indexes", limits.index.numIndexes));
}
if (limits.clusterManager != null) {
jsonLimits.put("clusterManager", mapOf("num_collections", limits.clusterManager.numCollections));
}
UrlQueryStringBuilder formParams = UrlQueryStringBuilder.create();
formParams.add("name", name);
if (!jsonLimits.isEmpty()) {
formParams.add("limits", Mapper.encodeAsString(jsonLimits));
}
CoreHttpClient client = adminCluster.core().httpClient(RequestTarget.manager());
CoreHttpResponse result = client.post(path("/pools/default/buckets/" + bucket + "/scopes"), CoreCommonOptions.DEFAULT).form(formParams).exec(adminCluster.core()).get();
assertEquals(ResponseStatus.SUCCESS, result.status());
}
use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method createRateLimitedUser.
/**
* Creates a user which is rate limited to perform the tests.
*/
static void createRateLimitedUser(String username, Limits limits) throws Exception {
Map<String, Object> jsonLimits = new HashMap<>();
if (limits.keyValueLimits != null) {
KeyValueLimits kv = limits.keyValueLimits;
jsonLimits.put("kv", CbCollections.mapOf("num_connections", kv.numConnections, "num_ops_per_min", kv.numOpsPerMin, "ingress_mib_per_min", kv.ingressMibPerMin, "egress_mib_per_min", kv.egressMibPerMin));
}
if (limits.queryLimits != null) {
QueryLimits query = limits.queryLimits;
jsonLimits.put("query", mapOf("num_queries_per_min", query.numQueriesPerMin, "num_concurrent_requests", query.numConcurrentRequests, "ingress_mib_per_min", query.ingressMibPerMin, "egress_mib_per_min", query.egressMibPerMin));
}
if (limits.searchLimits != null) {
SearchLimits fts = limits.searchLimits;
jsonLimits.put("fts", mapOf("num_queries_per_min", fts.numQueriesPerMin, "num_concurrent_requests", fts.numConcurrentRequests, "ingress_mib_per_min", fts.ingressMibPerMin, "egress_mib_per_min", fts.egressMibPerMin));
}
if (limits.clusterManagerLimits != null) {
ClusterManagerLimits cm = limits.clusterManagerLimits;
jsonLimits.put("clusterManager", mapOf("num_concurrent_requests", cm.numConcurrentRequests, "ingress_mib_per_min", cm.ingressMibPerMin, "egress_mib_per_min", cm.egressMibPerMin));
}
UrlQueryStringBuilder formParams = UrlQueryStringBuilder.create();
formParams.add("password", RL_PASSWORD);
formParams.add("roles", "admin");
if (!jsonLimits.isEmpty()) {
formParams.add("limits", Mapper.encodeAsString(jsonLimits));
}
CoreHttpClient client = adminCluster.core().httpClient(RequestTarget.manager());
CoreHttpResponse result = client.put(path("/settings/rbac/users/local/" + username), CoreCommonOptions.DEFAULT).form(formParams).exec(adminCluster.core()).get();
assertEquals(ResponseStatus.SUCCESS, result.status());
}
Aggregations