-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (35 loc) · 1.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import requests
from requests.auth import HTTPBasicAuth
from flask import Flask, request, Response, jsonify
slack_token = os.environ.get('SLACK_TOKEN')
ttl = os.environ.get('SECRET_TTL', 259200) # 3 days
secret_user = os.environ.get('SECRET_USER')
secret_pass = os.environ.get('SECRET_PASS')
SECRET_BASE = "https://onetimesecret.com"
SECRET_LINK = "{}/secret/".format(SECRET_BASE)
SECRET_SHARE = "{}/api/v1/share".format(SECRET_BASE)
app = Flask(__name__)
@app.route('/secret', methods=['post'])
def secret():
token = request.values.get('token')
text = request.values.get('text')
if token != slack_token:
return Response('You are not authorized to use slack-secret',
content_type='text/plain; charset=utf-8')
d = {'secret': text, 'ttl': ttl}
r = requests.post(SECRET_SHARE, data=d, auth=HTTPBasicAuth(secret_user, secret_pass))
res = r.json()
rd = {
'response_type': 'ephemeral',
'text': '{}{}'.format(SECRET_LINK, res.get('secret_key')),
'attachments': [
{
'text': "The above link will expire in {} seconds.".format(res.get('secret_ttl'))
}
]
}
return jsonify(**rd)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)