def __init__(self, config, **kwargs):
        """
        Creates a new service client

        :param dict config:
            Configuration keys and values as per `SDK and Tool Configuration <https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm>`__.
            The :py:meth:`~oci.config.from_file` method can be used to load configuration from a file. Alternatively, a ``dict`` can be passed. You can validate_config
            the dict using :py:meth:`~oci.config.validate_config`

        :param str service_endpoint: (optional)
            The endpoint of the service to call using this client. For example ``https://iaas.us-ashburn-1.oraclecloud.com``. If this keyword argument is
            not provided then it will be derived using the region in the config parameter. You should only provide this keyword argument if you have an explicit
            need to specify a service endpoint.

        :param timeout: (optional)
            The connection and read timeouts for the client. The default values are connection timeout 10 seconds and read timeout 60 seconds. This keyword argument can be provided
            as a single float, in which case the value provided is used for both the read and connection timeouts, or as a tuple of two floats. If
            a tuple is provided then the first value is used as the connection timeout and the second value as the read timeout.
        :type timeout: float or tuple(float, float)

        :param signer: (optional)
            The signer to use when signing requests made by the service client. The default is to use a :py:class:`~oci.signer.Signer` based on the values
            provided in the config parameter.

            One use case for this parameter is for `Instance Principals authentication <https://docs.cloud.oracle.com/Content/Identity/Tasks/callingservicesfrominstances.htm>`__
            by passing an instance of :py:class:`~oci.auth.signers.InstancePrincipalsSecurityTokenSigner` as the value for this keyword argument
        :type signer: :py:class:`~oci.signer.AbstractBaseSigner`

        :param obj retry_strategy: (optional)
            A retry strategy to apply to all calls made by this service client (i.e. at the client level). There is no retry strategy applied by default.
            Retry strategies can also be applied at the operation level by passing a ``retry_strategy`` keyword argument as part of calling the operation.
            Any value provided at the operation level will override whatever is specified at the client level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. A convenience :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY`
            is also available. The specifics of the default retry strategy are described `here <https://oracle-cloud-infrastructure-python-sdk.readthedocs.io/en/latest/sdk_behaviors/retries.html>`__.
        """
        validate_config(config, signer=kwargs.get('signer'))
        if 'signer' in kwargs:
            signer = kwargs['signer']

        elif AUTHENTICATION_TYPE_FIELD_NAME in config:
            signer = get_signer_from_authentication_type(config)

        else:
            signer = Signer(tenancy=config["tenancy"],
                            user=config["user"],
                            fingerprint=config["fingerprint"],
                            private_key_file_location=config.get("key_file"),
                            pass_phrase=get_config_value_or_default(
                                config, "pass_phrase"),
                            private_key_content=config.get("key_content"))

        base_client_init_kwargs = {
            'regional_client': True,
            'service_endpoint': kwargs.get('service_endpoint'),
            'timeout': kwargs.get('timeout'),
            'base_path': '/20190912',
            'service_endpoint_template':
            'https://cp.oce.{region}.ocp.{secondLevelDomain}',
            'skip_deserialization': kwargs.get('skip_deserialization', False)
        }
        self.base_client = BaseClient("oce_instance", config, signer,
                                      oce_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
示例#2
0
# Tag Value : FALSE
# Instances running with Value=FALSE will not be stopped
# Instances running without Tags will be stopped

#############################################

# Default config file and profile
config = oci.config.from_file(configfile, profile)
tenancy_id = config['tenancy']

if use_instance_principal == 'TRUE':
    signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
else:
    signer = Signer(tenancy=config['tenancy'],
                    user=config['user'],
                    fingerprint=config['fingerprint'],
                    private_key_file_location=config['key_file'],
                    pass_phrase=config['pass_phrase'])

print(
    "\n===========================[ Login check ]============================="
)
login(config, signer)

print(
    "\n==========================[ Target regions ]==========================="
)
all_regions = get_region_subscription_list(config, signer, tenancy_id)
target_regions = []
for region in all_regions:
    if (not target_region_names) or (region.region_name
示例#3
0
# config = oci.config.from_file()
# auth = Signer(
#     tenancy=config['tenancy'],
#     user=config['user'],
#     fingerprint=config['fingerprint'],
#     private_key_file_location=config['key_file']
# pass_phrase=config['pass_phrase']
# )

lines = os.environ['PRIVATE_KEY'].split("\\n")
file = open("oci_api_key.pem", "w")
file.write('\n'.join(lines) + '\n')
file.close()

auth = Signer(tenancy=os.environ['TENANCY_ID'],
              user=os.environ['USER'],
              fingerprint=os.environ['FINGURE'],
              private_key_file_location='oci_api_key.pem')
url = os.environ['URL']

# url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/n/ZTE/b/artifacts-apps/o/cpu-load-0.0.1-SNAPSHOT.war'

local_filename = url.split('/')[-1]
r = requests.get(url, stream=True, auth=auth)
with open(local_filename, 'wb') as f:
    for chunk in r.iter_content(chunk_size=1024):
        if chunk:
            f.write(chunk)

# response = requests.get(url, auth=auth)
os.remove("oci_api_key.pem")
    def __init__(self, config, **kwargs):
        """
        Creates a new service client

        :param dict config:
            Configuration keys and values as per `SDK and Tool Configuration <https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm>`__.
            The :py:meth:`~oci.config.from_file` method can be used to load configuration from a file. Alternatively, a ``dict`` can be passed. You can validate_config
            the dict using :py:meth:`~oci.config.validate_config`

        :param str service_endpoint: (optional)
            The endpoint of the service to call using this client. For example ``https://iaas.us-ashburn-1.oraclecloud.com``. If this keyword argument is
            not provided then it will be derived using the region in the config parameter. You should only provide this keyword argument if you have an explicit
            need to specify a service endpoint.

        :param timeout: (optional)
            The connection and read timeouts for the client. The default values are connection timeout 10 seconds and read timeout 60 seconds. This keyword argument can be provided
            as a single float, in which case the value provided is used for both the read and connection timeouts, or as a tuple of two floats. If
            a tuple is provided then the first value is used as the connection timeout and the second value as the read timeout.
        :type timeout: float or tuple(float, float)

        :param signer: (optional)
            The signer to use when signing requests made by the service client. The default is to use a :py:class:`~oci.signer.Signer` based on the values
            provided in the config parameter.

            One use case for this parameter is for `Instance Principals authentication <https://docs.cloud.oracle.com/Content/Identity/Tasks/callingservicesfrominstances.htm>`__
            by passing an instance of :py:class:`~oci.auth.signers.InstancePrincipalsSecurityTokenSigner` as the value for this keyword argument
        :type signer: :py:class:`~oci.signer.AbstractBaseSigner`

        :param obj retry_strategy: (optional)
            A retry strategy to apply to all calls made by this service client (i.e. at the client level). There is no retry strategy applied by default.
            Retry strategies can also be applied at the operation level by passing a ``retry_strategy`` keyword argument as part of calling the operation.
            Any value provided at the operation level will override whatever is specified at the client level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. A convenience :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY`
            is also available. The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

        :param obj circuit_breaker_strategy: (optional)
            A circuit breaker strategy to apply to all calls made by this service client (i.e. at the client level).
            This client uses :py:data:`~oci.circuit_breaker.DEFAULT_CIRCUIT_BREAKER_STRATEGY` as default if no circuit breaker strategy is provided.
            The specifics of circuit breaker strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/circuit_breakers.html>`__.

        :param function circuit_breaker_callback: (optional)
            Callback function to receive any exceptions triggerred by the circuit breaker.

        :param allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this client should allow control characters in the response object. By default, the client will not
            allow control characters to be in the response object.
        """
        validate_config(config, signer=kwargs.get('signer'))
        if 'signer' in kwargs:
            signer = kwargs['signer']

        elif AUTHENTICATION_TYPE_FIELD_NAME in config:
            signer = get_signer_from_authentication_type(config)

        else:
            signer = Signer(tenancy=config["tenancy"],
                            user=config["user"],
                            fingerprint=config["fingerprint"],
                            private_key_file_location=config.get("key_file"),
                            pass_phrase=get_config_value_or_default(
                                config, "pass_phrase"),
                            private_key_content=config.get("key_content"))

        base_client_init_kwargs = {
            'regional_client':
            True,
            'service_endpoint':
            kwargs.get('service_endpoint'),
            'base_path':
            '/oalapp/service/onesubs/proxy/20210501',
            'service_endpoint_template':
            'https://csaap-e.oracle.com',
            'skip_deserialization':
            kwargs.get('skip_deserialization', False),
            'circuit_breaker_strategy':
            kwargs.get('circuit_breaker_strategy',
                       circuit_breaker.GLOBAL_CIRCUIT_BREAKER_STRATEGY)
        }
        if 'timeout' in kwargs:
            base_client_init_kwargs['timeout'] = kwargs.get('timeout')
        if base_client_init_kwargs.get('circuit_breaker_strategy') is None:
            base_client_init_kwargs[
                'circuit_breaker_strategy'] = circuit_breaker.DEFAULT_CIRCUIT_BREAKER_STRATEGY
        if 'allow_control_chars' in kwargs:
            base_client_init_kwargs['allow_control_chars'] = kwargs.get(
                'allow_control_chars')
        self.base_client = BaseClient("subscription", config, signer,
                                      osub_subscription_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')
示例#5
0
lines = os.environ['PRIVATE_KEY'].split("\\n")
file = open("oci_api_key.pem", "w")
# file.writelines(lines)
file.write('\n'.join(lines) + '\n')
file.close()

# with open("oci_api_key.pem", "r") as file1:
#     data=file1.read()

# print data

# print(os.environ['PRIVATE_KEY'])

auth = Signer(tenancy=os.environ['TENANCY_ID'],
              user=os.environ['USER'],
              fingerprint=os.environ['FINGURE'],
              private_key_file_location='oci_api_key.pem'
              # #    pass_phrase='hunter2'  # optional
              )
url = 'https://objectstorage.us-ashburn-1.oraclecloud.com/n/zte/b/artifacts-apps/o/cpu-load-0.0.1-SNAPSHOT.war'

local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
    for chunk in r.iter_content(chunk_size=1024):
        if chunk:  # filter out keep-alive new chunks
            f.write(chunk)
            # f.flush() commented by recommendation from J.F.Sebastian

response = requests.get(url, auth=auth)
os.remove("oci_api_key.pem")