Philip/dry run prep

This commit is contained in:
Philip Wafula 2021-03-05 16:28:07 +00:00
parent aa99b16ad2
commit ea336283dc
11 changed files with 38 additions and 30 deletions

View File

@ -1,7 +1,7 @@
[database]
NAME=cic_ussd
USER=postgres
PASSWORD=password
PASSWORD=
HOST=localhost
PORT=5432
ENGINE=postgresql

View File

@ -1,4 +1,5 @@
[keys]
public = ../cic-internal-integration/apps/contract-migration/testdata/pgp/publickeys_meta.asc
private = ../cic-internal-integration/apps/contract-migration/testdata/pgp/privatekeys_meta.asc
passphrase = merman
[pgp]
export_dir = /usr/src/pgp/keys/
keys_path = /usr/src/secrets/
private_keys = privatekeys_meta.asc
passphrase =

View File

@ -1,4 +1,5 @@
[keys]
public = ../cic-internal-integration/apps/contract-migration/testdata/pgp/publickeys_meta.asc
private = ../cic-internal-integration/apps/contract-migration/testdata/pgp/privatekeys_meta.asc
passphrase = merman
[pgp]
export_dir = /usr/src/pgp/keys/
keys_path = /usr/src/secrets/
private_keys = privatekeys_meta.asc
passphrase =

View File

