Apply Vit advices about .env and few stuff
This commit is contained in:
parent
dea707babf
commit
02ae104da2
|
@ -0,0 +1,4 @@
|
|||
DUNIKEY="" # Chemin de la clé privé Ḡ1 de l'émetteur, au format PubSec
|
||||
#POD="https://g1.data.duniter.fr" # Adresse du pod Cesium ou Gchange à utiliser
|
||||
POD="https://g1.data.le-sou.org" # Adresse du pod Cesium de secours
|
||||
#POD="https://data.gchange.fr" # Adresse du pod ḠChange à utiliser
|
|
@ -1,3 +1,2 @@
|
|||
.env
|
||||
userEnv.py
|
||||
__pycache__
|
||||
|
|
26
dialog.py
26
dialog.py
|
@ -1,18 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse, os, sys
|
||||
import argparse, sys, os
|
||||
from os.path import join, dirname
|
||||
from shutil import copyfile
|
||||
if not os.path.isfile("userEnv.py"):
|
||||
copyfile("userEnv.py.template", "userEnv.py")
|
||||
try:
|
||||
from userEnv import dunikey, pod
|
||||
if dunikey == "":
|
||||
raise ValueError("Dunikey is empty")
|
||||
except:
|
||||
sys.stderr.write("Please fill the path to your private key (PubSec), and a Cesium ES address in userEnv.py\n")
|
||||
sys.exit(1)
|
||||
from dotenv import load_dotenv
|
||||
from lib.cesiumMessaging import ReadFromCesium, SendToCesium, DeleteFromCesium
|
||||
|
||||
# Get varriables environment
|
||||
if not os.path.isfile('.env'):
|
||||
copyfile(".env.template", ".env")
|
||||
dotenv_path = join(dirname(__file__), '.env')
|
||||
load_dotenv(dotenv_path)
|
||||
|
||||
dunikey = os.getenv('DUNIKEY')
|
||||
pod = os.getenv('POD')
|
||||
if not dunikey or not pod:
|
||||
sys.stderr.write("Please fill the path of your private key (PubSec), and a Cesium ES address in .env file\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@ from hashlib import sha256
|
|||
from datetime import datetime
|
||||
from termcolor import colored
|
||||
|
||||
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||
|
||||
class ReadFromCesium:
|
||||
def __init__(self, dunikey, pod):
|
||||
# Get my pubkey from my private key
|
||||
try:
|
||||
self.dunikey = dunikey
|
||||
if dunikey == "":
|
||||
if not dunikey:
|
||||
raise ValueError("Dunikey is empty")
|
||||
except:
|
||||
sys.stderr.write("Please fill the path to your private key (PubSec)\n")
|
||||
|
@ -21,7 +22,7 @@ class ReadFromCesium:
|
|||
self.recipient = get_privkey(dunikey, "pubsec").pubkey
|
||||
self.pod = pod
|
||||
|
||||
if not re.match(r"(?![OIl])[1-9A-Za-z]{42,45}", self.recipient):
|
||||
if not re.match(PUBKEY_REGEX, self.recipient) or len(self.recipient) > 45:
|
||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -117,6 +118,8 @@ class SendToCesium:
|
|||
# Get my pubkey from my private key
|
||||
try:
|
||||
self.dunikey = dunikey
|
||||
if not dunikey:
|
||||
raise ValueError("Dunikey is empty")
|
||||
except:
|
||||
sys.stderr.write("Please fill the path to your private key (PubSec)\n")
|
||||
sys.exit(1)
|
||||
|
@ -132,7 +135,7 @@ class SendToCesium:
|
|||
nonce.append(random.choice(string.ascii_letters + string.digits))
|
||||
self.nonce = base64.b64decode(''.join(nonce))
|
||||
|
||||
if not re.match(r"(?![OIl])[1-9A-Za-z]{42,45}", recipient):
|
||||
if not re.match(PUBKEY_REGEX, recipient) or len(recipient) > 45:
|
||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
@ -200,6 +203,8 @@ class DeleteFromCesium:
|
|||
# Get my pubkey from my private key
|
||||
try:
|
||||
self.dunikey = dunikey
|
||||
if not dunikey:
|
||||
raise ValueError("Dunikey is empty")
|
||||
except:
|
||||
sys.stderr.write("Please fill the path to your private key (PubSec)\n")
|
||||
sys.exit(1)
|
||||
|
|
|
@ -3,3 +3,4 @@ base58
|
|||
pybase64
|
||||
duniterpy
|
||||
termcolor
|
||||
python-dotenv
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
dunikey = "" # Chemin de la clé privé Ḡ1 de l'émetteur, au format PubSec
|
||||
#pod = "https://g1.data.duniter.fr" # Adresse du pod Cesium à utiliser
|
||||
pod = "https://g1.data.le-sou.org" # Adresse du pod Cesium de secours
|
||||
#pod = "https://data.gchange.fr" # Adresse du pod GChange à utiliser
|
Loading…
Reference in New Issue