From cdc0b8f341ef8487f516f726cb398349819e4d0c Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 10 Apr 2023 22:50:49 -0500 Subject: [PATCH 01/28] Create enode_auth.py --- pv_site_api/enode_auth.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 pv_site_api/enode_auth.py diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py new file mode 100644 index 0000000..e69de29 From 0ddd7fbb896b52f85e16f576bd2c97391a6aaf1c Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 17:00:29 -0500 Subject: [PATCH 02/28] Define basic auth function --- pv_site_api/enode_auth.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index e69de29..6f18350 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -0,0 +1,26 @@ +import httpx + +def get_enode_access_token(client_id: str, client_secret: str) -> str: + # Replace these with your actual credentials + your_client_id = "YOUR_CLIENT_ID" + your_client_secret = "YOUR_CLIENT_SECRET" + + url = "https://oauth.sandbox.enode.io/oauth2/token" + + # Encode the client_id and client_secret using Basic Auth + auth = httpx.BasicAuth(username=your_client_id, password=your_client_secret) + + data = { + "grant_type": "client_credentials" + } + + response = httpx.post(url, auth=auth, data=data) + + # Check if the request was successful + if response.status_code == 200: + print("Access token:", response.json()["access_token"]) + else: + print("Error:", response.status_code, response.text) + + return response.json()["access_token"] + From 181592a9df0d59bb3dc452bb08b2e79fb2389315 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 18:20:36 -0500 Subject: [PATCH 03/28] Get api key from env --- pv_site_api/enode_auth.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 6f18350..ee527aa 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,9 +1,10 @@ +import os import httpx -def get_enode_access_token(client_id: str, client_secret: str) -> str: +def get_enode_access_token() -> str: # Replace these with your actual credentials - your_client_id = "YOUR_CLIENT_ID" - your_client_secret = "YOUR_CLIENT_SECRET" + your_client_id = os.getenv("CLIENTID") + your_client_secret = os.getenv("CLIENTSECRET") url = "https://oauth.sandbox.enode.io/oauth2/token" From 78938ad49b10c1e34727f20a7eab5e544ca14a4b Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 18:35:09 -0500 Subject: [PATCH 04/28] Finish part 1 --- pv_site_api/enode_auth.py | 8 ++++---- pv_site_api/main.py | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index ee527aa..303fd15 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -3,8 +3,8 @@ def get_enode_access_token() -> str: # Replace these with your actual credentials - your_client_id = os.getenv("CLIENTID") - your_client_secret = os.getenv("CLIENTSECRET") + your_client_id = os.getenv("CLIENT_ID") + your_client_secret = os.getenv("CLIENT_SECRET") url = "https://oauth.sandbox.enode.io/oauth2/token" @@ -22,6 +22,6 @@ def get_enode_access_token() -> str: print("Access token:", response.json()["access_token"]) else: print("Error:", response.status_code, response.text) - - return response.json()["access_token"] + + return response.json()["access_token"] diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 1a51a7f..fd384d8 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -42,6 +42,7 @@ from .redoc_theme import get_redoc_html_with_theme from .session import get_session from .utils import get_yesterday_midnight +from .enode_auth import get_enode_access_token load_dotenv() @@ -354,6 +355,10 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res +# @app.get("/enode_token") +# def get_enode_token(session: Session = Depends(get_session)): +# token = get_enode_access_token() +# return {"token": token} # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) From 553cc31382cade43a5fe416bccfc9aff7e2aab82 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:05:23 -0500 Subject: [PATCH 05/28] Create httpx auth class --- pv_site_api/enode_auth.py | 28 +++++++++++++++++++++++----- pv_site_api/main.py | 19 +++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 303fd15..153daca 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,5 +1,7 @@ import os -import httpx + +import httpx + def get_enode_access_token() -> str: # Replace these with your actual credentials @@ -11,9 +13,7 @@ def get_enode_access_token() -> str: # Encode the client_id and client_secret using Basic Auth auth = httpx.BasicAuth(username=your_client_id, password=your_client_secret) - data = { - "grant_type": "client_credentials" - } + data = {"grant_type": "client_credentials"} response = httpx.post(url, auth=auth, data=data) @@ -23,5 +23,23 @@ def get_enode_access_token() -> str: else: print("Error:", response.status_code, response.text) - return response.json()["access_token"] + return response.json()["access_token"] + + +class EnodeAuth(httpx.Auth): + def __init__(self): + self.access_token = get_enode_access_token() + + def auth_flow(self, request): + # Add the Authorization header to the request using the current access token + request.headers["Authorization"] = f"Bearer {self.access_token}" + response = yield request + if response.status_code == 401: + # The access token is no longer valid, refresh it + self.access_token = get_enode_access_token() + # Update the request's Authorization header with the new access token + request.headers["Authorization"] = f"Bearer {self.access_token}" + # Resend the request with the new access token + response = yield request + return response diff --git a/pv_site_api/main.py b/pv_site_api/main.py index fd384d8..76351c2 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -4,6 +4,7 @@ import pandas as pd import sentry_sdk +import httpx from dotenv import load_dotenv from fastapi import Depends, FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware @@ -42,8 +43,9 @@ from .redoc_theme import get_redoc_html_with_theme from .session import get_session from .utils import get_yesterday_midnight -from .enode_auth import get_enode_access_token - +from .enode_auth import ( + EnodeAuth, +) load_dotenv() logger = logging.getLogger(__name__) @@ -95,6 +97,7 @@ def traces_sampler(sampling_context): allow_headers=["*"], ) + # name the api # test that the routes are there on swagger # Following on from #1 now will be good to set out models @@ -355,10 +358,14 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res -# @app.get("/enode_token") -# def get_enode_token(session: Session = Depends(get_session)): -# token = get_enode_access_token() -# return {"token": token} +auth = EnodeAuth() +enode_client = httpx.Client(auth = auth) + + +@app.get("/enode_token") +def test_enode_client(): + return enode_client.get("https://enode-api.production.enode.io/random").json() + # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) From c803632bd57e8e2ca83c1d446919cd8dad11f4fc Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:08:11 -0500 Subject: [PATCH 06/28] Add commnet --- pv_site_api/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 76351c2..99b4933 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -361,7 +361,7 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess auth = EnodeAuth() enode_client = httpx.Client(auth = auth) - +# Test enode client @app.get("/enode_token") def test_enode_client(): return enode_client.get("https://enode-api.production.enode.io/random").json() From 806c37aee4d6d02141d5029b9c08a6ce009e056e Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:11:15 -0500 Subject: [PATCH 07/28] Remove test end point --- pv_site_api/enode_auth.py | 1 - pv_site_api/main.py | 9 ++------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 153daca..279b6a0 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,5 +1,4 @@ import os - import httpx diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 99b4933..4197de9 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -97,6 +97,8 @@ def traces_sampler(sampling_context): allow_headers=["*"], ) +auth = EnodeAuth() +enode_client = httpx.Client(auth = auth) # name the api # test that the routes are there on swagger @@ -358,13 +360,6 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res -auth = EnodeAuth() -enode_client = httpx.Client(auth = auth) - -# Test enode client -@app.get("/enode_token") -def test_enode_client(): - return enode_client.get("https://enode-api.production.enode.io/random").json() # get_status: get the status of the system From 4f663aefb67484db08effe2d6d95910b0ff93568 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:11:44 -0500 Subject: [PATCH 08/28] clean up --- pv_site_api/enode_auth.py | 1 + pv_site_api/main.py | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 279b6a0..153daca 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,4 +1,5 @@ import os + import httpx diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 4197de9..4d42bde 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -2,9 +2,9 @@ import logging import os +import httpx import pandas as pd import sentry_sdk -import httpx from dotenv import load_dotenv from fastapi import Depends, FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware @@ -25,6 +25,7 @@ get_generation_by_sites, site_to_pydantic, ) +from .enode_auth import EnodeAuth from .fake import ( fake_site_uuid, make_fake_forecast, @@ -43,9 +44,7 @@ from .redoc_theme import get_redoc_html_with_theme from .session import get_session from .utils import get_yesterday_midnight -from .enode_auth import ( - EnodeAuth, -) + load_dotenv() logger = logging.getLogger(__name__) @@ -98,7 +97,7 @@ def traces_sampler(sampling_context): ) auth = EnodeAuth() -enode_client = httpx.Client(auth = auth) +enode_client = httpx.Client(auth=auth) # name the api # test that the routes are there on swagger @@ -361,7 +360,6 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess return res - # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) def get_status(session: Session = Depends(get_session)): From ed843753d12124fbff8b3ccd9bccd08e2c483976 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:17:54 -0500 Subject: [PATCH 09/28] Remove print messages --- pv_site_api/enode_auth.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 153daca..7bfa26e 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -17,12 +17,6 @@ def get_enode_access_token() -> str: response = httpx.post(url, auth=auth, data=data) - # Check if the request was successful - if response.status_code == 200: - print("Access token:", response.json()["access_token"]) - else: - print("Error:", response.status_code, response.text) - return response.json()["access_token"] From 97fa1695faedb8c4d26290dd2e225b2fc45158e5 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:23:46 -0500 Subject: [PATCH 10/28] poetry lock && install --- poetry.lock | 10 +++++----- pv_site_api/main.py | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index ed6ba62..ff346a7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. [[package]] name = "anyio" @@ -781,14 +781,14 @@ files = [ [[package]] name = "packaging" -version = "23.0" +version = "23.1" description = "Core utilities for Python packages" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "packaging-23.0-py3-none-any.whl", hash = "sha256:714ac14496c3e68c99c29b00845f7a2b85f3bb6f1078fd9f72fd20f0570002b2"}, - {file = "packaging-23.0.tar.gz", hash = "sha256:b6ad297f8907de0fa2fe1ccbd26fdaf387f5f47c7275fedf8cce89f99446cf97"}, + {file = "packaging-23.1-py3-none-any.whl", hash = "sha256:994793af429502c4ea2ebf6bf664629d07c1a9fe974af92966e4b8d2df7edc61"}, + {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"}, ] [[package]] @@ -1085,7 +1085,7 @@ sqlalchemy = "1.4.46" type = "git" url = "https://github.com/openclimatefix/pv-site-datamodel.git" reference = "enode-updates" -resolved_reference = "83e91e390106e76637495de6baeb1e4afe337836" +resolved_reference = "613aa36152da107b8d7efae41d486fbfb9cbfe92" [[package]] name = "pydantic" diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 4d42bde..8f1728c 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -96,8 +96,7 @@ def traces_sampler(sampling_context): allow_headers=["*"], ) -auth = EnodeAuth() -enode_client = httpx.Client(auth=auth) +enode_client = httpx.Client(auth=EnodeAuth()) # name the api # test that the routes are there on swagger From 1ac31c0ea66ce64df70db5aae66802b94a0bc3f0 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:31:46 -0500 Subject: [PATCH 11/28] Make getenv set variable to str --- .coverage | Bin 0 -> 53248 bytes coverage.xml | 394 ++++++++++++++++++++++++++++++++++++++ pv_site_api/enode_auth.py | 4 +- 3 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 .coverage create mode 100644 coverage.xml diff --git a/.coverage b/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..c591d2de665adf5d6161460252603d6bbb329eae GIT binary patch literal 53248 zcmeI4Ux*vW9mjXIE3Ni)(%4*#d_BTVAj$cf`;$xBw5d~SH$EGm)4FL*Q&Px!C5=w& z)9%WV6&>EVw6x>2_!2Qks zIh|}@FmfP{^IfFb+1Z)j{(hhN{bn?hcE9oXV@@P^(+^xb;twi26jfFBajqzeN$)bf zv(2E4o*mF$-ICufYbpy*td!X|mGQ#&74}s5D4QSuarxfT`El3$Zs|qCHtTc(8wh{^ z2!OyRn?V2ZaicmpsXq6e$gZ_T6xekUBx(84uP^UEw#<+1|MFwYJSpRQ#yD;B^L#%K z{L{Q60^W4mf;(QrsoRm`t@5ZPvfABHG~`4_Wi-{viVJajnX{Y*wTi?liRc85YX?2P zCVF#mh4gBXSdWqd5+a;cPuAdj(&n=~5KR#XuP(wwi#<+bc5L>{Gh;?|VnRJDVw>!s zPOs9CHB>M#<#3Y()%~C$wXX%XS8s`Mj@z3S)_u}*JxZ(%e0MSOdE4<~GriD>9N*(& zUDUggXk6F8ISDP>2;Np}NY-&_(D9^YdaW&V292-NGOeCAZjy4IpJ5#|l$WN)vCdxC ztr7AQUAH4Uhgu{Tj{NOfZr3*QQ)6$qZ?4mq1AB+MGea(WG-=iKoReL#+4*yP&~h#| z!}I63G=eHOu@Pw+6SBmxUWSc&3S#~$_<710D-&&$%{P~?lqdGmUo;?{mio|2p zoG9GPm_tspS-g$w$n)F#jf|3ECy`OqZgamGhm35^lg=S;-WoHD84Np+fyVu`B5C@O zdYe?1bl|nNUmNzd*keLL0YYOzR;}6f>M~S9X+zyVB?5a@ETm_XVd0~8Byyc4vrt{0 z-p+M4UBFt}%#QUZ3r2NnN`20Z-6-v?bY~2?P}Y;z8Ah{HuCT*ykPRdsG)QJG2BTya zBk373XWl4O_fKtSPFl}eN;Ad2p&Qj*yVQOX5prCT@BEMvvSbhfS4{*ru71akTKrnw zWicr}lP^^F?%Gaqse-j6)54i==VF!5PR8_I8uaB`8&X-83{*ZMdh@63HjO47+X*OS zX$($g04^&wY^rS6{B9KcuRM(1Q_ejDeG>tLmTstd$X&@u)Ng1oBW@4SP$wdzH$0+Es_@a#K z+Fm1_ujDkGNTsn~2B*AEGKf$^K0`qnQixt9GZUJgl_ORrf1yK6q*T{#B;hVQWsAhq zEpd&wWHvfrMO}vX*2jSII^BQLaC&8rA#m zQ~TXC7?W|v3TaYz?M&_TFgN5RSDhUA%TXF|>C?_uKauRV;E;#O73AQS^k6Nakkv{* z>x|9H1-{BIEA+w!0w4eaAOHd&00JNY0w4eaAOHd&aQhL^)SPO_^?#22Rbl_41RDr| z00@8p2!H?xfB*=900@8p2!O!HlfZaRyOU*q@wlI<+Eg|D6Ts&d9$0vAjI7GBiwe8Q z{`2uP5L$x(2!H?xfB*=900@8p2!H?xfB*<&1je;H)$Ch<+?Y0Hre6Zc-~Y{WTVdx| z!0xU5q4GlIU_~jvL`B#@00ck)1V8`;KmY_l00ck)1V$uq(A1Uw&c&ARip3LleXZBA zgSCf0|Jer?TXggp$L-klXt8r@o}S_&=IxF{c}wOknGXfszVCZVqY4q8--w^9(jrk`)k)M{ zql)VE8nzcXb;~7@v3)BV$s3ut)u>r5(Wb`}#jJ8S!^*WC=>msT5;8HWftKZXPGngm zNdEqBmR*It!e%Pps~los<&Wi;%WmaHp6)kd9H1EpfB*=900@8p2!H?xfB*>G_5=>; z{hjKli?+e~-#nuCCr6euy#6mP>;3Y`va&wfB*=900@8p2!H?xfB*=900`WM1T?K|#`piTg9`f} zdzJl&JbN{^Z z#Qi%u_v|x!C*C)oJ@flt8|%;fPEmG0a{0iZ(e_B^4#0+PCtEl_wM7r z)ppav8kD>9s&1N+w$0;$1GM(-#2o@Bhk + + + + + /home/jackypark9852/hack4impact/pv-site-api/pv_site_api + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 7bfa26e..6a97b57 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -5,8 +5,8 @@ def get_enode_access_token() -> str: # Replace these with your actual credentials - your_client_id = os.getenv("CLIENT_ID") - your_client_secret = os.getenv("CLIENT_SECRET") + your_client_id = os.getenv("CLIENT_ID") if os.getenv("CLIENT_ID") != None else "" + your_client_secret = os.getenv("CLIENT_SECRET") if os.getenv("CLIENT_SECRET") != None else "" url = "https://oauth.sandbox.enode.io/oauth2/token" From 233c7ed38c15d331e3720cc1f335128797bffdce Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:34:23 -0500 Subject: [PATCH 12/28] make format --- pv_site_api/enode_auth.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 6a97b57..dc5c615 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -5,13 +5,13 @@ def get_enode_access_token() -> str: # Replace these with your actual credentials - your_client_id = os.getenv("CLIENT_ID") if os.getenv("CLIENT_ID") != None else "" - your_client_secret = os.getenv("CLIENT_SECRET") if os.getenv("CLIENT_SECRET") != None else "" + client_id = os.getenv("CLIENT_ID") if os.getenv("CLIENT_ID") is not None else "" + client_secret = os.getenv("CLIENT_SECRET") if os.getenv("CLIENT_SECRET") is not None else "" url = "https://oauth.sandbox.enode.io/oauth2/token" # Encode the client_id and client_secret using Basic Auth - auth = httpx.BasicAuth(username=your_client_id, password=your_client_secret) + auth = httpx.BasicAuth(username=client_id, password=client_secret) data = {"grant_type": "client_credentials"} From 0849563be2b1c013c054df3f4c5e7e35046f76e2 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:37:38 -0500 Subject: [PATCH 13/28] Comment out enode client in main --- pv_site_api/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 8f1728c..eed50e4 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -96,7 +96,8 @@ def traces_sampler(sampling_context): allow_headers=["*"], ) -enode_client = httpx.Client(auth=EnodeAuth()) +# Uncomment once environment variables are set for enode +# enode_client = httpx.Client(auth=EnodeAuth()) # name the api # test that the routes are there on swagger From d43a9e73c9bd694d3890e1bb685f36857cca7fe4 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:39:35 -0500 Subject: [PATCH 14/28] lint and format --- pv_site_api/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pv_site_api/main.py b/pv_site_api/main.py index eed50e4..8fb3ace 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -2,7 +2,6 @@ import logging import os -import httpx import pandas as pd import sentry_sdk from dotenv import load_dotenv @@ -25,7 +24,6 @@ get_generation_by_sites, site_to_pydantic, ) -from .enode_auth import EnodeAuth from .fake import ( fake_site_uuid, make_fake_forecast, From 69ee29ca91cbe1d740c358eb83643366b4e99b81 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:42:21 -0500 Subject: [PATCH 15/28] Remove unecessary check --- pv_site_api/enode_auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index dc5c615..0427cad 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -5,8 +5,8 @@ def get_enode_access_token() -> str: # Replace these with your actual credentials - client_id = os.getenv("CLIENT_ID") if os.getenv("CLIENT_ID") is not None else "" - client_secret = os.getenv("CLIENT_SECRET") if os.getenv("CLIENT_SECRET") is not None else "" + client_id = os.getenv("CLIENT_ID") + client_secret = os.getenv("CLIENT_SECRET") url = "https://oauth.sandbox.enode.io/oauth2/token" From 47e497e626f3a1e2955f4b7d9673af835e0594b6 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:44:34 -0500 Subject: [PATCH 16/28] Remove test files --- .coverage | Bin 53248 -> 0 bytes coverage.xml | 394 --------------------------------------------------- 2 files changed, 394 deletions(-) delete mode 100644 .coverage delete mode 100644 coverage.xml diff --git a/.coverage b/.coverage deleted file mode 100644 index c591d2de665adf5d6161460252603d6bbb329eae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 53248 zcmeI4Ux*vW9mjXIE3Ni)(%4*#d_BTVAj$cf`;$xBw5d~SH$EGm)4FL*Q&Px!C5=w& z)9%WV6&>EVw6x>2_!2Qks zIh|}@FmfP{^IfFb+1Z)j{(hhN{bn?hcE9oXV@@P^(+^xb;twi26jfFBajqzeN$)bf zv(2E4o*mF$-ICufYbpy*td!X|mGQ#&74}s5D4QSuarxfT`El3$Zs|qCHtTc(8wh{^ z2!OyRn?V2ZaicmpsXq6e$gZ_T6xekUBx(84uP^UEw#<+1|MFwYJSpRQ#yD;B^L#%K z{L{Q60^W4mf;(QrsoRm`t@5ZPvfABHG~`4_Wi-{viVJajnX{Y*wTi?liRc85YX?2P zCVF#mh4gBXSdWqd5+a;cPuAdj(&n=~5KR#XuP(wwi#<+bc5L>{Gh;?|VnRJDVw>!s zPOs9CHB>M#<#3Y()%~C$wXX%XS8s`Mj@z3S)_u}*JxZ(%e0MSOdE4<~GriD>9N*(& zUDUggXk6F8ISDP>2;Np}NY-&_(D9^YdaW&V292-NGOeCAZjy4IpJ5#|l$WN)vCdxC ztr7AQUAH4Uhgu{Tj{NOfZr3*QQ)6$qZ?4mq1AB+MGea(WG-=iKoReL#+4*yP&~h#| z!}I63G=eHOu@Pw+6SBmxUWSc&3S#~$_<710D-&&$%{P~?lqdGmUo;?{mio|2p zoG9GPm_tspS-g$w$n)F#jf|3ECy`OqZgamGhm35^lg=S;-WoHD84Np+fyVu`B5C@O zdYe?1bl|nNUmNzd*keLL0YYOzR;}6f>M~S9X+zyVB?5a@ETm_XVd0~8Byyc4vrt{0 z-p+M4UBFt}%#QUZ3r2NnN`20Z-6-v?bY~2?P}Y;z8Ah{HuCT*ykPRdsG)QJG2BTya zBk373XWl4O_fKtSPFl}eN;Ad2p&Qj*yVQOX5prCT@BEMvvSbhfS4{*ru71akTKrnw zWicr}lP^^F?%Gaqse-j6)54i==VF!5PR8_I8uaB`8&X-83{*ZMdh@63HjO47+X*OS zX$($g04^&wY^rS6{B9KcuRM(1Q_ejDeG>tLmTstd$X&@u)Ng1oBW@4SP$wdzH$0+Es_@a#K z+Fm1_ujDkGNTsn~2B*AEGKf$^K0`qnQixt9GZUJgl_ORrf1yK6q*T{#B;hVQWsAhq zEpd&wWHvfrMO}vX*2jSII^BQLaC&8rA#m zQ~TXC7?W|v3TaYz?M&_TFgN5RSDhUA%TXF|>C?_uKauRV;E;#O73AQS^k6Nakkv{* z>x|9H1-{BIEA+w!0w4eaAOHd&00JNY0w4eaAOHd&aQhL^)SPO_^?#22Rbl_41RDr| z00@8p2!H?xfB*=900@8p2!O!HlfZaRyOU*q@wlI<+Eg|D6Ts&d9$0vAjI7GBiwe8Q z{`2uP5L$x(2!H?xfB*=900@8p2!H?xfB*<&1je;H)$Ch<+?Y0Hre6Zc-~Y{WTVdx| z!0xU5q4GlIU_~jvL`B#@00ck)1V8`;KmY_l00ck)1V$uq(A1Uw&c&ARip3LleXZBA zgSCf0|Jer?TXggp$L-klXt8r@o}S_&=IxF{c}wOknGXfszVCZVqY4q8--w^9(jrk`)k)M{ zql)VE8nzcXb;~7@v3)BV$s3ut)u>r5(Wb`}#jJ8S!^*WC=>msT5;8HWftKZXPGngm zNdEqBmR*It!e%Pps~los<&Wi;%WmaHp6)kd9H1EpfB*=900@8p2!H?xfB*>G_5=>; z{hjKli?+e~-#nuCCr6euy#6mP>;3Y`va&wfB*=900@8p2!H?xfB*=900`WM1T?K|#`piTg9`f} zdzJl&JbN{^Z z#Qi%u_v|x!C*C)oJ@flt8|%;fPEmG0a{0iZ(e_B^4#0+PCtEl_wM7r z)ppav8kD>9s&1N+w$0;$1GM(-#2o@Bhk - - - - - /home/jackypark9852/hack4impact/pv-site-api/pv_site_api - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 742def9fec8ffa509d3bdb92999a0d84412c96c3 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 13 Apr 2023 19:54:01 -0500 Subject: [PATCH 17/28] Use env var for enode token url --- pv_site_api/enode_auth.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 0427cad..83c9d8f 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -4,11 +4,10 @@ def get_enode_access_token() -> str: - # Replace these with your actual credentials + # TODO: Add environment variables client_id = os.getenv("CLIENT_ID") client_secret = os.getenv("CLIENT_SECRET") - - url = "https://oauth.sandbox.enode.io/oauth2/token" + url = os.getenv("ENODE_TOKEN_URL") # Encode the client_id and client_secret using Basic Auth auth = httpx.BasicAuth(username=client_id, password=client_secret) From 96e87e506fe710ea01f46b0f52c34a599a14e217 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 21:39:14 -0500 Subject: [PATCH 18/28] Change get_enode_access_token to return request --- pv_site_api/enode_auth.py | 27 ++++++++++++++++++--------- pv_site_api/main.py | 7 ++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 83c9d8f..265c4ff 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -8,15 +8,13 @@ def get_enode_access_token() -> str: client_id = os.getenv("CLIENT_ID") client_secret = os.getenv("CLIENT_SECRET") url = os.getenv("ENODE_TOKEN_URL") + basic_auth = httpx.BasicAuth(client_id, client_secret); - # Encode the client_id and client_secret using Basic Auth - auth = httpx.BasicAuth(username=client_id, password=client_secret) - data = {"grant_type": "client_credentials"} - - response = httpx.post(url, auth=auth, data=data) - - return response.json()["access_token"] + data = {"grant_type": "client_credentials"} + temp = basic_auth.auth_flow(httpx.Request("POST", url, data=data)) + request = next(temp) + return request class EnodeAuth(httpx.Auth): @@ -28,9 +26,20 @@ def auth_flow(self, request): request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request - if response.status_code == 401: + # if response.status_code == 401: + # # If the server issues a 401 response then resend the request, + # # with a custom `X-Authentication` header. + # request.headers['X-Authentication'] = self.token + # yield request + + if response.status_code == 404: + # The access token is no longer valid, refresh it - self.access_token = get_enode_access_token() + token_request = get_enode_access_token() + token_response = yield token_request + token_response.read() + self.access_token = token_response.json()["access_token"] + print(f"New access token: {self.access_token}") # Update the request's Authorization header with the new access token request.headers["Authorization"] = f"Bearer {self.access_token}" # Resend the request with the new access token diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 8fb3ace..f8b899a 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -4,6 +4,7 @@ import pandas as pd import sentry_sdk +import httpx from dotenv import load_dotenv from fastapi import Depends, FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware @@ -17,6 +18,7 @@ from sqlalchemy.orm import Session import pv_site_api +from pv_site_api.enode_auth import EnodeAuth from ._db_helpers import ( does_site_exist, @@ -95,7 +97,7 @@ def traces_sampler(sampling_context): ) # Uncomment once environment variables are set for enode -# enode_client = httpx.Client(auth=EnodeAuth()) +enode_client = httpx.Client(auth=EnodeAuth()) # name the api # test that the routes are there on swagger @@ -357,6 +359,9 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res +@app.get("/test_enode") +def test_enode(): + enode_client.get("https://enode-api.production.enode.io/random"); # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) From 8cd01cac27fddf539df6de0c1e6d564185e10907 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 21:55:36 -0500 Subject: [PATCH 19/28] Refactor get_enode_access_token() into EnodeAuth class --- pv_site_api/enode_auth.py | 46 +++++++++++++++++---------------------- pv_site_api/main.py | 2 +- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 265c4ff..00c8e73 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -3,45 +3,39 @@ import httpx -def get_enode_access_token() -> str: - # TODO: Add environment variables - client_id = os.getenv("CLIENT_ID") - client_secret = os.getenv("CLIENT_SECRET") - url = os.getenv("ENODE_TOKEN_URL") - basic_auth = httpx.BasicAuth(client_id, client_secret); - - - data = {"grant_type": "client_credentials"} - temp = basic_auth.auth_flow(httpx.Request("POST", url, data=data)) - request = next(temp) - return request class EnodeAuth(httpx.Auth): - def __init__(self): - self.access_token = get_enode_access_token() + def __init__(self, access_token): + self.access_token = access_token def auth_flow(self, request): # Add the Authorization header to the request using the current access token request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request - # if response.status_code == 401: - # # If the server issues a 401 response then resend the request, - # # with a custom `X-Authentication` header. - # request.headers['X-Authentication'] = self.token - # yield request - if response.status_code == 404: - # The access token is no longer valid, refresh it - token_request = get_enode_access_token() - token_response = yield token_request - token_response.read() - self.access_token = token_response.json()["access_token"] - print(f"New access token: {self.access_token}") + token_response = yield self._build_refresh_request() + self._update_access_token(token_response) # Update the request's Authorization header with the new access token request.headers["Authorization"] = f"Bearer {self.access_token}" # Resend the request with the new access token response = yield request return response + + + def _build_refresh_request(self): + # TODO: Add environment variables + client_id = os.getenv("CLIENT_ID") + client_secret = os.getenv("CLIENT_SECRET") + basic_auth = httpx.BasicAuth(client_id, client_secret); + url = os.getenv("ENODE_TOKEN_URL") + data = {"grant_type": "client_credentials"} + request = next(basic_auth.auth_flow(httpx.Request("POST", url, data=data))) + return request + + def _update_access_token(self, response): + response.read() + self.access_token = response.json()["access_token"] + print(f"New access token: {self.access_token}") diff --git a/pv_site_api/main.py b/pv_site_api/main.py index f8b899a..ef9c193 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -97,7 +97,7 @@ def traces_sampler(sampling_context): ) # Uncomment once environment variables are set for enode -enode_client = httpx.Client(auth=EnodeAuth()) +enode_client = httpx.Client(auth=EnodeAuth("abc")) # name the api # test that the routes are there on swagger From 4aae6b3f28b4b156d2da47260fb1629de40a0af0 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 21:56:26 -0500 Subject: [PATCH 20/28] change 404 to 401 --- pv_site_api/enode_auth.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 00c8e73..d0058a4 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -2,9 +2,6 @@ import httpx - - - class EnodeAuth(httpx.Auth): def __init__(self, access_token): self.access_token = access_token @@ -14,7 +11,7 @@ def auth_flow(self, request): request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request - if response.status_code == 404: + if response.status_code == 401: # The access token is no longer valid, refresh it token_response = yield self._build_refresh_request() self._update_access_token(token_response) From c016e9cfba7fca3389dc02257023736b981085ad Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 22:01:23 -0500 Subject: [PATCH 21/28] format --- pv_site_api/enode_auth.py | 12 ++++++------ pv_site_api/main.py | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index d0058a4..10ed668 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -2,6 +2,7 @@ import httpx + class EnodeAuth(httpx.Auth): def __init__(self, access_token): self.access_token = access_token @@ -11,7 +12,7 @@ def auth_flow(self, request): request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request - if response.status_code == 401: + if response.status_code == 404: # The access token is no longer valid, refresh it token_response = yield self._build_refresh_request() self._update_access_token(token_response) @@ -20,18 +21,17 @@ def auth_flow(self, request): # Resend the request with the new access token response = yield request return response - - + def _build_refresh_request(self): # TODO: Add environment variables client_id = os.getenv("CLIENT_ID") client_secret = os.getenv("CLIENT_SECRET") - basic_auth = httpx.BasicAuth(client_id, client_secret); + basic_auth = httpx.BasicAuth(client_id, client_secret) url = os.getenv("ENODE_TOKEN_URL") - data = {"grant_type": "client_credentials"} + data = {"grant_type": "client_credentials"} request = next(basic_auth.auth_flow(httpx.Request("POST", url, data=data))) return request - + def _update_access_token(self, response): response.read() self.access_token = response.json()["access_token"] diff --git a/pv_site_api/main.py b/pv_site_api/main.py index ef9c193..848a473 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -2,9 +2,9 @@ import logging import os +import httpx import pandas as pd import sentry_sdk -import httpx from dotenv import load_dotenv from fastapi import Depends, FastAPI, HTTPException from fastapi.middleware.cors import CORSMiddleware @@ -359,9 +359,11 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res -@app.get("/test_enode") + +@app.get("/test_enode") def test_enode(): - enode_client.get("https://enode-api.production.enode.io/random"); + enode_client.get("https://enode-api.production.enode.io/random") + # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) From 7e1b845b7b9418acf7e5cd4a3fc40f71818522a3 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 22:02:50 -0500 Subject: [PATCH 22/28] Remove test code --- pv_site_api/main.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 848a473..70cb2df 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -2,7 +2,6 @@ import logging import os -import httpx import pandas as pd import sentry_sdk from dotenv import load_dotenv @@ -18,7 +17,6 @@ from sqlalchemy.orm import Session import pv_site_api -from pv_site_api.enode_auth import EnodeAuth from ._db_helpers import ( does_site_exist, @@ -96,9 +94,6 @@ def traces_sampler(sampling_context): allow_headers=["*"], ) -# Uncomment once environment variables are set for enode -enode_client = httpx.Client(auth=EnodeAuth("abc")) - # name the api # test that the routes are there on swagger # Following on from #1 now will be good to set out models @@ -359,12 +354,6 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res - -@app.get("/test_enode") -def test_enode(): - enode_client.get("https://enode-api.production.enode.io/random") - - # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) def get_status(session: Session = Depends(get_session)): From 5877f5d1e7c9c2f4f1d89f51bd5fd90588457aa3 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 22:03:29 -0500 Subject: [PATCH 23/28] Remove print --- pv_site_api/enode_auth.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 10ed668..e754644 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -35,4 +35,3 @@ def _build_refresh_request(self): def _update_access_token(self, response): response.read() self.access_token = response.json()["access_token"] - print(f"New access token: {self.access_token}") From b6f5252553f59c5cd87aa99d390ccf78313bee78 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Mon, 17 Apr 2023 22:03:29 -0500 Subject: [PATCH 24/28] Remove print --- pv_site_api/enode_auth.py | 1 - pv_site_api/main.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 10ed668..e754644 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -35,4 +35,3 @@ def _build_refresh_request(self): def _update_access_token(self, response): response.read() self.access_token = response.json()["access_token"] - print(f"New access token: {self.access_token}") diff --git a/pv_site_api/main.py b/pv_site_api/main.py index 70cb2df..1a51a7f 100644 --- a/pv_site_api/main.py +++ b/pv_site_api/main.py @@ -354,6 +354,7 @@ def get_pv_estimate_clearsky(site_uuid: str, session: Session = Depends(get_sess res = {"clearsky_estimate": pac.to_dict("records")} return res + # get_status: get the status of the system @app.get("/api_status", response_model=PVSiteAPIStatus) def get_status(session: Session = Depends(get_session)): From 03a2785aff3fb2f3d43455c42aa265ab019d86b5 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 20 Apr 2023 15:41:11 -0500 Subject: [PATCH 25/28] Address PR changes --- pv_site_api/enode_auth.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index e754644..f482bd2 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,18 +1,19 @@ import os +from typing import Optional import httpx class EnodeAuth(httpx.Auth): - def __init__(self, access_token): - self.access_token = access_token - + def __init__(self, access_token: Optional[str] = None): + self._access_token = access_token + def auth_flow(self, request): # Add the Authorization header to the request using the current access token request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request - if response.status_code == 404: + if response.status_code == 401: # The access token is no longer valid, refresh it token_response = yield self._build_refresh_request() self._update_access_token(token_response) @@ -23,14 +24,14 @@ def auth_flow(self, request): return response def _build_refresh_request(self): - # TODO: Add environment variables client_id = os.getenv("CLIENT_ID") - client_secret = os.getenv("CLIENT_SECRET") + client_secret = os.getenv("CLIENT_SECRET") basic_auth = httpx.BasicAuth(client_id, client_secret) + url = os.getenv("ENODE_TOKEN_URL") data = {"grant_type": "client_credentials"} request = next(basic_auth.auth_flow(httpx.Request("POST", url, data=data))) - return request + return request def _update_access_token(self, response): response.read() From 643ecb40b7c3591edc1093f348440cfae9d8a2b2 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 20 Apr 2023 18:42:44 -0500 Subject: [PATCH 26/28] Update enode constructor to take in client_id, secret, and url --- pv_site_api/enode_auth.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index f482bd2..17863cf 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -1,11 +1,13 @@ -import os from typing import Optional import httpx class EnodeAuth(httpx.Auth): - def __init__(self, access_token: Optional[str] = None): + def __init__(self, client_id: str, client_secret: str, enode_token_url: str, access_token: Optional[str] = None): + self._client_id = client_id + self._client_secret = client_secret + self._enode_token_url = enode_token_url self._access_token = access_token def auth_flow(self, request): @@ -24,13 +26,10 @@ def auth_flow(self, request): return response def _build_refresh_request(self): - client_id = os.getenv("CLIENT_ID") - client_secret = os.getenv("CLIENT_SECRET") - basic_auth = httpx.BasicAuth(client_id, client_secret) + basic_auth = httpx.BasicAuth(self._client_id, self._client_secret) - url = os.getenv("ENODE_TOKEN_URL") data = {"grant_type": "client_credentials"} - request = next(basic_auth.auth_flow(httpx.Request("POST", url, data=data))) + request = next(basic_auth.auth_flow(httpx.Request("POST", self._enode_token_url, data=data))) return request def _update_access_token(self, response): From 6fe62cae748f101e0178740600fd84e15f9b0cee Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 20 Apr 2023 18:46:21 -0500 Subject: [PATCH 27/28] Add type hints --- pv_site_api/enode_auth.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pv_site_api/enode_auth.py b/pv_site_api/enode_auth.py index 17863cf..00f6bb4 100644 --- a/pv_site_api/enode_auth.py +++ b/pv_site_api/enode_auth.py @@ -4,13 +4,15 @@ class EnodeAuth(httpx.Auth): - def __init__(self, client_id: str, client_secret: str, enode_token_url: str, access_token: Optional[str] = None): + def __init__( + self, client_id: str, client_secret: str, token_url: str, access_token: Optional[str] = None + ): self._client_id = client_id self._client_secret = client_secret - self._enode_token_url = enode_token_url + self._token_url = token_url self._access_token = access_token - - def auth_flow(self, request): + + def auth_flow(self, request: httpx.Request): # Add the Authorization header to the request using the current access token request.headers["Authorization"] = f"Bearer {self.access_token}" response = yield request @@ -29,8 +31,8 @@ def _build_refresh_request(self): basic_auth = httpx.BasicAuth(self._client_id, self._client_secret) data = {"grant_type": "client_credentials"} - request = next(basic_auth.auth_flow(httpx.Request("POST", self._enode_token_url, data=data))) - return request + request = next(basic_auth.auth_flow(httpx.Request("POST", self._token_url, data=data))) + return request def _update_access_token(self, response): response.read() From c931e79b083f4acf9b5e66e72cc6e39947fed664 Mon Sep 17 00:00:00 2001 From: Jacky Park Date: Thu, 20 Apr 2023 18:52:45 -0500 Subject: [PATCH 28/28] Fix poetry lock --- poetry.lock | 182 ++++++++++++++++++++++++------------------------- pyproject.toml | 2 +- 2 files changed, 90 insertions(+), 94 deletions(-) diff --git a/poetry.lock b/poetry.lock index ff346a7..29a6474 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1068,25 +1068,21 @@ test = ["pytest", "pytest-cov", "pytest-mock", "pytest-remotedata", "pytest-reru [[package]] name = "pvsite-datamodel" -version = "0.1.32" +version = "0.1.33" description = "SDK for interacting with the PVSite database" category = "main" optional = false -python-versions = "^3.10" -files = [] -develop = false +python-versions = ">=3.10,<4.0" +files = [ + {file = "pvsite_datamodel-0.1.33-py3-none-any.whl", hash = "sha256:f24968bef98fe6702df264826f855e517fab7e1fd818aa5cbd00e19a9c645862"}, + {file = "pvsite_datamodel-0.1.33.tar.gz", hash = "sha256:fd78605f8fa3f9d6b3082db678d12dc4cdadf5b1a6ac195b56d73364de68af88"}, +] [package.dependencies] -pandas = "^1.5.3" -psycopg2-binary = "^2.9.5" +pandas = ">=1.5.3,<2.0.0" +psycopg2-binary = ">=2.9.5,<3.0.0" sqlalchemy = "1.4.46" -[package.source] -type = "git" -url = "https://github.com/openclimatefix/pv-site-datamodel.git" -reference = "enode-updates" -resolved_reference = "613aa36152da107b8d7efae41d486fbfb9cbfe92" - [[package]] name = "pydantic" version = "1.10.7" @@ -1142,14 +1138,14 @@ email = ["email-validator (>=1.0.3)"] [[package]] name = "pygments" -version = "2.15.0" +version = "2.15.1" description = "Pygments is a syntax highlighting package written in Python." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "Pygments-2.15.0-py3-none-any.whl", hash = "sha256:77a3299119af881904cd5ecd1ac6a66214b6e9bed1f2db16993b54adede64094"}, - {file = "Pygments-2.15.0.tar.gz", hash = "sha256:f7e36cffc4c517fbc252861b9a6e4644ca0e5abadf9a113c72d1358ad09b9500"}, + {file = "Pygments-2.15.1-py3-none-any.whl", hash = "sha256:db2db3deb4b4179f399a09054b023b6a586b76499d36965813c71aa8ed7b5fd1"}, + {file = "Pygments-2.15.1.tar.gz", hash = "sha256:8ace4d3c1dd481894b2005f560ead0f9f19ee64fe983366be1a21e171d12775c"}, ] [package.extras] @@ -1157,14 +1153,14 @@ plugins = ["importlib-metadata"] [[package]] name = "pytest" -version = "7.3.0" +version = "7.3.1" description = "pytest: simple powerful testing with Python" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.3.0-py3-none-any.whl", hash = "sha256:933051fa1bfbd38a21e73c3960cebdad4cf59483ddba7696c48509727e17f201"}, - {file = "pytest-7.3.0.tar.gz", hash = "sha256:58ecc27ebf0ea643ebfdf7fb1249335da761a00c9f955bcd922349bcb68ee57d"}, + {file = "pytest-7.3.1-py3-none-any.whl", hash = "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362"}, + {file = "pytest-7.3.1.tar.gz", hash = "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"}, ] [package.dependencies] @@ -1421,14 +1417,14 @@ test = ["asv", "gmpy2", "mpmath", "pytest", "pytest-cov", "pytest-xdist", "sciki [[package]] name = "sentry-sdk" -version = "1.19.1" +version = "1.20.0" description = "Python client for Sentry (https://sentry.io)" category = "main" optional = false python-versions = "*" files = [ - {file = "sentry-sdk-1.19.1.tar.gz", hash = "sha256:7ae78bd921981a5010ab540d6bdf3b793659a4db8cccf7f16180702d48a80d84"}, - {file = "sentry_sdk-1.19.1-py2.py3-none-any.whl", hash = "sha256:885a11c69df23e53eb281d003b9ff15a5bdfa43d8a2a53589be52104a1b4582f"}, + {file = "sentry-sdk-1.20.0.tar.gz", hash = "sha256:a3410381ae769a436c0852cce140a5e5e49f566a07fb7c2ab445af1302f6ad89"}, + {file = "sentry_sdk-1.20.0-py2.py3-none-any.whl", hash = "sha256:0ad6bbbe78057b8031a07de7aca6d2a83234e51adc4d436eaf8d8c697184db71"}, ] [package.dependencies] @@ -1823,82 +1819,82 @@ test = ["websockets"] [[package]] name = "websockets" -version = "11.0.1" +version = "11.0.2" description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "websockets-11.0.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:3d30cc1a90bcbf9e22e1f667c1c5a7428e2d37362288b4ebfd5118eb0b11afa9"}, - {file = "websockets-11.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:dc77283a7c7b2b24e00fe8c3c4f7cf36bba4f65125777e906aae4d58d06d0460"}, - {file = "websockets-11.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0929c2ebdf00cedda77bf77685693e38c269011236e7c62182fee5848c29a4fa"}, - {file = "websockets-11.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:db234da3aff01e8483cf0015b75486c04d50dbf90004bd3e5b46d384e1bd6c9e"}, - {file = "websockets-11.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c7fdfbed727ce6b4b5e6622d15a6efb2098b2d9e22ba4dc54b2e3ce80f982045"}, - {file = "websockets-11.0.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d5f3d0d177b3db3d1d02cce7ba6c0063586499ac28afe0c992be74ffc40d9257"}, - {file = "websockets-11.0.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:25ea5dbd3b00c56b034639dc6fe4d1dd095b8205bab1782d9a47cb020695fdf4"}, - {file = "websockets-11.0.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:dbeada3b8f1f6d9497840f761906c4236f912a42da4515520168bc7c525b52b0"}, - {file = "websockets-11.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:892959b627eedcdf98ac7022f9f71f050a59624b380b67862da10c32ea3c221a"}, - {file = "websockets-11.0.1-cp310-cp310-win32.whl", hash = "sha256:fc0a96a6828bfa6f1ccec62b54630bcdcc205d483f5a8806c0a8abb26101c54b"}, - {file = "websockets-11.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:3a88375b648a2c479532943cc19a018df1e5fcea85d5f31963c0b22794d1bdc1"}, - {file = "websockets-11.0.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3cf18bbd44b36749b7b66f047a30a40b799b8c0bd9a1b9173cba86a234b4306b"}, - {file = "websockets-11.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:deb0dd98ea4e76b833f0bfd7a6042b51115360d5dfcc7c1daa72dfc417b3327a"}, - {file = "websockets-11.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:45a85dc6b3ff76239379feb4355aadebc18d6e587c8deb866d11060755f4d3ea"}, - {file = "websockets-11.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d68bd2a3e9fff6f7043c0a711cb1ebba9f202c196a3943d0c885650cd0b6464"}, - {file = "websockets-11.0.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cfd0b9b18d64c51e5cd322e16b5bf4fe490db65c9f7b18fd5382c824062ead7e"}, - {file = "websockets-11.0.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ef0e6253c36e42f2637cfa3ff9b3903df60d05ec040c718999f6a0644ce1c497"}, - {file = "websockets-11.0.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:12180bc1d72c6a9247472c1dee9dfd7fc2e23786f25feee7204406972d8dab39"}, - {file = "websockets-11.0.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:a797da96d4127e517a5cb0965cd03fd6ec21e02667c1258fa0579501537fbe5c"}, - {file = "websockets-11.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:07cc20655fb16aeef1a8f03236ba8671c61d332580b996b6396a5b7967ba4b3d"}, - {file = "websockets-11.0.1-cp311-cp311-win32.whl", hash = "sha256:a01c674e0efe0f14aec7e722ed0e0e272fa2f10e8ea8260837e1f4f5dc4b3e53"}, - {file = "websockets-11.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:2796f097841619acf053245f266a4f66cb27c040f0d9097e5f21301aab95ff43"}, - {file = "websockets-11.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:54d084756c50dfc8086dce97b945f210ca43950154e1e04a44a30c6e6a2bcbb1"}, - {file = "websockets-11.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4fe2aed5963ca267c40a2d29b1ee4e8ab008ac8d5daa284fdda9275201b8a334"}, - {file = "websockets-11.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:84e92dbac318a84fef722f38ca57acef19cbb89527aba5d420b96aa2656970ee"}, - {file = "websockets-11.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec4e87eb9916b481216b1fede7d8913be799915f5216a0c801867cbed8eeb903"}, - {file = "websockets-11.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:d4e0990b6a04b07095c969969da659eecf9069cf8e7b8f49c8f5ee1bb50e3352"}, - {file = "websockets-11.0.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c90343fd0774749d23c1891dd8b3e9210f9afd30986673ce0f9d5857f5cb1562"}, - {file = "websockets-11.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:ac042e8ba9d7f2618e84af27927fdce0f3e03528eb74f343977486c093868389"}, - {file = "websockets-11.0.1-cp37-cp37m-win32.whl", hash = "sha256:385c5391becb9b58e0a4f33345e12762fd857ccf9fbf6fee428669929ba45e4c"}, - {file = "websockets-11.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:aef1602db81096ce3d3847865128c8879635bdad7963fb2b7df290edb9e9150a"}, - {file = "websockets-11.0.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:52ba83ea132390e426f9a7b48848248a2dc0e7120ca8c65d5a8fc1efaa4eb51b"}, - {file = "websockets-11.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:007ed0d62f7e06eeb6e3a848b0d83b9fbd9e14674a59a61326845f27d20d7452"}, - {file = "websockets-11.0.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f888b9565ca1d1c25ab827d184f57f4772ffbfa6baf5710b873b01936cc335ee"}, - {file = "websockets-11.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:db78535b791840a584c48cf3f4215eae38a7e2f43271ecd27ce4ba8a798beaaa"}, - {file = "websockets-11.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fa1c23ed3a02732fba906ec337df65d4cc23f9f453635e1a803c285b59c7d987"}, - {file = "websockets-11.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e039f106d48d3c241f1943bccfb383bd38ec39900d6dcaad0c73cc5fe129f346"}, - {file = "websockets-11.0.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b0ed24a3aa4213029e100257e5e73c5f912e70ca35630081de94b7f9e2cf4a9b"}, - {file = "websockets-11.0.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:d5a3022f9291bf2d35ebf65929297d625e68effd3a5647b8eb8b89d51b09394c"}, - {file = "websockets-11.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:1cb23597819f68ac6a6d133a002a1b3ef12a22850236b083242c93f81f206d5a"}, - {file = "websockets-11.0.1-cp38-cp38-win32.whl", hash = "sha256:349dd1fa56a30d530555988be98013688de67809f384671883f8bf8b8c9de984"}, - {file = "websockets-11.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:87ae582cf2319e45bc457a57232daded27a3c771263cab42fb8864214bbd74ea"}, - {file = "websockets-11.0.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:a88815a0c6253ad1312ef186620832fb347706c177730efec34e3efe75e0e248"}, - {file = "websockets-11.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d5a6fa353b5ef36970c3bd1cd7cecbc08bb8f2f1a3d008b0691208cf34ebf5b0"}, - {file = "websockets-11.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:5ffe6fc5e5fe9f2634cdc59b805e4ba1fcccf3a5622f5f36c3c7c287f606e283"}, - {file = "websockets-11.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b138f4bf8a64c344e12c76283dac279d11adab89ac62ae4a32ac8490d3c94832"}, - {file = "websockets-11.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:aedd94422745da60672a901f53de1f50b16e85408b18672b9b210db4a776b5a6"}, - {file = "websockets-11.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a4667d4e41fa37fa3d836b2603b8b40d6887fa4838496d48791036394f7ace39"}, - {file = "websockets-11.0.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:43e0de552be624e5c0323ff4fcc9f0b4a9a6dc6e0116b8aa2cbb6e0d3d2baf09"}, - {file = "websockets-11.0.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:ceeef57b9aec8f27e523de4da73c518ece7721aefe7064f18aa28baabfe61b94"}, - {file = "websockets-11.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:9d91279d57f6546eaf43671d1de50621e0578f13c2f17c96c458a72d170698d7"}, - {file = "websockets-11.0.1-cp39-cp39-win32.whl", hash = "sha256:29282631da3bfeb5db497e4d3d94d56ee36222fbebd0b51014e68a2e70736fb1"}, - {file = "websockets-11.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:e2654e94c705ce9b768441d8e3a387a84951ca1056efdc4a26a4a6ee723c01b6"}, - {file = "websockets-11.0.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:60a19d4ff5f451254f8623f6aa4169065f73a50ec7b59ab6b9dcddff4aa00267"}, - {file = "websockets-11.0.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2a58e83f82098d062ae5d4cbe7073b8783999c284d6f079f2fefe87cd8957ac8"}, - {file = "websockets-11.0.1-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b91657b65355954e47f0df874917fa200426b3a7f4e68073326a8cfc2f6deef8"}, - {file = "websockets-11.0.1-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:53b8e1ee01eb5b8be5c8a69ae26b0820dbc198d092ad50b3451adc3cdd55d455"}, - {file = "websockets-11.0.1-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:5d8d5d17371ed9eb9f0e3a8d326bdf8172700164c2e705bc7f1905a719a189be"}, - {file = "websockets-11.0.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:e53419201c6c1439148feb99de6b307651a88b8defd41348cc23bbe2a290de1d"}, - {file = "websockets-11.0.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:718d19c494637f28e651031b3df6a791b9e86e0097c65ed5e8ec49b400b1210e"}, - {file = "websockets-11.0.1-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f7b2544eb3e7bc39ce59812371214cd97762080dab90c3afc857890039384753"}, - {file = "websockets-11.0.1-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec4a887d2236e3878c07033ad5566f6b4d5d954b85f92a219519a1745d0c93e9"}, - {file = "websockets-11.0.1-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:ae59a9f0a77ecb0cbdedea7d206a547ff136e8bfbc7d2d98772fb02d398797bb"}, - {file = "websockets-11.0.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ef35cef161f76031f833146f895e7e302196e01c704c00d269c04d8e18f3ac37"}, - {file = "websockets-11.0.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:79b6548e57ab18f071b9bfe3ffe02af7184dd899bc674e2817d8fe7e9e7489ec"}, - {file = "websockets-11.0.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a8d9793f3fb0da16232503df14411dabafed5a81fc9077dc430cfc6f60e71179"}, - {file = "websockets-11.0.1-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42aa05e890fcf1faed8e535c088a1f0f27675827cbacf62d3024eb1e6d4c9e0c"}, - {file = "websockets-11.0.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:5d4f4b341100d313b08149d7031eb6d12738ac758b0c90d2f9be8675f401b019"}, - {file = "websockets-11.0.1-py3-none-any.whl", hash = "sha256:85b4127f7da332feb932eee833c70e5e1670469e8c9de7ef3874aa2a91a6fbb2"}, - {file = "websockets-11.0.1.tar.gz", hash = "sha256:369410925b240b30ef1c1deadbd6331e9cd865ad0b8966bf31e276cc8e0da159"}, + {file = "websockets-11.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:580cc95c58118f8c39106be71e24d0b7e1ad11a155f40a2ee687f99b3e5e432e"}, + {file = "websockets-11.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:143782041e95b63083b02107f31cda999f392903ae331de1307441f3a4557d51"}, + {file = "websockets-11.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8df63dcd955eb6b2e371d95aacf8b7c535e482192cff1b6ce927d8f43fb4f552"}, + {file = "websockets-11.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ca9b2dced5cbbc5094678cc1ec62160f7b0fe4defd601cd28a36fde7ee71bbb5"}, + {file = "websockets-11.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e0eeeea3b01c97fd3b5049a46c908823f68b59bf0e18d79b231d8d6764bc81ee"}, + {file = "websockets-11.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:502683c5dedfc94b9f0f6790efb26aa0591526e8403ad443dce922cd6c0ec83b"}, + {file = "websockets-11.0.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d3cc3e48b6c9f7df8c3798004b9c4b92abca09eeea5e1b0a39698f05b7a33b9d"}, + {file = "websockets-11.0.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:808b8a33c961bbd6d33c55908f7c137569b09ea7dd024bce969969aa04ecf07c"}, + {file = "websockets-11.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:34a6f8996964ccaa40da42ee36aa1572adcb1e213665e24aa2f1037da6080909"}, + {file = "websockets-11.0.2-cp310-cp310-win32.whl", hash = "sha256:8f24cd758cbe1607a91b720537685b64e4d39415649cac9177cd1257317cf30c"}, + {file = "websockets-11.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:3b87cd302f08ea9e74fdc080470eddbed1e165113c1823fb3ee6328bc40ca1d3"}, + {file = "websockets-11.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3565a8f8c7bdde7c29ebe46146bd191290413ee6f8e94cf350609720c075b0a1"}, + {file = "websockets-11.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f97e03d4d5a4f0dca739ea274be9092822f7430b77d25aa02da6775e490f6846"}, + {file = "websockets-11.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:8f392587eb2767afa8a34e909f2fec779f90b630622adc95d8b5e26ea8823cb8"}, + {file = "websockets-11.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7742cd4524622cc7aa71734b51294644492a961243c4fe67874971c4d3045982"}, + {file = "websockets-11.0.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:46dda4bc2030c335abe192b94e98686615f9274f6b56f32f2dd661fb303d9d12"}, + {file = "websockets-11.0.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d6b2bfa1d884c254b841b0ff79373b6b80779088df6704f034858e4d705a4802"}, + {file = "websockets-11.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:1df2413266bf48430ef2a752c49b93086c6bf192d708e4a9920544c74cd2baa6"}, + {file = "websockets-11.0.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:cf45d273202b0c1cec0f03a7972c655b93611f2e996669667414557230a87b88"}, + {file = "websockets-11.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3a09cce3dacb6ad638fdfa3154d9e54a98efe7c8f68f000e55ca9c716496ca67"}, + {file = "websockets-11.0.2-cp311-cp311-win32.whl", hash = "sha256:2174a75d579d811279855df5824676d851a69f52852edb0e7551e0eeac6f59a4"}, + {file = "websockets-11.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:c78ca3037a954a4209b9f900e0eabbc471fb4ebe96914016281df2c974a93e3e"}, + {file = "websockets-11.0.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:3a2100b02d1aaf66dc48ff1b2a72f34f6ebc575a02bc0350cc8e9fbb35940166"}, + {file = "websockets-11.0.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:dca9708eea9f9ed300394d4775beb2667288e998eb6f542cdb6c02027430c599"}, + {file = "websockets-11.0.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:320ddceefd2364d4afe6576195201a3632a6f2e6d207b0c01333e965b22dbc84"}, + {file = "websockets-11.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b2a573c8d71b7af937852b61e7ccb37151d719974146b5dc734aad350ef55a02"}, + {file = "websockets-11.0.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:13bd5bebcd16a4b5e403061b8b9dcc5c77e7a71e3c57e072d8dff23e33f70fba"}, + {file = "websockets-11.0.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:95c09427c1c57206fe04277bf871b396476d5a8857fa1b99703283ee497c7a5d"}, + {file = "websockets-11.0.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:2eb042734e710d39e9bc58deab23a65bd2750e161436101488f8af92f183c239"}, + {file = "websockets-11.0.2-cp37-cp37m-win32.whl", hash = "sha256:5875f623a10b9ba154cb61967f940ab469039f0b5e61c80dd153a65f024d9fb7"}, + {file = "websockets-11.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:634239bc844131863762865b75211a913c536817c0da27f691400d49d256df1d"}, + {file = "websockets-11.0.2-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:3178d965ec204773ab67985a09f5696ca6c3869afeed0bb51703ea404a24e975"}, + {file = "websockets-11.0.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:955fcdb304833df2e172ce2492b7b47b4aab5dcc035a10e093d911a1916f2c87"}, + {file = "websockets-11.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cb46d2c7631b2e6f10f7c8bac7854f7c5e5288f024f1c137d4633c79ead1e3c0"}, + {file = "websockets-11.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:25aae96c1060e85836552a113495db6d857400288161299d77b7b20f2ac569f2"}, + {file = "websockets-11.0.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2abeeae63154b7f63d9f764685b2d299e9141171b8b896688bd8baec6b3e2303"}, + {file = "websockets-11.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:daa1e8ea47507555ed7a34f8b49398d33dff5b8548eae3de1dc0ef0607273a33"}, + {file = "websockets-11.0.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:954eb789c960fa5daaed3cfe336abc066941a5d456ff6be8f0e03dd89886bb4c"}, + {file = "websockets-11.0.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:3ffe251a31f37e65b9b9aca5d2d67fd091c234e530f13d9dce4a67959d5a3fba"}, + {file = "websockets-11.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:adf6385f677ed2e0b021845b36f55c43f171dab3a9ee0ace94da67302f1bc364"}, + {file = "websockets-11.0.2-cp38-cp38-win32.whl", hash = "sha256:aa7b33c1fb2f7b7b9820f93a5d61ffd47f5a91711bc5fa4583bbe0c0601ec0b2"}, + {file = "websockets-11.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:220d5b93764dd70d7617f1663da64256df7e7ea31fc66bc52c0e3750ee134ae3"}, + {file = "websockets-11.0.2-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:0fb4480556825e4e6bf2eebdbeb130d9474c62705100c90e59f2f56459ddab42"}, + {file = "websockets-11.0.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ec00401846569aaf018700249996143f567d50050c5b7b650148989f956547af"}, + {file = "websockets-11.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:87c69f50281126dcdaccd64d951fb57fbce272578d24efc59bce72cf264725d0"}, + {file = "websockets-11.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:232b6ba974f5d09b1b747ac232f3a3d8f86de401d7b565e837cc86988edf37ac"}, + {file = "websockets-11.0.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:392d409178db1e46d1055e51cc850136d302434e12d412a555e5291ab810f622"}, + {file = "websockets-11.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a4fe2442091ff71dee0769a10449420fd5d3b606c590f78dd2b97d94b7455640"}, + {file = "websockets-11.0.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ede13a6998ba2568b21825809d96e69a38dc43184bdeebbde3699c8baa21d015"}, + {file = "websockets-11.0.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:4c54086b2d2aec3c3cb887ad97e9c02c6be9f1d48381c7419a4aa932d31661e4"}, + {file = "websockets-11.0.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e37a76ccd483a6457580077d43bc3dfe1fd784ecb2151fcb9d1c73f424deaeba"}, + {file = "websockets-11.0.2-cp39-cp39-win32.whl", hash = "sha256:d1881518b488a920434a271a6e8a5c9481a67c4f6352ebbdd249b789c0467ddc"}, + {file = "websockets-11.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:25e265686ea385f22a00cc2b719b880797cd1bb53b46dbde969e554fb458bfde"}, + {file = "websockets-11.0.2-pp37-pypy37_pp73-macosx_10_9_x86_64.whl", hash = "sha256:ce69f5c742eefd039dce8622e99d811ef2135b69d10f9aa79fbf2fdcc1e56cd7"}, + {file = "websockets-11.0.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b985ba2b9e972cf99ddffc07df1a314b893095f62c75bc7c5354a9c4647c6503"}, + {file = "websockets-11.0.2-pp37-pypy37_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1b52def56d2a26e0e9c464f90cadb7e628e04f67b0ff3a76a4d9a18dfc35e3dd"}, + {file = "websockets-11.0.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d70a438ef2a22a581d65ad7648e949d4ccd20e3c8ed7a90bbc46df4e60320891"}, + {file = "websockets-11.0.2-pp37-pypy37_pp73-win_amd64.whl", hash = "sha256:752fbf420c71416fb1472fec1b4cb8631c1aa2be7149e0a5ba7e5771d75d2bb9"}, + {file = "websockets-11.0.2-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:dd906b0cdc417ea7a5f13bb3c6ca3b5fd563338dc596996cb0fdd7872d691c0a"}, + {file = "websockets-11.0.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3e79065ff6549dd3c765e7916067e12a9c91df2affea0ac51bcd302aaf7ad207"}, + {file = "websockets-11.0.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:46388a050d9e40316e58a3f0838c63caacb72f94129eb621a659a6e49bad27ce"}, + {file = "websockets-11.0.2-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5c7de298371d913824f71b30f7685bb07ad13969c79679cca5b1f7f94fec012f"}, + {file = "websockets-11.0.2-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:6d872c972c87c393e6a49c1afbdc596432df8c06d0ff7cd05aa18e885e7cfb7c"}, + {file = "websockets-11.0.2-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:b444366b605d2885f0034dd889faf91b4b47668dd125591e2c64bfde611ac7e1"}, + {file = "websockets-11.0.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e8b967a4849db6b567dec3f7dd5d97b15ce653e3497b8ce0814e470d5e074750"}, + {file = "websockets-11.0.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2acdc82099999e44fa7bd8c886f03c70a22b1d53ae74252f389be30d64fd6004"}, + {file = "websockets-11.0.2-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:518ed6782d9916c5721ebd61bb7651d244178b74399028302c8617d0620af291"}, + {file = "websockets-11.0.2-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:58477b041099bb504e1a5ddd8aa86302ed1d5c6995bdd3db2b3084ef0135d277"}, + {file = "websockets-11.0.2-py3-none-any.whl", hash = "sha256:5004c087d17251938a52cce21b3dbdabeecbbe432ce3f5bbbf15d8692c36eac9"}, + {file = "websockets-11.0.2.tar.gz", hash = "sha256:b1a69701eb98ed83dd099de4a686dc892c413d974fa31602bc00aca7cb988ac9"}, ] [[package]] @@ -1989,4 +1985,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "7d40ec6ff03dfcba06a62d9876081b3814157dad550e82e336448b646310f05c" +content-hash = "3f3f08a29e02d314d73afb60d14cf0fddd2f1f474721787d05354162812d7984" diff --git a/pyproject.toml b/pyproject.toml index b39f921..20bd750 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ pydantic = "^1.10.5" uvicorn = {extras = ["standard"], version = "^0.20.0"} psycopg2-binary = "^2.9.5" sqlalchemy = "^1.4.46" -pvsite-datamodel = { git = "https://github.com/openclimatefix/pv-site-datamodel.git", branch = "enode-updates" } +pvsite-datamodel = "^0.1.33" fastapi = "^0.92.0" httpx = "^0.23.3" sentry-sdk = "^1.16.0"