Skip to content

Commit

Permalink
update config, setup send grid and github oauth, disable google oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
Amirkhon committed Oct 6, 2019
1 parent 58c2bc8 commit 0183564
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 47 deletions.
50 changes: 25 additions & 25 deletions apiserver/apiserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,55 @@
# Max bot file size
MAX_BOT_FILE_SIZE = 100 * 1024 * 1024
# Secret key for Flask session cookies
FLASK_SECRET_KEY = ""
FLASK_SECRET_KEY = "24secret24"
# Where to look for API keys
API_KEY_HEADER = "X-Api-Key"
# What session cookie to use
SESSION_COOKIE = "user_id"
SESSION_SECRET = ""
SESSION_SECRET = "s24secret"

# Google Cloud
GCLOUD_PROJECT = ''
GCLOUD_PROJECT_ID = ''
GCLOUD_ZONE = 'us-central1-c'
GCLOUD_PROJECT = 'Students24'
GCLOUD_PROJECT_ID = 'dynamic-concept-254710'
GCLOUD_ZONE = 'us-east1-b'

GCLOUD_COMPILATION_BUCKET = ''
GCLOUD_BOT_BUCKET = ''
GCLOUD_COMPILATION_BUCKET = 's24_cb'
GCLOUD_BOT_BUCKET = 's24_ub'
# Replays are saved in different buckets based on player level
GCLOUD_REPLAY_BUCKETS = {
# 0 is the normal bucket
0: '',
0: 's24_r',
# 1 is the bucket for gold and above players
1: '',
1: 's24_gr',
}
GCLOUD_ONDEMAND_REPLAY_BUCKET = ""
GCLOUD_ONDEMAND_REPLAY_BUCKET = "s24_or"
# Bucket for pre-assembled bots that players fight in the
# tutorial/online editor
GCLOUD_GYM_BUCKET = ""
GCLOUD_ERROR_LOG_BUCKET = ''
GCLOUD_DEPLOYED_ARTIFACTS_BUCKET = ''
GCLOUD_EDITOR_BUCKET = ''
GCLOUD_WORKER_LOG_BUCKET = ''
GCLOUD_GYM_BUCKET = "s24_g"
GCLOUD_ERROR_LOG_BUCKET = 's24_el'
GCLOUD_DEPLOYED_ARTIFACTS_BUCKET = 's24_da'
GCLOUD_EDITOR_BUCKET = 's24_e'
GCLOUD_WORKER_LOG_BUCKET = 's24_wl'

# The name of the worker source blob in the object storage bucket.
WORKER_ARTIFACT_KEY = ""
WORKER_ARTIFACT_KEY = "Halite.tgz"

DATABASE_PROJECT_ID = ""
DATABASE_URL = "postgresql+psycopg2://user:pass@localhost:{port}/dbname"
DATABASE_PROJECT_ID = "dynamic-concept-254710"
DATABASE_URL = "postgresql+psycopg2://postgres:postgres@localhost:{port}/halite3"
DATABASES = [
# Read-write master
("zone", "instance-name", 3307),
("us-east1-b", "dynamic-concept-254710:us-east1:halite3", 3307),
# Read replica
("zone", "instance-name", 3308),
("us-east1-b", "dynamic-concept-254710:us-east1:halite3-replica", 3308),
]

# OAuth
OAUTH_GITHUB_CONSUMER_KEY = ""
OAUTH_GITHUB_CONSUMER_SECRET = ""
OAUTH_GITHUB_CONSUMER_KEY = "3738a242abdf56ace0bd"
OAUTH_GITHUB_CONSUMER_SECRET = "5175d8e4c838c07a24845af8fcc7bc974b8c0887"

# CORS setup
SITE_URL = ""
API_URL = ""
SITE_URL = "http://35.237.189.116"
API_URL = "http://35.237.189.116"
CORS_ORIGINS = [SITE_URL]

# API Key authentication
Expand All @@ -102,7 +102,7 @@
DISCOURSE_URL = "https://forums.halite.io/sso"

