-
-
Notifications
You must be signed in to change notification settings - Fork 11
Enode API Changes #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndrewLester
wants to merge
23
commits into
main
Choose a base branch
from
h4i/enode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
23e4aa8
Create BaseModels for inverter data
neha-vard cd99e2e
Test
neha-vard db19834
Add fake inverter test
anyaparekh 0eddcde
Create httpx auth class
jackypark9852 e1dadaf
Add enode link URL endpoint (#86)
AndrewLester 3541f2f
[WIP] Add put endpoint for editing site (#88)
ericcccsliu f491656
Add post inverters for site endpoint
AndrewLester f4258e3
Add Enode auth test
AndrewLester ec1898c
Fix format
AndrewLester 6715206
Change update inverters for site from post to put
AndrewLester d904f3a
Fix all review comments besides blocking client queries
AndrewLester ab5a5c1
remove redirectresponse class
ericcccsliu e4c0922
lint and format
ericcccsliu 94c3767
Add client fetch to auth dependency and create new dependency for asy…
AndrewLester 6329cb1
Use a pydantic model for client to serialize it in auth
AndrewLester af3ca34
Merge remote-tracking branch 'origin/main' into h4i/enode
AndrewLester 4a04fd5
Add sentry init back and fix tests
AndrewLester 381f849
Add logs for enode link and site inverters
AndrewLester 5d622a2
Use httpx-auth to remove Enode auth code
AndrewLester e185d93
Fix format
AndrewLester 246724d
Add test default values for Enode auth
AndrewLester 7e80ee4
Handle case where no Enode user exists
AndrewLester 819f55f
Fix import order
AndrewLester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from typing import Optional | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| class EnodeAuth(httpx.Auth): | ||
| 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._token_url = token_url | ||
| self._access_token = access_token | ||
|
|
||
| def sync_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 | ||
|
|
||
| if response.status_code == 401: | ||
| # The access token is no longer valid, refresh it | ||
| token_response = yield self._build_refresh_request() | ||
| token_response.read() | ||
| 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 | ||
| yield request | ||
|
|
||
| async def async_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 | ||
|
|
||
| if response.status_code == 401: | ||
| # The access token is no longer valid, refresh it | ||
| token_response = yield self._build_refresh_request() | ||
| await token_response.aread() | ||
| 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 | ||
| yield request | ||
|
|
||
| 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._token_url, data=data))) | ||
| return request | ||
|
|
||
| def _update_access_token(self, response): | ||
| self._access_token = response.json()["access_token"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.