Esempio n. 1
0
def main():
    args = add_args()
    logger.info(f"PaymentProvider: {args.payment_provider} TXID: {args.tx_id} "
                f"Status: Script executing Action: Processing")

    if args.debug:
        logging.root.setLevel(logging.DEBUG)
    else:
        logging.root.setLevel(logging.INFO)

    settings.security_level = args.security_level

    payment_providers = {"Monero": MoneroFactory}

    if args.payment_provider in payment_providers:
        transaction_factory = payment_providers[args.payment_provider](
            server_config_file=args.server_config_file)
    else:
        logger.critical("The supplied payment provider is not supported")
        exit(1)

    try:
        transaction = transaction_factory.get_transaction(
            tx_id=args.tx_id,
            get_tx_data=args.get_tx_data,
            get_raw_data=args.get_raw_data,
        )
    except Exception as e:
        logger.exception(e)
        exit(1)

    try:
        apprise_result = transaction.notify(
            urls=split_urls(args.urls),
            body=args.body,
            title=args.title,
            attach=args.attach,
        )
        if apprise_result:
            logger.info(
                f"PaymentProvider: {transaction.payment_provider} TXID: {transaction.tx_id} "
                f"Status: Notification(s) sent via apprise")
    except Exception as ae:
        logger.exception(ae)
        exit(1)
Esempio n. 2
0
def test_split_urls():
    """utils: split_urls() testing """
    # A simple single array entry (As str)
    results = utils.split_urls('')
    assert isinstance(results, list)
    assert len(results) == 0

    # just delimeters
    results = utils.split_urls(',  ,, , ,,, ')
    assert isinstance(results, list)
    assert len(results) == 0

    results = utils.split_urls(',')
    assert isinstance(results, list)
    assert len(results) == 0

    results = utils.split_urls(None)
    assert isinstance(results, list)
    assert len(results) == 0

    results = utils.split_urls(42)
    assert isinstance(results, list)
    assert len(results) == 0

    results = utils.split_urls('this is not a parseable url at all')
    assert isinstance(results, list)
    assert len(results) == 0

    # Now test valid URLs
    results = utils.split_urls('windows://')
    assert isinstance(results, list)
    assert len(results) == 1
    assert 'windows://' in results

    results = utils.split_urls('windows:// gnome://')
    assert isinstance(results, list)
    assert len(results) == 2
    assert 'windows://' in results
    assert 'gnome://' in results

    # Commas and spaces found inside URLs are ignored
    urls = [
        'mailgun://[email protected]/apikey/[email protected],'
        '[email protected],, [email protected]',
        'mailgun://[email protected]/apikey/'
        '[email protected],,[email protected],, [email protected], ,',
        'windows://',
    ]

    # Since comma's and whitespace are the delimiters; they won't be
    # present at the end of the URL; so we just need to write a special
    # rstrip() as a regular exression to handle whitespace (\s) and comma
    # delimiter
    rstrip_re = re.compile(r'[\s,]+$')

    # Since a comma acts as a delimiter, we run a risk of a problem where the
    # comma exists as part of the URL and is therefore lost if it was found
    # at the end of it.

    results = utils.split_urls(', '.join(urls))
    assert isinstance(results, list)
    assert len(results) == len(urls)
    for url in urls:
        assert rstrip_re.sub('', url) in results

    # However if a comma is found at the end of a single url without a new
    # match to hit, it is saved and not lost

    # The comma at the end of the password will not be lost if we're
    # dealing with a single entry:
    url = 'http://hostname?password=,abcd,'
    results = utils.split_urls(url)
    assert isinstance(results, list)
    assert len(results) == 1
    assert url in results

    # however if we have multiple entries, commas and spaces between
    # URLs will be lost, however the last URL will not lose the comma
    urls = [
        'schema1://hostname?password=,abcd,',
        'schema2://hostname?password=,abcd,',
    ]
    results = utils.split_urls(', '.join(urls))
    assert isinstance(results, list)
    assert len(results) == len(urls)

    # No match because the comma is gone in the results entry
    # schema1://hostname?password=,abcd
    assert urls[0] not in results
    assert urls[0][:-1] in results

    # However we wouldn't have lost the comma in the second one:
    # schema2://hostname?password=,abcd,
    assert urls[1] in results