Search in sources :

Example 1 with HugeTarget

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Status(com.baidu.hugegraph.api.filter.StatusFilter.Status) POST(jakarta.ws.rs.POST) Consumes(jakarta.ws.rs.Consumes) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with HugeTarget

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);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 3 with HugeTarget

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;
}
Also used : HugeTarget(com.baidu.hugegraph.auth.HugeTarget)

Example 4 with HugeTarget

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Example 5 with HugeTarget

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) AuthManager(com.baidu.hugegraph.auth.AuthManager) HashMap(java.util.HashMap) Id(com.baidu.hugegraph.backend.id.Id) HugeTarget(com.baidu.hugegraph.auth.HugeTarget) Test(org.junit.Test)

Aggregations

HugeTarget (com.baidu.hugegraph.auth.HugeTarget)15 HugeGraph (com.baidu.hugegraph.HugeGraph)12 AuthManager (com.baidu.hugegraph.auth.AuthManager)8 Test (org.junit.Test)8 Id (com.baidu.hugegraph.backend.id.Id)6 Timed (com.codahale.metrics.annotation.Timed)4 Produces (jakarta.ws.rs.Produces)4 HugeUser (com.baidu.hugegraph.auth.HugeUser)2 Consumes (jakarta.ws.rs.Consumes)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Status (com.baidu.hugegraph.api.filter.StatusFilter.Status)1 HugeGroup (com.baidu.hugegraph.auth.HugeGroup)1 HugeProject (com.baidu.hugegraph.auth.HugeProject)1 HugeResource (com.baidu.hugegraph.auth.HugeResource)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1 POST (jakarta.ws.rs.POST)1 PUT (jakarta.ws.rs.PUT)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1