@ -102,9 +102,9 @@ def process_exit_successful_transaction(display_key: str, user: User, ussd_sessi
transaction_amount = to_wei(int(ussd_session.get('session_data').get('transaction_amount')))
token_symbol = 'SRF'
recipient_phone_number = ussd_session.get('session_data').get('recipient_phone_number')
sender_phone_number = user.phone_number
tx_recipient_information = recipient_phone_number
tx_sender_information = sender_phone_number
recipient = get_user_by_phone_number(phone_number=recipient_phone_number)
tx_recipient_information = define_account_tx_metadata(user=recipient)
tx_sender_information = define_account_tx_metadata(user=user)
return translation_for(
key=display_key,
@ -184,10 +184,10 @@ def format_transactions(transactions: list, preferred_language: str):
for transaction in transactions:
recipient_phone_number = transaction.get('recipient_phone_number')
sender_phone_number = transaction.get('sender_phone_number')
value = transaction.get('destination_value')
value = transaction.get('to_value')
timestamp = transaction.get('timestamp')
action_tag = transaction.get('action_tag')
token_symbol = transaction.get('destination_token_symbol')
token_symbol = 'SRF'
if action_tag == 'SENT' or action_tag == 'ULITUMA':
formatted_transactions += f'{action_tag} {value} {token_symbol} {recipient_phone_number} {timestamp}.\n'
@ -222,6 +222,8 @@ def process_account_statement(user: User, display_key: str, ussd_session: dict):
middle_transaction_set = []
last_transaction_set = []
transactions = json.loads(transactions)
if len(transactions) > 6:
last_transaction_set += transactions[6:]
middle_transaction_set += transactions[3:][:3]
@ -233,10 +235,7 @@ def process_account_statement(user: User, display_key: str, ussd_session: dict):
else:
first_transaction_set += transactions[:3]
logg.debug(f'TRANSACTIONS: {transactions}')
if display_key == 'ussd.kenya.first_transaction_set':
logg.debug(f'FIRST TRANSACTION SET: {first_transaction_set}')
return translation_for(
key=display_key,
preferred_language=user.preferred_language,

View File

@ -101,9 +101,9 @@ InMemoryUssdSession.redis_cache = InMemoryStore.cache
UserMetadata.base_url = config.get('CIC_META_URL')
# define signer values
Signer.gpg_path = '/tmp/.gpg'
Signer.gpg_passphrase = config.get('KEYS_PASSPHRASE')
Signer.key_file_path = config.get('KEYS_PRIVATE')
Signer.gpg_path = config.get('PGP_EXPORT_DIR')
Signer.gpg_passphrase = config.get('PGP_PASSPHRASE')
Signer.key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
# initialize celery app
celery.Celery(backend=config.get('CELERY_RESULT_URL'), broker=config.get('CELERY_BROKER_URL'))

View File

@ -39,7 +39,6 @@ config.censor('PASSWORD', 'DATABASE')
# define log levels
if args.vv:
logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
elif args.v:
logging.getLogger().setLevel(logging.INFO)
@ -66,9 +65,9 @@ InMemoryUssdSession.redis_cache = InMemoryStore.cache
UserMetadata.base_url = config.get('CIC_META_URL')
# define signer values
Signer.gpg_path = '/tmp/.gpg'
Signer.gpg_passphrase = config.get('KEYS_PASSPHRASE')
Signer.key_file_path = config.get('KEYS_PRIVATE')
Signer.gpg_path = config.get('PGP_EXPORT_DIR')
Signer.gpg_passphrase = config.get('PGP_PASSPHRASE')
Signer.key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
# set up celery
current_app = celery.Celery(__name__)

View File

@ -165,7 +165,6 @@ def process_statement_callback(result, param: str, status_code: int):
sender_blockchain_address = transaction.get('sender')
recipient_address = transaction.get('recipient')
source_token = transaction.get('source_token')
destination_token_symbol = transaction.get('destination_token_symbol')
# filter out any transactions that are "gassy"
if '0x0000000000000000000000000000000000000000' in source_token:
@ -198,9 +197,8 @@ def process_statement_callback(result, param: str, status_code: int):
logg.warning(f'Tx with recipient not found in cic-ussd')
# add transaction values
processed_transaction['destination_value'] = from_wei(value=transaction.get('destination_value'))
processed_transaction['destination_token_symbol'] = destination_token_symbol
processed_transaction['source_value'] = from_wei(value=transaction.get('source_value'))
processed_transaction['to_value'] = from_wei(value=transaction.get('to_value'))
processed_transaction['from_value'] = from_wei(value=transaction.get('from_value'))
raw_timestamp = transaction.get('timestamp')
timestamp = datetime.utcfromtimestamp(raw_timestamp).strftime('%d/%m/%y, %H:%M')

View File

@ -11,6 +11,9 @@ RUN apk update && \
apk add git linux-headers postgresql-dev gnupg bash
RUN apk add --update musl-dev gcc libffi-dev
# create secrets directory
RUN mkdir -vp pgp/keys
# create application directory
RUN mkdir -vp cic-ussd

View File

@ -33,6 +33,7 @@ packages =
cic_ussd.db.models
cic_ussd.files
cic_ussd.menu
cic_ussd.metadata
cic_ussd.runnable
cic_ussd.session
cic_ussd.state_machine

View File

@ -114,8 +114,8 @@ def setup_metadata_signer(load_config):
temp_dir = tempfile.mkdtemp(dir='/tmp')
logg.debug(f'Created temp dir: {temp_dir}')
Signer.gpg_path = temp_dir
Signer.key_file_path = load_config.get('KEYS_PRIVATE')
Signer.gpg_passphrase = load_config.get('KEYS_PASSPHRASE')
Signer.gpg_passphrase = load_config.get('PGP_PASSPHRASE')
Signer.key_file_path = f"{load_config.get('PGP_KEYS_PATH')}{load_config.get('PGP_PRIVATE_KEYS')}"
@pytest.fixture(scope='function')

View File

@ -466,12 +466,15 @@ services:
DATABASE_NAME: cic_ussd
DATABASE_ENGINE: postgresql
DATABASE_DRIVER: psycopg2
PGP_PASSPHRASE: merman
SERVER_PORT: 8000
ports:
- ${HTTP_PORT_CIC_USSD:-63315}:8000
depends_on:
- postgres
- redis
volumes:
- ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
deploy:
restart_policy:
condition: on-failure
@ -492,9 +495,12 @@ services:
DATABASE_DRIVER: psycopg2
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
PGP_PASSPHRASE: merman
depends_on:
- postgres
- redis
volumes:
- ./apps/contract-migration/testdata/pgp/:/usr/src/secrets/
deploy:
restart_policy:
condition: on-failure