Compare commits
13 Commits
lash/custo
...
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e637ce04e | |||
| 0db8e56603 | |||
| 1dba2d09d1 | |||
| 618aa7716e | |||
| 17ae29887f | |||
| fbb5168b40 | |||
| c269318528 | |||
| c3e8883f15 | |||
|
5f62287913
|
|||
| 28d7699a4a | |||
|
05224a9dd6
|
|||
| 2f65aa37ff | |||
|
|
be7dea24ac
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,3 +2,7 @@ __pycache__
|
||||
*.egg-info
|
||||
build/
|
||||
*.pyc
|
||||
.venv
|
||||
.clicada
|
||||
dist/
|
||||
.vscode/
|
||||
@@ -1,3 +1,5 @@
|
||||
- 0.0.7
|
||||
* fix: make store_path relative to the users home
|
||||
- 0.0.6
|
||||
* Add cache encryption, with AES-CTR-128
|
||||
- 0.0.5
|
||||
|
||||
87
README.md
Normal file
87
README.md
Normal file
@@ -0,0 +1,87 @@
|
||||
## Clicada
|
||||
|
||||
> Admin Command Line Interface to interact with cic-meta and cic-cache
|
||||
|
||||
### Pre-requisites
|
||||
|
||||
- Public key uploaded to `cic-auth-helper`
|
||||
- PGP Keyring for your key
|
||||
|
||||
### Installation
|
||||
|
||||
Use either of the following installation methods:
|
||||
|
||||
1. Install from git release (recommended)
|
||||
|
||||
```bash
|
||||
wget https://git.grassecon.net/grassrootseconomics/clicada/archive/v0.0.6.zip
|
||||
unzip clicada-v0.0.6.zip
|
||||
cd clicada
|
||||
python3 -m venv .venv
|
||||
source .venv/bin/activate
|
||||
pip install -r requirements.txt --extra-index-url=https://pip.grassrootseconomics.net
|
||||
```
|
||||
|
||||
2. Install from pip to path (non sudo)
|
||||
|
||||
```bash
|
||||
pip3 install -UI --extra-index-url=https://pip.grassrootseconomics.net clicada
|
||||
```
|
||||
|
||||
### GPG Keyring setup
|
||||
|
||||
PGP uses the default keyring, you can however pass in a custom keyring path.
|
||||
|
||||
To create a keyring from a specific key and get its path for `AUTH_KEYRING_PATH`:
|
||||
|
||||
```bash
|
||||
# In some dir
|
||||
gpg --homedir .gnupg --import private.pgp
|
||||
pwd
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
usage: clicada [...optional arguments] [...positional arguments]
|
||||
|
||||
positional arguments:
|
||||
{user,u,tag,t}
|
||||
user (u) retrieve transactions for a user
|
||||
tag (t) locally assign a display value to an identifier
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--no-logs Turn off all logging
|
||||
-v Be verbose
|
||||
-vv Be very verbose
|
||||
-c CONFIG, --config CONFIG
|
||||
Configuration directory
|
||||
-n NAMESPACE, --namespace NAMESPACE
|
||||
Configuration namespace
|
||||
--dumpconfig {env,ini}
|
||||
Output configuration and quit. Use with --raw to omit values and output schema only.
|
||||
--env-prefix ENV_PREFIX
|
||||
environment prefix for variables to overwrite configuration
|
||||
-p P, --rpc-provider P
|
||||
RPC HTTP(S) provider url
|
||||
--rpc-dialect RPC_DIALECT
|
||||
RPC HTTP(S) backend dialect
|
||||
--height HEIGHT Block height to execute against
|
||||
-i I, --chain-spec I Chain specification string
|
||||
-u, --unsafe Do not verify address checksums
|
||||
--seq Use sequential rpc ids
|
||||
-y Y, --key-file Y Keystore file to use for signing or address
|
||||
--raw Do not decode output
|
||||
--fee-price FEE_PRICE
|
||||
override fee price
|
||||
--fee-limit FEE_LIMIT
|
||||
override fee limit
|
||||
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
AUTH_PASSPHRASE=queenmarlena AUTH_KEYRING_PATH=/home/kamikaze/grassroots/usumbufu/tests/testdata/pgp/.gnupg/ AUTH_KEY=CCE2E1D2D0E36ADE0405E2D0995BB21816313BD5 CHAIN_SPEC=evm:byzantium:8996:bloxberg CIC_REGISTRY_ADDRESS=0xcf60ebc445b636a5ab787f9e8bc465a2a3ef8299 RPC_PROVIDER=https://rpc.grassecon.net TX_CACHE_URL=https://cache.grassecon.net HTTP_CORS_ORIGIN=https://auth.grassecon.net META_HTTP_ORIGIN=https://auth.grassecon.net:443 PYTHONPATH=. python clicada/runnable/view.py u --meta-url https://auth.grassecon.net +254711000000
|
||||
```
|
||||
@@ -73,19 +73,8 @@ class CmdCtrl:
|
||||
|
||||
self.remote_openers = {}
|
||||
if self.get('META_URL') != None:
|
||||
sctx = None
|
||||
if self.cmd_args.cafile != None:
|
||||
import ssl
|
||||
sctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||
sctx.load_verify_locations(self.cmd_args.cafile)
|
||||
|
||||
auth_client_session = PGPClientSession(self.__auth)
|
||||
self.remote_openers['meta'] = HTTPSession(
|
||||
self.get('META_URL'),
|
||||
auth=auth_client_session,
|
||||
origin=self.config.get('META_HTTP_ORIGIN'),
|
||||
ssl_context=sctx,
|
||||
)
|
||||
self.remote_openers['meta'] = HTTPSession(self.get('META_URL'), auth=auth_client_session, origin=self.config.get('META_HTTP_ORIGIN'))
|
||||
|
||||
|
||||
def blockchain(self):
|
||||
|
||||
@@ -12,7 +12,6 @@ from usumbufu.client.base import (
|
||||
)
|
||||
from usumbufu.client.bearer import BearerClientSession
|
||||
from usumbufu.client.hoba import HobaClientSession
|
||||
from urlybird.host import url_apply_port_string
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@@ -22,7 +21,6 @@ class PGPClientSession(HobaClientSession):
|
||||
alg = '969'
|
||||
|
||||
def __init__(self, auth):
|
||||
super(PGPClientSession, self).__init__()
|
||||
self.auth = auth
|
||||
self.origin = None
|
||||
self.fingerprint = self.auth.fingerprint()
|
||||
@@ -48,12 +46,23 @@ class HTTPSession:
|
||||
|
||||
token_dir = '/run/user/{}/clicada/usumbufu/.token'.format(os.getuid())
|
||||
|
||||
def __init__(self, url, auth=None, origin=None, ssl_context=None):
|
||||
def __init__(self, url, auth=None, origin=None):
|
||||
self.base_url = url
|
||||
|
||||
if origin == None:
|
||||
origin = url_apply_port_string(url, as_origin=True)
|
||||
url_parts = urllib.parse.urlsplit(self.base_url)
|
||||
url_parts_origin_host = url_parts[1].split(":")
|
||||
host = url_parts_origin_host[0]
|
||||
try:
|
||||
host = host + ':' + url_parts_origin_host[1]
|
||||
except IndexError:
|
||||
host = host + ':' + str(getservbyname(url_parts[0]))
|
||||
logg.info('changed origin with missing port number from {} to {}'.format(url_parts[1], host))
|
||||
url_parts_origin = (url_parts[0], host, '', '', '',)
|
||||
|
||||
self.origin = origin
|
||||
if self.origin == None:
|
||||
self.origin = urllib.parse.urlunsplit(url_parts_origin)
|
||||
else:
|
||||
logg.debug('overriding http origin for {} with {}'.format(url, self.origin))
|
||||
|
||||
h = hashlib.sha256()
|
||||
h.update(self.base_url.encode('utf-8'))
|
||||
@@ -63,7 +72,7 @@ class HTTPSession:
|
||||
os.makedirs(token_store_dir, exist_ok=True)
|
||||
self.token_store = BaseTokenStore(path=token_store_dir)
|
||||
|
||||
self.session = ClientSession(self.origin, token_store=self.token_store, ssl_context=ssl_context)
|
||||
self.session = ClientSession(self.origin, token_store=self.token_store)
|
||||
|
||||
bearer_handler = BearerClientSession(self.origin, token_store=self.token_store)
|
||||
self.session.add_subhandler(bearer_handler)
|
||||
@@ -79,9 +88,6 @@ class HTTPSession:
|
||||
url = urllib.parse.urljoin(self.base_url, endpoint)
|
||||
logg.debug('open {} with opener {}'.format(url, self))
|
||||
r = self.opener.open(url)
|
||||
logg.debug('response code {} for {}'.format(r.code, endpoint))
|
||||
if r.code == 404:
|
||||
raise FileNotFoundError()
|
||||
return r.read().decode('utf-8')
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ import json
|
||||
|
||||
# external imports
|
||||
from clicada.user import FileUserStore
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
categories = [
|
||||
'phone',
|
||||
@@ -35,7 +36,7 @@ def validate(config, args):
|
||||
|
||||
|
||||
def execute(ctrl):
|
||||
store_path = '.clicada'
|
||||
store_path = os.path.join(str(Path.home()), '.clicada')
|
||||
user_store = FileUserStore(None, ctrl.chain(), ctrl.get('_CATEGORY'), store_path, int(ctrl.get('FILESTORE_TTL')))
|
||||
user_store.put(ctrl.get('_IDENTIFIER'), json.dumps(ctrl.get('_TAG')), force=True)
|
||||
user_store.stick(ctrl.get('_IDENTIFIER'))
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import logging
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from chainlib.encode import TxHexNormalizer
|
||||
from chainlib.eth.address import is_address, to_checksum_address
|
||||
# external imports
|
||||
from cic_eth_registry import CICRegistry
|
||||
from cic_eth_registry.lookup.tokenindex import TokenIndexLookup
|
||||
from cic_types.models.person import Person
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.encode import TxHexNormalizer
|
||||
from hexathon import add_0x
|
||||
|
||||
# local imports
|
||||
from clicada.tx import TxGetter
|
||||
from clicada.user import FileUserStore
|
||||
from clicada.token import (
|
||||
FileTokenStore,
|
||||
token_balance,
|
||||
)
|
||||
from clicada.tx import ResolvedTokenTx
|
||||
from clicada.error import MetadataNotFoundError
|
||||
from clicada.token import FileTokenStore, token_balance
|
||||
# local imports
|
||||
from clicada.tx import ResolvedTokenTx, TxGetter
|
||||
from clicada.user import FileUserStore
|
||||
from hexathon import add_0x
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@@ -29,9 +26,8 @@ tx_normalizer = TxHexNormalizer()
|
||||
def process_args(argparser):
|
||||
argparser.add_argument('-m', '--method', type=str, help='lookup method')
|
||||
argparser.add_argument('--meta-url', dest='meta_url', type=str, help='Url to retrieve metadata from')
|
||||
argparser.add_argument('--cafile', type=str, help='CA certificate chain file to use for verifying SSL session')
|
||||
argparser.add_argument('-f', '--force-update', dest='force_update', action='store_true', help='Update records of mutable entries')
|
||||
argparser.add_argument('identifier', type=str, help='user identifier')
|
||||
argparser.add_argument('identifier', type=str, help='user identifier (phone_number or address)')
|
||||
|
||||
|
||||
def extra_args():
|
||||
@@ -55,22 +51,26 @@ def validate(config, args):
|
||||
def execute(ctrl):
|
||||
tx_getter = TxGetter(ctrl.get('TX_CACHE_URL'), 10)
|
||||
|
||||
store_path = '.clicada'
|
||||
store_path = os.path.join(str(Path.home()), '.clicada')
|
||||
user_phone_file_label = 'phone'
|
||||
user_phone_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_phone_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
||||
|
||||
ctrl.notify('resolving identifier {} to wallet address'.format(ctrl.get('_IDENTIFIER')))
|
||||
user_address = user_phone_store.by_phone(ctrl.get('_IDENTIFIER'), update=ctrl.get('_FORCE'))
|
||||
identifier = ctrl.get('_IDENTIFIER')
|
||||
ctrl.notify('resolving identifier {} to wallet address'.format(identifier))
|
||||
if is_address(identifier):
|
||||
user_address = identifier
|
||||
else:
|
||||
user_address = user_phone_store.by_phone(identifier, update=ctrl.get('_FORCE'))
|
||||
if user_address == None:
|
||||
ctrl.ouch('unknown identifier: {}\n'.format(ctrl.get('_IDENTIFIER')))
|
||||
ctrl.ouch('unknown identifier: {}\n'.format(identifier))
|
||||
sys.exit(1)
|
||||
try:
|
||||
user_address = to_checksum_address(user_address)
|
||||
except ValueError:
|
||||
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, ctrl.get('_IDENTIFIER')))
|
||||
ctrl.ouch('invalid response "{}" for {}\n'.format(user_address, identifier))
|
||||
sys.exit(1)
|
||||
|
||||
logg.debug('loaded user address {} for {}'.format(user_address, ctrl.get('_IDENTIFIER')))
|
||||
logg.debug('loaded user address {} for {}'.format(user_address, identifier))
|
||||
|
||||
user_address_normal = tx_normalizer.wallet_address(user_address)
|
||||
ctrl.notify('retrieving txs for address {}'.format(user_address_normal))
|
||||
@@ -82,31 +82,21 @@ def execute(ctrl):
|
||||
user_address_store = FileUserStore(ctrl.opener('meta'), ctrl.chain(), user_address_file_label, store_path, int(ctrl.get('FILESTORE_TTL')), encrypter=ctrl.encrypter)
|
||||
|
||||
ctrl.notify('resolving metadata for address {}'.format(user_address_normal))
|
||||
r = None
|
||||
try:
|
||||
r = user_address_store.by_address(user_address_normal, update=ctrl.get('_FORCE'))
|
||||
except MetadataNotFoundError as e:
|
||||
ctrl.ouch('could not resolve metadata for user: {}'.format(e))
|
||||
sys.exit(1)
|
||||
|
||||
ctrl.write("""Phone: {}
|
||||
Network address: {}
|
||||
Chain: {}
|
||||
Name: {}
|
||||
Registered: {}
|
||||
Gender: {}
|
||||
Location: {}
|
||||
Products: {}
|
||||
Tags: {}""".format(
|
||||
ctrl.get('_IDENTIFIER'),
|
||||
add_0x(user_address),
|
||||
ctrl.chain().common_name(),
|
||||
str(r),
|
||||
datetime.datetime.fromtimestamp(r.date_registered).ctime(),
|
||||
r.gender,
|
||||
r.location['area_name'],
|
||||
','.join(r.products),
|
||||
','.join(r.tags),
|
||||
)
|
||||
ctrl.write(f"""Phone: {ctrl.get('_IDENTIFIER')}
|
||||
Network address: {add_0x(user_address)}
|
||||
Chain: {ctrl.chain().common_name()}
|
||||
Name: {str(r)}
|
||||
Registered: {r and datetime.datetime.fromtimestamp(r).ctime()}
|
||||
Gender: {r and r.gender}
|
||||
Location: {r and r.location['area_name']}
|
||||
Products: {r and ','.join(r.products)}
|
||||
Tags: {r and ','.join(r.tags)}"""
|
||||
)
|
||||
|
||||
tx_lines = []
|
||||
|
||||
@@ -12,7 +12,7 @@ from cic_types.condiments import MetadataPointer
|
||||
from cic_types.models.person import Person
|
||||
from cic_types.ext.requests import make_request
|
||||
from cic_types.processor import generate_metadata_pointer
|
||||
import requests.exceptions
|
||||
from requests.exceptions import HTTPError
|
||||
import phonenumbers
|
||||
|
||||
# local imports
|
||||
@@ -222,7 +222,7 @@ class FileUserStore:
|
||||
try:
|
||||
r = getter.open(ptr)
|
||||
user_address = json.loads(r)
|
||||
except requests.exceptions.HTTPError as e:
|
||||
except HTTPError as e:
|
||||
logg.debug('no address found for phone {}: {}'.format(phone, e))
|
||||
return None
|
||||
|
||||
@@ -268,8 +268,8 @@ class FileUserStore:
|
||||
r = getter.open(ptr)
|
||||
except Exception as e:
|
||||
logg.debug('no metadata found for {}: {}'.format(address, e))
|
||||
|
||||
if r == None:
|
||||
|
||||
if not r:
|
||||
self.failed_entities[address] = True
|
||||
raise MetadataNotFoundError()
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
usumbufu~=0.3.6
|
||||
confini~=0.5.4
|
||||
cic-eth-registry~=0.6.1
|
||||
cic-types~=0.2.1a8
|
||||
usumbufu~=0.3.8
|
||||
confini~=0.6.0
|
||||
cic-eth-registry~=0.6.9
|
||||
cic-types~=0.2.2
|
||||
phonenumbers==8.12.12
|
||||
eth-erc20~=0.1.2
|
||||
eth-erc20~=0.3.0
|
||||
hexathon~=0.1.0
|
||||
pycryptodome~=3.10.1
|
||||
chainlib-eth~=0.0.21
|
||||
chainlib~=0.0.17
|
||||
urlybird~=0.0.2
|
||||
chainlib-eth~=0.1.0
|
||||
chainlib~=0.1.0
|
||||
|
||||
Reference in New Issue
Block a user