Beispiel #1
0
def get_handle_config(tenant_id):
    config = NoSQLHandleConfig(
        endpoint, generate_authorization_provider(
            tenant_id)).set_default_compartment(tenant_id)
    if ca_certs is not None:
        config.set_ssl_ca_certs(ca_certs)
    return config
Beispiel #2
0
def get_handle():
    """
    Constructs a NoSQLHandle. Additional configuration options can be added
    here. Use the tenant_id as the default compartment for all operations. This
    puts tables in the root compartment of the tenancy.
    """
    provider = StoreAccessTokenProvider()
    config = NoSQLHandleConfig(endpoint)
    config.set_authorization_provider(provider)
    return NoSQLHandle(config)
Beispiel #3
0
 def setUp(self):
     self.base = 'http://localhost:' + str(8000)
     self._generate_credentials_file()
     self.token_provider = None
     # Not matter which request.
     self.request = TableRequest()
     self.handle_config = NoSQLHandleConfig(self.base)
Beispiel #4
0
def get_simple_handle_config(tenant_id, ep=endpoint):
    # Creates a simple NoSQLHandleConfig
    get_logger()
    config = NoSQLHandleConfig(ep).set_logger(
        logger)
    set_access_token_provider(config, tenant_id)
    return config
def get_simple_handle_config(tenant_id, ep=endpoint):
    # Creates a simple NoSQLHandleConfig
    get_logger()
    config = NoSQLHandleConfig(ep).set_authorization_provider(
        generate_authorization_provider(tenant_id)).set_default_compartment(
        tenant_id).set_logger(logger)
    return config
Beispiel #6
0
def get_handle(tenant_id):
    """
    Constructs a NoSQLHandle. Additional configuration options can be added
    here.
    """
    config = NoSQLHandleConfig(endpoint).set_authorization_provider(
        create_access_token_provider(tenant_id))
    return NoSQLHandle(config)
Beispiel #7
0
def get_handle_config(tenant_id):
    # Creates a NoSQLHandleConfig
    get_logger()
    config = NoSQLHandleConfig(endpoint).set_timeout(
        timeout).set_consistency(consistency).set_pool_connections(
        pool_connections).set_pool_maxsize(pool_maxsize).set_retry_handler(
        retry_handler).set_logger(logger).set_table_request_timeout(
        table_request_timeout).set_sec_info_timeout(sec_info_timeout)
    if proxy_host is not None:
        config.set_proxy_host(proxy_host)
    if proxy_port != 0:
        config.set_proxy_port(proxy_port)
    if proxy_username is not None:
        config.set_proxy_username(proxy_username)
    if proxy_password is not None:
        config.set_proxy_password(proxy_password)
    set_access_token_provider(config, tenant_id)
    return config
Beispiel #8
0
    def create_handler(oci_config, log_handler):
        """Create the handle used to perform OCI NoSQL operations on tables.

      """
        sigprov = SignatureProvider(tenant_id=oci_config['tenancy'],
                                    user_id=oci_config['user'],
                                    private_key=oci_config['key_file'],
                                    fingerprint=oci_config['fingerprint'])

        nosql_handle_config = NoSQLHandleConfig(Regions.SA_SAOPAULO_1)
        nosql_handle_config.set_authorization_provider(sigprov)
        nosql_handle_config.set_default_compartment(oci_config['compartment'])
        nosql_handle_config.set_logger(log_handler)

        nosql_handle = NoSQLHandle(nosql_handle_config)

        sigprov.close()

        return nosql_handle
Beispiel #9
0
def handler(ctx, data: io.BytesIO = None):

    return_citizens = []

    try:
        provider = SignatureProvider(
            tenant_id='Your Tenant OCID',
            user_id='Your User OCID',
            private_key='location of Pem file',
            fingerprint='The fingerprint for your key pair goes here',
            pass_phrase='The pass phrase for your key goes here')
        compartment = 'Your Compartment Name Goes Here'
        config = NoSQLHandleConfig(Regions.US_ASHBURN_1, provider)
        config.set_default_compartment(compartment)
        logger = logging.getLogger('Citizens')
        logger.setLevel(logging.WARNING)
        config.set_logger(logger)
        handle = NoSQLHandle(config)
        table_name = 'Citizens'

        ## Prepare select statement#
        statement = 'select * from ' + table_name
        request = PrepareRequest().set_statement(statement)
        prepared_result = handle.prepare(request)

        ## Query, using the prepared statement#
        request = QueryRequest().set_prepared_statement(prepared_result)

        while True:
            result = handle.query(request)
            for r in result.get_results():
                return_citizens.append(dict(r))
            if request.is_done():
                break

    except (Exception, ValueError) as ex:
        logging.getLogger().info('error parsing json payload: ' + str(ex))

    logging.getLogger().info("Inside OCI function")
    return response.Response(ctx,
                             response_data=json.dumps(return_citizens),
                             headers={"Content-Type": "application/json"})
