Beispiel #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)
Beispiel #2
0
 def check_table_result(self,
                        result,
                        state,
                        table_limits=None,
                        has_schema=True,
                        has_operation_id=True,
                        check_limit=True,
                        check_schema=True,
                        check_operation_id=True):
     assert isinstance(self, TestCase)
     # check compartment id
     if (version is None or is_onprem() or version is not None
             and is_cloudsim() and compare_version(version, '1.4.0') >= 0):
         self.assertIsNone(result.get_compartment_id())
     else:
         self.assertEqual(result.get_compartment_id(), tenant_id)
     # check table name
     self.assertEqual(result.get_table_name(), table_name)
     # check state
     if isinstance(state, str):
         self.assertEqual(result.get_state(), state)
     else:
         self.assertTrue(result.get_state() in state)
     # check table limits
     if check_limit:
         if table_limits is None or is_onprem():
             self.assertIsNone(result.get_table_limits())
         else:
             self.assertEqual(result.get_table_limits().get_read_units(),
                              table_limits.get_read_units())
             self.assertEqual(result.get_table_limits().get_write_units(),
                              table_limits.get_write_units())
             self.assertEqual(result.get_table_limits().get_storage_gb(),
                              table_limits.get_storage_gb())
     # check table schema
     # TODO: For on-prem proxy, TableResult.get_schema() always return None,
     # This is a known bug, when it is fixed, the test should be change.
     if check_schema and not_cloudsim() and not is_onprem():
         (self.assertIsNotNone(result.get_schema())
          if has_schema else self.assertIsNone(result.get_schema()))
     # check operation id
     if check_operation_id:
         operation_id = result.get_operation_id()
         (self.assertIsNotNone(operation_id)
          if has_operation_id else self.assertIsNone(operation_id))
Beispiel #3
0
    def setUpClass(cls):
        cls.set_up_class()
        index_name = 'idx_' + table_name
        create_statement = (
            'CREATE TABLE ' + table_name + '(fld_sid INTEGER, fld_id INTEGER, \
fld_long LONG, fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, \
fld_str STRING, fld_bin BINARY, fld_time TIMESTAMP(6), 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(SHARD(fld_sid), fld_id))')
        limits = TableLimits(100, 100, 1)
        create_request = TableRequest().set_statement(
            create_statement).set_table_limits(limits)
        cls.table_request(create_request)

        if (version is not None and
            (is_cloudsim() and compare_version(version, '1.4.0') == -1 or
             is_onprem() and compare_version(version, '20.2.0') == -1)):
            create_idx_request = TableRequest()
            create_idx_statement = (
                'CREATE INDEX ' + index_name + '1 ON ' + table_name +
                '(fld_long)')
            create_idx_request.set_statement(create_idx_statement)
            cls.table_request(create_idx_request)
            create_idx_statement = (
                'CREATE INDEX ' + index_name + '2 ON ' + table_name +
                '(fld_str)')
            create_idx_request.set_statement(create_idx_statement)
            cls.table_request(create_idx_request)
            create_idx_statement = (
                'CREATE INDEX ' + index_name + '3 ON ' + table_name +
                '(fld_bool)')
            create_idx_request.set_statement(create_idx_statement)
            cls.table_request(create_idx_request)
            create_idx_statement = (
                'CREATE INDEX ' + index_name + '4 ON ' + table_name +
                '(fld_json.location as point)')
            create_idx_request.set_statement(create_idx_statement)
            cls.table_request(create_idx_request)

        global query_statement
        query_statement = ('SELECT fld_sid, fld_id FROM ' + table_name +
                           ' WHERE fld_sid = 1')
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
Beispiel #5
0
    internal_list = internal.split(".")
    specified_len = len(specified_list)
    internal_len = len(internal_list)
    if specified_len < internal_len:
        for i in range(internal_len - specified_len):
            specified_list.append("0")
    for i in range(internal_len):
        if int(specified_list[i]) > int(internal_list[i]):
            return 1
        if int(specified_list[i]) < int(internal_list[i]):
            return -1
    return 0


if version is not None:
    if (is_cloudsim() and compare_version(version, '1.2.0') == -1
            or is_onprem() and compare_version(version, '20.1.0') == -1):
        raise IllegalArgumentException(
            'The version number for CloudSim should be newer than 1.2.0, for '
            + 'on-prem should be newer than 20.1.0.')


def get_handle_config(tenant_id):
    # Creates a NoSQLHandleConfig
    get_logger()
    provider = generate_authorization_provider(tenant_id)
    config = NoSQLHandleConfig(endpoint, provider).set_table_request_timeout(
        table_request_timeout).set_timeout(timeout).set_default_compartment(
            tenant_id).set_pool_connections(pool_connections).set_pool_maxsize(
                pool_maxsize).set_retry_handler(retry_handler).set_consistency(
                    consistency).set_logger(logger)