potiuk commented on code in PR #33213: URL: https://github.com/apache/airflow/pull/33213#discussion_r1304902521
########## airflow/auth/managers/models/resource_details.py: ########## @@ -0,0 +1,31 @@ +# +# 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. +from __future__ import annotations + +from dataclasses import dataclass + + +@dataclass +class ResourceDetails: + """ + Represents the details of a resource. + + All fields must be optional. These details can be used in authorization decision. + """ + + id: str | None = None Review Comment: Could be. And I see what you mean (and feel the sentiment) - but it would require to get a way to convert the ResourceDetail class into the resource-specific dataclass. And somewhere you need ot do casting. I am not sure if it can be done nicely with the "callback" kind of authorisation and single `is_authorized` method. I have a feeling that single `is_authorized` goes well together with a dictionary detail than with dataclasses. You will have to get a call "is_authorized" and it will receive resource type and resource details - and in Python you can't specify "if resource-type = DAG, your implementation shoudl expect DagResource details"... But maybe... I have a thouhg. Maybe it can be actually connected with the Enum on the resources and the interface should be a bit more elaborated than single "is_authorized". while it is appealing to have one method for all the different resource types, I think it might be quite not necessary. We could have a set of is_authorized_methods... * is_authorized_dag(DagResourceDetails details) * is_authorized_task(TaskResourceDetails details) * .... and so on.. Then passing a deticated "details" structure to such a callback would make much more sense. If you have one `is_authorized' method to handle, then in the implementaiton, you have to do - (and in every implementation broadly speaking): ``` if resource_type = DAG: dag_details = cast(DagDetails, details) if resource_type = TASK: task_details = cast(TaskDetails, details) ``` That makes little sense when we are using dataclasses with deticated fields/structure. In a way I think the interface where you have separate `is_authorized_<type>` method is a lot cleaner if you are using dataclasses. -- 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]
