Skip to content

Commit 41f4563

Browse files
committed
Allowing library to be accessed via sandwich shop
1 parent 0f4c895 commit 41f4563

File tree

7 files changed

+49
-22
lines changed

7 files changed

+49
-22
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
API_TOKEN=beep-boop

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
sites/*.json
131+
sites/*.json
132+
!sites/example.com.json

sites/example.com.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"path": "/home/projects/example.com",
3+
"release": {
4+
"deploy": "rsync -ai --delete --exclude='.git/' --exclude='.gitignore' /home/projects/example.com/ /www/html/example.com/"
5+
}
6+
}

src/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from auth import auth
22
from parse import parse
33
from quart import Quart, request
4-
4+
from dotenv import load_dotenv
5+
load_dotenv()
56

67
app = Quart(__name__)
78

src/auth.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
import hmac
22
import hashlib
33
import os
4-
from dotenv import load_dotenv
5-
load_dotenv()
6-
7-
token = os.environ.get("API_TOKEN")
8-
tokenb = bytes(token, 'utf-8')
4+
import sys
95

106

117
async def auth(header, data):
8+
token = os.environ.get("API_TOKEN")
9+
tokenb = bytes(token, 'utf-8')
10+
1211
signature = 'sha256=' + hmac.new(tokenb, data, hashlib.sha256).hexdigest()
1312
if hmac.compare_digest(signature, header):
1413
return True
1514
return False
15+
16+
17+
if __name__ == "__main__":
18+
if len(sys.argv) == 3:
19+
body = sys.argv[1]
20+
header = sys.argv[2]
21+
if auth(header, body):
22+
print('true')
23+
else:
24+
print('false')
25+
elif len(sys.argv) == 2:
26+
body = sys.argv[0]
27+
header = sys.argv[1]
28+
if auth(header, body):
29+
print('true')
30+
else:
31+
print('false')
32+
else:
33+
print('false')

src/parse.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from multiprocessing import Process
22
from release import processRelease
3+
import sys
34

45

56
async def parse(repo, payload):
@@ -9,3 +10,13 @@ async def parse(repo, payload):
910
args=(repo, payload))
1011
print(p.pid)
1112
p.start()
13+
14+
if __name__ == "__main__":
15+
if len(sys.argv) == 3:
16+
repo = sys.argv[1]
17+
payload = sys.argv[2]
18+
parse(repo, payload)
19+
elif len(sys.argv) == 2:
20+
repo = sys.argv[0]
21+
payload = sys.argv[1]
22+
parse(repo, payload)

src/release.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
import json
22
import subprocess
33

4-
from os import path
5-
from pathlib import Path
4+
from os import environ
65
from pybars import Compiler
76

87
compiler = Compiler()
98

109

1110
def processRelease(repo, payload):
12-
base_path = Path(__file__).parent
11+
base_path = environ.get("SITES")
1312
file_name = repo + '.json'
14-
file_path = (base_path / '..' / 'sites' / file_name).resolve()
13+
file_path = (base_path / file_name).resolve()
1514

1615
with open(file_path) as f:
1716
data = json.load(f)
1817

1918
if 'release' in data.keys() and 'path' in data.keys():
2019
commands = []
21-
22-
cwd = data['cwd']
23-
24-
if path.exists(base_path / '..' / '.nvmrc'):
25-
commands.append('. ' + cwd + '/.nvm/nvm.sh')
26-
commands.append('nvm use')
27-
elif 'node' in data.keys():
28-
commands.append('. ' + cwd + '/.nvm/nvm.sh')
29-
commands.append('nvm use ' + data['node'])
30-
3120
if 'build' in data['release'].keys():
3221
source = data['release']['build']
3322
template = compiler.compile(source)
@@ -60,4 +49,4 @@ def processRelease(repo, payload):
6049
process.communicate()
6150
print('Release complete!')
6251

63-
return
52+
return

0 commit comments

Comments
 (0)