bugraoz93 commented on code in PR #45300:
URL: https://github.com/apache/airflow/pull/45300#discussion_r1996413052


##########
airflow/cli/api/client.py:
##########
@@ -0,0 +1,264 @@
+# 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
+
+import contextlib
+import json
+import os
+import sys
+from functools import wraps
+from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast
+
+import httpx
+import keyring
+import structlog
+from platformdirs import user_config_path
+from uuid6 import uuid7
+
+from airflow.cli.api.operations import (
+    AssetsOperations,
+    BackfillsOperations,
+    ConfigOperations,
+    ConnectionsOperations,
+    DagOperations,
+    DagRunOperations,
+    JobsOperations,
+    PoolsOperations,
+    ProvidersOperations,
+    ServerResponseError,
+    VariablesOperations,
+    VersionOperations,
+)
+from airflow.exceptions import AirflowNotFoundException
+from airflow.typing_compat import ParamSpec
+from airflow.version import version
+
+if TYPE_CHECKING:
+    # # methodtools doesn't have typestubs, so give a stub
+    def lru_cache(maxsize: int | None = 128):
+        def wrapper(f):
+            return f
+
+        return wrapper
+else:
+    from methodtools import lru_cache
+
+log = structlog.get_logger(logger_name=__name__)
+
+__all__ = [
+    "Client",
+    "Credentials",
+]
+
+PS = ParamSpec("PS")
+RT = TypeVar("RT")
+
+
+def add_correlation_id(request: httpx.Request):
+    request.headers["correlation-id"] = str(uuid7())
+
+
+def get_json_error(response: httpx.Response):
+    """Raise a ServerResponseError if we can extract error info from the 
error."""
+    err = ServerResponseError.from_response(response)
+    if err:
+        log.warning("Server error ", extra=dict(err.response.json()))
+        raise err
+
+
+def raise_on_4xx_5xx(response: httpx.Response):
+    return get_json_error(response) or response.raise_for_status()
+
+
+# Credentials for the API
+class Credentials:
+    """Credentials for the API."""
+
+    api_url: str | None
+    api_token: str | None
+    api_environment: str
+
+    def __init__(
+        self,
+        api_url: str | None = None,
+        api_token: str | None = None,
+        api_environment: str = "production",

Review Comment:
   It was raised earlier in the PR. I agree instance URL is unique but the URLs 
aren't changing that much so I persist under a file and aimed to separate with 
using multiple files. In the current state, maybe it does not bring any value 
but I think we can store more configs locally in the file in the future to make 
this more usable. 
   What is your suggestion for the unique URL? Should the user use the URL in 
CLI or just set an env var?



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