Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<argLine>
<!--
Gson (used for JSON serialization) utilizes reflection and needs to be able to access private fields of
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/weaviate/client/WeaviateClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.weaviate.client.v1.contextionary.Contextionary;
import io.weaviate.client.v1.data.Data;
import io.weaviate.client.v1.graphql.GraphQL;
import io.weaviate.client.v1.groups.Groups;
import io.weaviate.client.v1.grpc.GRPC;
import io.weaviate.client.v1.misc.Misc;
import io.weaviate.client.v1.misc.api.MetaGetter;
Expand Down Expand Up @@ -112,6 +113,10 @@ public Users users() {
return new Users(httpClient, config);
}

public Groups groups() {
return new Groups(httpClient, config);
}

public Aliases alias() {
return new Aliases(httpClient, config);
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/io/weaviate/client/base/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ public Result<R> parse(HttpResponse response, String body, ContentType contentTy
* }</pre>
*/
public static <T> Result<List<T>> toList(Response<T[]> response) {
return new Result<>(response, Arrays.asList(response.getBody()));
return toList(response, Function.identity());
}

public static <T, R> Result<List<R>> toList(Response<T[]> response, Function<? super T, ? extends R> mapper) {
List<R> mapped = Optional.ofNullable(response.getBody())
.map(Arrays::asList).orElse(new ArrayList<>())
.stream().map(mapper).collect(Collectors.toList());
return new Result<>(response, mapped);
}

/**
Expand Down Expand Up @@ -243,10 +250,10 @@ public static <T, R> ResponseParser<List<R>> arrayToListParser(Class<T[]> cls,
@Override
public Result<List<R>> parse(HttpResponse response, String body, ContentType contentType) {
Response<T[]> resp = this.serializer.toResponse(response.getCode(), body, cls);
List<R> roles = Optional.ofNullable(resp.getBody())
List<R> mapped = Optional.ofNullable(resp.getBody())
.map(Arrays::asList).orElse(new ArrayList<>())
.stream().map(mapper).collect(Collectors.toList());
return new Result<>(resp.getStatusCode(), roles, resp.getErrors());
return new Result<>(resp.getStatusCode(), mapped, resp.getErrors());
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.weaviate.client.v1.async.cluster.Cluster;
import io.weaviate.client.v1.async.data.Data;
import io.weaviate.client.v1.async.graphql.GraphQL;
import io.weaviate.client.v1.async.groups.Groups;
import io.weaviate.client.v1.async.misc.Misc;
import io.weaviate.client.v1.async.rbac.Roles;
import io.weaviate.client.v1.async.schema.Schema;
Expand Down Expand Up @@ -85,6 +86,10 @@ public Users users() {
return new Users(client, config, tokenProvider);
}

public Groups groups() {
return new Groups(client, config, tokenProvider);
}

public Aliases alias() {
return new Aliases(client, config, tokenProvider);
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/weaviate/client/v1/async/groups/Groups.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.weaviate.client.v1.async.groups;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;

import io.weaviate.client.Config;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class Groups {
private final CloseableHttpAsyncClient client;
private final Config config;
private final AccessTokenProvider tokenProvider;

public OidcGroups oidc() {
return new OidcGroups(client, config, tokenProvider);
}
}
34 changes: 34 additions & 0 deletions src/main/java/io/weaviate/client/v1/async/groups/OidcGroups.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.weaviate.client.v1.async.groups;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;

import io.weaviate.client.Config;
import io.weaviate.client.v1.async.groups.api.oidc.AssignedRolesGetter;
import io.weaviate.client.v1.async.groups.api.oidc.KnownGroupNamesGetter;
import io.weaviate.client.v1.async.groups.api.oidc.RoleAssigner;
import io.weaviate.client.v1.async.groups.api.oidc.RoleRevoker;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class OidcGroups {
private final CloseableHttpAsyncClient client;
private final Config config;
private final AccessTokenProvider tokenProvider;

public RoleAssigner roleAssigner() {
return new RoleAssigner(client, config, tokenProvider);
}

public RoleRevoker roleRevoker() {
return new RoleRevoker(client, config, tokenProvider);
}

public AssignedRolesGetter assignedRolesGetter() {
return new AssignedRolesGetter(client, config, tokenProvider);
}

public KnownGroupNamesGetter knownGroupNamesGetter() {
return new KnownGroupNamesGetter(client, config, tokenProvider);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.weaviate.client.v1.async.groups.api.oidc;

import java.util.List;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.base.util.UrlEncoder;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import io.weaviate.client.v1.rbac.api.WeaviateRole;
import io.weaviate.client.v1.rbac.model.Role;

public class AssignedRolesGetter extends AsyncBaseClient<List<Role>> implements AsyncClientResult<List<Role>> {
private String groupId;
private boolean includePermissions = false;

public AssignedRolesGetter(CloseableHttpAsyncClient httpClient, Config config, AccessTokenProvider tokenProvider) {
super(httpClient, config, tokenProvider);
}

public AssignedRolesGetter withGroupId(String id) {
this.groupId = id;
return this;
}

public AssignedRolesGetter includePermissions(boolean include) {
this.includePermissions = include;
return this;
}

private String _groupId() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change the name just getGroupId or groupId having an _ in method naming feels like Python / Rust code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed in all files

return UrlEncoder.encode(this.groupId);
}

@Override
public Future<Result<List<Role>>> run(FutureCallback<Result<List<Role>>> callback) {
return sendGetRequest(path(), callback, Result.arrayToListParser(WeaviateRole[].class, WeaviateRole::toRole));
}

private String path() {
return String.format("/authz/groups/%s/roles/oidc?includeFullRoles=%s", _groupId(), includePermissions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.weaviate.client.v1.async.groups.api.oidc;

import java.util.List;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.aliases.model.Alias;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;

public class KnownGroupNamesGetter extends AsyncBaseClient<List<String>> implements AsyncClientResult<List<String>> {

public KnownGroupNamesGetter(CloseableHttpAsyncClient httpClient, Config config, AccessTokenProvider tokenProvider) {
super(httpClient, config, tokenProvider);
}

static class ResponseBody {
List<Alias> aliases;
}

@Override
public Future<Result<List<String>>> run(FutureCallback<Result<List<String>>> callback) {
return sendGetRequest("/authz/groups/oidc", callback, Result.arrayToListParser(String[].class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.weaviate.client.v1.async.groups.api.oidc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import com.google.gson.annotations.SerializedName;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.base.util.UrlEncoder;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import lombok.AllArgsConstructor;

public class RoleAssigner extends AsyncBaseClient<Boolean> implements AsyncClientResult<Boolean> {
private String groupId;
private List<String> roles = new ArrayList<>();

public RoleAssigner(CloseableHttpAsyncClient httpClient, Config config, AccessTokenProvider tokenProvider) {
super(httpClient, config, tokenProvider);
}

public RoleAssigner withGroupId(String id) {
this.groupId = id;
return this;
}

public RoleAssigner witRoles(String... roles) {
this.roles = Arrays.asList(roles);
return this;
}

private String _groupId() {
return UrlEncoder.encode(this.groupId);
}

/** The API signature for this method is { "roles": [...] } */
@AllArgsConstructor
private class Body {
@SerializedName("roles")
final List<String> roles;
@SerializedName("groupType")
final String groupType = "oidc";
}

@Override
public Future<Result<Boolean>> run(FutureCallback<Result<Boolean>> callback) {
return sendPostRequest(path(), new Body(this.roles), callback,
Result.voidToBooleanParser());
}

private String path() {
return String.format("/authz/groups/%s/assign", _groupId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.weaviate.client.v1.async.groups.api.oidc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.core5.concurrent.FutureCallback;

import com.google.gson.annotations.SerializedName;

import io.weaviate.client.Config;
import io.weaviate.client.base.AsyncBaseClient;
import io.weaviate.client.base.AsyncClientResult;
import io.weaviate.client.base.Result;
import io.weaviate.client.base.util.UrlEncoder;
import io.weaviate.client.v1.auth.provider.AccessTokenProvider;
import lombok.AllArgsConstructor;

public class RoleRevoker extends AsyncBaseClient<Boolean> implements AsyncClientResult<Boolean> {
private String groupId;
private List<String> roles = new ArrayList<>();

public RoleRevoker(CloseableHttpAsyncClient httpClient, Config config, AccessTokenProvider tokenProvider) {
super(httpClient, config, tokenProvider);
}

public RoleRevoker withGroupId(String id) {
this.groupId = id;
return this;
}

public RoleRevoker witRoles(String... roles) {
this.roles = Arrays.asList(roles);
return this;
}

private String _groupId() {
return UrlEncoder.encode(this.groupId);
}

/** The API signature for this method is { "roles": [...] } */
@AllArgsConstructor
private class Body {
@SerializedName("roles")
final List<String> roles;
@SerializedName("groupType")
final String groupType = "oidc";
}

@Override
public Future<Result<Boolean>> run(FutureCallback<Result<Boolean>> callback) {
return sendPostRequest(path(), new Body(this.roles), callback,
Result.voidToBooleanParser());
}

private String path() {
return String.format("/authz/groups/%s/revoke", _groupId());
}
}
11 changes: 8 additions & 3 deletions src/main/java/io/weaviate/client/v1/async/rbac/Roles.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import io.weaviate.client.Config;
import io.weaviate.client.v1.async.rbac.api.AssignedUsersGetter;
import io.weaviate.client.v1.async.rbac.api.GroupAssignmentsGetter;
import io.weaviate.client.v1.async.rbac.api.PermissionAdder;
import io.weaviate.client.v1.async.rbac.api.PermissionChecker;
import io.weaviate.client.v1.async.rbac.api.PermissionRemover;
Expand Down Expand Up @@ -64,7 +65,7 @@ public RoleAllGetter allGetter() {
/** Get role and its assiciated permissions. */
public RoleGetter getter() {
return new RoleGetter(client, config, tokenProvider);
};
}

/**
* Get users assigned to a role.
Expand All @@ -74,7 +75,7 @@ public RoleGetter getter() {
@Deprecated
public AssignedUsersGetter assignedUsersGetter() {
return new AssignedUsersGetter(client, config, tokenProvider);
};
}

/**
* Get role assignments.
Expand All @@ -89,7 +90,11 @@ public AssignedUsersGetter assignedUsersGetter() {
*/
public UserAssignmentsGetter userAssignmentsGetter() {
return new UserAssignmentsGetter(client, config, tokenProvider);
};
}

public GroupAssignmentsGetter groupAssignmentsGetter() {
return new GroupAssignmentsGetter(client, config, tokenProvider);
}

/** Check if a role exists. */
public RoleExists exists() {
Expand Down
Loading