snazy commented on code in PR #3031:
URL: https://github.com/apache/polaris/pull/3031#discussion_r2517334010


##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Resource.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.extension.auth.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents the resource(s) being accessed in an authorization request.
+ *
+ * <p>Contains primary target entities and optional secondary entities.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResource.class)
+@JsonDeserialize(as = ImmutableResource.class)
+public interface Resource {
+  /** The primary target entities being accessed. */
+  @JsonProperty("targets")
+  List<ResourceEntity> targets();
+
+  /** Secondary entities involved in the operation (e.g., source table in 
RENAME). */
+  @JsonProperty("secondaries")
+  List<ResourceEntity> secondaries();

Review Comment:
   If the whole property is optional, maybe add
   ```
   @JsonInclude(JsonInclude.Include.NON_EMPTY)
   ```
   But I'm not sure whether the JSON schema generator respects this.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Context.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.extension.auth.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Additional context information for the authorization request.
+ *
+ * <p>Used for tracking and correlation purposes.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableContext.class)
+@JsonDeserialize(as = ImmutableContext.class)
+public interface Context {
+  /** A unique identifier for correlating this request with OPA server logs. */
+  @JsonProperty("request_id")

Review Comment:
   Hint:
   you can use
   ```java
   @JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)
   ```
   on a type and IIRC also at the package level.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/Actor.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.extension.auth.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents the actor (principal) making an authorization request.
+ *
+ * <p>Contains the principal identifier and associated roles.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableActor.class)
+@JsonDeserialize(as = ImmutableActor.class)
+public interface Actor {
+  /** The principal name or identifier. */
+  @JsonProperty("principal")

Review Comment:
   Nit: no need to specify this, if the property name's the same.



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/ResourceEntity.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.extension.auth.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import jakarta.annotation.Nullable;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents a single resource entity in the authorization context.
+ *
+ * <p>Contains the entity type, name, and hierarchical parent path.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResourceEntity.class)
+@JsonDeserialize(as = ImmutableResourceEntity.class)
+public interface ResourceEntity {
+  /** The type of the resource (e.g., "CATALOG", "NAMESPACE", "TABLE"). */
+  @JsonProperty("type")
+  String type();
+
+  /** The name of the resource. */
+  @JsonProperty("name")
+  String name();
+
+  /**
+   * The hierarchical path of parent entities.
+   *
+   * <p>For example, a table might have parents: [catalog, namespace].
+   */
+  @Nullable
+  @JsonProperty("parents")
+  List<ResourceEntity> parents();

Review Comment:
   ```suggestion
     @JsonInclude(JsonInclude.Include.NON_NULL)
     List<ResourceEntity> parents();
   ```
   (same as above)



##########
extensions/auth/opa/impl/build.gradle.kts:
##########
@@ -58,3 +59,64 @@ dependencies {
   testImplementation(project(":polaris-async-java"))
   testImplementation(project(":polaris-idgen-mocks"))
 }
+
+// Task to generate JSON Schema from model classes

Review Comment:
   Couple of Gradle improvements could be applied.
   I've created PR against your branch, as it's a bit more: sungwy#3
   
   The idea to have separate generation and validation steps is good IMO, as it 
makes it obvious that such changes affect the expected OPA contract.
   
   Summary:
   * Make both tasks cacheable
   * Adjust logging output (keep output brief)
   * Moved schema generator class to a separate source-set/configurations, 
because it's not prod code, but more importantly to not let the 
json-schema-generator dependency leak into the production runtime classpath



##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/model/ResourceEntity.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.extension.auth.opa.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import jakarta.annotation.Nullable;
+import java.util.List;
+import org.apache.polaris.immutables.PolarisImmutable;
+
+/**
+ * Represents a single resource entity in the authorization context.
+ *
+ * <p>Contains the entity type, name, and hierarchical parent path.
+ */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableResourceEntity.class)
+@JsonDeserialize(as = ImmutableResourceEntity.class)
+public interface ResourceEntity {
+  /** The type of the resource (e.g., "CATALOG", "NAMESPACE", "TABLE"). */
+  @JsonProperty("type")
+  String type();
+
+  /** The name of the resource. */
+  @JsonProperty("name")
+  String name();
+
+  /**
+   * The hierarchical path of parent entities.
+   *
+   * <p>For example, a table might have parents: [catalog, namespace].
+   */
+  @Nullable

Review Comment:
   I suspect this is for the JSON schema generator?



##########
extensions/auth/opa/impl/SCHEMA.md:
##########
@@ -0,0 +1,106 @@
+# OPA Input Schema Management

Review Comment:
   Will need a license header to pass CI.



-- 
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