Exemplo n.º 1
0
def generate(client, parameters, progress_callback):
    product_rql = R().status.eq('active')

    if parameters.get('product') and parameters['product']['all'] is False:
        product_rql &= R().product.id.oneof(parameters['product']['choices'])

    assets = client.ns('subscriptions').assets.filter(product_rql)

    total = assets.count()
    progress = Progress(progress_callback, total)
    start_date = parameters['period']['after']
    end_date = parameters['period']['before']

    ex = futures.ThreadPoolExecutor()

    wait_for = []
    try:
        for asset in assets:
            wait_for.append(
                ex.submit(
                    get_record,
                    client,
                    asset,
                    start_date,
                    end_date,
                    progress,
                ), )
        for future in futures.as_completed(wait_for):
            yield future.result()
    except ClientError:
        for future in wait_for:
            future.cancel()
        raise
Exemplo n.º 2
0
def cmd_list_products(config, query, page_size, always_continue):
    acc_id = config.active.id
    acc_name = config.active.name
    if not config.silent:
        click.echo(
            click.style(
                f'Current active account: {acc_id} - {acc_name}\n',
                fg='blue',
            ), )
    client = ConnectClient(
        api_key=config.active.api_key,
        endpoint=config.active.endpoint,
        use_specs=False,
        max_retries=3,
    )

    if acc_id.startswith('VA'):
        default_query = R().visibility.owner.eq(True) & R().version.null(True)
    else:
        default_query = R().visibility.listing.eq(
            True) | R().visibility.syndication.eq(True)

    query = query or default_query
    paging = 0
    query_products = client.products.filter(query).limit(page_size)

    for prod in query_products:
        paging += 1
        click.echo(f"{prod['id']} - {prod['name']}", )
        if paging % page_size == 0 and paging != query_products.count(
        ) and not always_continue:
            if not continue_or_quit():
                return
Exemplo n.º 3
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('tier_type') and parameters['tier_type']['all'] is False:
        query &= R().scopes.oneof(parameters['tier_type']['choices'])
    marketplaces_list = client.marketplaces.all()
    hubs = {}
    for marketplace in marketplaces_list:
        if 'hubs' in marketplace:
            for hub in marketplace['hubs']:
                if 'hub' in hub and hub['hub']['id'] not in hubs:
                    hubs[hub['hub']['id']] = marketplace['owner']

    customers = client.ns('tier').accounts.filter(query).order_by(
        '-events.created.at').limit(1000)

    total = customers.count()

    def get_provider(hub, prop):
        if not hub or hub == '-' or hub not in hubs:  # pragma: no branch
            return '-'  # pragma: no cover
        return hubs[hub][prop]

    def create_phone(pn):
        return f'{pn["country_code"]}{pn["area_code"]}{pn["phone_number"]}{pn["extension"]}'

    progress = 0

    for customer in customers:
        contact = customer['contact_info']

        yield (
            get_basic_value(customer, 'id'),
            get_basic_value(customer, 'external_id'),
            'Yes' if 'customer' in customer['scopes'] else '-',
            'Yes' if 'tier1' in customer['scopes'] else '-',
            'Yes' if 'tier2' in customer['scopes'] else '-',
            get_provider(get_value(customer, 'hub', 'id'), 'id'),
            get_provider(get_value(customer, 'hub', 'id'), 'name'),
            get_basic_value(customer, 'name'),
            get_basic_value(customer, 'tax_id'),
            get_basic_value(contact, 'address_line1'),
            get_basic_value(contact, 'address_line2'),
            get_basic_value(contact, 'city'),
            get_basic_value(contact, 'state'),
            get_basic_value(contact, 'postal_code'),
            get_basic_value(contact, 'country'),
            get_value(contact, 'contact', 'first_name'),
            get_value(contact, 'contact', 'last_name'),
            get_value(contact, 'contact', 'email'),
            create_phone(contact['contact']['phone_number']),
            'Available',
        )
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 4
0
def _get_contracts(client, parameters):
    query = R()

    if parameters.get('type') and parameters['type']['all'] is False:
        query &= R().type.oneof(parameters['type']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])

    return client.contracts.filter(query).select("agreement").order_by(
        "-status")
