From a0cbead5aa671b543409b7b87a3c51c361b7bbd8 Mon Sep 17 00:00:00 2001 From: jakedt Date: Thu, 17 Apr 2014 16:18:37 -0400 Subject: [PATCH 1/3] Update the subscription change webhook to be more friendly and not send emails for payments. --- endpoints/webhooks.py | 18 +++++++++++++++++- util/email.py | 14 ++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/endpoints/webhooks.py b/endpoints/webhooks.py index a68d819c7..b5815bf0d 100644 --- a/endpoints/webhooks.py +++ b/endpoints/webhooks.py @@ -46,7 +46,23 @@ def stripe_webhook(): cust = model.get_user_or_org_by_customer_id(customer_id) cust_email = cust.email if cust is not None else 'unknown@domain.com' quay_username = cust.username if cust is not None else 'unknown' - send_subscription_change(event_type, customer_id, cust_email, quay_username) + + change_type = '' + if event_type.endswith('.deleted'): + plan_id = request_data['data']['object']['plan']['id'] + change_type = 'canceled %s' % plan_id + send_subscription_change(change_type, customer_id, cust_email, quay_username) + elif event_type.endswith('.created'): + plan_id = request_data['data']['object']['plan']['id'] + change_type = 'subscribed %s' % plan_id + send_subscription_change(change_type, customer_id, cust_email, quay_username) + elif event_type.endswith('.updated'): + if 'previous_attributes' in request_data['data']: + if 'plan' in request_data['data']['previous_attributes']: + old_plan = request_data['data']['previous_attributes']['plan']['id'] + new_plan = request_data['data']['object']['plan']['id'] + change_type = 'switched %s -> %s' % (old_plan, new_plan) + send_subscription_change(change_type, customer_id, cust_email, quay_username) return make_response('Okay') diff --git a/util/email.py b/util/email.py index e4e97ebea..14159b325 100644 --- a/util/email.py +++ b/util/email.py @@ -35,12 +35,14 @@ not given access. Please disregard this email.
SUBSCRIPTION_CHANGE = """ -Event name: {0}
+Change: {0}
Customer id: {1}
Customer email: {2}
Quay user or org name: {3}
""" +SUBSCRIPTION_CHANGE_TITLE = 'Subscription Change - {0} {1}' + def send_change_email(username, email, token): msg = Message('Quay.io email change. Please confirm your email.', @@ -74,9 +76,9 @@ def send_invoice_email(email, contents): mail.send(msg) -def send_subscription_change(event_name, customer_id, customer_email, quay_username): - msg = Message('Quay.io Customer Subscription Change', - sender='support@quay.io', # Why do I need this? - recipients=['stripe@quay.io']) - msg.html = SUBSCRIPTION_CHANGE.format(event_name, customer_id, customer_email, quay_username) +def send_subscription_change(change_description, customer_id, customer_email, quay_username): + title = SUBSCRIPTION_CHANGE_TITLE.format(quay_username, change_description) + msg = Message(title, sender='support@quay.io', recipients=['stripe@quay.io']) + msg.html = SUBSCRIPTION_CHANGE.format(change_description, customer_id, customer_email, + quay_username) mail.send(msg) From 0d8725e778c7ee8715ec4cbbc9353a1d25a10d6d Mon Sep 17 00:00:00 2001 From: jakedt Date: Thu, 17 Apr 2014 16:18:53 -0400 Subject: [PATCH 2/3] Update the instructions for starting and running the workers. --- workers/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/workers/README.md b/workers/README.md index d4d2a3f14..70d5ae3cd 100644 --- a/workers/README.md +++ b/workers/README.md @@ -18,6 +18,10 @@ sudo gdebi --n binary_dependencies/builder/nsexec_1.22ubuntu1trusty1_amd64.deb sudo gdebi --n binary_dependencies/builder/lxc-docker-0.9.0-tutum2_0.9.0-tutum2-20140327210604-4c49268-dirty_amd64.deb sudo chown -R 100000:100000 /var/lib/docker sudo shutdown -r now + +cd ~ +git clone https://bitbucket.org/yackob03/quayconfig.git +ln -s ../../quayconfig/production/ quay/conf/stack ``` pull some base images if you want (optional) @@ -35,5 +39,5 @@ cd quay virtualenv --distribute venv source venv/bin/activate pip install -r requirements.txt -sudo STACK=prod venv/bin/python -m workers.dockerfilebuild -D +sudo venv/bin/python -m workers.dockerfilebuild -D ``` From 5a2a64074ff35ba070cf60d7f7d4501bb2d7eea3 Mon Sep 17 00:00:00 2001 From: jakedt Date: Thu, 17 Apr 2014 16:49:04 -0400 Subject: [PATCH 3/3] Make the command portion of the dockerfile parser case insensitive. --- util/dockerfileparse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/dockerfileparse.py b/util/dockerfileparse.py index 3bb9ed35a..4a08e5dd8 100644 --- a/util/dockerfileparse.py +++ b/util/dockerfileparse.py @@ -1,7 +1,7 @@ import re LINE_CONTINUATION_REGEX = re.compile('\s*\\\s*\n') -COMMAND_REGEX = re.compile('([A-Z]+)\s(.*)') +COMMAND_REGEX = re.compile('([A-Za-z]+)\s(.*)') COMMENT_CHARACTER = '#' @@ -70,7 +70,7 @@ def parse_dockerfile(contents): for line in lines: match_command = COMMAND_REGEX.match(line) if match_command: - command = match_command.group(1) + command = match_command.group(1).upper() parameters = match_command.group(2) commands.append({