Beispiel #10
0
#
# https://blogs.oracle.com/lad-cloud-experts/pt/introducao-ao-oracle-nosql-database-cloud-parte-1
# https://blogs.oracle.com/lad-cloud-experts/pt/introducao-ao-oracle-nosql-database-cloud-parte-2
# ---------------------------------------------------------------------------

from borneo.iam import SignatureProvider
from borneo import NoSQLHandleConfig, NoSQLHandle, Regions
from borneo import Consistency, QueryRequest

# create and close AuthorizationProvider
at_provider = SignatureProvider(config_file='~/.oci/config')
at_provider.close()

# create handle config using a desired region as endpoint and set a
# default compartment.
handle_config = NoSQLHandleConfig(Regions.SA_SAOPAULO_1)
handle_config.set_authorization_provider(at_provider)
handle_config.set_default_compartment('<your-compartment-id>')

# create the handle.
nosql_handle = NoSQLHandle(handle_config)

query = """

  SELECT propriedades, valor, frete_gratis FROM produtos

"""

query_request = QueryRequest()

# set ABSOLUTE consistency for read requests.
    def testNoSQLHandleEndpointConfig(self):
        # set only the host as endpoint
        config = get_simple_handle_config(tenant_id, 'ndcs.com')
        self._check_service_url(config, 'https', 'ndcs.com', 443)
        # set protocol://host as endpoint
        config = get_simple_handle_config(tenant_id, 'Http://ndcs.com')
        self._check_service_url(config, 'http', 'ndcs.com', 8080)
        config = get_simple_handle_config(tenant_id, 'https://ndcs.com')
        self._check_service_url(config, 'https', 'ndcs.com', 443)
        # set protocol:host as endpoint
        config = get_simple_handle_config(tenant_id, 'Http:ndcs.com')
        self._check_service_url(config, 'http', 'ndcs.com', 8080)
        config = get_simple_handle_config(tenant_id, 'https:ndcs.com')
        self._check_service_url(config, 'https', 'ndcs.com', 443)
        # set host:port as endpoint
        config = get_simple_handle_config(tenant_id, 'localhost:80')
        self._check_service_url(config, 'http', 'localhost', 80)
        config = get_simple_handle_config(tenant_id, 'localhost:443')
        self._check_service_url(config, 'https', 'localhost', 443)
        # set protocol://host:port as endpoint
        config = get_simple_handle_config(tenant_id, 'HTTPS://ndcs.com:8080')
        self._check_service_url(config, 'https', 'ndcs.com', 8080)
        # set protocol:host:port as endpoint
        config = get_simple_handle_config(tenant_id, 'Http:ndcs.com:443')
        self._check_service_url(config, 'http', 'ndcs.com', 443)

        # set a Region's id 'us-AshBURN-1' as endpoint.
        config = get_simple_handle_config(tenant_id, 'us-AshBURN-1')
        self._check_service_url(
            config, 'https', 'nosql.us-ashburn-1.oci.oraclecloud.com', 443)
        # set a Region's id 'US-LangLEY-1' as endpoint.
        config = get_simple_handle_config(tenant_id, 'US-LangLEY-1')
        self._check_service_url(
            config, 'https', 'nosql.us-langley-1.oci.oraclegovcloud.com', 443)
        # set a Region's id 'UK-GOV-LONDON-1' as endpoint.
        config = get_simple_handle_config(tenant_id, 'UK-GOV-LONDON-1')
        self._check_service_url(
            config, 'https', 'nosql.uk-gov-london-1.oci.oraclegovcloud.uk', 443)
        # set a Region's id 'Ap-CHiyODA-1' as endpoint.
        config = get_simple_handle_config(tenant_id, 'Ap-CHiyODA-1')
        self._check_service_url(
            config, 'https', 'nosql.ap-chiyoda-1.oci.oraclecloud8.com', 443)

        # set a Region Regions.US_ASHBURN_1 as endpoint.
        config = get_simple_handle_config(tenant_id, Regions.US_ASHBURN_1)
        self._check_service_url(
            config, 'https', 'nosql.us-ashburn-1.oci.oraclecloud.com', 443)
        # set a Region Regions.US_LANGLEY_1 as endpoint.
        config = get_simple_handle_config(tenant_id, Regions.US_LANGLEY_1)
        self._check_service_url(
            config, 'https', 'nosql.us-langley-1.oci.oraclegovcloud.com', 443)
        # set a Region Regions.UK_GOV_LONDON_1 as endpoint.
        config = get_simple_handle_config(tenant_id, Regions.UK_GOV_LONDON_1)
        self._check_service_url(
            config, 'https', 'nosql.uk-gov-london-1.oci.oraclegovcloud.uk', 443)
        # set a Region Regions.AP_CHIYODA_1 as endpoint.
        config = get_simple_handle_config(tenant_id, Regions.AP_CHIYODA_1)
        self._check_service_url(
            config, 'https', 'nosql.ap-chiyoda-1.oci.oraclecloud8.com', 443)

        # set a provider with region
        provider = SignatureProvider(
            tenant_id='ocid1.tenancy.oc1..tenancy',
            user_id='ocid1.user.oc1..user', fingerprint='fingerprint',
            private_key=fake_key_file, region=Regions.US_ASHBURN_1)
        config = NoSQLHandleConfig(provider=provider)
        self._check_service_url(
            config, 'https', 'nosql.us-ashburn-1.oci.oraclecloud.com', 443)
        self.assertEqual(config.get_region(), Regions.US_ASHBURN_1)
        # set a endpoint and provider with region
        config = NoSQLHandleConfig('us-ashburn-1', provider)
        self._check_service_url(
            config, 'https', 'nosql.us-ashburn-1.oci.oraclecloud.com', 443)
        self.assertEqual(config.get_region(), Regions.US_ASHBURN_1)
        provider.close()