Exemplo n.º 5
0
def _get_customers(client, parameters):
    query = R()

    if parameters.get('date') and parameters['date'].get('after'):
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('tier_type') and parameters['tier_type']['all'] is False:
        query &= R().scopes.oneof(parameters['tier_type']['choices'])

    return client.ns('tier').accounts.filter(query).order_by('-events.created.at').limit(1000)
Exemplo n.º 6
0
def _get_requests(client, parameters):
    all_status = ['tiers_setup', 'inquiring', 'pending', 'approved', 'failed']

    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_status)
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('hub') and parameters['hub']['all'] is False:
        query &= R().asset.connection.hub.id.oneof(
            parameters['hub']['choices'])

    return client.requests.filter(query).select(
        '-asset.items',
        '-asset.params',
        '-asset.configuration',
    )
Exemplo n.º 7
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('type') and parameters['type']['all'] is False:
        query &= R().type.oneof(parameters['type']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])
    contracts = client.contracts.filter(query).select("agreement").order_by(
        "-status")
    progress = 0
    total = contracts.count()

    for contract in contracts:
        yield (
            get_basic_value(contract, 'id'),
            get_basic_value(contract, 'type'),
            get_basic_value(contract, 'version'),
            'Yes' if get_basic_value(contract, 'latest') is False else '-',
            get_value(contract, 'agreement', 'id'),
            get_value(contract, 'agreement', 'name'),
            get_value(contract, 'issuer', 'name'),
            convert_to_datetime(get_value(contract['events'], 'created',
                                          'at')),
            get_value(contract, 'marketplace', 'id'),
            get_value(contract, 'marketplace', 'name'),
            get_value(contract['sourcing'], 'product', 'id')
            if 'sourcing' in contract else '-',
            get_value(contract['sourcing'], 'product', 'name')
            if 'sourcing' in contract else '-',
            get_value(
                contract['events']['signed'],
                'by',
                'name',
            ) if 'signed' in contract['events'] else '-',
            convert_to_datetime(
                get_value(
                    contract['events'],
                    'signed',
                    'at',
                ), ) if 'created' in contract['events'] else '-',
            get_value(
                contract['events']['countersigned'],
                'by',
                'name',
            ) if 'countersigned' in contract['events'] else '-',
            convert_to_datetime(
                get_value(
                    contract['events'],
                    'countersigned',
                    'at',
                ), ) if 'countersigned' in contract['events'] else '-',
        )
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 8
0
def product_list(config, client, param):
    if config.id.startswith('VA'):
        default_query = R().visibility.owner.eq(True) & R().version.null(True)
    else:
        default_query = R().visibility.listing.eq(
            True) | R().visibility.syndication.eq(True)
    products = client.products.filter(default_query).order_by('name')
    return {
        'name': param['id'],
        'type': 'selectmany',
        'description': f'{param["description"]}',
        'values': [(p['id'], f'{p["name"]} ({p["id"]})') for p in products],
        'validators': required_validator(param),
    }
Exemplo n.º 9
0
def generate(
    client=None,
    parameters=None,
    progress_callback=None,
    renderer_type=None,
    extra_context_callback=None,
):
    product_rql = R().status.eq('active')

    if parameters.get('product') and parameters['product']['all'] is False:
        product_rql &= R().product.id.oneof(parameters['product']['choices'])

    assets = client.ns('subscriptions').assets.filter(product_rql)

    total = assets.count()
    start_date = parameters['period']['after']
    end_date = parameters['period']['before']

    ex = futures.ThreadPoolExecutor()
    if renderer_type == 'csv':
        total += 1
        progress = Progress(progress_callback, total)
        progress.increment()
        yield HEADERS
    else:
        progress = Progress(progress_callback, total)

    wait_for = []
    try:
        for asset in assets:
            wait_for.append(
                ex.submit(
                    get_record,
                    client,
                    asset,
                    start_date,
                    end_date,
                    progress,
                    renderer_type,
                ), )
        for future in futures.as_completed(wait_for):
            yield future.result()
    except ClientError:  # pragma: no cover
        for future in wait_for:
            future.cancel()
        raise
