use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class TargetAPI method create.
@POST
@Timed
@Status(Status.CREATED)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String create(@Context GraphManager manager, @PathParam("graph") String graph, JsonTarget jsonTarget) {
LOG.debug("Graph [{}] create target: {}", graph, jsonTarget);
checkCreatingBody(jsonTarget);
HugeGraph g = graph(manager, graph);
HugeTarget target = jsonTarget.build();
target.id(manager.authManager().createTarget(target));
return manager.serializer(g).writeAuthElement(target);
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class TargetAPI method list.
@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String list(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("limit") @DefaultValue("100") long limit) {
LOG.debug("Graph [{}] list targets", graph);
HugeGraph g = graph(manager, graph);
List<HugeTarget> targets = manager.authManager().listAllTargets(limit);
return manager.serializer(g).writeAuthElements("targets", targets);
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method makeTarget.
private static HugeTarget makeTarget(String name, String url) {
HugeTarget target = new HugeTarget(name, url);
target.creator("admin");
return target;
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method testListTargets.
@Test
public void testListTargets() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createTarget(makeTarget("target1", "url1"));
Id id2 = authManager.createTarget(makeTarget("target2", "url2"));
List<HugeTarget> targets = authManager.listTargets(ImmutableList.of(id1, id2));
Assert.assertEquals(2, targets.size());
Assert.assertEquals("target1", targets.get(0).name());
Assert.assertEquals("target2", targets.get(1).name());
targets = authManager.listTargets(ImmutableList.of(id1, id2, id2));
Assert.assertEquals(3, targets.size());
Assert.assertEquals("target1", targets.get(0).name());
Assert.assertEquals("target2", targets.get(1).name());
Assert.assertEquals("target2", targets.get(2).name());
targets = authManager.listTargets(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
Assert.assertEquals(2, targets.size());
}
use of com.baidu.hugegraph.auth.HugeTarget in project incubator-hugegraph by apache.
the class AuthTest method testCreateTarget.
@Test
public void testCreateTarget() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
HugeTarget target = makeTarget("graph1", "127.0.0.1:8080");
target.creator("admin");
Id id = authManager.createTarget(target);
target = authManager.getTarget(id);
Assert.assertEquals("graph1", target.name());
Assert.assertEquals("127.0.0.1:8080", target.url());
Assert.assertEquals(target.create(), target.update());
HashMap<String, Object> expected = new HashMap<>();
expected.putAll(ImmutableMap.of("target_name", "graph1", "target_graph", "graph1", "target_url", "127.0.0.1:8080", "target_creator", "admin"));
expected.putAll(ImmutableMap.of("target_create", target.create(), "target_update", target.update(), "id", target.id()));
Assert.assertEquals(expected, target.asMap());
}
Aggregations