Add some python tools and .gitignore
This commit is contained in:
parent
dc53b1c176
commit
aeaed5bf45
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
@ -6,6 +6,13 @@ To avoud cluttering it too bad there is also the `docker` folder, as my workflow
|
|||||||
This too is in my `PATH`.
|
This too is in my `PATH`.
|
||||||
|
|
||||||
|
|
||||||
|
### Python and pip
|
||||||
|
|
||||||
|
Everyone should know that pip kinda sucks.
|
||||||
|
So to make use of all the Python scripts in here I **highly** recommend to use `poetry` to make a virtual env.
|
||||||
|
Then all you'll have to do is run `poetry shell` in the root of this repo and you'll be ready to run all those nice, juicy Python scripts of mine.
|
||||||
|
|
||||||
|
|
||||||
### deploy.py
|
### deploy.py
|
||||||
|
|
||||||
To use this one you'll need to `pip install docker` and maybe also `pip install paramiko` depending on what you put in the `DOCKER_HOST` env var.
|
To use this one you'll need to `pip install docker` and maybe also `pip install paramiko` depending on what you put in the `DOCKER_HOST` env var.
|
||||||
|
22
aes.py
Executable file
22
aes.py
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from Cryptodome.Cipher import AES
|
||||||
|
from base64 import b64decode
|
||||||
|
|
||||||
|
KEY = b'931069B52546C2DF278CD52EE695D4F2'
|
||||||
|
|
||||||
|
|
||||||
|
def decode(enc):
|
||||||
|
enc = b64decode(enc)
|
||||||
|
return enc[16:], enc[0:16]
|
||||||
|
|
||||||
|
|
||||||
|
def decipher(enc, iv):
|
||||||
|
cipher = AES.new(KEY, AES.MODE_CBC, iv=iv)
|
||||||
|
return cipher.decrypt(enc)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from sys import argv
|
||||||
|
enc, iv = decode(argv[1])
|
||||||
|
print(decipher(enc, iv))
|
||||||
|
|
49
apikeygen.py
Executable file
49
apikeygen.py
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#!/usr/bin/env -S python3
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from jwt import decode, encode
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
unix_time = lambda x: (x - datetime(1970, 1, 1)).total_seconds()
|
||||||
|
EXP = int('{:.0f}'.format(
|
||||||
|
unix_time(datetime.now() + timedelta(weeks=52 * 9))
|
||||||
|
))
|
||||||
|
|
||||||
|
SECRET = r'Sd-{01i*_6Ns22xk^|?/*%g`LP327$4yrLYF#H5zo'
|
||||||
|
ALGO = 'HS256'
|
||||||
|
SKEL = {
|
||||||
|
'role': 'SystemAdministrator',
|
||||||
|
# 'role': 'User',
|
||||||
|
'iss': 'portal.byndle.no',
|
||||||
|
'aud': 'portal.byndle.no',
|
||||||
|
# 'iss': 'localhost:4200',
|
||||||
|
# 'aud': 'localhost:4200',
|
||||||
|
'generator': argv[0],
|
||||||
|
'exp': EXP
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# PROD
|
||||||
|
UID=2322
|
||||||
|
CID=14
|
||||||
|
|
||||||
|
# DEV
|
||||||
|
UID=1367 #133 # 10
|
||||||
|
CID=236
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(argv) > 1:
|
||||||
|
payload = decode(argv[1], algorithms=[ALGO], options={'verify_signature': False})
|
||||||
|
payload.update({
|
||||||
|
# 'role': 'AccountOwner',
|
||||||
|
'modificator': argv[0],
|
||||||
|
'exp': EXP
|
||||||
|
})
|
||||||
|
print(payload)
|
||||||
|
print(encode(payload, SECRET, algorithm=ALGO))
|
||||||
|
else:
|
||||||
|
payload = SKEL.copy()
|
||||||
|
payload.update({
|
||||||
|
'customerId': CID,
|
||||||
|
'userId': UID,
|
||||||
|
})
|
||||||
|
print(encode(payload, SECRET, algorithm=ALGO))
|
13
pyproject.toml
Normal file
13
pyproject.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "byndle-tools"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Tools to make the Byndle DX go brrr 😜"
|
||||||
|
authors = ["Sivert V. Sæther <sivert@byndle.no>"]
|
||||||
|
readme = "README.md"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.10"
|
||||||
|
pycryptodomex = "^3.21.0"
|
||||||
|
docker = "^7.1.0"
|
||||||
|
pyjwt = "^2.10.1"
|
||||||
|
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pycryptodomex==3.21.0
|
||||||
|
docker==7.1.0
|
||||||
|
pyjwt==2.10.1
|
Loading…
x
Reference in New Issue
Block a user