dimas-b commented on code in PR #590:
URL: https://github.com/apache/polaris/pull/590#discussion_r1913550138


##########
integration-tests/src/main/java/org/apache/polaris/service/it/env/ManagementApi.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.it.env;
+
+import static jakarta.ws.rs.core.Response.Status.CREATED;
+import static jakarta.ws.rs.core.Response.Status.NO_CONTENT;
+import static jakarta.ws.rs.core.Response.Status.OK;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.Response;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogGrant;
+import org.apache.polaris.core.admin.model.CatalogPrivilege;
+import org.apache.polaris.core.admin.model.CatalogRole;
+import org.apache.polaris.core.admin.model.CatalogRoles;
+import org.apache.polaris.core.admin.model.Catalogs;
+import org.apache.polaris.core.admin.model.CreatePrincipalRequest;
+import org.apache.polaris.core.admin.model.GrantCatalogRoleRequest;
+import org.apache.polaris.core.admin.model.GrantPrincipalRoleRequest;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.core.admin.model.GrantResources;
+import org.apache.polaris.core.admin.model.Principal;
+import org.apache.polaris.core.admin.model.PrincipalRole;
+import org.apache.polaris.core.admin.model.PrincipalRoles;
+import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
+import org.apache.polaris.core.admin.model.Principals;
+import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
+
+public class ManagementApi extends RestApi {
+  ManagementApi(Client client, PolarisApiEndpoints endpoints, String 
authToken, URI uri) {
+    super(client, endpoints, authToken, uri);
+  }
+
+  public PrincipalWithCredentials createPrincipalWithRole(String 
principalName, String roleName) {
+    PrincipalWithCredentials credentials = createPrincipal(principalName);
+    createPrincipalRole(roleName);
+    assignPrincipalRole(principalName, roleName);
+    return credentials;
+  }
+
+  public PrincipalWithCredentials createPrincipal(String name) {
+    try (Response createPResponse =
+        request("v1/principals").post(Entity.json(new Principal(name)))) {
+      assertThat(createPResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+      return createPResponse.readEntity(PrincipalWithCredentials.class);
+    }
+  }
+
+  public PrincipalWithCredentials createPrincipal(CreatePrincipalRequest 
request) {
+    try (Response createPResponse = 
request("v1/principals").post(Entity.json(request))) {
+      assertThat(createPResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+      return createPResponse.readEntity(PrincipalWithCredentials.class);
+    }
+  }
+
+  public void createPrincipalRole(String name) {
+    createPrincipalRole(new PrincipalRole(name));
+  }
+
+  public void createPrincipalRole(PrincipalRole role) {
+    try (Response createPrResponse = 
request("v1/principal-roles").post(Entity.json(role))) {
+      assertThat(createPrResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void assignPrincipalRole(String principalName, String roleName) {
+    try (Response assignPrResponse =
+        request("v1/principals/{prince}/principal-roles", Map.of("prince", 
principalName))
+            .put(Entity.json(new GrantPrincipalRoleRequest(new 
PrincipalRole(roleName))))) {
+      assertThat(assignPrResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void createCatalogRole(String catalogName, String catalogRoleName) {
+    try (Response response =
+        request("v1/catalogs/{cat}/catalog-roles", Map.of("cat", catalogName))
+            .post(Entity.json(new CatalogRole(catalogRoleName)))) {
+      assertThat(response.getStatus()).isEqualTo(CREATED.getStatusCode());
+    }
+  }
+
+  public void addGrant(String catalogName, String catalogRoleName, 
GrantResource grant) {
+    try (Response response =
+        request(
+                "v1/catalogs/{cat}/catalog-roles/{role}/grants",
+                Map.of("cat", catalogName, "role", catalogRoleName))
+            .put(Entity.json(grant))) {
+      assertThat(response).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void grantCatalogRoleToPrincipalRole(
+      String principalRoleName, String catalogName, CatalogRole catalogRole) {
+    try (Response response =
+        request(
+                "v1/principal-roles/{role}/catalog-roles/{cat}",
+                Map.of("role", principalRoleName, "cat", catalogName))
+            .put(Entity.json(new GrantCatalogRoleRequest(catalogRole)))) {
+      assertThat(response).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public GrantResources listGrants(String catalogName, String catalogRoleName) 
{
+    try (Response response =
+        request(
+                "v1/catalogs/{cat}/catalog-roles/{role}/grants",
+                Map.of("cat", catalogName, "role", catalogRoleName))
+            .get()) {
+      assertThat(response).returns(OK.getStatusCode(), Response::getStatus);
+      return response.readEntity(GrantResources.class);
+    }
+  }
+
+  public void createCatalog(String principalRoleName, Catalog catalog) {
+    createCatalog(catalog);
+
+    // Create a new CatalogRole that has CATALOG_MANAGE_CONTENT and 
CATALOG_MANAGE_ACCESS
+    String catalogRoleName = "custom-admin";
+    createCatalogRole(catalog.getName(), catalogRoleName);

Review Comment:
   I believe this code keeps old bebaviour, unless I make a mistake.



##########
integration-tests/src/main/java/org/apache/polaris/service/it/env/ManagementApi.java:
##########
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.it.env;
+
+import static jakarta.ws.rs.core.Response.Status.CREATED;
+import static jakarta.ws.rs.core.Response.Status.NO_CONTENT;
+import static jakarta.ws.rs.core.Response.Status.OK;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.Response;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogGrant;
+import org.apache.polaris.core.admin.model.CatalogPrivilege;
+import org.apache.polaris.core.admin.model.CatalogRole;
+import org.apache.polaris.core.admin.model.CatalogRoles;
+import org.apache.polaris.core.admin.model.Catalogs;
+import org.apache.polaris.core.admin.model.CreatePrincipalRequest;
+import org.apache.polaris.core.admin.model.GrantCatalogRoleRequest;
+import org.apache.polaris.core.admin.model.GrantPrincipalRoleRequest;
+import org.apache.polaris.core.admin.model.GrantResource;
+import org.apache.polaris.core.admin.model.GrantResources;
+import org.apache.polaris.core.admin.model.Principal;
+import org.apache.polaris.core.admin.model.PrincipalRole;
+import org.apache.polaris.core.admin.model.PrincipalRoles;
+import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
+import org.apache.polaris.core.admin.model.Principals;
+import org.apache.polaris.core.admin.model.UpdateCatalogRequest;
+
+public class ManagementApi extends RestApi {
+  ManagementApi(Client client, PolarisApiEndpoints endpoints, String 
authToken, URI uri) {
+    super(client, endpoints, authToken, uri);
+  }
+
+  public PrincipalWithCredentials createPrincipalWithRole(String 
principalName, String roleName) {
+    PrincipalWithCredentials credentials = createPrincipal(principalName);
+    createPrincipalRole(roleName);
+    assignPrincipalRole(principalName, roleName);
+    return credentials;
+  }
+
+  public PrincipalWithCredentials createPrincipal(String name) {
+    try (Response createPResponse =
+        request("v1/principals").post(Entity.json(new Principal(name)))) {
+      assertThat(createPResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+      return createPResponse.readEntity(PrincipalWithCredentials.class);
+    }
+  }
+
+  public PrincipalWithCredentials createPrincipal(CreatePrincipalRequest 
request) {
+    try (Response createPResponse = 
request("v1/principals").post(Entity.json(request))) {
+      assertThat(createPResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+      return createPResponse.readEntity(PrincipalWithCredentials.class);
+    }
+  }
+
+  public void createPrincipalRole(String name) {
+    createPrincipalRole(new PrincipalRole(name));
+  }
+
+  public void createPrincipalRole(PrincipalRole role) {
+    try (Response createPrResponse = 
request("v1/principal-roles").post(Entity.json(role))) {
+      assertThat(createPrResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void assignPrincipalRole(String principalName, String roleName) {
+    try (Response assignPrResponse =
+        request("v1/principals/{prince}/principal-roles", Map.of("prince", 
principalName))
+            .put(Entity.json(new GrantPrincipalRoleRequest(new 
PrincipalRole(roleName))))) {
+      assertThat(assignPrResponse).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void createCatalogRole(String catalogName, String catalogRoleName) {
+    try (Response response =
+        request("v1/catalogs/{cat}/catalog-roles", Map.of("cat", catalogName))
+            .post(Entity.json(new CatalogRole(catalogRoleName)))) {
+      assertThat(response.getStatus()).isEqualTo(CREATED.getStatusCode());
+    }
+  }
+
+  public void addGrant(String catalogName, String catalogRoleName, 
GrantResource grant) {
+    try (Response response =
+        request(
+                "v1/catalogs/{cat}/catalog-roles/{role}/grants",
+                Map.of("cat", catalogName, "role", catalogRoleName))
+            .put(Entity.json(grant))) {
+      assertThat(response).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public void grantCatalogRoleToPrincipalRole(
+      String principalRoleName, String catalogName, CatalogRole catalogRole) {
+    try (Response response =
+        request(
+                "v1/principal-roles/{role}/catalog-roles/{cat}",
+                Map.of("role", principalRoleName, "cat", catalogName))
+            .put(Entity.json(new GrantCatalogRoleRequest(catalogRole)))) {
+      assertThat(response).returns(CREATED.getStatusCode(), 
Response::getStatus);
+    }
+  }
+
+  public GrantResources listGrants(String catalogName, String catalogRoleName) 
{
+    try (Response response =
+        request(
+                "v1/catalogs/{cat}/catalog-roles/{role}/grants",
+                Map.of("cat", catalogName, "role", catalogRoleName))
+            .get()) {
+      assertThat(response).returns(OK.getStatusCode(), Response::getStatus);
+      return response.readEntity(GrantResources.class);
+    }
+  }
+
+  public void createCatalog(String principalRoleName, Catalog catalog) {
+    createCatalog(catalog);
+
+    // Create a new CatalogRole that has CATALOG_MANAGE_CONTENT and 
CATALOG_MANAGE_ACCESS
+    String catalogRoleName = "custom-admin";
+    createCatalogRole(catalog.getName(), catalogRoleName);

Review Comment:
   I believe this code keeps old behaviour, unless I make a mistake.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to