-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only require Heroku API key when accessing Heroku API
- Loading branch information
1 parent
f522e8f
commit 0f4e6bf
Showing
3 changed files
with
38 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,12 +1,35 @@ | ||
import os | ||
import sys | ||
from typing import Any, cast | ||
|
||
import heroku3 | ||
from heroku3.core import Heroku | ||
from rich import print | ||
from rich.text import Text | ||
|
||
try: | ||
heroku = heroku3.from_key(os.environ["HEROKU_API_KEY"]) | ||
except KeyError: | ||
print(Text("Please set $HEROKU_API_KEY to a valid Heroku API key.", style="red")) | ||
sys.exit(1) | ||
__all__ = ["heroku"] | ||
|
||
|
||
class LazyHerokuWrapper: | ||
""" | ||
A lazy heroku wrapper which only requires an API key when it's used | ||
""" | ||
|
||
_heroku = None | ||
|
||
def __get__(self, obj: Any, objtype: Any = None) -> Heroku: | ||
if self._heroku is None: | ||
try: | ||
self._heroku = heroku3.from_key(os.environ["HEROKU_API_KEY"]) | ||
except KeyError: | ||
print( | ||
Text( | ||
"Please set $HEROKU_API_KEY to a valid Heroku API key.", | ||
style="red", | ||
) | ||
) | ||
sys.exit(1) | ||
return self._heroku | ||
|
||
|
||
heroku = cast(Heroku, LazyHerokuWrapper()) |
This file contains 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 |
---|---|---|
@@ -1,11 +1,3 @@ | ||
from requests import Session | ||
|
||
from .models.app import App | ||
|
||
class Heroku: | ||
_session: Session | ||
|
||
def apps(self) -> list[App]: ... | ||
def app(self, id_or_name: str) -> App: ... | ||
from .core import Heroku | ||
|
||
def from_key(api_key: str) -> Heroku: ... |
This file contains 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,9 @@ | ||
from requests import Session | ||
|
||
from .models.app import App | ||
|
||
class Heroku: | ||
_session: Session | ||
|
||
def apps(self) -> list[App]: ... | ||
def app(self, id_or_name: str) -> App: ... |