Exemplo n.º 10
0
def generate(
    client=None,
    parameters=None,
    progress_callback=None,
    renderer_type=None,
    extra_context_callback=None,
):
    try:
        offset_red = int(parameters['offset_red_days'])
        offset_yellow = int(parameters['offset_yellow_days'])

    except Exception:
        raise RuntimeError(
            "Yellow and Red zone must be defined as amount of days")

    if offset_red <= offset_yellow:
        raise RuntimeError("Red zone must be for more days than yellow one")

    query = R()
    query &= R().status.eq('pending')
    if parameters.get(
            'trans_type') and parameters['trans_type']['all'] is False:
        query &= R().asset.connection.type.oneof(
            parameters['trans_type']['choices'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    requests = client.requests.filter(query).select(
        '-asset.items',
        '-asset.params',
        '-asset.configuration',
    ).order_by('created')

    total = requests.count()

    progress = 0

    levels = {
        'red': offset_red,
        'yellow': offset_yellow,
    }

    for request in requests:
        yield _process_line(request, levels)
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 11
0
def generate(client, parameters, progress_callback):
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('period') and parameters['period']['all'] is False:
        query &= R().billing.period.uom.oneof(parameters['period']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])

    subscriptions = client.ns('subscriptions').assets.filter(query)
    progress = 0
    total = subscriptions.count()

    for subscription in subscriptions:
        yield (
            subscription.get('id'),
            subscription.get('external_id', '-'),
            convert_to_datetime(subscription['events']['created']['at']),
            convert_to_datetime(subscription['events']['updated']['at']),
            subscription.get('status'),
            calculate_period(
                subscription['billing']['period']['delta'],
                subscription['billing']['period']['uom'],
            ) if 'billing' in subscription else '-',
            get_anniversary_day(subscription['billing'])
            if 'billing' in subscription else '-',
            get_anniversary_month(subscription['billing'])
            if 'billing' in subscription else '-',
            subscription['contract']['id']
            if 'contract' in subscription else '-',
            subscription['contract']['name']
            if 'contract' in subscription else '-',
            get_value(subscription.get('tiers', ''), 'customer', 'id'),
            get_value(subscription.get('tiers', ''), 'customer', 'name'),
            get_value(subscription.get('tiers', ''), 'customer',
                      'external_id'),
            get_value(subscription.get('tiers', ''), 'tier1', 'id'),
            get_value(subscription.get('tiers', ''), 'tier1', 'name'),
            get_value(subscription.get('tiers', ''), 'tier1', 'external_id'),
            get_value(subscription.get('tiers', ''), 'tier2', 'id'),
            get_value(subscription.get('tiers', ''), 'tier2', 'name'),
            get_value(subscription.get('tiers', ''), 'tier2', 'external_id'),
            get_value(subscription['connection'], 'provider', 'id'),
            get_value(subscription['connection'], 'provider', 'name'),
            get_value(subscription['connection'], 'vendor', 'id'),
            get_value(subscription['connection'], 'vendor', 'name'),
            get_value(subscription, 'product', 'id'),
            get_value(subscription, 'product', 'name'),
            get_value(subscription['connection'], 'hub', 'id'),
            get_value(subscription['connection'], 'hub', 'name'),
        )
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 12
0
def get_item_by_mpn(client, product_id, mpn):
    rql = R().mpn.eq(mpn)

    try:
        res = (client.products[product_id].items.filter(rql))
        return res.first()

    except ClientError as error:
        if error.status_code == 404:
            return
        handle_http_error(error)
Exemplo n.º 13
0
def generate(client, parameters, progress_callback):

    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    query &= R().status.eq('failed')
    if parameters.get('connection_type') and parameters['connection_type']['all'] is False:
        query &= R().asset.connection.type.oneof(parameters['connection_type']['choices'])
    requests = client.requests.filter(query)
    progress = 0
    total = requests.count()
    today = datetime.today().strftime('%Y-%m-%d-%H:%M:%S')
    for request in requests:
        connection = request['asset']['connection']
        yield (
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            convert_to_datetime(
                get_basic_value(request, 'created'),
            ),
            convert_to_datetime(
                get_basic_value(request, 'updated'),
            ),
            today,
            get_value(request['asset']['tiers'], 'customer', 'id'),
            get_value(request['asset']['tiers'], 'customer', 'name'),
            get_value(request['asset']['tiers'], 'customer', 'external_id'),
            get_value(request['asset']['tiers'], 'tier1', 'id'),
            get_value(request['asset']['tiers'], 'tier1', 'name'),
            get_value(request['asset']['tiers'], 'tier1', 'external_id'),
            get_value(request['asset']['tiers'], 'tier2', 'id'),
            get_value(request['asset']['tiers'], 'tier2', 'name'),
            get_value(request['asset']['tiers'], 'tier2', 'external_id'),
            get_value(request['asset']['connection'], 'provider', 'id'),
            get_value(request['asset']['connection'], 'provider', 'name'),
            get_value(request['asset']['connection'], 'vendor', 'id'),
            get_value(request['asset']['connection'], 'vendor', 'name'),
            get_value(request['asset'], 'product', 'id'),
            get_value(request['asset'], 'product', 'name'),
            get_value(request, 'asset', 'id'),
            get_value(request, 'asset', 'external_id'),
            get_value(request['asset'], 'connection', 'type'),
            get_value(connection, 'hub', 'id') if 'hub' in connection else '',
            get_value(connection, 'hub', 'name') if 'hub' in connection else '',
            get_value(request, 'asset', 'status'),
            get_basic_value(request, 'reason'),
        )

        progress += 1
        progress_callback(progress, total)
Exemplo n.º 14
0
def _dump_translations(wb, client, product_id, silent):
    ws = wb.create_sheet('Translations')
    _setup_ws_header(ws, 'translations')
    ws.column_dimensions['F'].width = 30
    ws.column_dimensions['J'].width = 15
    ws.column_dimensions['K'].width = 15

    rql = R().context.instance_id.eq(product_id)

    translations = (client.ns('localization').translations.filter(rql))
    count = translations.count()

    action_validation = DataValidation(
        type='list',
        formula1='"-,delete,update,create"',
        allow_blank=False,
    )
    no_action_validation = DataValidation(
        type='list',
        formula1='"-"',
        allow_blank=False,
    )
    disabled_enabled = DataValidation(
        type='list',
        formula1='"Disabled,Enabled"',
        allow_blank=False,
    )
    ws.add_data_validation(action_validation)
    ws.add_data_validation(no_action_validation)
    ws.add_data_validation(disabled_enabled)

    progress = trange(0,
                      count,
                      disable=silent,
                      leave=True,
                      bar_format=DEFAULT_BAR_FORMAT)

    for row_idx, translation in enumerate(translations, 2):
        progress.set_description(f'Processing translation {translation["id"]}')
        progress.update(1)
        fill_translation_row(ws, row_idx, translation)
        if translation['primary']:
            no_action_validation.add(ws[f'B{row_idx}'])
        else:
            action_validation.add(ws[f'B{row_idx}'])
        disabled_enabled.add(ws[f'I{row_idx}'])
        _dump_translation_attr(wb, client, translation)

    setup_locale_data_validation(wb['General Information'], ws)
    progress.close()
    print()
Exemplo n.º 15
0
def _get_request_count_group_by_type(client, parameters):
    final_status = (
        'approved',
        'failed',
        'revoked',
    )
    rr_types = ('adjustment', 'purchase', 'change', 'suspend', 'resume',
                'cancel')
    filters = R().created.ge(parameters['date']['after'])
    filters &= R().created.le(parameters['date']['before'])
    filters &= R().status.oneof(final_status)

    if parameters.get('product') and parameters['product']['all'] is False:
        filters &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        rr_types = parameters['rr_type']['choices']

    result = {}
    for rtype in rr_types:
        result[rtype] = client.requests.filter(filters
                                               & R().type.eq(rtype)).count()

    return result, client.requests.filter(filters).count()
Exemplo n.º 16
0
def generate(
    client=None,
    parameters=None,
    progress_callback=None,
    renderer_type=None,
    extra_context_callback=None,
):
    syndication_group = 'PRG-5440-3996'
    products = client.ns('catalog').collection(
        'groups')[syndication_group].products.all().order_by('name')
    total_products = products.count()
    progress = 0
    for prod in products:
        product = client.products[prod['id']].get()
        output = {
            'id': product['id'],
            'name': product['name'],
            'vendor_id': product['owner']['id'],
            'vendor_name': product['owner']['name']
        }
        rql = R()
        rql &= R().product.id.eq(product['id'])
        rql &= R().status.eq('listed')
        listings = client.listings.filter(rql).all()
        marketplaces = []
        for listing in listings:
            marketplaces.append({
                'id':
                listing['contract']['marketplace']['id'],
                'name':
                listing['contract']['marketplace']['name']
            })
        output['marketplaces'] = marketplaces
        yield output
        progress += 1
        progress_callback(progress, total_products)
Exemplo n.º 17
0
def generate(client, parameters, progress_callback):
    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('hub') and parameters['hub']['all'] is False:
        query &= R().asset.connection.hub.id.oneof(parameters['hub']['choices'])

    requests = client.ns('subscriptions').requests.filter(query)
    progress = 0
    total = requests.count()
    for request in requests:
        connection = request['asset']['connection']
        for item in request['items']:
            yield (
                request['id'],
                convert_to_datetime(request['period']['from']),
                convert_to_datetime(request['period']['to']),
                get_basic_value(request['period'], 'delta'),
                get_basic_value(request['period'], 'uom'),
                get_basic_value(item['billing'], 'cycle_number'),
                get_basic_value(item, 'global_id'),
                get_basic_value(item, 'display_name'),
                get_basic_value(item, 'item_type'),
                get_basic_value(item, 'type'),
                get_basic_value(item, 'mpn'),
                get_basic_value(item, 'period'),
                get_basic_value(item, 'quantity'),
                get_value(request['asset']['tiers'], 'customer', 'id'),
                get_value(request['asset']['tiers'], 'customer', 'name'),
                get_value(request['asset']['tiers'], 'customer', 'external_id'),
                get_value(request['asset']['tiers'], 'tier1', 'id'),
                get_value(request['asset']['tiers'], 'tier1', 'name'),
                get_value(request['asset']['tiers'], 'tier1', 'external_id'),
                get_value(request['asset']['tiers'], 'tier2', 'id'),
                get_value(request['asset']['tiers'], 'tier2', 'name'),
                get_value(request['asset']['tiers'], 'tier2', 'external_id'),
                get_value(request['asset']['connection'], 'provider', 'id'),
                get_value(request['asset']['connection'], 'provider', 'name'),
                get_value(request['asset']['connection'], 'vendor', 'id'),
                get_value(request['asset']['connection'], 'vendor', 'name'),
                get_value(request['asset'], 'product', 'id'),
                get_value(request['asset'], 'product', 'name'),
                get_value(request, 'asset', 'id'),
                get_value(request, 'asset', 'external_id'),
                get_value(request, 'asset', 'status'),
                get_value(request['asset'], 'connection', 'type'),
                get_value(connection, 'hub', 'id') if 'hub' in connection else '',
                get_value(connection, 'hub', 'name') if 'hub' in connection else '',
            )
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 18
0
def _get_requests(client, parameters):
    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    query &= R().asset.connection.provider.id.ne('PA-239-689')

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().asset.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('hub') and parameters['hub']['all'] is False:
        query &= R().asset.connection.hub.id.oneof(
            parameters['hub']['choices'])

    return client.ns('subscriptions').requests.filter(query)
Exemplo n.º 19
0
def _get_subscriptions(client, parameters):
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('period') and parameters['period']['all'] is False:
        query &= R().billing.period.uom.oneof(parameters['period']['choices'])
    if parameters.get('status') and parameters['status']['all'] is False:
        query &= R().status.oneof(parameters['status']['choices'])

    return client.ns('subscriptions').assets.filter(query)
Exemplo n.º 20
0
def _get_requests(client, parameters):
    all_types = ['tiers_setup', 'inquiring', 'pending', 'approved', 'failed']

    query = R()
    query &= R().events.created.at.ge(parameters['date']['after'])
    query &= R().events.created.at.le(parameters['date']['before'])

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)

    return client.ns('tier').collection('config-requests').filter(query).order_by('-created')
