o-nikolas commented on code in PR #72036:
URL: https://github.com/apache/airflow/pull/72036#discussion_r3884676937


##########
airflow-core/newsfragments/72036.feature.rst:
##########
@@ -0,0 +1 @@
+Add an ``airflow teams inspect`` CLI command for displaying resources 
associated with a team, including DAG bundles, pools, connections, and 
variables.

Review Comment:
   ```suggestion
   Add an ``airflow teams inspect`` CLI command for displaying resources 
associated with a team, including Dag bundles, pools, connections, and 
variables.
   ```



##########
airflow-core/src/airflow/cli/commands/team_command.py:
##########
@@ -308,3 +308,51 @@ def team_verify(args, *, session=NEW_SESSION):
         raise SystemExit(1)
 
     print("Verification succeeded.")
+
+
+@cli_utils.action_cli
+@providers_configuration_loaded
+@provide_session
+def team_inspect(args, *, session=NEW_SESSION):
+    """Inspect resources belonging to a team."""
+    team_name = _extract_team_name(args)
+
+    team = session.scalar(select(Team).where(Team.name == team_name))
+    if team is None:
+        raise SystemExit(f"Team '{team_name}' does not exist")
+
+    bundle_names = session.scalars(
+        select(dag_bundle_team_association_table.c.dag_bundle_name)
+        .where(dag_bundle_team_association_table.c.team_name == team_name)
+        .order_by(dag_bundle_team_association_table.c.dag_bundle_name)
+    ).all()
+
+    pool_names = session.scalars(
+        select(Pool.pool).where(Pool.team_name == 
team_name).order_by(Pool.pool)
+    ).all()
+
+    connection_ids = session.scalars(
+        select(Connection.conn_id).where(Connection.team_name == 
team_name).order_by(Connection.conn_id)
+    ).all()
+
+    variable_keys = session.scalars(
+        select(Variable.key).where(Variable.team_name == 
team_name).order_by(Variable.key)
+    ).all()
+
+    print(f"Team: {team_name}")
+    print()
+
+    def print_section(title: str, values: list[str]) -> None:

Review Comment:
   There is `AirflowConsole().print_as(...)` that can be used to ensure the 
output is printed in a machine readable format and consistent with other 
methods here. See `_show_teams(...)` for details on how it's used



##########
airflow-core/tests/unit/cli/commands/test_team_command.py:
##########
@@ -624,3 +624,87 @@ def test_team_verify_unknown_bundle_team(self, 
stdout_capture):
                     team_command.team_verify(self.parser.parse_args(["teams", 
"verify"]))
 
         assert "references unknown team 'missing-team'" in stdout.getvalue()
+
+    def test_team_inspect(self, stdout_capture):

Review Comment:
   Adding a team2 and some resources for it and ensuring they're _not_ in the 
output would help ensure that the team filtering in the code is working 
correctly.



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