diff --git a/src/main/java/dev/warrant/WarrantBaseClient.java b/src/main/java/dev/warrant/WarrantBaseClient.java index a5258e5..bfa3df5 100644 --- a/src/main/java/dev/warrant/WarrantBaseClient.java +++ b/src/main/java/dev/warrant/WarrantBaseClient.java @@ -64,12 +64,8 @@ public Warrant createWarrant(WarrantObject object, String relation, WarrantSubje public Warrant createWarrant(WarrantObject object, String relation, WarrantSubject subject, String policy, RequestOptions requestOptions) throws WarrantException { - try { Warrant toCreate = new Warrant(object.type(), object.id(), relation, subject, policy); return makePostRequest("/v1/warrants", toCreate, Warrant.class, requestOptions.asMap()); - } catch (WarrantException e) { - throw e; - } } public void deleteWarrant(WarrantObject object, String relation, WarrantSubject subject) throws WarrantException { @@ -85,12 +81,8 @@ public void deleteWarrant(WarrantObject object, String relation, WarrantSubject } public void deleteWarrant(WarrantObject object, String relation, WarrantSubject subject, String policy, RequestOptions requestOptions) throws WarrantException { - try { Warrant toDelete = new Warrant(object.type(), object.id(), relation, subject, policy); makeDeleteRequest("/v1/warrants", toDelete, requestOptions.asMap()); - } catch (WarrantException e) { - throw e; - } } public Warrant[] listWarrants(WarrantFilters filters, ListParams listParams) throws WarrantException { @@ -151,6 +143,68 @@ public WarrantCheck checkAllOf(List warrants, RequestOptions reques return checkWithOp(warrants, "allOf", WarrantCheck.class, new RequestOptions()); } + // public BaseWarrantObject createObject(String objectType) throws WarrantException { + // return createObject(objectType, null, Collections.emptyMap(), BaseWarrantObject.class); + // } + + // public T createObject(String objectType, Class resultType) throws WarrantException { + // return createObject(objectType, null, Collections.emptyMap(), resultType); + // } + + // public T createObject(String objectType, Class resultType, RequestOptions requestOptions) throws WarrantException { + // return createObject(objectType, null, Collections.emptyMap(), resultType); + // } + + // public BaseWarrantObject createObject(String objectType, Map meta) throws WarrantException { + // return createObject(objectType, null, meta, BaseWarrantObject.class); + // } + + // public T createObject(String objectType, Map meta, Class resultType) throws WarrantException { + // return createObject(objectType, null, meta, resultType); + // } + + // public BaseWarrantObject createObject(String objectType, String objectId) throws WarrantException { + // return createObject(objectType, objectId, Collections.emptyMap(), BaseWarrantObject.class); + // } + + // public T createObject(String objectType, String objectId, Class resultType) throws WarrantException { + // return createObject(objectType, objectId, Collections.emptyMap(), resultType); + // } + + // public BaseWarrantObject createObject(String objectType, String objectId, Map meta) throws WarrantException { + // return createObject(objectType, objectId, meta, BaseWarrantObject.class); + // } + + // public T createObject(String objectType, String objectId, Map meta, Class resultType) throws WarrantException { + // return createObject(objectType, objectId, meta, resultType, new RequestOptions()); + // } + + // public T createObject(String objectType, String objectId, Map meta, Class resultType, RequestOptions requestOptions) throws WarrantException { + // BaseWarrantObject obj = new BaseWarrantObject(objectType, objectId, meta); + // return makePostRequest("/v1/objects", obj, resultType, requestOptions.asMap()); + // } + + // public BaseWarrantObject getObject(String objectType, String objectId) throws WarrantException { + // return getObject(objectType, objectId, BaseWarrantObject.class); + // } + + // public T getObject(String objectType, String objectId, Class resultType) throws WarrantException { + // return makeGetRequest("/v1/objects/" + objectType + "/" + objectId, resultType); + // } + + // public BaseWarrantObject updateObject(String objectType, String objectId, Map meta) throws WarrantException { + // BaseWarrantObject obj = new BaseWarrantObject(objectType, objectId, meta); + // return makePutRequest("/v1/objects/" + objectType + "/" + objectId, obj, BaseWarrantObject.class); + // } + + public void deleteObject(WarrantObject obj) throws WarrantException { + deleteObject(obj.type(), obj.id()); + } + + public void deleteObject(String objectType, String objectId) throws WarrantException { + makeDeleteRequest("/v1/objects/" + objectType + "/" + objectId); + } + public String createUserAuthzSession(String userId) throws WarrantException { return createUserAuthzSession(userId, new RequestOptions()); } @@ -175,11 +229,7 @@ public String createUserSelfServiceDashboardUrl(String userId, String tenantId, } WarrantCheck makeCheckRequest(WarrantCheckSpec toCheck) throws WarrantException { - try { - return makeCheckRequest(toCheck, Collections.emptyMap()); - } catch (WarrantException e) { - throw e; - } + return makeCheckRequest(toCheck, Collections.emptyMap()); } WarrantCheck makeCheckRequest(WarrantCheckSpec toCheck, Map requestOptions) throws WarrantException { @@ -330,11 +380,7 @@ T makePutRequest(String uri, Object reqPayload, Class type, Map makePutRequest(String uri, Object reqPayload) throws WarrantException { - try { - return makePutRequest(uri, reqPayload, Collections.emptyMap()); - } catch (WarrantException e) { - throw e; - } + return makePutRequest(uri, reqPayload, Collections.emptyMap()); } private HttpResponse makePutRequest(String uri, Object reqPayload, Map requestOptions) throws WarrantException { @@ -366,27 +412,15 @@ private HttpResponse makePutRequest(String uri, Object reqPayload, Map makeDeleteRequest(String uri) throws WarrantException { - try { - return makeDeleteRequest(uri, null, Collections.emptyMap()); - } catch (WarrantException e) { - throw e; - } + return makeDeleteRequest(uri, null, Collections.emptyMap()); } HttpResponse makeDeleteRequest(String uri, Object reqPayload) throws WarrantException { - try { - return makeDeleteRequest(uri, reqPayload, Collections.emptyMap()); - } catch (WarrantException e) { - throw e; - } + return makeDeleteRequest(uri, reqPayload, Collections.emptyMap()); } HttpResponse makeDeleteRequest(String uri, Map requestOptions) throws WarrantException { - try { - return makeDeleteRequest(uri, null, requestOptions); - } catch (WarrantException e) { - throw e; - } + return makeDeleteRequest(uri, null, requestOptions); } HttpResponse makeDeleteRequest(String uri, Object reqPayload, Map requestOptions) throws WarrantException { @@ -459,11 +493,7 @@ T makeGetRequest(String uri, Map queryParams, Class type, } private HttpResponse makeGetRequest(String uri, Map queryParams) throws WarrantException { - try { - return makeGetRequest(uri, queryParams, Collections.emptyMap()); - } catch (WarrantException e) { - throw e; - } + return makeGetRequest(uri, queryParams, Collections.emptyMap()); } private HttpResponse makeGetRequest(String uri, Map queryParams, Map requestOptions) throws WarrantException { diff --git a/src/main/java/dev/warrant/model/object/Feature.java b/src/main/java/dev/warrant/model/object/Feature.java index a5b2b0d..0a9ccfa 100644 --- a/src/main/java/dev/warrant/model/object/Feature.java +++ b/src/main/java/dev/warrant/model/object/Feature.java @@ -30,4 +30,9 @@ public String id() { public String type() { return "feature"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/Permission.java b/src/main/java/dev/warrant/model/object/Permission.java index c353d63..dbcfe05 100644 --- a/src/main/java/dev/warrant/model/object/Permission.java +++ b/src/main/java/dev/warrant/model/object/Permission.java @@ -54,4 +54,9 @@ public String id() { public String type() { return "permission"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/PricingTier.java b/src/main/java/dev/warrant/model/object/PricingTier.java index b3a951d..141dff2 100644 --- a/src/main/java/dev/warrant/model/object/PricingTier.java +++ b/src/main/java/dev/warrant/model/object/PricingTier.java @@ -30,4 +30,9 @@ public String id() { public String type() { return "pricing-tier"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/Role.java b/src/main/java/dev/warrant/model/object/Role.java index 3162814..8c6e451 100644 --- a/src/main/java/dev/warrant/model/object/Role.java +++ b/src/main/java/dev/warrant/model/object/Role.java @@ -59,4 +59,9 @@ public String id() { public String type() { return "role"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/Tenant.java b/src/main/java/dev/warrant/model/object/Tenant.java index 6e9e4ca..f35db8f 100644 --- a/src/main/java/dev/warrant/model/object/Tenant.java +++ b/src/main/java/dev/warrant/model/object/Tenant.java @@ -44,4 +44,9 @@ public String id() { public String type() { return "tenant"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/User.java b/src/main/java/dev/warrant/model/object/User.java index 67531e8..a341c97 100644 --- a/src/main/java/dev/warrant/model/object/User.java +++ b/src/main/java/dev/warrant/model/object/User.java @@ -44,4 +44,9 @@ public String id() { public String type() { return "user"; } + + // @Override + // public Map meta() { + // return null; + // } } diff --git a/src/main/java/dev/warrant/model/object/WarrantObject.java b/src/main/java/dev/warrant/model/object/WarrantObject.java index b7f4b07..c401acd 100644 --- a/src/main/java/dev/warrant/model/object/WarrantObject.java +++ b/src/main/java/dev/warrant/model/object/WarrantObject.java @@ -4,4 +4,6 @@ public interface WarrantObject { public String id(); public String type(); + + // public Map meta(); } diff --git a/src/test/java/dev/warrant/LiveTest.java b/src/test/java/dev/warrant/LiveTest.java index a169d26..df67229 100644 --- a/src/test/java/dev/warrant/LiveTest.java +++ b/src/test/java/dev/warrant/LiveTest.java @@ -184,6 +184,42 @@ public void crudPricingTiers() throws WarrantException { Assertions.assertEquals(0, tiers.length); } + @Test + public void crudObjects() throws WarrantException { + // BaseWarrantObject roleGeneratedId = client.createObject("role"); + // Assertions.assertEquals("role", roleGeneratedId.getObjectType()); + // Assertions.assertNotNull(roleGeneratedId.getObjectId()); + // Assertions.assertNull(roleGeneratedId.getMeta()); + + // Map meta = new HashMap<>(); + // meta.put("name", "admin role"); + // BaseWarrantObject roleWithMeta = client.createObject("role", "admin", meta); + // Assertions.assertEquals("role", roleWithMeta.getObjectType()); + // Assertions.assertEquals("admin", roleWithMeta.getObjectId()); + // Assertions.assertNotNull(roleWithMeta.getMeta()); + // Assertions.assertEquals("admin role", roleWithMeta.getMeta().get("name")); + + // Map updatedMeta = new HashMap<>(); + // updatedMeta.put("name", "admin role"); + // updatedMeta.put("description", "role description"); + // BaseWarrantObject updatedRole = client.updateObject(roleWithMeta.getObjectType(), roleWithMeta.getObjectId(), updatedMeta); + // Assertions.assertEquals(roleWithMeta.getObjectType(), updatedRole.getObjectType()); + // Assertions.assertEquals(roleWithMeta.getObjectId(), updatedRole.getObjectId()); + // Assertions.assertEquals(2, updatedRole.getMeta().size()); + // Assertions.assertEquals("admin role", updatedRole.getMeta().get("name")); + // Assertions.assertEquals("role description", updatedRole.getMeta().get("description")); + + // BaseWarrantObject fetchedObj = client.getObject(roleGeneratedId.getObjectType(), roleGeneratedId.getObjectId()); + // Assertions.assertEquals(roleGeneratedId.getObjectType(), fetchedObj.getObjectType()); + // Assertions.assertEquals(roleGeneratedId.getObjectId(), fetchedObj.getObjectId()); + // Assertions.assertEquals(roleGeneratedId.getMeta(), fetchedObj.getMeta()); + + User user = client.createUser(new User("object_test_1", "email@email.com")); + Assertions.assertEquals("object_test_1", user.getUserId()); + Assertions.assertEquals("email@email.com", user.getEmail()); + client.deleteObject(user); + } + @Test public void batchCreateUsersAndTenants() throws WarrantException { User[] newUsers = { new User("user-1"), new User("user-2") };