Skip to content

Commit

Permalink
pref: Move credentials to config
Browse files Browse the repository at this point in the history
Move API credentials from hardcoded values to environment variables, improving security and flexibility. This change allows for easier management of API keys without modifying the code directly.
  • Loading branch information
RedAtman committed Jul 31, 2024
1 parent 07aa256 commit 3ea7309
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
:doc: https://simperium.com/docs/reference/http/#auth
"""

import base64
import functools
import json
import logging
Expand All @@ -22,16 +21,11 @@
__all__ = ["Simplenote"]


SIMPLENOTE_APP_ID: str = "chalk-bump-f49"
SIMPLENOTE_APP_KEY: str = base64.b64decode("YzhjMmI4NjMzNzE1NGNkYWJjOTg5YjIzZTMwYzZiZjQ=").decode("utf-8")
SIMPLENOTE_BUCKET: str = "note"


class URL:
BASE: str = "simperium.com/1"
AUTH = f"https://auth.{BASE}"
DATA = f"https://api.{BASE}/{SIMPLENOTE_APP_ID}/{SIMPLENOTE_BUCKET}"
__auth = f"{AUTH}/{SIMPLENOTE_APP_ID}/authorize/"
DATA = f"https://api.{BASE}/{CONFIG.SIMPLENOTE_APP_ID}/{CONFIG.SIMPLENOTE_BUCKET}"
__auth = f"{AUTH}/{CONFIG.SIMPLENOTE_APP_ID}/authorize/"
__index = DATA + "/index"
__retrieve = DATA + "/i/%s"
__modify = __retrieve
Expand Down Expand Up @@ -113,7 +107,7 @@ def authenticate(username: str, password: str):
response = request(
URL.auth(),
method="POST",
headers={"X-Simperium-API-Key": SIMPLENOTE_APP_KEY},
headers={"X-Simperium-API-Key": CONFIG.SIMPLENOTE_APP_KEY},
data={"username": username, "password": password},
data_as_json=False,
)
Expand Down

0 comments on commit 3ea7309

Please sign in to comment.