Beispiel #12
0
#
# For more information, check the SDK documentation at the link below:
# https://nosql-python-sdk.readthedocs.io/en/latest/installation.html#configure-for-the-cloud-simulator
#
#

#----------------------------------------------------------------------------
# This Git repository belongs to my ([email protected]) studies about
# Oracle NoSQL. To known more, check the blog post (pt-br):
#
# https://blogs.oracle.com/lad-cloud-experts/pt/introducao-ao-oracle-nosql-database-cloud-parte-1
# https://blogs.oracle.com/lad-cloud-experts/pt/introducao-ao-oracle-nosql-database-cloud-parte-2
# ---------------------------------------------------------------------------

from borneo import NoSQLHandle, NoSQLHandleConfig
from borneo.kv import StoreAccessTokenProvider

# NoSQL Cloud Simulator endpoint
simulator_endpoint = 'http://localhost:5000'

# create the AuthorizationProvider for a not secure store:
ap = StoreAccessTokenProvider()

# create handle config
handle_config = NoSQLHandleConfig(simulator_endpoint)
handle_config.set_authorization_provider(ap)

# create the handle.
nosql_handle = NoSQLHandle(handle_config)
nosql_handle.close()
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_sec_info_timeout(
        sec_info_timeout).set_pool_maxsize(pool_maxsize).set_retry_handler(
        retry_handler).set_consistency(consistency).set_logger(logger)
    if proxy_host is not None:
        config.set_proxy_host(proxy_host)
    if proxy_port != 0:
        config.set_proxy_port(proxy_port)
    if proxy_username is not None:
        config.set_proxy_username(proxy_username)
    if proxy_password is not None:
        config.set_proxy_password(proxy_password)
    if ssl_cipher_suites is not None:
        config.set_ssl_cipher_suites(ssl_cipher_suites)
    if ssl_protocol is not None:
        config.set_ssl_protocol(ssl_protocol)
    if ca_certs is not None:
        config.set_ssl_ca_certs(ca_certs)
    return config
## OCI
oci_config_file = '../fotogal/oci_config/oci.conf'
oci_private_key = '../fotogal/oci_config/oci_api_key.pem'
oci_compartment_ocid = 'ocid1.compartment.oc1..aaaaaaaaro7baesjtceeuntyqxajzotsthm4bg46bwumacmbltuhw6gvb2mq'

oci_config = oci.config.from_file(oci_config_file, 'DEFAULT')
oci_config['key_file'] = oci_private_key

## OCI NoSQL
nosql_sig_prov = SignatureProvider(tenant_id=oci_config['tenancy'],
                                   user_id=oci_config['user'],
                                   private_key=oci_config['key_file'],
                                   fingerprint=oci_config['fingerprint'])

nosql_config = NoSQLHandleConfig(
    Regions.SA_SAOPAULO_1).set_authorization_provider(
        nosql_sig_prov).set_default_compartment(oci_compartment_ocid)
nosql_handler = NoSQLHandle(nosql_config)

## OCI Object Storage
object_storage = oci.object_storage.ObjectStorageClient(oci_config)


def return_random_string():
    RANDOM_STR_LENGTH = 50

    ts = datetime.datetime.now().strftime('%s')

    letters_and_digits = string.ascii_letters + string.digits
    result_str = ''.join((random.choice(letters_and_digits)
                          for i in range(RANDOM_STR_LENGTH))) + '_' + ts