Exemple #1
0
def set_access_token_provider(config, tenant_id):
    if is_cloudsim():
        authorization_provider = NoSecurityAccessTokenProvider(tenant_id)
    elif is_dev_pod() or is_minicloud():
        authorization_provider = KeystoreAccessTokenProvider().set_tenant(
            tenant_id)
    elif is_prod_pod():
        if credentials_file is None:
            raise IllegalArgumentException(
                'Must specify the credentials file path.')
        creds_provider = PropertiesCredentialsProvider().set_properties_file(
            credentials_file)
        authorization_provider = DefaultAccessTokenProvider(
            idcs_url=idcs_url(), entitlement_id=entitlement_id,
            creds_provider=creds_provider, timeout_ms=timeout)
    elif is_onprem():
        if user_name is None and password is None:
            authorization_provider = StoreAccessTokenProvider()
        else:
            if user_name is None or password is None:
                raise IllegalArgumentException(
                    'Please set both the user_name and password.')
            authorization_provider = StoreAccessTokenProvider(
                user_name, password)
    else:
        raise IllegalArgumentException('Please set the test server.')
    config.set_authorization_provider(authorization_provider)
 def setUp(self):
     self.handles = list()
     self.list_tables_requests = list()
     self.num_handles = 1 if is_prod_pod() or is_onprem() else 2
     for handle in range(self.num_handles):
         tenant = tenant_id + ('' if handle == 0 else str(handle))
         self.handles.append(get_handle(tenant))
         self.list_tables_requests.append(
             ListTablesRequest().set_timeout(timeout))
     self.list_tables_request = ListTablesRequest().set_timeout(timeout)
def generate_authorization_provider(tenant_id):
    if is_cloudsim():
        authorization_provider = InsecureAuthorizationProvider(tenant_id)
    elif is_dev_pod() or is_minicloud():
        authorization_provider = TestSignatureProvider(tenant_id)
    elif is_prod_pod():
        if iam_principal() == 'user principal':
            if credentials_file is None:
                raise IllegalArgumentException(
                    'Must specify the credentials file path.')
            authorization_provider = SignatureProvider(
                config_file=credentials_file)
        elif iam_principal() == 'instance principal':
            if isinstance(endpoint, str):
                region = Regions.from_region_id(endpoint)
            else:
                region = endpoint
            if region is None:
                authorization_provider = (
                    SignatureProvider.create_with_instance_principal())
            else:
                authorization_provider = (
                    SignatureProvider.create_with_instance_principal(
                        region=region))
        elif iam_principal() == 'resource principals':
            authorization_provider = (
                SignatureProvider.create_with_resource_principal())
        else:
            raise IllegalArgumentException('Must specify the principal.')
    elif is_onprem():
        if user_name is None and password is None:
            authorization_provider = StoreAccessTokenProvider()
        else:
            if user_name is None or password is None:
                raise IllegalArgumentException(
                    'Please set both the user_name and password.')
            authorization_provider = StoreAccessTokenProvider(
                user_name, password)
    else:
        raise IllegalArgumentException('Please set the test server.')
    return authorization_provider
    def setUpClass(cls):
        add_tier()
        cls.handles = list()
        global table_names
        table_names = list()
        num_tables = 3
        #
        # In pod env create 1 handle, otherwise create 2 handles for additional
        # testing
        #
        num_handles = 1 if is_prod_pod() or is_onprem() else 2
        for handle in range(num_handles):
            tenant = tenant_id + ('' if handle == 0 else str(handle))
            add_tenant(tenant)
            table_names.append(list())
            cls.handles.append(get_handle(tenant))
            for table in range(handle + num_tables):
                tb_name = table_name + str(table)
                table_names[handle].append(tb_name)
                #
                # Add a sleep for a pod to let things happen
                #
                if is_pod():
                    sleep(60)
                drop_request = TableRequest().set_statement(
                    'DROP TABLE IF EXISTS ' + tb_name)
                cls.table_request(drop_request, cls.handles[handle])
                create_statement = ('CREATE TABLE ' + tb_name +
                                    '(fld_id INTEGER, \
fld_long LONG, fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, \
fld_str STRING, fld_bin BINARY, fld_time TIMESTAMP(2), fld_num NUMBER, \
fld_json JSON, fld_arr ARRAY(STRING), fld_map MAP(STRING), \
fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \
PRIMARY KEY(fld_id)) USING TTL 16 HOURS')
                limits = TableLimits(10, 10, 1)
                create_request = TableRequest().set_statement(
                    create_statement).set_table_limits(limits)
                cls.table_request(create_request, cls.handles[handle])