From e78c3be3ba07aff37fa18abf9e390e920325555b Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Tue, 27 Aug 2024 15:21:30 +0200 Subject: [PATCH] Cleanup and make metadata optional --- openbrokerapi/api.py | 2 +- openbrokerapi/auth.py | 5 +---- openbrokerapi/catalog.py | 20 ++++++++++-------- openbrokerapi/router.py | 2 +- openbrokerapi/service_broker.py | 16 +++++++-------- tests/test_integration_using_async_flow.py | 24 +++++++++++----------- tests/test_provisioning.py | 1 + 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/openbrokerapi/api.py b/openbrokerapi/api.py index 8f8f8e1..920746e 100644 --- a/openbrokerapi/api.py +++ b/openbrokerapi/api.py @@ -81,7 +81,7 @@ def get_blueprint( if openbrokerapi.settings.DISABLE_VERSION_CHECK: logger.warning( "Minimum API version is not checked, this can cause illegal contracts between service broker and platform!", - stacklevel=0 + stacklevel=0, ) else: logger.debug("Apply check_version filter for version %s" % str(openbrokerapi.settings.MIN_VERSION)) diff --git a/openbrokerapi/auth.py b/openbrokerapi/auth.py index e4bb0d2..9e0c073 100644 --- a/openbrokerapi/auth.py +++ b/openbrokerapi/auth.py @@ -16,10 +16,7 @@ def __call__(self, *args, **kwargs): return self.authenticate() @abstractmethod - def authenticate(self) -> Union[ - Optional[ResponseReturnValue], - Awaitable[Optional[ResponseReturnValue]] - ]: + def authenticate(self) -> Union[Optional[ResponseReturnValue], Awaitable[Optional[ResponseReturnValue]]]: """ Implement an `flask.typing.BeforeRequestCallable` diff --git a/openbrokerapi/catalog.py b/openbrokerapi/catalog.py index 4ebcbb1..4fb2540 100644 --- a/openbrokerapi/catalog.py +++ b/openbrokerapi/catalog.py @@ -1,17 +1,19 @@ +from __future__ import annotations + from typing import List, Dict, Optional class ServiceMetadata: def __init__( self, - displayName: str, - imageUrl: str, - longDescription: str, - providerDisplayName: str, - documentationUrl: str, - supportUrl: str, + displayName: str | None = None, + imageUrl: str | None = None, + longDescription: str | None = None, + providerDisplayName: str | None = None, + documentationUrl: str | None = None, + supportUrl: str | None = None, shareable: Optional[bool] = None, - **kwargs + **kwargs, ): self.displayName = displayName self.imageUrl = imageUrl @@ -47,7 +49,7 @@ def __init__( displayName: Optional[str] = None, bullets: Optional[List[str]] = None, costs: Optional[List[ServicePlanCost]] = None, - **kwargs + **kwargs, ): self.displayName = displayName self.bullets = bullets @@ -74,7 +76,7 @@ def __init__( free: Optional[bool] = None, bindable: Optional[bool] = None, schemas: Optional[Schemas] = None, - **kwargs + **kwargs, ): self.id = id self.name = name diff --git a/openbrokerapi/router.py b/openbrokerapi/router.py index d4cf586..1e666f1 100644 --- a/openbrokerapi/router.py +++ b/openbrokerapi/router.py @@ -93,7 +93,7 @@ def last_operation( operation_data: Optional[str], service_id: Optional[str] = None, plan_id: Optional[str] = None, - **kwargs + **kwargs, ) -> LastOperation: if operation_data is None: raise errors.ErrInvalidParameters("Invalid operation string") diff --git a/openbrokerapi/service_broker.py b/openbrokerapi/service_broker.py index 6403ce2..15cf98c 100644 --- a/openbrokerapi/service_broker.py +++ b/openbrokerapi/service_broker.py @@ -18,7 +18,7 @@ def __init__( space_guid: Optional[str] = None, parameters: Optional[dict] = None, context: Optional[dict] = None, - **kwargs + **kwargs, ): self.service_id = service_id self.plan_id = plan_id @@ -105,7 +105,7 @@ def __init__( service_id: Optional[str] = None, organization_id: Optional[str] = None, space_id: Optional[str] = None, - **kwargs + **kwargs, ): self.plan_id = plan_id self.service_id = service_id @@ -121,7 +121,7 @@ def __init__( parameters: Optional[dict] = None, previous_values: Optional[dict] = None, context: Optional[dict] = None, - **kwargs + **kwargs, ): self.service_id = service_id self.plan_id = plan_id @@ -160,7 +160,7 @@ def __init__( bind_resource: Optional[dict] = None, parameters: Optional[dict] = None, context: Optional[dict] = None, - **kwargs + **kwargs, ): self.app_guid = app_guid self.plan_id = plan_id @@ -227,7 +227,7 @@ def __init__( route_service_url: Optional[str] = None, volume_mounts: Optional[List[VolumeMount]] = None, parameters: Optional[dict] = None, - **kwargs + **kwargs, ): self.credentials = credentials self.syslog_drain_url = syslog_drain_url @@ -278,7 +278,7 @@ def __init__( plan_updateable: bool = False, instances_retrievable: bool = False, bindings_retrievable: bool = False, - **kwargs + **kwargs, ): """ :param requires: syslog_drain, route_forwarding or volume_mount @@ -420,7 +420,7 @@ def last_operation( operation_data: Optional[str], service_id: Optional[str], plan_id: Optional[str], - **kwargs + **kwargs, ) -> LastOperation: """ Further readings `CF Broker API#LastOperation `_ @@ -441,7 +441,7 @@ def last_binding_operation( operation_data: Optional[str], service_id: Optional[str], plan_id: Optional[str], - **kwargs + **kwargs, ) -> LastOperation: """ Further readings `CF Broker API#LastOperationForBindings `_ diff --git a/tests/test_integration_using_async_flow.py b/tests/test_integration_using_async_flow.py index 07d3dde..359cb55 100644 --- a/tests/test_integration_using_async_flow.py +++ b/tests/test_integration_using_async_flow.py @@ -86,7 +86,7 @@ def test_lifecycle(self): # GET BINDING response = requests.get( "http://localhost:5003/v2/service_instances/{}/service_bindings/{}".format(instance_guid, binding_guid), - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.OK, response.status_code) self.assertDictEqual({}, response.json()) @@ -118,7 +118,7 @@ def check_unbind(self, binding_guid, instance_guid): "plan_id": self.plan_guid, "accepts_incomplete": "true", }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.ACCEPTED, response.status_code) operation = response.json().get("operation") @@ -135,7 +135,7 @@ def check_last_operation_after_bind(self, binding_guid, instance_guid, operation "plan_id": self.plan_guid, "operation": operation, }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.OK, response.status_code) self.assertEqual("succeeded", response.json()["state"]) @@ -150,7 +150,7 @@ def check_last_operation_after_unbind(self, binding_guid, instance_guid, operati "plan_id": self.plan_guid, "operation": operation, }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.OK, response.status_code) self.assertEqual("succeeded", response.json()["state"]) @@ -161,7 +161,7 @@ def check_bind(self, binding_guid, instance_guid): instance_guid, binding_guid ), data=json.dumps({"service_id": self.service_guid, "plan_id": self.plan_guid}), - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.ACCEPTED, response.status_code) operation = response.json().get("operation") @@ -176,7 +176,7 @@ def check_deprovision_after_deprovision_done(self, instance_guid): "plan_id": self.plan_guid, "accepts_incomplete": "true", }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.GONE, response.status_code) @@ -188,7 +188,7 @@ def check_deprovision(self, instance_guid, operation): "plan_id": self.plan_guid, "accepts_incomplete": "true", }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.ACCEPTED, response.status_code) operation = response.json()["operation"] @@ -203,7 +203,7 @@ def check_last_operation_after_deprovision(self, instance_guid, operation): "plan_id": self.plan_guid, "operation": operation, }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.GONE, response.status_code) self.assertEqual("succeeded", response.json()["state"]) @@ -216,7 +216,7 @@ def check_last_operation_after_provision(self, instance_guid, operation): "plan_id": self.plan_guid, "operation": operation, }, - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.OK, response.status_code) self.assertEqual("succeeded", response.json()["state"]) @@ -236,7 +236,7 @@ def check_provision(self, instance_guid, org_guid, space_guid, service_guid, pla # } } ), - **self.request_ads + **self.request_ads, ) self.assertEqual(HTTPStatus.ACCEPTED, response.status_code) @@ -355,7 +355,7 @@ def last_operation( operation_data: Optional[str], service_id: Optional[str], plan_id: Optional[str], - **kwargs + **kwargs, ) -> LastOperation: instance = self.service_instances.get(instance_id) if instance is None: @@ -375,7 +375,7 @@ def last_binding_operation( operation_data: Optional[str], service_id: Optional[str], plan_id: Optional[str], - **kwargs + **kwargs, ) -> LastOperation: instance = self.service_instances.get(instance_id, {}) if instance.get("state") == self.BINDING: diff --git a/tests/test_provisioning.py b/tests/test_provisioning.py index 9354f6a..c72926d 100644 --- a/tests/test_provisioning.py +++ b/tests/test_provisioning.py @@ -17,6 +17,7 @@ class ProvisioningTest(BrokerTestCase): def setUp(self): # default config import openbrokerapi.settings + openbrokerapi.settings.DISABLE_SPACE_ORG_GUID_CHECK = False self.broker.catalog.return_value = [