Repository: PrefectHQ/prefect

Issue:
Cloud PR references Core
See https://github.com/PrefectHQ/cloud/pull/266 for more details


Discussion:

Resolving patch:
diff --git a/src/prefect/client/client.py b/src/prefect/client/client.py
--- a/src/prefect/client/client.py
+++ b/src/prefect/client/client.py
@@ -32,8 +32,6 @@ class Client:
     token will only be present in the current context.
 
     Args:
-        - api_server (str, optional): the URL to send all basic POST requests
-            to; if not provided, will be pulled from `cloud.api` config var
         - graphql_server (str, optional): the URL to send all GraphQL requests
             to; if not provided, will be pulled from `cloud.graphql` config var
     """
@@ -46,21 +44,14 @@ def _initialize_logger(self) -> None:
         self.logger.addHandler(handler)
         self.logger.setLevel(prefect.config.logging.level)
 
-    def __init__(self, api_server: str = None, graphql_server: str = None):
+    def __init__(self, graphql_server: str = None):
         self._initialize_logger()
-        if not api_server:
-            api_server = prefect.config.cloud.get("api", None)
-            if not api_server:
-                raise ClientError("Could not determine API server.")
-        self.api_server = api_server
 
         if not graphql_server:
-            graphql_server = prefect.config.cloud.get("graphql") or self.api_server
+            graphql_server = prefect.config.cloud.get("graphql")
         self.graphql_server = graphql_server
         self.logger.debug(
-            "Client initialized with api_server='{0}' and graphql_server='{1}'".format(
-                self.api_server, self.graphql_server
-            )
+            "Client initialized graphql_server='{0}'".format(self.graphql_server)
         )
 
         token = prefect.config.cloud.get("auth_token", None)
@@ -88,7 +79,7 @@ def get(self, path: str, server: str = None, **params: BuiltIn) -> dict:
             - path (str): the path of the API url. For example, to GET
                 http://prefect-server/v1/auth/login, path would be 'auth/login'.
             - server (str, optional): the server to send the GET request to;
-                defaults to `self.api_server`
+                defaults to `self.graphql_server`
             - params (dict): GET parameters
 
         Returns:
@@ -108,7 +99,7 @@ def post(self, path: str, server: str = None, **params: BuiltIn) -> dict:
             - path (str): the path of the API url. For example, to POST
                 http://prefect-server/v1/auth/login, path would be 'auth/login'.
             - server (str, optional): the server to send the POST request to;
-                defaults to `self.api_server`
+                defaults to `self.graphql_server`
             - params (dict): POST parameters
 
         Returns:
@@ -175,7 +166,7 @@ def _request(
         import requests
 
         if server is None:
-            server = self.api_server
+            server = self.graphql_server
         assert isinstance(server, str)  # mypy assert
 
         if self.token is None:
@@ -238,7 +229,8 @@ def login(
         # lazy import for performance
         import requests
 
-        url = os.path.join(self.api_server, "login_email")
+        # TODO: This needs to call the main graphql server and be adjusted for auth0
+        url = os.path.join(self.graphql_server, "login_email")  # type: ignore
         response = requests.post(
             url,
             auth=(email, password),
@@ -272,7 +264,8 @@ def refresh_token(self) -> None:
         # lazy import for performance
         import requests
 
-        url = os.path.join(self.api_server, "refresh_token")
+        # TODO: This needs to call the main graphql server
+        url = os.path.join(self.graphql_server, "refresh_token")  # type: ignore
         response = requests.post(
             url, headers={"Authorization": "Bearer {}".format(self.token)}
         )


Test patch:
diff --git a/tests/client/test_client.py b/tests/client/test_client.py
--- a/tests/client/test_client.py
+++ b/tests/client/test_client.py
@@ -60,42 +60,22 @@ def serialize(self, result):
 
 def test_client_initializes_from_config():
     with set_temporary_config(
-        {
-            "cloud.api": "api_server",
-            "cloud.graphql": "graphql_server",
-            "cloud.auth_token": "token",
-        }
+        {"cloud.graphql": "graphql_server", "cloud.auth_token": "token"}
     ):
         client = Client()
-    assert client.api_server == "api_server"
     assert client.graphql_server == "graphql_server"
     assert client.token == "token"
 
 
 def test_client_initializes_and_prioritizes_kwargs():
     with set_temporary_config(
-        {
-            "cloud.api": "api_server",
-            "cloud.graphql": "graphql_server",
-            "cloud.auth_token": "token",
-        }
+        {"cloud.graphql": "graphql_server", "cloud.auth_token": "token"}
     ):
-        client = Client(api_server="my-api", graphql_server="my-graphql")
-    assert client.api_server == "my-api"
+        client = Client(graphql_server="my-graphql")
     assert client.graphql_server == "my-graphql"
     assert client.token == "token"
 
 
-def test_client_graphql_server_falls_back_to_api_server():
-    with set_temporary_config(
-        {"cloud.api": "api_server", "cloud.graphql": None, "cloud.auth_token": "token"}
-    ):
-        client = Client()
-    assert client.api_server == "api_server"
-    assert client.graphql_server == "api_server"
-    assert client.token == "token"
-
-
 def test_client_token_initializes_from_file(monkeypatch):
     monkeypatch.setattr("os.path.exists", MagicMock(return_value=True))
     monkeypatch.setattr("builtins.open", mock_open(read_data="TOKEN"))
@@ -116,7 +96,7 @@ def test_client_doesnt_write_to_file_if_token_provided_from_config(monkeypatch):
     mock_file = mock_open()
     monkeypatch.setattr("builtins.open", mock_file)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "token"}
     ):
         client = Client()
     assert not mock_file.called
@@ -134,7 +114,7 @@ def test_client_doesnt_login_if_no_tokens_available(monkeypatch, cloud):
     monkeypatch.setattr("requests.post", post)
 
     config = {
-        "cloud.api": "http://my-cloud.foo",
+        "cloud.graphql": "http://my-cloud.foo",
         "cloud.auth_token": None,
         "cloud.email": "test@example.com",
         "cloud.password": "1234",
@@ -160,7 +140,7 @@ def test_client_logs_out_and_deletes_auth_token(monkeypatch):
         )
     )
     monkeypatch.setattr("requests.post", post)
-    with set_temporary_config({"cloud.api": "http://my-cloud.foo"}):
+    with set_temporary_config({"cloud.graphql": "http://my-cloud.foo"}):
         client = Client()
     client.login("test@example.com", "1234")
     token_path = os.path.expanduser("~/.prefect/.credentials/auth_token")
@@ -174,7 +154,7 @@ def test_client_logs_out_and_deletes_auth_token(monkeypatch):
 def test_client_raises_if_login_fails(monkeypatch):
     post = MagicMock(return_value=MagicMock(ok=False))
     monkeypatch.setattr("requests.post", post)
-    with set_temporary_config({"cloud.api": "http://my-cloud.foo"}):
+    with set_temporary_config({"cloud.graphql": "http://my-cloud.foo"}):
         client = Client()
     with pytest.raises(AuthorizationError):
         client.login("test@example.com", "1234")
@@ -185,20 +165,20 @@ def test_client_raises_if_login_fails(monkeypatch):
 def test_client_posts_raises_with_no_token(monkeypatch):
     post = MagicMock()
     monkeypatch.setattr("requests.post", post)
-    with set_temporary_config({"cloud.api": "http://my-cloud.foo"}):
+    with set_temporary_config({"cloud.graphql": "http://my-cloud.foo"}):
         client = Client()
     with pytest.raises(AuthorizationError) as exc:
         result = client.post("/foo/bar")
     assert "Client.login" in str(exc.value)
 
 
-def test_client_posts_to_api_server(monkeypatch):
+def test_client_posts_to_graphql_server(monkeypatch):
     post = MagicMock(
         return_value=MagicMock(json=MagicMock(return_value=dict(success=True)))
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.post("/foo/bar")
@@ -218,7 +198,7 @@ def test_client_posts_retries_if_token_needs_refreshing(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     with pytest.raises(requests.HTTPError) as exc:
@@ -237,11 +217,7 @@ def test_client_posts_graphql_to_graphql_server(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {
-            "cloud.api": "http://my-cloud.foo",
-            "cloud.auth_token": "secret_token",
-            "cloud.graphql": None,
-        }
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.graphql("{projects{name}}")
@@ -261,11 +237,7 @@ def test_client_graphql_retries_if_token_needs_refreshing(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {
-            "cloud.api": "http://my-cloud.foo",
-            "cloud.auth_token": "secret_token",
-            "cloud.graphql": None,
-        }
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     with pytest.raises(requests.HTTPError) as exc:
@@ -285,7 +257,7 @@ def test_graphql_errors_get_raised(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     with pytest.raises(ClientError) as exc:
@@ -309,7 +281,7 @@ def test_client_deploy(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     flow = prefect.Flow(name="test")
@@ -324,7 +296,7 @@ def test_client_deploy_rejects_setting_active_schedules_for_flows_with_req_param
     post = MagicMock()
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
 
@@ -364,7 +336,7 @@ def test_get_flow_run_info(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.get_flow_run_info(flow_run_id="74-salt")
@@ -389,7 +361,7 @@ def test_get_flow_run_info_raises_informative_error(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     with pytest.raises(ClientError) as exc:
@@ -412,7 +384,7 @@ def test_set_flow_run_state(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.set_flow_run_state(
@@ -436,7 +408,7 @@ def test_set_flow_run_state_with_error(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     with pytest.raises(ClientError) as exc:
@@ -470,7 +442,7 @@ def test_get_task_run_info(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.get_task_run_info(
@@ -500,7 +472,7 @@ def test_get_task_run_info_with_error(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
 
@@ -527,7 +499,7 @@ def test_set_task_run_state(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
     result = client.set_task_run_state(
@@ -552,7 +524,7 @@ def test_set_task_run_state_with_error(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
     ):
         client = Client()
 
@@ -567,7 +539,7 @@ def test_set_flow_run_state_calls_result_handler(self, monkeypatch):
         monkeypatch.setattr(prefect.client.client, "json", MagicMock())
 
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
@@ -591,7 +563,7 @@ def test_set_task_run_state_calls_result_handler(self, monkeypatch):
         monkeypatch.setattr(prefect.client.client, "json", MagicMock())
 
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
@@ -635,7 +607,7 @@ def test_get_flow_run_info_doesnt_call_result_handler_if_result_is_none(
         )
         monkeypatch.setattr("requests.post", post)
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
@@ -674,7 +646,7 @@ def test_get_task_run_info_doesnt_call_result_handler_if_result_is_none(
         )
         monkeypatch.setattr("requests.post", post)
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
@@ -710,7 +682,7 @@ def test_get_flow_run_info_calls_result_handler(self, monkeypatch):
         )
         monkeypatch.setattr("requests.post", post)
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
@@ -747,7 +719,7 @@ def test_get_task_run_info_calls_result_handler(self, monkeypatch):
         )
         monkeypatch.setattr("requests.post", post)
         with set_temporary_config(
-            {"cloud.api": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
         ):
             client = Client()
 
diff --git a/tests/client/test_secrets.py b/tests/client/test_secrets.py
--- a/tests/client/test_secrets.py
+++ b/tests/client/test_secrets.py
@@ -54,11 +54,7 @@ def test_secrets_use_client(monkeypatch):
     )
     monkeypatch.setattr("requests.post", post)
     with set_temporary_config(
-        {
-            "cloud.api": "http://my-cloud.foo",
-            "cloud.auth_token": "secret_token",
-            "cloud.use_local_secrets": False,
-        }
+        {"cloud.auth_token": "secret_token", "cloud.use_local_secrets": False}
     ):
         my_secret = Secret(name="the-key")
         val = my_secret.get()
diff --git a/tests/engine/cloud/test_cloud_task_runner.py b/tests/engine/cloud/test_cloud_task_runner.py
--- a/tests/engine/cloud/test_cloud_task_runner.py
+++ b/tests/engine/cloud/test_cloud_task_runner.py
@@ -29,7 +29,6 @@
 def cloud_settings():
     with set_temporary_config(
         {
-            "cloud.api": "http://my-cloud.foo",
             "engine.flow_runner.default_class": "prefect.engine.cloud.CloudFlowRunner",
             "engine.task_runner.default_class": "prefect.engine.cloud.CloudTaskRunner",
             "cloud.auth_token": "token",