From 9a800368af4d43b95355a8273cdc996d2735bee7 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Sat, 23 Oct 2021 11:57:33 +0000 Subject: [PATCH 1/7] Change lines: 34, 56, 86 --- picoapi/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/picoapi/api.py b/picoapi/api.py index 7ec0ae0..37f7927 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -31,7 +31,7 @@ def register_uservice(): }, } - requests.put(os.getenv("API_REGISTER_PATH"), json=uservice_definition) + requests.get(os.getenv("API_REGISTER_PATH"), json=uservice_definition) async def healthcheck(): @@ -53,6 +53,7 @@ def __init__( allow_headers: List[str] = [ x for x in os.getenv("API_CORS_ALLOW_HEADERS", "*").split() ], + on_startup = None, *args, **kwargs ) -> None: @@ -82,7 +83,7 @@ def __init__( else: # add the service registration event - self.router.on_event("startup", register_uservice) + self.on_startup = [ register_uservice() ] async def get_services_status(self): return JSONResponse( From 8ccea7b3c720b52f10f2ebf05c446a85c9730379 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Sat, 23 Oct 2021 12:42:02 +0000 Subject: [PATCH 2/7] picoapi/api: change line 82 --- picoapi/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picoapi/api.py b/picoapi/api.py index 37f7927..e9479f2 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -79,7 +79,7 @@ def __init__( # add service registration self.add_api_route("/register", self.add_service) self.add_api_route("/services/status", self.get_services_status) - self.add_api_route("/services/definition", self.get_services_status) + self.add_api_route("/services/definition", self.get_services_openapi) else: # add the service registration event From 7e17256e280e89b1ec223b6c973cf95de7f1d5d4 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Wed, 27 Oct 2021 09:36:04 +0000 Subject: [PATCH 3/7] picoapi/api: Added PUT method to /register route, moved super().__init__ and middleware --- picoapi/api.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/picoapi/api.py b/picoapi/api.py index e9479f2..24846e1 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -31,7 +31,7 @@ def register_uservice(): }, } - requests.get(os.getenv("API_REGISTER_PATH"), json=uservice_definition) + requests.put(os.getenv("API_REGISTER_PATH"), json=uservice_definition) async def healthcheck(): @@ -53,37 +53,39 @@ def __init__( allow_headers: List[str] = [ x for x in os.getenv("API_CORS_ALLOW_HEADERS", "*").split() ], - on_startup = None, *args, **kwargs ) -> None: - # call super class __init__ - super().__init__(*args, **kwargs) - - # add the cors middleware - self.add_middleware( - CORSMiddleware, - allow_origins=allow_origins, - allow_credentials=allow_credentials, - allow_methods=allow_methods, - allow_headers=allow_headers, - ) - self.is_master = is_master self.services = [] self.healthchecks = {} self.add_api_route(api_health_path, healthcheck) if self.is_master: + # call super class __init__ + super().__init__(*args, **kwargs) + # add service registration - self.add_api_route("/register", self.add_service) + self.add_api_route("/register", self.add_service, , methods=["PUT"]) self.add_api_route("/services/status", self.get_services_status) self.add_api_route("/services/definition", self.get_services_openapi) else: # add the service registration event - self.on_startup = [ register_uservice() ] + kwargs["on_startup"] = [register_uservice, *[x for x in kwargs.get("on_startup")]] if kwargs.get("on_startup") else [register_uservice] + + # call super class __init__ + super().__init__(*args, **kwargs) + + # add the cors middleware + self.add_middleware( + CORSMiddleware, + allow_origins=allow_origins, + allow_credentials=allow_credentials, + allow_methods=allow_methods, + allow_headers=allow_headers, + ) async def get_services_status(self): return JSONResponse( From 21e67214a65644f4dfba53e81c490066d5152909 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Wed, 27 Oct 2021 09:49:12 +0000 Subject: [PATCH 4/7] picoapi/api: Added PUT method to /register route, moved super().__init__ and middleware --- picoapi/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picoapi/api.py b/picoapi/api.py index 24846e1..881b199 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -73,7 +73,7 @@ def __init__( else: # add the service registration event - kwargs["on_startup"] = [register_uservice, *[x for x in kwargs.get("on_startup")]] if kwargs.get("on_startup") else [register_uservice] + kwargs["on_startup"] = [register_uservice, *[x for x in kwargs.get("on_startup")]] if kwargs.get("on_startup") else [register_uservice,] # call super class __init__ super().__init__(*args, **kwargs) From c6466321a8863e609da5ef7f165ee4da46d6fc2b Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Wed, 27 Oct 2021 10:04:08 +0000 Subject: [PATCH 5/7] picoapi/api: Correction an error in line 70 --- picoapi/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/picoapi/api.py b/picoapi/api.py index 881b199..6a7a157 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -67,13 +67,13 @@ def __init__( super().__init__(*args, **kwargs) # add service registration - self.add_api_route("/register", self.add_service, , methods=["PUT"]) + self.add_api_route("/register", self.add_service, methods=["PUT"]) self.add_api_route("/services/status", self.get_services_status) self.add_api_route("/services/definition", self.get_services_openapi) else: # add the service registration event - kwargs["on_startup"] = [register_uservice, *[x for x in kwargs.get("on_startup")]] if kwargs.get("on_startup") else [register_uservice,] + kwargs["on_startup"] = [register_uservice, *[x for x in kwargs.get("on_startup")]] if kwargs.get("on_startup") else [register_uservice] # call super class __init__ super().__init__(*args, **kwargs) From fe6cfc9df2495ce1b8408d58fd7615a03187b1d9 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Wed, 27 Oct 2021 10:11:41 +0000 Subject: [PATCH 6/7] picoapi/api: Route "/health" was moved into if else --- picoapi/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/picoapi/api.py b/picoapi/api.py index 6a7a157..832acd5 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -60,13 +60,13 @@ def __init__( self.is_master = is_master self.services = [] self.healthchecks = {} - self.add_api_route(api_health_path, healthcheck) if self.is_master: # call super class __init__ super().__init__(*args, **kwargs) # add service registration + self.add_api_route(api_health_path, healthcheck) self.add_api_route("/register", self.add_service, methods=["PUT"]) self.add_api_route("/services/status", self.get_services_status) self.add_api_route("/services/definition", self.get_services_openapi) @@ -77,6 +77,7 @@ def __init__( # call super class __init__ super().__init__(*args, **kwargs) + self.add_api_route(api_health_path, healthcheck) # add the cors middleware self.add_middleware( From 94817516c9db76f643d5554c065a3bf35c90efd5 Mon Sep 17 00:00:00 2001 From: Wojciech Kiwerski Date: Wed, 27 Oct 2021 10:28:00 +0000 Subject: [PATCH 7/7] picoapi/api: move healthcheck route --- picoapi/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/picoapi/api.py b/picoapi/api.py index 832acd5..5bc1aa5 100644 --- a/picoapi/api.py +++ b/picoapi/api.py @@ -66,7 +66,6 @@ def __init__( super().__init__(*args, **kwargs) # add service registration - self.add_api_route(api_health_path, healthcheck) self.add_api_route("/register", self.add_service, methods=["PUT"]) self.add_api_route("/services/status", self.get_services_status) self.add_api_route("/services/definition", self.get_services_openapi) @@ -77,7 +76,6 @@ def __init__( # call super class __init__ super().__init__(*args, **kwargs) - self.add_api_route(api_health_path, healthcheck) # add the cors middleware self.add_middleware( @@ -86,7 +84,10 @@ def __init__( allow_credentials=allow_credentials, allow_methods=allow_methods, allow_headers=allow_headers, - ) + ) + + # add healthcheck route + self.add_api_route(api_health_path, healthcheck) async def get_services_status(self): return JSONResponse(