From 0841ffcf4972fe29c3940d3c78d648bc9456791d Mon Sep 17 00:00:00 2001 From: poka Date: Tue, 8 Dec 2020 23:15:24 +0100 Subject: [PATCH] Skip dunikey if don't needed --- jaklis.py | 49 ++++++++++++++++++++++++++++++--------------- lib/cesium.py | 4 ++-- lib/cesiumCommon.py | 10 ++++++--- lib/gva.py | 9 +++++++-- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/jaklis.py b/jaklis.py index 12d3e18..0f40166 100755 --- a/jaklis.py +++ b/jaklis.py @@ -105,30 +105,47 @@ def createTmpDunikey(): return keyPath -# if not cmd in ('history','balance','get') and args.profile: -# print('pubpass') +# Check if we need dunikey +try: + pubkey = args.pubkey +except: + pubkey = False +try: + profile = args.profile +except: + profile = False -if args.key: - dunikey = args.key +if cmd in ('history','balance','get') and (pubkey or profile): + noNeedDunikey = True keyPath = False + try: + dunikey = args.pubkey + except: + dunikey = args.profile else: - dunikey = os.getenv('DUNIKEY') - if not dunikey: - keyPath = createTmpDunikey() - dunikey = keyPath - else: + noNeedDunikey = False + if args.key: + dunikey = args.key keyPath = False -if not os.path.isfile(dunikey): - HOME = os.getenv("HOME") - dunikey = HOME + dunikey + else: + dunikey = os.getenv('DUNIKEY') + if not dunikey: + keyPath = createTmpDunikey() + dunikey = keyPath + else: + keyPath = False if not os.path.isfile(dunikey): - sys.stderr.write('Le fichier de trousseau {0} est introuvable.\n'.format(dunikey)) - sys.exit(1) + HOME = os.getenv("HOME") + dunikey = HOME + dunikey + if not os.path.isfile(dunikey): + sys.stderr.write('Le fichier de trousseau {0} est introuvable.\n'.format(dunikey)) + sys.exit(1) # Construct CesiumPlus object if cmd in ("read","send","delete","set","get","erase","like","unlike"): from lib.cesium import CesiumPlus + if args.node: pod = args.node else: @@ -136,7 +153,7 @@ if cmd in ("read","send","delete","set","get","erase","like","unlike"): if not pod: pod="https://g1.data.le-sou.org" - cesium = CesiumPlus(dunikey, pod) + cesium = CesiumPlus(dunikey, pod, noNeedDunikey) # Messaging if cmd == "read": @@ -195,7 +212,7 @@ elif cmd in ("pay","history","balance"): else: destPubkey = False - gva = GvaApi(dunikey, node, destPubkey) + gva = GvaApi(dunikey, node, destPubkey, noNeedDunikey) if cmd == "pay": gva.pay(args.amount, args.comment, args.mempool, args.verbose) diff --git a/lib/cesium.py b/lib/cesium.py index 642ac1d..6a07fd9 100644 --- a/lib/cesium.py +++ b/lib/cesium.py @@ -48,7 +48,7 @@ class CesiumPlus(CesiumCommon): return result def get(self, profile=None, avatar=None): - getProfile = Profiles(self.dunikey, self.pod) + getProfile = Profiles(self.dunikey, self.pod, self.noNeedDunikey) if not profile: profile = self.pubkey if not re.match(PUBKEY_REGEX, profile) or len(profile) > 45: @@ -72,7 +72,7 @@ class CesiumPlus(CesiumCommon): #################### Likes #################### def readLikes(self, profile=False): - likes = ReadLikes(self.dunikey, self.pod) + likes = ReadLikes(self.dunikey, self.pod, self.noNeedDunikey) document = likes.configDoc(profile) result = likes.sendDocument(document) result = likes.parseResult(result) diff --git a/lib/cesiumCommon.py b/lib/cesiumCommon.py index b4c5ab4..b68337d 100644 --- a/lib/cesiumCommon.py +++ b/lib/cesiumCommon.py @@ -13,7 +13,9 @@ def pp_json(json_thing, sort=True, indents=4): return None class CesiumCommon: - def __init__(self, dunikey, pod): + def __init__(self, dunikey, pod, noNeedDunikey=False): + self.pod = pod + self.noNeedDunikey = noNeedDunikey # Get my pubkey from my private key try: self.dunikey = dunikey @@ -23,8 +25,10 @@ class CesiumCommon: sys.stderr.write("Please fill the path to your private key (PubSec)\n") sys.exit(1) - self.pubkey = get_privkey(dunikey, "pubsec").pubkey - self.pod = pod + if noNeedDunikey: + self.pubkey = self.dunikey + else: + self.pubkey = get_privkey(dunikey, "pubsec").pubkey if not re.match(PUBKEY_REGEX, self.pubkey) or len(self.pubkey) > 45: sys.stderr.write("La clé publique n'est pas au bon format.\n") diff --git a/lib/gva.py b/lib/gva.py index f240290..eaf22fd 100644 --- a/lib/gva.py +++ b/lib/gva.py @@ -5,10 +5,15 @@ from lib.gvaHistory import History from lib.gvaBalance import Balance class GvaApi(): - def __init__(self, dunikey, node, pubkey): + def __init__(self, dunikey, node, pubkey, noNeedDunikey=False): + self.noNeedDunikey = noNeedDunikey self.dunikey = dunikey self.node = node - self.pubkey = get_privkey(dunikey, "pubsec").pubkey + if noNeedDunikey: + self.pubkey = self.dunikey + else: + self.pubkey = get_privkey(dunikey, "pubsec").pubkey + if pubkey: self.destPubkey = pubkey else: