Skip to content

Commit

Permalink
Stop using environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Sep 25, 2020
1 parent 9eb7899 commit 16299d8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
config.py
.env
**/.DS_Store
logs/
Expand Down
5 changes: 2 additions & 3 deletions helpers/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,14 @@ def can_evolve(self, ctx):
class Pokemon(PokemonBase, Document):
class Meta:
strict = False

pass


class EmbeddedPokemon(PokemonBase, EmbeddedDocument):
class Meta:
strict = False

pass


Expand Down Expand Up @@ -329,9 +331,6 @@ class Blacklist(Document):

class Database:
def __init__(self, bot, host, dbname):
database_uri = os.getenv("DATABASE_URI")
database_name = os.getenv("DATABASE_NAME")

self.db = AsyncIOMotorClient(host, io_loop=bot.loop)[dbname]
instance = Instance(self.db)

Expand Down
13 changes: 7 additions & 6 deletions launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import requests

import config
from bot import ClusterBot

TOKEN = os.getenv("BOT_TOKEN")
TOKEN = config.BOT_TOKEN


log = logging.getLogger("Cluster#Launcher")
Expand Down Expand Up @@ -171,17 +172,17 @@ def __init__(self, launcher, name, shard_ids, max_shards):
self.process = None
self.kwargs = dict(
token=TOKEN,
env=os.getenv("ENV"),
env=config.ENV,
shard_ids=shard_ids,
shard_count=max_shards,
cluster_name=name,
cluster_idx=CLUSTER_NAMES.index(name),
case_insensitive=True,
fetch_offline_members=False,
dbl_token=os.getenv("DBL_TOKEN"),
database_uri=os.getenv("DATABASE_URI"),
database_name=os.getenv("DATABASE_NAME"),
secret_key=os.getenv("SECRET_KEY"),
dbl_token=config.DBL_TOKEN,
database_uri=config.DATABASE_URI,
database_name=config.DATABASE_NAME,
secret_key=config.SECRET_KEY,
)
self.name = name
self.log = logging.getLogger(f"Cluster#{name}")
Expand Down
7 changes: 4 additions & 3 deletions migrations/2020-09-06-make_global_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
6 September 2020
"""

from pymongo import MongoClient
import os

import config
from pymongo import MongoClient

client = MongoClient(os.getenv("DATABASE_URI"))
db = client[os.getenv("DATABASE_NAME")]
client = MongoClient(config.DATABASE_URI)
db = client[config.DATABASE_NAME]

result = db["member"].aggregate(
[
Expand Down
7 changes: 4 additions & 3 deletions migrations/2020-09-06-remove_local_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
6 September 2020
"""

from pymongo import MongoClient
import os

import config
from pymongo import MongoClient

client = MongoClient(os.getenv("DATABASE_URI"))
db = client[os.getenv("DATABASE_NAME")]
client = MongoClient(config.DATABASE_URI)
db = client[config.DATABASE_NAME]

result = db["member"].update_many({}, {"$unset": {"pokemon": 1}})
8 changes: 5 additions & 3 deletions migrations/2020-09-06-update_listings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
This is a one-shot script used to migrate all Pokémon from array fields to a global collection.
6 September 2020
"""
from pymongo import MongoClient
import os

import bson
import config
from pymongo import MongoClient

client = MongoClient(os.getenv("DATABASE_URI"))
db = client[os.getenv("DATABASE_NAME")]
client = MongoClient(config.DATABASE_URI)
db = client[config.DATABASE_NAME]

result = db["listing"].update_many(
{},
Expand Down
6 changes: 3 additions & 3 deletions migrations/2020-09-09-backfill_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from multiprocessing import Pool

import bson
import config
from pymongo import MongoClient, UpdateOne

sys.path.append(os.getcwd())

import helpers


data = helpers.data.make_data_manager()

client = MongoClient(os.getenv("DATABASE_URI"))
db = client[os.getenv("DATABASE_NAME")]
client = MongoClient(config.DATABASE_URI)
db = client[config.DATABASE_NAME]


def make_request(i):
Expand Down
7 changes: 4 additions & 3 deletions migrations/2020-09-17-create_timestamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
17 September 2020
"""

from pymongo import MongoClient
import os

import config
from pymongo import MongoClient

client = MongoClient(os.getenv("DATABASE_URI"))
db = client[os.getenv("DATABASE_NAME")]
client = MongoClient(config.DATABASE_URI)
db = client[config.DATABASE_NAME]

result = db["pokemon"].update_many(
{"timestamp": {"$exists": False}}, [{"$set": {"timestamp": {"$toDate": "$_id"}}}]
Expand Down
14 changes: 7 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from motor.motor_asyncio import AsyncIOMotorClient
from quart import Quart, request

import config

# Constants

purchase_amounts = {
Expand All @@ -20,16 +22,14 @@

# Setup

stripe.api_key = os.getenv("STRIPE_KEY")
endpoint_secret = os.getenv("STRIPE_WEBHOOK_SECRET")
stripe.api_key = config.STRIPE_KEY
endpoint_secret = config.STRIPE_WEBHOOK_SECRET

app = Quart(__name__)
web_ipc = Client(secret_key=os.getenv("SECRET_KEY"))
web_ipc = Client(secret_key=config.SECRET_KEY)

loop = asyncio.get_event_loop()
db = AsyncIOMotorClient(os.getenv("DATABASE_URI"), io_loop=loop)[
os.getenv("DATABASE_NAME")
]
db = AsyncIOMotorClient(config.DATABASE_URI, io_loop=loop)[config.DATABASE_NAME]


# IPC Routes
Expand All @@ -44,7 +44,7 @@ def login_required(func):
async def pred():
key = request.args.get("key", "")
hashed = hashlib.sha224(key.encode("utf-8")).hexdigest()
if hashed != os.getenv("LOGIN_KEY"):
if hashed != config.LOGIN_KEY:
return "Unauthorized", 401
return await func()

Expand Down

0 comments on commit 16299d8

Please sign in to comment.