# SendGrid
SENDGRID_API_KEY = ""
SENDGRID_API_KEY = "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"
SENDGRID_SANDBOX_MODE = True

# Emails
Expand Down
8 changes: 4 additions & 4 deletions apiserver/apiserver/coordinator/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def update_compilation_status():
(model.bots.c.id == bot_id)
)).first()

notify.send_templated_notification(
'''notify.send_templated_notification(
notify.Recipient(str(user["id"]), user["username"], user["email"],
user["organization_name"], user["player_level"],
user["creation_time"].isoformat()),
Expand All @@ -197,7 +197,7 @@ def update_compilation_status():
},
config.GOODNEWS_ACCOMPLISHMENTS,
config.C_COMPLIATION_SUCCESS
)
)'''

return util.response_success()
else:
Expand All @@ -208,7 +208,7 @@ def update_compilation_status():
chunk_size=262144)
blob.upload_from_string(errors)

notify.send_templated_notification(
'''notify.send_templated_notification(
notify.Recipient(str(user["id"]), user["username"], user["email"],
user["organization_name"], user["player_level"],
user["creation_time"].isoformat()),
Expand All @@ -222,5 +222,5 @@ def update_compilation_status():
},
config.GAME_ERROR_MESSAGES,
config.C_COMPILATION_ERROR
)
)'''
return util.response_success()
8 changes: 4 additions & 4 deletions apiserver/apiserver/coordinator/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def update_user_timeout(conn, game_id, user):
user["player_level"],
user["creation_time"].isoformat())
if timed_out_count == 1 and not timeout_sent:
notify.send_templated_notification(
'''notify.send_templated_notification(
recipient,
config.FIRST_TIMEOUT_TEMPLATE,
{
Expand All @@ -519,7 +519,7 @@ def update_user_timeout(conn, game_id, user):
config.API_URL, user["user_id"], game_id),
},
config.GAME_ERROR_MESSAGES,
config.C_BOT_TIMED_OUT)
config.C_BOT_TIMED_OUT)'''

conn.execute(model.bots.update().values(timeout_sent=True).where(
(model.bots.c.user_id == user["user_id"]) &
Expand All @@ -536,7 +536,7 @@ def update_user_timeout(conn, game_id, user):
).where((model.bots.c.user_id == user["user_id"]) &
(model.bots.c.id == user["bot_id"])))

notify.send_templated_notification(
'''notify.send_templated_notification(
recipient,
config.BOT_DISABLED_TEMPLATE,
{
Expand All @@ -552,4 +552,4 @@ def update_user_timeout(conn, game_id, user):
config.API_URL, user["user_id"], game_id),
},
config.GAME_ERROR_MESSAGES,
config.C_BOT_DISABLED)
config.C_BOT_DISABLED)'''
14 changes: 8 additions & 6 deletions apiserver/apiserver/login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
access_token_url="https://github.com/login/oauth/access_token",
authorize_url="https://github.com/login/oauth/authorize",
)
google = oauth.remote_app(
'''google = oauth.remote_app(
"google",
consumer_key=config.OAUTH_GOOGLE_CONSUMER_KEY,
consumer_secret=config.OAUTH_GOOGLE_CONSUMER_SECRET,
Expand All @@ -43,7 +43,7 @@
access_token_method='POST',
access_token_url='https://accounts.google.com/o/oauth2/token',
authorize_url='https://accounts.google.com/o/oauth2/auth',
)
)'''


@oauth_login.route("/github")
Expand All @@ -56,6 +56,7 @@ def github_login_init():
return github.authorize(callback=full_url)


'''
@oauth_login.route("/google")
def google_login_init():
url = urllib.parse.urlparse(config.API_URL)
Expand All @@ -64,7 +65,7 @@ def google_login_init():
base_url,
flask.url_for(".google_login_callback"))
return google.authorize(callback=full_url)

'''

@oauth_login.route("/me")
@cross_origin(methods=["GET"], origins=config.CORS_ORIGINS, supports_credentials=True)
Expand Down Expand Up @@ -142,7 +143,7 @@ def github_login_callback():
default_username=default_username)


@oauth_login.route("/response/google")
'''@oauth_login.route("/response/google")
def google_login_callback():
try:
response = google.authorized_response()
Expand Down Expand Up @@ -174,7 +175,7 @@ def google_login_callback():
google_user_id = user_data["id"]
email = user_data["email"]
return generic_login_callback(email, GOOGLE_PROVIDER, google_user_id)

'''

def generic_login_callback(email, oauth_provider, oauth_id, default_username=None):
with model.engine.connect() as conn:
Expand Down Expand Up @@ -239,7 +240,8 @@ def generic_login_callback(email, oauth_provider, oauth_id, default_username=Non
def github_tokengetter():
return flask.session.get("github_token")


'''
@google.tokengetter
def google_tokengetter():
return flask.session.get("google_token")
'''
8 changes: 4 additions & 4 deletions apiserver/apiserver/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def send_notification(recipient_email, recipient_name, subject, body,
attachments=None):
mail = sendgrid.helpers.mail.Mail()

mail.from_email = sendgrid.Email("[email protected]", "Halite Challenge")
mail.from_email = sendgrid.Email("[email protected]", "Studets24 Hackathon")
personalization = sendgrid.helpers.mail.Personalization()
personalization.add_to(sendgrid.helpers.mail.Email(recipient_email, recipient_name))
personalization.subject = "Halite Challenge: " + subject
personalization.subject = "Studets24 Hackathon: " + subject
mail.add_personalization(personalization)

mail.add_content(sendgrid.helpers.mail.Content("text/html", body))
Expand Down Expand Up @@ -60,7 +60,7 @@ def send_templated_notification(recipient, template_id, substitutions, group_id,
if not recipient.organization:
recipient = recipient._replace(organization="(no affiliation)")

mail.from_email = sendgrid.Email("[email protected]", "Halite Challenge")
mail.from_email = sendgrid.Email("[email protected]", "Studets24 Hackathon")
personalization = sendgrid.helpers.mail.Personalization()
personalization.add_to(sendgrid.helpers.mail.Email(recipient.email, recipient.username))

Expand Down Expand Up @@ -94,7 +94,7 @@ def send_templated_notification_simple(email, template_id, group_id, category):
"""
mail = sendgrid.helpers.mail.Mail()

mail.from_email = sendgrid.Email("[email protected]", "Halite Challenge")
mail.from_email = sendgrid.Email("[email protected]", "Studets24 Hackathon")
personalization = sendgrid.helpers.mail.Personalization()
personalization.add_to(sendgrid.helpers.mail.Email(email, email))

Expand Down
8 changes: 4 additions & 4 deletions apiserver/apiserver/web/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,22 +768,22 @@ def delete_user(intended_user_id, *, user_id):
@web_api.route("/user/addsubscriber/<string:recipient>", methods=["POST"])
@util.cross_origin(methods=["POST"])
def add_subscriber(recipient):
notify.add_user_to_contact_list(recipient)
'''notify.add_user_to_contact_list(recipient)
notify.send_templated_notification_simple(
recipient,
config.NEW_SUBSCRIBER_TEMPLATE,
config.GOODNEWS_ACCOMPLISHMENTS,
config.C_NEWSLETTER_SUBSCRIPTION)
config.C_NEWSLETTER_SUBSCRIPTION)'''
return util.response_success()

@web_api.route("/invitation/user/<string:recipient>", methods=["POST"])
@util.cross_origin(methods=["POST"])
def invite_friend(recipient):
notify.send_templated_notification_simple(
'''notify.send_templated_notification_simple(
recipient,
config.INVITE_FRIEND_TEMPLATE,
config.GOODNEWS_ACCOMPLISHMENTS,
config.C_INVITE_FRIEND)
config.C_INVITE_FRIEND)'''
return util.response_success()

@web_api.route("/api_key", methods=["POST"])
Expand Down

0 comments on commit 0183564

Please sign in to comment.