コード例 #1
0
ファイル: retry_utils.py プロジェクト: partly-cloudy/oci-cli
def list_call_get_up_to_limit(list_func_ref, record_limit, page_size,
                              retry_strategy_name, **func_kwargs):
    # If no limit was provided, make a single call
    if record_limit is None:
        return call_function_with_retries(list_func_ref, retry_strategy_name,
                                          **func_kwargs)

    # If we have a limit, make calls until we get that amount of data
    keep_paginating = True
    remaining_items_to_fetch = record_limit
    call_result = None
    aggregated_results = []
    while keep_paginating and remaining_items_to_fetch > 0:
        if page_size:
            func_kwargs['limit'] = min(page_size, remaining_items_to_fetch)
        elif 'limit' in func_kwargs:
            func_kwargs['limit'] = min(func_kwargs['limit'],
                                       remaining_items_to_fetch)

        call_result = call_function_with_retries(list_func_ref,
                                                 retry_strategy_name,
                                                 **func_kwargs)
        aggregated_results.extend(call_result.data)
        remaining_items_to_fetch -= len(call_result.data)

        if call_result.next_page is not None:
            func_kwargs['page'] = call_result.next_page

        keep_paginating = call_result.has_next_page

    # Truncate the list to the first limit items, as potentially we could have gotten more than what the caller asked for
    final_response = Response(call_result.status, call_result.headers,
                              aggregated_results[:record_limit],
                              call_result.request)
    return final_response
コード例 #2
0
ファイル: retry_utils.py プロジェクト: partly-cloudy/oci-cli
def list_call_get_all_results(list_func_ref, retry_strategy_name,
                              **func_kwargs):
    keep_paginating = True
    call_result = None
    aggregated_results = []

    while keep_paginating:
        call_result = call_function_with_retries(list_func_ref,
                                                 retry_strategy_name,
                                                 **func_kwargs)
        aggregated_results.extend(call_result.data)

        if call_result.next_page is not None:
            func_kwargs['page'] = call_result.next_page

        keep_paginating = call_result.has_next_page

    post_processed_results = aggregated_results
    if 'sort_by' in func_kwargs:
        if func_kwargs['sort_by'].upper() == 'DISPLAYNAME':
            sort_direction = 'ASC'
            if 'sort_order' in func_kwargs:
                sort_direction = func_kwargs['sort_order'].upper()

            post_processed_results = sorted(
                aggregated_results,
                key=lambda r: retrieve_attribute_for_sort(r, 'display_name'),
                reverse=(sort_direction == 'DESC'))
        elif func_kwargs['sort_by'].upper() == 'TIMECREATED':
            sort_direction = 'DESC'
            if 'sort_order' in func_kwargs:
                sort_direction = func_kwargs['sort_order'].upper()

                post_processed_results = sorted(
                    aggregated_results,
                    key=lambda r: retrieve_attribute_for_sort(
                        r, 'time_created'),
                    reverse=(sort_direction == 'DESC'))

    # Most of this is just dummy since we're discarding the intermediate requests
    final_response = Response(call_result.status, call_result.headers,
                              post_processed_results, call_result.request)

    return final_response
コード例 #3
0
 def mock_get_user():
     return Response(200, {}, "test-user",
                     Request("mock.method", "mock.url"))
コード例 #4
0
 def mock_get_namespace():
     return Response(200, {}, "test-namespace",
                     Request("mock.method", "mock.url"))
コード例 #5
0
from oci import identity, Response
import oci_cli
import os
import tempfile
import shutil
import unittest.mock as mock
import click

REGION = 'us-phoenix-1'
TEST_JWT_TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPQ0kgVGVzdCBKV1QgVG9rZW4iLCJpYXQiOjE1MzkxMTAzOTAsImV4cCI6MTc2MDAzNTE5MCwiYXVkIjoid3d3Lm9yYWNsZWNsb3VkLmNvbSIsInN1YiI6Im9jaWQxLnVzZXIub2MxLi5hYWFhYWFhYTR2eGZvdnd5Z3R5amxxY3ptbjZqdTNrb3JrdGlkemxrNmF1dzZjNHRnc3h4eHh4eHh4eHgiLCJ0ZW5hbnQiOiJ0ZXN0X3RlbmFuY3kifQ.i9PP_5up4UAgFx7usppp_okaFDRpmzF0YECDsfN-gjU'
LIST_REGION_SUBSCRIPTIONS_RESPONSE = Response(
    status=None,
    headers=None,
    data=[
        identity.models.RegionSubscription(region_name="non-home-region",
                                           is_home_region=False),
        identity.models.RegionSubscription(region_name=REGION,
                                           is_home_region=True)
    ],
    request=None)


def test_missing_user(runner, malformed_config_file):
    result = invoke_example_operation(runner, malformed_config_file,
                                      'MISSING_USER')
    validate_missing_param_error(result, 'user', 'log into the console')


def test_missing_fingerprint(runner, malformed_config_file):
    result = invoke_example_operation(runner, malformed_config_file,
                                      'MISSING_FINGERPRINT')