nastra commented on code in PR #12555:
URL: https://github.com/apache/iceberg/pull/12555#discussion_r2011744113


##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthScopes.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import java.util.Map;
+import javax.annotation.Nonnull;
+import org.apache.iceberg.catalog.SessionCatalog;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.rest.RESTUtil;
+import org.immutables.value.Value;
+
+/** Well-known scopes for authentication. */
[email protected]
+public interface AuthScopes {
+
+  /**
+   * A scope that represents the initial authentication request from the 
catalog to the config
+   * endpoint. This is a short-lived scope that has no parent and is never 
cached.
+   */
+  @Value.Immutable
+  abstract class Initial implements AuthScope {
+
+    @Value.Parameter(order = 1)

Review Comment:
   I'm not a big fan of using `@Value.Parameter` to have an `of()` method being 
generated with the correct paramters. In all other places we typically create 
the `of()` method ourselves to better control the signature of the method. This 
also makes it easier for us down the line in case anything changes with the 
parameters, since we can properly deprecate and create overloading methods when 
needed. When the `of()` method is generated, it's more difficult to go through 
our API deprecation cycle.
   
   That being said, I would change this to 
   ```
   diff --git a/core/src/main/java/org/apache/iceberg/rest/auth/AuthScopes.java 
b/core/src/main/java/org/apache/iceberg/rest/auth/AuthScopes.java
   index 4465c95290..c9ab1fc5e3 100644
   --- a/core/src/main/java/org/apache/iceberg/rest/auth/AuthScopes.java
   +++ b/core/src/main/java/org/apache/iceberg/rest/auth/AuthScopes.java
   @@ -36,7 +36,6 @@ public interface AuthScopes {
      @Value.Immutable
      abstract class Initial implements AuthScope {
    
   -    @Value.Parameter(order = 1)
        @Override
        public abstract Map<String, String> properties();
    
   @@ -49,6 +48,10 @@ public interface AuthScopes {
        public final boolean cacheable() {
          return false;
        }
   +
   +    public static Initial of(Map<String, String> properties) {
   +      return 
ImmutableAuthScopes.Initial.builder().properties(properties).build();
   +    }
      }
    
      /**
   @@ -58,7 +61,6 @@ public interface AuthScopes {
      @Value.Immutable
      abstract class Catalog implements AuthScope {
    
   -    @Value.Parameter(order = 1)
        @Override
        public abstract Map<String, String> properties();
    
   @@ -71,6 +73,10 @@ public interface AuthScopes {
        public final boolean cacheable() {
          return false;
        }
   +
   +    public static Catalog of(Map<String, String> properties) {
   +      return 
ImmutableAuthScopes.Catalog.builder().properties(properties).build();
   +    }
      }
    
      /**
   @@ -80,10 +86,8 @@ public interface AuthScopes {
      @Value.Immutable
      abstract class Contextual implements AuthScope {
    
   -    @Value.Parameter(order = 1)
        public abstract SessionCatalog.SessionContext context();
    
   -    @Value.Parameter(order = 2)
        @Value.Lazy
        @Override
        public Map<String, String> properties() {
   @@ -94,7 +98,6 @@ public interface AuthScopes {
          return RESTUtil.merge(properties, credentials);
        }
    
   -    @Value.Parameter(order = 3)
        @Override
        @Nonnull
        public abstract AuthSession parent();
   @@ -103,6 +106,10 @@ public interface AuthScopes {
        public final boolean cacheable() {
          return true;
        }
   +
   +    public static Contextual of(SessionCatalog.SessionContext context, 
AuthSession parent) {
   +      return 
ImmutableAuthScopes.Contextual.builder().context(context).parent(parent).build();
   +    }
      }
    
      /**
   @@ -112,14 +119,11 @@ public interface AuthScopes {
      @Value.Immutable
      abstract class Table implements AuthScope {
    
   -    @Value.Parameter(order = 1)
        public abstract TableIdentifier identifier();
    
   -    @Value.Parameter(order = 2)
        @Override
        public abstract Map<String, String> properties();
    
   -    @Value.Parameter(order = 3)
        @Override
        @Nonnull
        public abstract AuthSession parent();
   @@ -128,6 +132,15 @@ public interface AuthScopes {
        public final boolean cacheable() {
          return true;
        }
   +
   +    public static Table of(
   +        TableIdentifier identifier, Map<String, String> properties, 
AuthSession parent) {
   +      return ImmutableAuthScopes.Table.builder()
   +          .identifier(identifier)
   +          .properties(properties)
   +          .parent(parent)
   +          .build();
   +    }
      }
    
      /**
   @@ -137,7 +150,6 @@ public interface AuthScopes {
      @Value.Immutable
      abstract class Standalone implements AuthScope {
    
   -    @Value.Parameter(order = 1)
        @Override
        public abstract Map<String, String> properties();
    
   @@ -146,5 +158,9 @@ public interface AuthScopes {
        public boolean cacheable() {
          return false;
        }
   +
   +    public static Standalone of(Map<String, String> properties) {
   +      return 
ImmutableAuthScopes.Standalone.builder().properties(properties).build();
   +    }
      }
    }
   ```
   
   And when a scope is instantiated I would use `AuthScopes.Xyz.of(..)` instead 
of `ImmutableAuthScopes.Xyz.of(..)`



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to