This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit e42f0961f21712e57026ed50ecd7e71d1b8c2198
Author: Madhan Neethiraj <[email protected]>
AuthorDate: Mon Feb 20 00:12:56 2023 -0800

    RANGER-4101: Java client updated with addition of 2 security-zone APIs
---
 .../main/java/org/apache/ranger/RangerClient.java  | 31 +++++++++++++---------
 .../java/org/apache/ranger/TestRangerClient.java   | 26 ++++++++++++++++++
 2 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/intg/src/main/java/org/apache/ranger/RangerClient.java 
b/intg/src/main/java/org/apache/ranger/RangerClient.java
index ff281112f..92149c9e0 100644
--- a/intg/src/main/java/org/apache/ranger/RangerClient.java
+++ b/intg/src/main/java/org/apache/ranger/RangerClient.java
@@ -80,6 +80,8 @@ public class RangerClient {
     private static final String URI_ZONE                  = URI_BASE + 
"/zones";
     private static final String URI_ZONE_BY_ID            = URI_ZONE + "/%d";
     private static final String URI_ZONE_BY_NAME          = URI_ZONE + 
"/name/%s";
+    private static final String URI_ZONE_HEADERS          = URI_BASE + 
"/zone-headers";
+    private static final String URI_ZONE_SERVICE_HEADERS  = URI_ZONE + 
"/%d/service-headers";
 
     private static final String URI_SERVICE_TAGS          = URI_SERVICE + 
"/%s/tags";
     private static final String URI_PLUGIN_INFO           = URI_BASE + 
"/plugins/info";
@@ -116,14 +118,15 @@ public class RangerClient {
     public static final API GET_POLICIES_IN_SERVICE  = new 
API(URI_POLICIES_IN_SERVICE, HttpMethod.GET, Response.Status.OK);
     public static final API FIND_POLICIES            = new API(URI_POLICY, 
HttpMethod.GET, Response.Status.OK);
 
-    public static final API CREATE_ZONE         = new API(URI_ZONE, 
HttpMethod.POST, Response.Status.OK);
-    public static final API UPDATE_ZONE_BY_ID   = new API(URI_ZONE_BY_ID, 
HttpMethod.PUT, Response.Status.OK);
-    public static final API UPDATE_ZONE_BY_NAME = new API(URI_ZONE_BY_NAME, 
HttpMethod.PUT, Response.Status.OK);
-    public static final API DELETE_ZONE_BY_ID   = new API(URI_ZONE_BY_ID, 
HttpMethod.DELETE, Response.Status.NO_CONTENT);
-    public static final API DELETE_ZONE_BY_NAME = new API(URI_ZONE_BY_NAME, 
HttpMethod.DELETE, Response.Status.NO_CONTENT);
-    public static final API GET_ZONE_BY_ID      = new API(URI_ZONE_BY_ID, 
HttpMethod.GET, Response.Status.OK);
-    public static final API GET_ZONE_BY_NAME    = new API(URI_ZONE_BY_NAME, 
HttpMethod.GET, Response.Status.OK);
-    public static final API FIND_ZONES          = new API(URI_ZONE, 
HttpMethod.GET, Response.Status.OK);
+    public static final API CREATE_ZONE              = new API(URI_ZONE, 
HttpMethod.POST, Response.Status.OK);
+    public static final API UPDATE_ZONE_BY_ID        = new API(URI_ZONE_BY_ID, 
HttpMethod.PUT, Response.Status.OK);
+    public static final API DELETE_ZONE_BY_ID        = new API(URI_ZONE_BY_ID, 
HttpMethod.DELETE, Response.Status.NO_CONTENT);
+    public static final API DELETE_ZONE_BY_NAME      = new 
API(URI_ZONE_BY_NAME, HttpMethod.DELETE, Response.Status.NO_CONTENT);
+    public static final API GET_ZONE_BY_ID           = new API(URI_ZONE_BY_ID, 
HttpMethod.GET, Response.Status.OK);
+    public static final API GET_ZONE_BY_NAME         = new 
API(URI_ZONE_BY_NAME, HttpMethod.GET, Response.Status.OK);
+    public static final API GET_ZONE_HEADERS         = new 
API(URI_ZONE_HEADERS, HttpMethod.GET, Response.Status.OK);
+    public static final API GET_ZONE_SERVICE_HEADERS = new 
API(URI_ZONE_SERVICE_HEADERS, HttpMethod.GET, Response.Status.OK);
+    public static final API FIND_ZONES               = new API(URI_ZONE, 
HttpMethod.GET, Response.Status.OK);
 
     public static final API CREATE_ROLE         = new API(URI_ROLE, 
HttpMethod.POST, Response.Status.OK);
     public static final API UPDATE_ROLE_BY_ID   = new API(URI_ROLE_BY_ID, 
HttpMethod.PUT, Response.Status.OK);
@@ -332,10 +335,6 @@ public class RangerClient {
         return callAPI(UPDATE_ZONE_BY_ID.applyUrlFormat(zoneId), null, 
securityZone, RangerSecurityZone.class);
     }
 
-    public RangerSecurityZone updateSecurityZone(String zoneName, 
RangerSecurityZone securityZone) throws RangerServiceException {
-        return callAPI(UPDATE_ZONE_BY_NAME.applyUrlFormat(zoneName), null, 
securityZone, RangerSecurityZone.class);
-    }
-
     public void deleteSecurityZone(long zoneId) throws RangerServiceException {
         callAPI(DELETE_ZONE_BY_ID.applyUrlFormat(zoneId), null);
     }
@@ -352,6 +351,14 @@ public class RangerClient {
         return callAPI(GET_ZONE_BY_NAME.applyUrlFormat(zoneName), null, null, 
RangerSecurityZone.class);
     }
 
+    public List<RangerSecurityZoneHeaderInfo> 
getSecurityZoneHeaders(Map<String, String> filter) throws 
RangerServiceException {
+        return callAPI(GET_ZONE_HEADERS, filter, null, new 
GenericType<List<RangerSecurityZoneHeaderInfo>>(){});
+    }
+
+    public List<RangerServiceHeaderInfo> 
getSecurityZoneServiceHeaders(Map<String, String> filter) throws 
RangerServiceException {
+        return callAPI(GET_ZONE_SERVICE_HEADERS, filter, null, new 
GenericType<List<RangerServiceHeaderInfo>>(){});
+    }
+
     public List<RangerSecurityZone> findSecurityZones(Map<String, String> 
filter) throws RangerServiceException {
         return callAPI(FIND_ZONES, filter, null, new 
GenericType<List<RangerSecurityZone>>(){});
     }
diff --git a/intg/src/test/java/org/apache/ranger/TestRangerClient.java 
b/intg/src/test/java/org/apache/ranger/TestRangerClient.java
index 08e1b38a8..054881f4b 100644
--- a/intg/src/test/java/org/apache/ranger/TestRangerClient.java
+++ b/intg/src/test/java/org/apache/ranger/TestRangerClient.java
@@ -19,7 +19,9 @@
 package org.apache.ranger;
 
 import com.sun.jersey.api.client.ClientResponse;
+import org.apache.ranger.plugin.model.RangerSecurityZoneHeaderInfo;
 import org.apache.ranger.plugin.model.RangerService;
+import org.apache.ranger.plugin.model.RangerServiceHeaderInfo;
 import org.apache.ranger.plugin.util.RangerRESTClient;
 import org.junit.Assert;
 import org.junit.Test;
@@ -147,4 +149,28 @@ public class TestRangerClient {
             
Assert.assertTrue(exp.getMessage().contains("IllegalFormatConversionException"));
         }
     }
+
+    @Test
+    public void testGetSecurityZoneHeaders() throws RangerServiceException {
+        RangerClient        client = Mockito.mock(RangerClient.class);
+        Map<String, String> filter = Collections.emptyMap();
+
+        
when(client.getSecurityZoneHeaders(filter)).thenReturn(Collections.emptyList());
+
+        List<RangerSecurityZoneHeaderInfo> zoneHeaders = 
client.getSecurityZoneHeaders(filter);
+
+        Assert.assertEquals(Collections.emptyList(), zoneHeaders);
+    }
+
+    @Test
+    public void testGetSecurityZoneServiceHeaders() throws 
RangerServiceException {
+        RangerClient        client = Mockito.mock(RangerClient.class);
+        Map<String, String> filter = Collections.emptyMap();
+
+        
when(client.getSecurityZoneServiceHeaders(filter)).thenReturn(Collections.emptyList());
+
+        List<RangerServiceHeaderInfo> serviceHeaders = 
client.getSecurityZoneServiceHeaders(filter);
+
+        Assert.assertEquals(Collections.emptyList(), serviceHeaders);
+    }
 }
\ No newline at end of file

Reply via email to