Skip to content

Commit

Permalink
Rename config variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Feb 26, 2024
1 parent fe74b62 commit 19dec65
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 76 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ jobs:
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
GCP_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS_JSON }}
GCP_JSON_CREDENTIALS: ${{ secrets.GCP_JSON_CREDENTIALS }}
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}
GCP_PROJECT_NAME: ${{ secrets.GCP_PROJECT_NAME }}
GCP_PROJECT: ${{ secrets.GCP_PROJECT }}
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_BIGQUERY_TABLE: ${{ secrets.GCP_BIGQUERY_TABLE }}
GCP_BIGQUERY_DATASET: ${{ secrets.GCP_BIGQUERY_DATASET }}
GCP_BUCKET_URL: ${{ secrets.GCP_BUCKET_URL }}
GCP_BUCKET_NAME: ${{ secrets.GCP_BUCKET_NAME }}
GHOST_BASE_URL: ${{ secrets.GHOST_BASE_URL }}
GHOST_ADMIN_BASE_URL: ${{ secrets.GHOST_ADMIN_BASE_URL }}
GHOST_ADMIN_API_URL: ${{ secrets.GHOST_ADMIN_API_URL }}
GHOST_CONTENT_API_URL: ${{ secrets.GHOST_CONTENT_API_URL }}
GHOST_CLIENT_ID: ${{ secrets.GHOST_CLIENT_ID }}
GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }}
GHOST_CONTENT_API_KEY: ${{ secrets.GHOST_CONTENT_API_KEY }}
GHOST_API_USERNAME: ${{ secrets.GHOST_API_USERNAME }}
GHOST_API_PASSWORD: ${{ secrets.GHOST_API_PASSWORD }}
GHOST_ADMIN_API_KEY: ${{ secrets.GHOST_ADMIN_API_KEY }}
GHOST_CONTENT_API_KEY: ${{ secrets.GHOST_CONTENT_API_KEY }}
MAILGUN_EMAIL_SERVER: ${{ secrets.MAILGUN_EMAIL_SERVER }}
MAILGUN_NEWSLETTER_TEMPLATE: ${{ secrets.MAILGUN_NEWSLETTER_TEMPLATE }}
MAILGUN_SENDER_API_KEY: ${{ secrets.MAILGUN_SENDER_API_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions app/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def github_pr(request: Request) -> JSONResponse:
user = payload["sender"].get("login")
pull_request = payload["pull_request"]
repo = payload["repository"]
if user in (settings.GITHUB_USERNAME, "dependabot-preview[bot]", "renovate[bot]"):
if user in (settings.GH_USERNAME, "dependabot-preview[bot]", "renovate[bot]"):
return JSONResponse(
{
"pr": {
Expand Down Expand Up @@ -94,7 +94,7 @@ async def github_issue(request: Request) -> JSONResponse:
user = payload["sender"].get("login")
issue = payload["issue"]
repo = payload["repository"]
if user in (settings.GITHUB_USERNAME, "dependabot-preview[bot]", "renovate[bot]"):
if user in (settings.GH_USERNAME, "dependabot-preview[bot]", "renovate[bot]"):
return JSONResponse(
{
"issue": {
Expand Down
9 changes: 1 addition & 8 deletions app/posts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,8 @@ async def batch_update_metadata() -> JSONResponse:
)


@router.get("/backup/")
async def backup_database():
"""Export JSON backup of database."""
json = ghost.get_json_backup()
return json


@router.get(
"/post/",
"/{post_id}/",
summary="Get a post.",
)
async def get_single_post(post_id: str) -> JSONResponse:
Expand Down
10 changes: 5 additions & 5 deletions clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

# Google Cloud Storage
images = ImageTransformer(
gcp_project_name=settings.GOOGLE_CLOUD_PROJECT_NAME,
gcp_api_credentials=settings.GOOGLE_CLOUD_CREDENTIALS,
gcp_project_name=settings.GCP_PROJECT_NAME,
gcp_api_credentials=settings.GCP_CREDENTIALS,
bucket_name=settings.GCP_BUCKET_NAME,
bucket_url=settings.GCP_BUCKET_URL,
)
Expand All @@ -37,8 +37,8 @@

# Google BigQuery
gbq = bigquery.Client(
project=settings.GOOGLE_CLOUD_PROJECT_NAME,
credentials=settings.GOOGLE_CLOUD_CREDENTIALS,
project=settings.GCP_PROJECT_NAME,
credentials=settings.GCP_CREDENTIALS,
)

# Mailgun SMTP
Expand All @@ -49,4 +49,4 @@
)

# Github
gh = Github(settings.GITHUB_API_KEY)
gh = Github(settings.GH_API_KEY)
26 changes: 0 additions & 26 deletions clients/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,32 +235,6 @@ def create_member(self, body: dict) -> Tuple[str, int]:
LOGGER.error(f"Failed to create Ghost member: {e.response.content}")
return e.response.content, e.response.status_code

def get_json_backup(self) -> Optional[dict]:
"""
Download JSON snapshot of Ghost database.
Optional[dict]
"""
self._https_session()
headers = {
"Authorization": self.session_token,
"accept": "text/html,application/xhtml+xml,application/xml;\
q=0.9,image/webp,image/apng,*/*;\
q=0.8,application/signed-exchange;\
v=b3;q=0.9",
"accept-encoding": "gzip, deflate, br",
"Origin": "hackersandslackers.com",
"Authority": "hackersandslackers.com",
}
endpoint = f"{self.admin_api_url}/db/"
try:
resp = requests.get(endpoint, headers=headers, timeout=20)
return resp.json()
except HTTPError as e:
LOGGER.error(f"HTTPError occurred while fetching JSON backup: {e}")
except Exception as e:
LOGGER.error(f"Unexpected error occurred while fetching JSON backup: {e}")

def get_all_posts(self) -> Optional[List[str]]:
"""
Fetch all Ghost post URLs.
Expand Down
4 changes: 2 additions & 2 deletions clients/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ def mailgun() -> Mailgun:
@pytest.fixture
def gbq() -> gbqClient:
return gbqClient(
project=settings.GOOGLE_CLOUD_PROJECT_NAME,
credentials=settings.GOOGLE_CLOUD_CREDENTIALS,
project=settings.GCP_PROJECT_NAME,
credentials=settings.GCP_CREDENTIALS,
)
8 changes: 4 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Settings(BaseSettings):

# Google Cloud Auth
GCP_PROJECT_NAME: str = getenv("GCP_PROJECT_NAME")
GCP_CREDENTIALS_JSON: str = getenv("GCP_CREDENTIALS_JSON")
GCP_JSON_CREDENTIALS: str = getenv("GCP_JSON_CREDENTIALS")
GCP_CREDENTIALS: Credentials = service_account.Credentials.from_service_account_info(
json.loads(GCP_CREDENTIALS_JSON)
json.loads(GCP_JSON_CREDENTIALS)
)

# Google BigQuery
Expand Down Expand Up @@ -125,8 +125,8 @@ class Settings(BaseSettings):
TWILIO_ACCOUNT_SID: str = getenv("TWILIO_ACCOUNT_SID")

# Github
GITHUB_USERNAME: str = getenv("GH_USERNAME")
GITHUB_API_KEY: str = getenv("GH_API_KEY")
GH_USERNAME: str = getenv("GH_USERNAME")
GH_API_KEY: str = getenv("GH_API_KEY")


settings = Settings()
38 changes: 19 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dnspython==2.6.1 ; python_version >= "3.10" and python_version < "4.0"
email-validator==2.1.0.post1 ; python_version >= "3.10" and python_version < "4.0"
exceptiongroup==1.2.0 ; python_version >= "3.10" and python_version < "3.11"
fastapi-mail==1.4.1 ; python_version >= "3.10" and python_version < "4.0"
fastapi==0.109.2 ; python_version >= "3.10" and python_version < "4.0"
fastapi==0.110.0 ; python_version >= "3.10" and python_version < "4.0"
frozenlist==1.4.1 ; python_version >= "3.10" and python_version < "4.0"
google-api-core==2.17.1 ; python_version >= "3.10" and python_version < "4.0"
google-auth==2.28.1 ; python_version >= "3.10" and python_version < "4.0"
Expand Down Expand Up @@ -70,11 +70,11 @@ pytz==2024.1 ; python_version >= "3.10" and python_version < "4.0"
requests==2.31.0 ; python_version >= "3.10" and python_version < "4.0"
rsa==4.9 ; python_version >= "3.10" and python_version < "4"
six==1.16.0 ; python_version >= "3.10" and python_version < "4.0"
sniffio==1.3.0 ; python_version >= "3.10" and python_version < "4.0"
sniffio==1.3.1 ; python_version >= "3.10" and python_version < "4.0"
sqlalchemy==2.0.27 ; python_version >= "3.10" and python_version < "4.0"
starlette==0.36.3 ; python_version >= "3.10" and python_version < "4.0"
twilio==8.13.0 ; python_version >= "3.10" and python_version < "4.0"
typing-extensions==4.9.0 ; python_version >= "3.10" and python_version < "4.0"
typing-extensions==4.10.0 ; python_version >= "3.10" and python_version < "4.0"
tzdata==2024.1 ; python_version >= "3.10" and python_version < "4.0"
urllib3==2.0.7 ; python_version >= "3.10" and python_version < "4.0"
uvicorn==0.27.1 ; python_version >= "3.10" and python_version < "4.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def gh() -> Github:
:returns: Github
"""
return Github(
settings.GITHUB_API_KEY,
settings.GH_API_KEY,
)


Expand Down

0 comments on commit 19dec65

Please sign in to comment.