Exemplo n.º 21
0
def _get_configurations(client, parameters):
    all_types = ['active', 'processing']
    query = R()

    if parameters.get("date") and parameters['date']['after'] != '':
        query &= R().events.created.at.ge(parameters['date']['after'])
        query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)

    return client.ns('tier').configs.filter(query).order_by('-created')
Exemplo n.º 22
0
def _get_requests(client, parameters):
    final_status = ('approved', 'failed', 'revoked')

    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])
    query &= R().status.oneof(final_status)

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    return client.requests.filter(query).select('-asset.params',
                                                '-asset.configuration')
Exemplo n.º 23
0
def _get_listings(client, parameters):
    all_status = ['listed', 'unlisted']
    query = R()

    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().created.ge(parameters['date']['after'])
        query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().contract.marketplace.id.oneof(
            parameters['mkp']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().state.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().state.oneof(all_status)

    return client.listings.filter(query).order_by("-created")
Exemplo n.º 24
0
def _get_requests(client, parameters):
    all_status = ['draft', 'reviewing', 'deploying', 'completed', 'canceled']
    query = R()

    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().created.ge(parameters['date']['after'])
        query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().listing.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().listing.contract.marketplace.id.oneof(
            parameters['mkp']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().state.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().state.oneof(all_status)

    return client.listing_requests.filter(query).order_by("-created")
Exemplo n.º 25
0
def generate(client, parameters, progress_callback):
    all_status = ['draft', 'reviewing', 'deploying', 'completed', 'canceled']
    query = R()
    if parameters.get('date') and parameters['date']['after'] != '':
        query &= R().created.ge(parameters['date']['after'])
        query &= R().created.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().listing.product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().listing.contract.marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().state.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().state.oneof(all_status)
    requests = client.listing_requests.filter(query).order_by("-created")
    progress = 0
    total = requests.count()
    today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')

    for request in requests:
        yield (
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            get_basic_value(request, 'state'),
            convert_to_datetime(
                get_basic_value(request, 'created'),
            ),
            convert_to_datetime(
                get_basic_value(request, 'updated'),
            ),
            today,
            get_value(request, 'listing', 'id'),
            get_value(request['listing'], 'contract', 'id'),
            get_value(request, 'product', 'id'),
            get_value(request, 'product', 'name'),
            get_value(request['listing'], 'provider', 'id'),
            get_value(request['listing'], 'provider', 'name'),
            get_value(request['listing'], 'vendor', 'id'),
            get_value(request['listing'], 'vendor', 'name'),
        )
        progress += 1
        progress_callback(progress, total)
Exemplo n.º 26
0
def _get_requests(client, parameters):
    query = R()
    query &= R().created.ge(parameters['date']['after'])
    query &= R().created.le(parameters['date']['before'])

    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().asset.product.id.oneof(parameters['product']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    query &= R().status.eq('failed')
    if parameters.get('connection_type'
                      ) and parameters['connection_type']['all'] is False:
        query &= R().asset.connection.type.oneof(
            parameters['connection_type']['choices'])

    return client.requests.filter(query).select(
        '-asset.items',
        '-asset.params,'
        '-asset.configuration',
    )
Exemplo n.º 27
0
def _dump_parameters(ws, client, product_id, param_type, silent):
    _setup_ws_header(ws, 'params')

    rql = R().phase.eq(param_type)

    row_idx = 2

    params = client.products[product_id].parameters.filter(rql)
    count = params.count()

    if count == 0:
        # Product without params is strange, but may exist
        return
    action_validation = DataValidation(
        type='list',
        formula1='"-,create,update,delete"',
        allow_blank=False,
    )
    type_validation = DataValidation(
        type='list',
        formula1='"{params}"'.format(params=','.join(PARAM_TYPES), ),
        allow_blank=False,
    )
    ordering_fulfillment_scope_validation = DataValidation(
        type='list',
        formula1='"asset,tier1,tier2"',
        allow_blank=False,
    )
    configuration_scope_validation = DataValidation(
        type='list',
        formula1='"product,marketplace,item,item_marketplace"',
        allow_blank=False,
    )
    bool_validation = DataValidation(
        type='list',
        formula1='"True,-"',
        allow_blank=False,
    )
    ws.add_data_validation(action_validation)
    ws.add_data_validation(type_validation)
    ws.add_data_validation(ordering_fulfillment_scope_validation)
    ws.add_data_validation(configuration_scope_validation)
    ws.add_data_validation(bool_validation)

    progress = trange(0,
                      count,
                      disable=silent,
                      leave=True,
                      bar_format=DEFAULT_BAR_FORMAT)

    for param in params:
        progress.set_description(
            f'Processing {param_type} parameter {param["id"]}')
        progress.update(1)
        _fill_param_row(ws, row_idx, param)
        action_validation.add(f'C{row_idx}')
        if param['phase'] == 'configuration':
            configuration_scope_validation.add(f'G{row_idx}')
        else:
            ordering_fulfillment_scope_validation.add(f'G{row_idx}')
        type_validation.add(f'H{row_idx}')
        bool_validation.add(f'I{row_idx}')
        bool_validation.add(f'J{row_idx}')
        bool_validation.add(f'K{row_idx}')
        row_idx += 1

    progress.close()
    print()
Exemplo n.º 28
0
    def sync(self):  # noqa: CCR001
        ws = self._wb['Customers']
        errors = {}
        skipped_count = 0
        created_items = []
        updated_items = []
        parent_uuid = {}
        parent_external_id = {}
        parent_id = []

        self.populate_hubs()
        row_indexes = trange(
            2, ws.max_row + 1, disable=self._silent, leave=True, bar_format=DEFAULT_BAR_FORMAT,
        )
        for row_idx in row_indexes:
            data = _RowData(*[ws.cell(row_idx, col_idx).value for col_idx in range(1, 21)])
            row_indexes.set_description(
                f'Processing item {data.id or data.external_id or data.external_uid}',
            )
            if data.action == '-':
                skipped_count += 1
                continue
            row_errors = self._validate_row(data)
            if row_errors:
                errors[row_idx] = row_errors
                continue
            if data.parent_search_criteria and not data.parent_search_value:
                errors[row_idx] = ["Parent search value is needed if criteria is set"]
                continue
            if data.hub_id and (data.hub_id != '' or data.hub_id != '-'):
                if data.hub_id not in self.hubs:
                    errors[row_idx] = [f"Accounts on hub {data.hub_id} can not be modified"]
                    continue
            name = f'{data.technical_contact_first_name} {data.technical_contact_last_name}'
            model = {
                "type": data.type,
                "name": data.company_name if data.company_name else name,
                "contact_info": {
                    "address_line1": data.address_line_1,
                    "address_line2": data.address_line_2,
                    "city": data.city,
                    "country": data.country,
                    "postal_code": data.zip,
                    "state": data.state,
                    "contact": {
                        "first_name": data.technical_contact_first_name,
                        "last_name": data.technical_contact_last_name,
                        "email": data.technical_contact_email,
                    },
                },
            }
            if data.external_id:
                model['external_id'] = data.external_id
            if data.external_uid:
                model['external_uid'] = data.external_uid
            else:
                model['external_uid'] = str(uuid.uuid4())
            if data.technical_contact_phone:
                try:
                    phone = phonenumbers.parse(data.technical_contact_phone, data.country)
                    phone_number = {
                        "country_code": f'+{str(phone.country_code)}',
                        "area_code": '',
                        "extension": str(phone.extension) if phone.extension else '-',
                        'phone_number': str(phone.national_number),
                    }
                    model['contact_info']['contact']['phone_number'] = phone_number
                except Exception:
                    pass
            if data.parent_search_criteria != '-':
                model['parent'] = {}
                if data.parent_search_criteria == 'id':
                    if data.parent_search_value not in parent_id:
                        try:
                            pacc = self._client.ns('tier').accounts[data.parent_search_value].get()
                            parent_id.append(pacc['id'])
                        except ClientError:
                            errors[row_idx] = [
                                f'Parent with id {data.parent_search_value} does not exist',
                            ]
                            continue
                    model['parent']['id'] = data.parent_search_value
                elif data.parent_search_criteria == 'external_id':
                    if data.parent_search_value not in parent_external_id:
                        try:
                            r = R().external_id.eq(str(data.parent_search_value))
                            pacc = self._client.ns('tier').accounts.filter(r).all()
                            pacc_count = pacc.count()
                            if pacc_count == 0:
                                errors[row_idx] = [
                                    f'Parent with external_id {data.parent_search_value} not found',
                                ]
                                continue
                            elif pacc_count > 1:
                                errors[row_idx] = [
                                    f'More than one Parent with external_id {data.parent_search_value}',
                                ]
                                continue
                            parent_external_id[data.parent_search_value] = pacc[0]['id']
                        except ClientError:
                            errors[row_idx] = ['Error when obtaining parent data from Connect']
                            continue
                    model['parent']['id'] = parent_external_id[data.parent_search_value]
                else:
                    if data.parent_search_value not in parent_uuid:
                        try:
                            r = R().external_uid.eq(str(data.parent_search_value))
                            pacc = self._client.ns('tier').accounts.filter(r).all()
                            if pacc.count() == 0:
                                errors[row_idx] = [
                                    f'Parent with external_uid {data.parent_search_value} not found',
                                ]
                                continue
                            elif pacc.count() > 1:
                                errors[row_idx] = [
                                    f'More than one Parent with external_uid {data.parent_search_value}',
                                ]
                                continue
                            parent_uuid[data.parent_search_value] = pacc[0]['id']
                        except ClientError:
                            errors[row_idx] = ['Error when obtaining parent data from Connect']
                            continue
                    model['parent']['id'] = parent_uuid[data.parent_search_value]
            if data.action == 'create':
                try:
                    account = self._client.ns('tier').accounts.create(model)
                except ClientError as e:
                    errors[row_idx] = [f'Error when creating account: {str(e)}']
                    continue
                created_items.append(account)
                self._update_sheet_row(ws, row_idx, account)
            else:
                try:
                    model['id'] = data.id
                    account = self._client.ns('tier').accounts[data.id].update(model)
                except ClientError as e:
                    errors[row_idx] = [f'Error when updating account: {str(e)}']
                    continue
                updated_items.append(account)
                self._update_sheet_row(ws, row_idx, account)
        return (
            skipped_count,
            len(created_items),
            len(updated_items),
            errors,
        )
Exemplo n.º 29
0
def generate(client, parameters, progress_callback):
    all_types = ['tiers_setup', 'inquiring', 'pending', 'approved', 'failed']
    query = R()
    query &= R().events.created.at.ge(parameters['date']['after'])
    query &= R().events.created.at.le(parameters['date']['before'])
    if parameters.get('product') and parameters['product']['all'] is False:
        query &= R().product.id.oneof(parameters['product']['choices'])
    if parameters.get('mkp') and parameters['mkp']['all'] is False:
        query &= R().marketplace.id.oneof(parameters['mkp']['choices'])
    if parameters.get('rr_type') and parameters['rr_type']['all'] is False:
        query &= R().type.oneof(parameters['rr_type']['choices'])
    if parameters.get('rr_status') and parameters['rr_status']['all'] is False:
        query &= R().status.oneof(parameters['rr_status']['choices'])
    else:
        query &= R().status.oneof(all_types)

    requests = client.ns('tier').collection('config-requests').filter(
        query).order_by('-created')
    progress = 0
    total = requests.count()
    today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')

    for request in requests:
        config = request['configuration']
        yield (
            get_basic_value(request, 'id'),
            get_basic_value(request, 'type'),
            convert_to_datetime(get_value(request['events'], 'created', 'at')),
            convert_to_datetime(get_value(request['events'], 'updated', 'at')),
            today,
            get_basic_value(request, 'status'),
            get_value(
                config,
                'connection',
                'type',
            ),
            get_value(request, 'configuration', 'id'),
            get_value(request, 'configuration', 'tier_level'),
            get_value(config, 'account', 'name'),
            get_value(config, 'account', 'external_id'),
            get_value(config, 'account', 'id'),
            get_value(request, 'parent_configuration', 'id'),
            get_value(request, 'parent_configuration', 'tier_level'),
            get_value(
                request['parent_configuration'],
                'account',
                'name',
            ) if 'parent_configuration' in request else '-',
            get_value(
                request['parent_configuration'],
                'account',
                'external_id',
            ) if 'parent_configuration' in request else '-',
            get_value(
                request['parent_configuration'],
                'account',
                'id',
            ) if 'parent_configuration' in request else '-',
            get_value(
                config['connection'],
                'provider',
                'id',
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'provider',
                'name',
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'vendor',
                'id',
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'vendor',
                'name',
            ) if 'connection' in config else '-',
            get_value(
                config,
                'product',
                'id',
            ),
            get_value(
                config,
                'product',
                'name',
            ),
            get_value(
                config['connection'],
                'hub',
                'id',
            ) if 'connection' in config else '-',
            get_value(
                config['connection'],
                'hub',
                'name',
            ) if 'connection' in config else '-',
            get_value(
                config,
                'contract',
                'id',
            ),
            get_value(
                config,
                'marketplace',
                'id',
            ),
            get_value(
                config,
                'marketplace',
                'name',
            ),
        )

        progress += 1
        progress_callback(progress, total)
Exemplo n.º 30
0
def _get_uf(client, parameters):
    rql = R()
    rql &= R().status.oneof(['pending', 'accepted'])
    return client.ns('usage').collection('files').filter(rql).order_by(
        '-created.at')