コード例 #1
0
class RedirectClient(object):
    """
    OCI Web Application Acceleration and Security Services
    """
    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': '/20181116',
            'service_endpoint_template':
            'https://waas.{region}.{secondLevelDomain}',
            'skip_deserialization': kwargs.get('skip_deserialization', False)
        }
        self.base_client = BaseClient("redirect", config, signer,
                                      waas_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')

    def change_http_redirect_compartment(
            self, http_redirect_id, change_http_redirect_compartment_details,
            **kwargs):
        """
        Moves HTTP Redirect into a different compartment. When provided, If-Match is checked against ETag values of the WAAS policy.


        :param str http_redirect_id: (required)
            The `OCID`__ of the HTTP Redirect.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param oci.waas.models.ChangeHttpRedirectCompartmentDetails change_http_redirect_compartment_details: (required)

        :param str if_match: (optional)
            For optimistic concurrency control. In the `PUT` or `DELETE` call for a resource, set the `if-match` parameter to the value of the etag from a previous `GET` or `POST` response for that resource. The resource will be updated or deleted only if the etag provided matches the resource's current etag value.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param str opc_retry_token: (optional)
            A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations
            *Example:* If a resource has been deleted and purged from the system, then a retry of the original delete request may be rejected.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type None
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/change_http_redirect_compartment.py.html>`__ to see an example of how to use change_http_redirect_compartment API.
        """
        resource_path = "/httpRedirects/{httpRedirectId}/actions/changeCompartment"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "if_match", "opc_request_id", "opc_retry_token"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "change_http_redirect_compartment got unknown kwargs: {!r}".
                format(extra_kwargs))

        path_params = {"httpRedirectId": http_redirect_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "if-match": kwargs.get("if_match", missing),
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=change_http_redirect_compartment_details)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=change_http_redirect_compartment_details)

    def create_http_redirect(self, create_http_redirect_details, **kwargs):
        """
        Creates a new HTTP Redirect on the WAF edge.


        :param oci.waas.models.CreateHttpRedirectDetails create_http_redirect_details: (required)
            The details of the HTTP Redirect.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param str opc_retry_token: (optional)
            A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations
            *Example:* If a resource has been deleted and purged from the system, then a retry of the original delete request may be rejected.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type None
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/create_http_redirect.py.html>`__ to see an example of how to use create_http_redirect API.
        """
        resource_path = "/httpRedirects"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "opc_retry_token"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "create_http_redirect got unknown kwargs: {!r}".format(
                    extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=create_http_redirect_details)
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             header_params=header_params,
                                             body=create_http_redirect_details)

    def delete_http_redirect(self, http_redirect_id, **kwargs):
        """
        Deletes a redirect.


        :param str http_redirect_id: (required)
            The `OCID`__ of the HTTP Redirect.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param str opc_retry_token: (optional)
            A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations
            *Example:* If a resource has been deleted and purged from the system, then a retry of the original delete request may be rejected.

        :param str if_match: (optional)
            For optimistic concurrency control. In the `PUT` or `DELETE` call for a resource, set the `if-match` parameter to the value of the etag from a previous `GET` or `POST` response for that resource. The resource will be updated or deleted only if the etag provided matches the resource's current etag value.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type None
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/delete_http_redirect.py.html>`__ to see an example of how to use delete_http_redirect API.
        """
        resource_path = "/httpRedirects/{httpRedirectId}"
        method = "DELETE"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "opc_retry_token", "if_match"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "delete_http_redirect got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"httpRedirectId": http_redirect_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing),
            "if-match": kwargs.get("if_match", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params)
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params)

    def get_http_redirect(self, http_redirect_id, **kwargs):
        """
        Gets the details of a HTTP Redirect.


        :param str http_redirect_id: (required)
            The `OCID`__ of the HTTP Redirect.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.waas.models.HttpRedirect`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/get_http_redirect.py.html>`__ to see an example of how to use get_http_redirect API.
        """
        resource_path = "/httpRedirects/{httpRedirectId}"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_http_redirect got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"httpRedirectId": http_redirect_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="HttpRedirect")
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params,
                                             response_type="HttpRedirect")

    def list_http_redirects(self, compartment_id, **kwargs):
        """
        Gets a list of HTTP Redirects.


        :param str compartment_id: (required)
            The `OCID`__ of the compartment. This number is generated when the compartment is created.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param int limit: (optional)
            The maximum number of items to return in a paginated call. If unspecified, defaults to `10`.

        :param str page: (optional)
            The value of the `opc-next-page` response header from the previous paginated call.

        :param str sort_order: (optional)
            The value of the sorting direction of resources in a paginated 'List' call. If unspecified, defaults to `DESC`.

            Allowed values are: "ASC", "DESC"

        :param str sort_by: (optional)
            The field to sort the results of the List query.

            Allowed values are: "id", "domain", "target", "displayName"

        :param list[str] id: (optional)
            Filter redirects using a list of redirect OCIDs.

        :param list[str] display_name: (optional)
            Filter redirects using a display name.

        :param list[str] lifecycle_state: (optional)
            Filter redirects using a list of lifecycle states.

            Allowed values are: "CREATING", "ACTIVE", "FAILED", "UPDATING", "DELETING", "DELETED"

        :param datetime time_created_greater_than_or_equal_to: (optional)
            A filter that matches redirects created on or after the specified date and time.

        :param datetime time_created_less_than: (optional)
            A filter that matches redirects created before the specified date-time. Default to 1 day before now.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.waas.models.HttpRedirectSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/list_http_redirects.py.html>`__ to see an example of how to use list_http_redirects API.
        """
        resource_path = "/httpRedirects"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "limit", "page", "sort_order",
            "sort_by", "id", "display_name", "lifecycle_state",
            "time_created_greater_than_or_equal_to", "time_created_less_than"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_http_redirects got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        if 'sort_by' in kwargs:
            sort_by_allowed_values = ["id", "domain", "target", "displayName"]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(
                        sort_by_allowed_values))

        if 'lifecycle_state' in kwargs:
            lifecycle_state_allowed_values = [
                "CREATING", "ACTIVE", "FAILED", "UPDATING", "DELETING",
                "DELETED"
            ]
            for lifecycle_state_item in kwargs['lifecycle_state']:
                if lifecycle_state_item not in lifecycle_state_allowed_values:
                    raise ValueError(
                        "Invalid value for `lifecycle_state`, must be one of {0}"
                        .format(lifecycle_state_allowed_values))

        query_params = {
            "compartmentId":
            compartment_id,
            "limit":
            kwargs.get("limit", missing),
            "page":
            kwargs.get("page", missing),
            "sortOrder":
            kwargs.get("sort_order", missing),
            "sortBy":
            kwargs.get("sort_by", missing),
            "id":
            self.base_client.generate_collection_format_param(
                kwargs.get("id", missing), 'multi'),
            "displayName":
            self.base_client.generate_collection_format_param(
                kwargs.get("display_name", missing), 'multi'),
            "lifecycleState":
            self.base_client.generate_collection_format_param(
                kwargs.get("lifecycle_state", missing), 'multi'),
            "timeCreatedGreaterThanOrEqualTo":
            kwargs.get("time_created_greater_than_or_equal_to", missing),
            "timeCreatedLessThan":
            kwargs.get("time_created_less_than", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[HttpRedirectSummary]")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[HttpRedirectSummary]")

    def update_http_redirect(self, http_redirect_id,
                             update_http_redirect_details, **kwargs):
        """
        Updates the details of a HTTP Redirect, including target and tags. Only the fields specified in the request body will be updated; all other properties will remain unchanged.


        :param str http_redirect_id: (required)
            The `OCID`__ of the HTTP Redirect.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param oci.waas.models.UpdateHttpRedirectDetails update_http_redirect_details: (required)
            The details of the HTTP Redirect to update.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param str opc_retry_token: (optional)
            A token that uniquely identifies a request so it can be retried in case of a timeout or server error without risk of executing that same action again. Retry tokens expire after 24 hours, but can be invalidated before then due to conflicting operations
            *Example:* If a resource has been deleted and purged from the system, then a retry of the original delete request may be rejected.

        :param str if_match: (optional)
            For optimistic concurrency control. In the `PUT` or `DELETE` call for a resource, set the `if-match` parameter to the value of the etag from a previous `GET` or `POST` response for that resource. The resource will be updated or deleted only if the etag provided matches the resource's current etag value.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type None
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/waas/update_http_redirect.py.html>`__ to see an example of how to use update_http_redirect API.
        """
        resource_path = "/httpRedirects/{httpRedirectId}"
        method = "PUT"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "opc_retry_token", "if_match"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "update_http_redirect got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"httpRedirectId": http_redirect_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing),
            "if-match": kwargs.get("if_match", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=update_http_redirect_details)
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params,
                                             body=update_http_redirect_details)
コード例 #2
0
class ThreatintelClient(object):
    """
    Use the Threat Intelligence API to view indicators of compromise and related items. For more information, see [Overview of Threat Intelligence](/Content/ThreatIntelligence/Concepts/threatintelligenceoverview.htm).
    """
    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':
            '/20210831',
            'service_endpoint_template':
            'https://api-threatintel.{region}.oci.{secondLevelDomain}',
            '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("threatintel", config, signer,
                                      threat_intelligence_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')

    def get_indicator(self, indicator_id, compartment_id, **kwargs):
        """
        Gets a detailed indicator by identifier


        :param str indicator_id: (required)
            unique indicator identifier

        :param str compartment_id: (required)
            The ID of the tenancy to use to filter results.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.threat_intelligence.models.Indicator`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/threatintelligence/get_indicator.py.html>`__ to see an example of how to use get_indicator API.
        """
        resource_path = "/indicators/{indicatorId}"
        method = "GET"
        operation_name = "get_indicator"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/threat-intel/20210831/Indicator/GetIndicator"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_indicator got unknown kwargs: {!r}".format(extra_kwargs))

        path_params = {"indicatorId": indicator_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        query_params = {"compartmentId": compartment_id}
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="Indicator",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="Indicator",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_indicator_counts(self, compartment_id, **kwargs):
        """
        Get the current count of each indicator type.  Results can be sorted ASC or DESC by count.


        :param str compartment_id: (required)
            The ID of the tenancy to use to filter results.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param str sort_order: (optional)
            The sort order to use, either 'ASC' or 'DESC'.

            Allowed values are: "ASC", "DESC"

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.threat_intelligence.models.IndicatorCountCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/threatintelligence/list_indicator_counts.py.html>`__ to see an example of how to use list_indicator_counts API.
        """
        resource_path = "/indicatorCounts"
        method = "GET"
        operation_name = "list_indicator_counts"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/threat-intel/20210831/IndicatorCountCollection/ListIndicatorCounts"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "opc_request_id",
            "sort_order"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_indicator_counts got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        query_params = {
            "compartmentId": compartment_id,
            "sortOrder": kwargs.get("sort_order", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="IndicatorCountCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="IndicatorCountCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_indicators(self, compartment_id, **kwargs):
        """
        Returns a list of IndicatorSummary objects.


        :param str compartment_id: (required)
            The ID of the tenancy to use to filter results.

        :param list[str] threat_type_name: (optional)
            The result set will include indicators that have any of the provided threat types. To filter for multiple threat types repeat the query parameter.

        :param str type: (optional)
            The indicator type of entities to be returned.

            Allowed values are: "DOMAIN_NAME", "FILE_NAME", "MD5_HASH", "SHA1_HASH", "SHA256_HASH", "IP_ADDRESS", "URL"

        :param str value: (optional)
            The indicator value of entities to be returned.

        :param int confidence_greater_than_or_equal_to: (optional)
            The minimum confidence score of entities to be returned.

        :param datetime time_updated_greater_than_or_equal_to: (optional)
            The oldest update time of entities to be returned.

        :param int limit: (optional)
            The maximum number of items to return.

        :param str page: (optional)
            A token representing the position at which to start retrieving results. This must come from the `opc-next-page` header field of a previous response.

        :param str sort_order: (optional)
            The sort order to use, either 'ASC' or 'DESC'.

            Allowed values are: "ASC", "DESC"

        :param str sort_by: (optional)
            The field to sort by. Only one field to sort by may be provided.

            Allowed values are: "confidence", "timeUpdated"

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.threat_intelligence.models.IndicatorSummaryCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/threatintelligence/list_indicators.py.html>`__ to see an example of how to use list_indicators API.
        """
        resource_path = "/indicators"
        method = "GET"
        operation_name = "list_indicators"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/threat-intel/20210831/IndicatorSummaryCollection/ListIndicators"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "threat_type_name",
            "type", "value", "confidence_greater_than_or_equal_to",
            "time_updated_greater_than_or_equal_to", "limit", "page",
            "sort_order", "sort_by", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError("list_indicators got unknown kwargs: {!r}".format(
                extra_kwargs))

        if 'type' in kwargs:
            type_allowed_values = [
                "DOMAIN_NAME", "FILE_NAME", "MD5_HASH", "SHA1_HASH",
                "SHA256_HASH", "IP_ADDRESS", "URL"
            ]
            if kwargs['type'] not in type_allowed_values:
                raise ValueError(
                    "Invalid value for `type`, must be one of {0}".format(
                        type_allowed_values))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        if 'sort_by' in kwargs:
            sort_by_allowed_values = ["confidence", "timeUpdated"]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(
                        sort_by_allowed_values))

        query_params = {
            "compartmentId":
            compartment_id,
            "threatTypeName":
            self.base_client.generate_collection_format_param(
                kwargs.get("threat_type_name", missing), 'multi'),
            "type":
            kwargs.get("type", missing),
            "value":
            kwargs.get("value", missing),
            "confidenceGreaterThanOrEqualTo":
            kwargs.get("confidence_greater_than_or_equal_to", missing),
            "timeUpdatedGreaterThanOrEqualTo":
            kwargs.get("time_updated_greater_than_or_equal_to", missing),
            "limit":
            kwargs.get("limit", missing),
            "page":
            kwargs.get("page", missing),
            "sortOrder":
            kwargs.get("sort_order", missing),
            "sortBy":
            kwargs.get("sort_by", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="IndicatorSummaryCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="IndicatorSummaryCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_threat_types(self, compartment_id, **kwargs):
        """
        Gets a list of threat types that are available to use as parameters when querying indicators.
        This is sorted by threat type name according to the sort order query param.


        :param str compartment_id: (required)
            The ID of the tenancy to use to filter results.

        :param int limit: (optional)
            The maximum number of items to return.

        :param str page: (optional)
            A token representing the position at which to start retrieving results. This must come from the `opc-next-page` header field of a previous response.

        :param str sort_order: (optional)
            The sort order to use, either 'ASC' or 'DESC'.

            Allowed values are: "ASC", "DESC"

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.threat_intelligence.models.ThreatTypesCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/threatintelligence/list_threat_types.py.html>`__ to see an example of how to use list_threat_types API.
        """
        resource_path = "/threatTypes"
        method = "GET"
        operation_name = "list_threat_types"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/threat-intel/20210831/ThreatTypesCollection/ListThreatTypes"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "limit", "page",
            "sort_order", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_threat_types got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        query_params = {
            "compartmentId": compartment_id,
            "limit": kwargs.get("limit", missing),
            "page": kwargs.get("page", missing),
            "sortOrder": kwargs.get("sort_order", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="ThreatTypesCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="ThreatTypesCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
コード例 #3
0
class MysqlaasClient(object):
    """
    The API for the MySQL Database Service
    """
    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>`__.
        """
        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': '/20190415',
            'service_endpoint_template':
            'https://mysql.{region}.ocp.{secondLevelDomain}',
            'skip_deserialization': kwargs.get('skip_deserialization', False)
        }
        if 'timeout' in kwargs:
            base_client_init_kwargs['timeout'] = kwargs.get('timeout')
        self.base_client = BaseClient("mysqlaas", config, signer,
                                      mysql_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')

    def create_configuration(self, create_configuration_details, **kwargs):
        """
        Creates a new Configuration.


        :param oci.mysql.models.CreateConfigurationDetails create_configuration_details: (required)
            Request to create a Configuration.

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param str opc_retry_token: (optional)
            A token that uniquely identifies a request so it can be retried in case
            of a timeout or server error without risk of executing that same action
            again. Retry tokens expire after 24 hours, but can be invalidated before
            then due to conflicting operations (for example, if a resource has been
            deleted and purged from the system, then a retry of the original
            creation request may be rejected).

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.mysql.models.Configuration`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/create_configuration.py.html>`__ to see an example of how to use create_configuration API.
        """
        resource_path = "/configurations"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "opc_retry_token"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "create_configuration got unknown kwargs: {!r}".format(
                    extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=create_configuration_details,
                response_type="Configuration")
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             header_params=header_params,
                                             body=create_configuration_details,
                                             response_type="Configuration")

    def delete_configuration(self, configuration_id, **kwargs):
        """
        Deletes a Configuration.
        The Configuration must not be in use by any DB Systems.


        :param str configuration_id: (required)
            The OCID of the Configuration.

        :param str if_match: (optional)
            For optimistic concurrency control. In the PUT or DELETE call for a
            resource, set the `If-Match` header to the value of the etag from a
            previous GET or POST response for that resource. The resource will be
            updated or deleted only if the etag you provide matches the resource's
            current etag value.

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type None
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/delete_configuration.py.html>`__ to see an example of how to use delete_configuration API.
        """
        resource_path = "/configurations/{configurationId}"
        method = "DELETE"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "if_match", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "delete_configuration got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"configurationId": configuration_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "if-match": kwargs.get("if_match", missing),
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params)
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params)

    def get_configuration(self, configuration_id, **kwargs):
        """
        Get the full details of the specified Configuration, including the list of MySQL Variables and their values.


        :param str configuration_id: (required)
            The OCID of the Configuration.

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param str if_none_match: (optional)
            For conditional requests. In the GET call for a resource, set the
            `If-None-Match` header to the value of the ETag from a previous GET (or
            POST or PUT) response for that resource. The server will return with
            either a 304 Not Modified response if the resource has not changed, or a
            200 OK response with the updated representation.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.mysql.models.Configuration`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/get_configuration.py.html>`__ to see an example of how to use get_configuration API.
        """
        resource_path = "/configurations/{configurationId}"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id", "if_none_match"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_configuration got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"configurationId": configuration_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing),
            "if-none-match": kwargs.get("if_none_match", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="Configuration")
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params,
                                             response_type="Configuration")

    def list_configurations(self, compartment_id, **kwargs):
        """
        Lists the Configurations available when creating a DB System.

        This may include DEFAULT configurations per Shape and CUSTOM configurations.

        The default sort order is a multi-part sort by:
          - shapeName, ascending
          - DEFAULT-before-CUSTOM
          - displayName ascending


        :param str compartment_id: (required)
            The compartment `OCID`__.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param str configuration_id: (optional)
            The requested Configuration instance.

        :param str lifecycle_state: (optional)
            Configuration Lifecycle State

            Allowed values are: "ACTIVE", "DELETED"

        :param list[str] type: (optional)
            The requested Configuration types.

            Allowed values are: "DEFAULT", "CUSTOM"

        :param str display_name: (optional)
            A filter to return only the resource matching the given display name exactly.

        :param str shape_name: (optional)
            The requested Shape name.

        :param str sort_by: (optional)
            The field to sort by. Only one sort order may be provided. Time fields are default ordered as descending. Display name is default ordered as ascending.

            Allowed values are: "displayName", "shapeName", "timeCreated", "timeUpdated"

        :param str sort_order: (optional)
            The sort order to use (ASC or DESC).

            Allowed values are: "ASC", "DESC"

        :param int limit: (optional)
            The maximum number of items to return in a paginated list call. For information about pagination, see
            `List Pagination`__.

            __ https://docs.cloud.oracle.com/#API/Concepts/usingapi.htm#List_Pagination

        :param str page: (optional)
            The value of the `opc-next-page` or `opc-prev-page` response header from
            the previous list call. For information about pagination, see `List
            Pagination`__.

            __ https://docs.cloud.oracle.com/#API/Concepts/usingapi.htm#List_Pagination

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.mysql.models.ConfigurationSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/list_configurations.py.html>`__ to see an example of how to use list_configurations API.
        """
        resource_path = "/configurations"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "configuration_id",
            "lifecycle_state", "type", "display_name", "shape_name", "sort_by",
            "sort_order", "limit", "page"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_configurations got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'lifecycle_state' in kwargs:
            lifecycle_state_allowed_values = ["ACTIVE", "DELETED"]
            if kwargs['lifecycle_state'] not in lifecycle_state_allowed_values:
                raise ValueError(
                    "Invalid value for `lifecycle_state`, must be one of {0}".
                    format(lifecycle_state_allowed_values))

        if 'type' in kwargs:
            type_allowed_values = ["DEFAULT", "CUSTOM"]
            for type_item in kwargs['type']:
                if type_item not in type_allowed_values:
                    raise ValueError(
                        "Invalid value for `type`, must be one of {0}".format(
                            type_allowed_values))

        if 'sort_by' in kwargs:
            sort_by_allowed_values = [
                "displayName", "shapeName", "timeCreated", "timeUpdated"
            ]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(
                        sort_by_allowed_values))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        query_params = {
            "compartmentId":
            compartment_id,
            "configurationId":
            kwargs.get("configuration_id", missing),
            "lifecycleState":
            kwargs.get("lifecycle_state", missing),
            "type":
            self.base_client.generate_collection_format_param(
                kwargs.get("type", missing), 'multi'),
            "displayName":
            kwargs.get("display_name", missing),
            "shapeName":
            kwargs.get("shape_name", missing),
            "sortBy":
            kwargs.get("sort_by", missing),
            "sortOrder":
            kwargs.get("sort_order", missing),
            "limit":
            kwargs.get("limit", missing),
            "page":
            kwargs.get("page", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ConfigurationSummary]")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ConfigurationSummary]")

    def list_shapes(self, compartment_id, **kwargs):
        """
        Gets a list of the shapes you can use to create a new MySQL DB System.
        The shape determines the resources allocated to the DB System:
        CPU cores and memory for VM shapes; CPU cores, memory and
        storage for non-VM (or bare metal) shapes.


        :param str compartment_id: (required)
            The compartment `OCID`__.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param list[str] is_supported_for: (optional)
            Return shapes that are supported by the service feature.

            Allowed values are: "DBSYSTEM", "ANALYTICSCLUSTER", "HEATWAVECLUSTER"

        :param str availability_domain: (optional)
            The name of the Availability Domain.

        :param str name: (optional)
            Name

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.mysql.models.ShapeSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/list_shapes.py.html>`__ to see an example of how to use list_shapes API.
        """
        resource_path = "/shapes"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "is_supported_for",
            "availability_domain", "name"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_shapes got unknown kwargs: {!r}".format(extra_kwargs))

        if 'is_supported_for' in kwargs:
            is_supported_for_allowed_values = [
                "DBSYSTEM", "ANALYTICSCLUSTER", "HEATWAVECLUSTER"
            ]
            for is_supported_for_item in kwargs['is_supported_for']:
                if is_supported_for_item not in is_supported_for_allowed_values:
                    raise ValueError(
                        "Invalid value for `is_supported_for`, must be one of {0}"
                        .format(is_supported_for_allowed_values))

        query_params = {
            "isSupportedFor":
            self.base_client.generate_collection_format_param(
                kwargs.get("is_supported_for", missing), 'multi'),
            "availabilityDomain":
            kwargs.get("availability_domain", missing),
            "compartmentId":
            compartment_id,
            "name":
            kwargs.get("name", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ShapeSummary]")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ShapeSummary]")

    def list_versions(self, compartment_id, **kwargs):
        """
        Get a list of supported and available MySQL database major versions.

        The list is sorted by version family.


        :param str compartment_id: (required)
            The compartment `OCID`__.

            __ https://docs.cloud.oracle.com/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.mysql.models.VersionSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/list_versions.py.html>`__ to see an example of how to use list_versions API.
        """
        resource_path = "/versions"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_versions got unknown kwargs: {!r}".format(extra_kwargs))

        query_params = {"compartmentId": compartment_id}
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[VersionSummary]")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[VersionSummary]")

    def update_configuration(self, configuration_id,
                             update_configuration_details, **kwargs):
        """
        Updates the Configuration details.


        :param str configuration_id: (required)
            The OCID of the Configuration.

        :param oci.mysql.models.UpdateConfigurationDetails update_configuration_details: (required)
            Request to update a Configuration.

        :param str if_match: (optional)
            For optimistic concurrency control. In the PUT or DELETE call for a
            resource, set the `If-Match` header to the value of the etag from a
            previous GET or POST response for that resource. The resource will be
            updated or deleted only if the etag you provide matches the resource's
            current etag value.

        :param str opc_request_id: (optional)
            Customer-defined unique identifier for the request. If you need to
            contact Oracle about a specific request, please provide the request
            ID that you supplied in this header with the request.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set 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>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.mysql.models.Configuration`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/mysql/update_configuration.py.html>`__ to see an example of how to use update_configuration API.
        """
        resource_path = "/configurations/{configurationId}"
        method = "PUT"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "if_match", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "update_configuration got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"configurationId": configuration_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "if-match": kwargs.get("if_match", missing),
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.retry_strategy
        if kwargs.get('retry_strategy'):
            retry_strategy = kwargs.get('retry_strategy')

        if retry_strategy:
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=update_configuration_details,
                response_type="Configuration")
        else:
            return self.base_client.call_api(resource_path=resource_path,
                                             method=method,
                                             path_params=path_params,
                                             header_params=header_params,
                                             body=update_configuration_details,
                                             response_type="Configuration")
コード例 #4
0
class ComputedUsageClient(object):
    """
    OneSubscription APIs
    """
    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':
            '/20190111',
            'service_endpoint_template':
            'https://identity.{region}.oci.{secondLevelDomain}',
            '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("computed_usage", config, signer,
                                      onesubscription_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')

    def get_computed_usage(self, computed_usage_id, compartment_id, **kwargs):
        """
        This is an API which returns Computed Usage corresponding to the id passed


        :param str computed_usage_id: (required)
            The Computed Usage Id

        :param str compartment_id: (required)
            The OCID of the root compartment.

        :param list[str] fields: (optional)
            Partial response refers to an optimization technique offered
            by the RESTful web APIs to return only the information
            (fields) required by the client. This parameter is used to control what fields to
            return.

        :param str opc_request_id: (optional)
            Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.onesubscription.models.ComputedUsage`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/onesubscription/get_computed_usage.py.html>`__ to see an example of how to use get_computed_usage API.
        """
        resource_path = "/computedUsages/{computedUsageId}"
        method = "GET"
        operation_name = "get_computed_usage"
        api_reference_link = ""

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "fields", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_computed_usage got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"computedUsageId": computed_usage_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        query_params = {
            "compartmentId":
            compartment_id,
            "fields":
            self.base_client.generate_collection_format_param(
                kwargs.get("fields", missing), 'multi')
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="ComputedUsage",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="ComputedUsage",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_aggregated_computed_usages(self, compartment_id, subscription_id,
                                        time_from, time_to, **kwargs):
        """
        This is a collection API which returns a list of aggregated computed usage details (there can be multiple Parent Products under a given SubID each of which is represented under Subscription Service Line # in SPM).


        :param str compartment_id: (required)
            The OCID of the root compartment.

        :param str subscription_id: (required)
            Subscription Id is an identifier associated to the service used for filter the Computed Usage in SPM.

        :param datetime time_from: (required)
            Initial date to filter Computed Usage data in SPM. In the case of non aggregated data the time period between of fromDate and toDate , expressed in RFC 3339 timestamp format.

        :param datetime time_to: (required)
            Final date to filter Computed Usage data in SPM, expressed in RFC 3339 timestamp format.

        :param str parent_product: (optional)
            Product part number for subscribed service line, called parent product.

        :param str grouping: (optional)
            Grouping criteria to use for aggregate the computed Usage, either hourly (`HOURLY`), daily (`DAILY`), monthly(`MONTHLY`) or none (`NONE`) to not follow a grouping criteria by date.

            Allowed values are: "HOURLY", "DAILY", "MONTHLY", "NONE"

        :param int limit: (optional)
            The maximum number aggregatedComputedUsages of items to return within the Subscription \"List\" call, this
            counts the overall count across all items
            Example: `500`

        :param str page: (optional)
            The value of the 'opc-next-page' response header from the previous \"List\" call.

        :param str opc_request_id: (optional)
            Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.onesubscription.models.AggregatedComputedUsageSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/onesubscription/list_aggregated_computed_usages.py.html>`__ to see an example of how to use list_aggregated_computed_usages API.
        """
        resource_path = "/aggregatedComputedUsages"
        method = "GET"
        operation_name = "list_aggregated_computed_usages"
        api_reference_link = ""

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "parent_product",
            "grouping", "limit", "page", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_aggregated_computed_usages got unknown kwargs: {!r}".
                format(extra_kwargs))

        if 'grouping' in kwargs:
            grouping_allowed_values = ["HOURLY", "DAILY", "MONTHLY", "NONE"]
            if kwargs['grouping'] not in grouping_allowed_values:
                raise ValueError(
                    "Invalid value for `grouping`, must be one of {0}".format(
                        grouping_allowed_values))

        query_params = {
            "compartmentId": compartment_id,
            "subscriptionId": subscription_id,
            "timeFrom": time_from,
            "timeTo": time_to,
            "parentProduct": kwargs.get("parent_product", missing),
            "grouping": kwargs.get("grouping", missing),
            "limit": kwargs.get("limit", missing),
            "page": kwargs.get("page", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[AggregatedComputedUsageSummary]",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[AggregatedComputedUsageSummary]",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_computed_usages(self, compartment_id, subscription_id, time_from,
                             time_to, **kwargs):
        """
        This is a collection API which returns a list of Computed Usages for given filters.


        :param str compartment_id: (required)
            The OCID of the root compartment.

        :param str subscription_id: (required)
            Subscription Id is an identifier associated to the service used for filter the Computed Usage in SPM.

        :param datetime time_from: (required)
            Initial date to filter Computed Usage data in SPM. In the case of non aggregated data the time period between of fromDate and toDate , expressed in RFC 3339 timestamp format.

        :param datetime time_to: (required)
            Final date to filter Computed Usage data in SPM, expressed in RFC 3339 timestamp format.

        :param str parent_product: (optional)
            Product part number for subscribed service line, called parent product.

        :param str computed_product: (optional)
            Product part number for Computed Usage .

        :param int limit: (optional)
            The maximum number of items to return in a paginated \"List\" call. Default: (`50`)

            Example: '500'

        :param str page: (optional)
            The value of the 'opc-next-page' response header from the previous \"List\" call.

        :param str sort_order: (optional)
            The sort order to use, either ascending ('ASC') or descending ('DESC').

            Allowed values are: "ASC", "DESC"

        :param str sort_by: (optional)
            The field to sort by. You can provide one sort order (`sortOrder`).

            Allowed values are: "timeCreated", "timeOfArrival", "timeMeteredOn"

        :param str opc_request_id: (optional)
            Unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.onesubscription.models.ComputedUsageSummary`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/onesubscription/list_computed_usages.py.html>`__ to see an example of how to use list_computed_usages API.
        """
        resource_path = "/computedUsages"
        method = "GET"
        operation_name = "list_computed_usages"
        api_reference_link = ""

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "parent_product",
            "computed_product", "limit", "page", "sort_order", "sort_by",
            "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_computed_usages got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        if 'sort_by' in kwargs:
            sort_by_allowed_values = [
                "timeCreated", "timeOfArrival", "timeMeteredOn"
            ]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(
                        sort_by_allowed_values))

        query_params = {
            "compartmentId": compartment_id,
            "subscriptionId": subscription_id,
            "timeFrom": time_from,
            "timeTo": time_to,
            "parentProduct": kwargs.get("parent_product", missing),
            "computedProduct": kwargs.get("computed_product", missing),
            "limit": kwargs.get("limit", missing),
            "page": kwargs.get("page", missing),
            "sortOrder": kwargs.get("sort_order", missing),
            "sortBy": kwargs.get("sort_by", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ComputedUsageSummary]",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="list[ComputedUsageSummary]",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
コード例 #5
0
class InvoiceServiceClient(object):
    """
    This site describes all the Rest endpoints of Billing Center Gateway.
    """

    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.
        """
        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': '/20191001',
            'service_endpoint_template': 'https://ospap.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
        self.base_client = BaseClient("invoice_service", config, signer, osp_gateway_type_mapping, **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')

    def download_pdf_content(self, osp_home_region, compartment_id, internal_invoice_id, **kwargs):
        """
        Returns an invoice in pdf format


        :param str osp_home_region: (required)
            The home region's public name of the logged in user.

        :param str compartment_id: (required)
            The `OCID`__ of the compartment.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param str internal_invoice_id: (required)
            The identifier of the invoice.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a
            particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type stream
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ospgateway/download_pdf_content.py.html>`__ to see an example of how to use download_pdf_content API.
        """
        resource_path = "/invoices/{internalInvoiceId}/actions/downloadPdfContent"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy",
            "opc_request_id"
        ]
        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
        if extra_kwargs:
            raise ValueError(
                "download_pdf_content got unknown kwargs: {!r}".format(extra_kwargs))

        path_params = {
            "internalInvoiceId": internal_invoice_id
        }

        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))

        query_params = {
            "ospHomeRegion": osp_home_region,
            "compartmentId": compartment_id
        }
        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}

        header_params = {
            "accept": "application/pdf",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy
        )

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="stream")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="stream")

    def get_invoice(self, osp_home_region, compartment_id, internal_invoice_id, **kwargs):
        """
        Returns an invoice by invoice id


        :param str osp_home_region: (required)
            The home region's public name of the logged in user.

        :param str compartment_id: (required)
            The `OCID`__ of the compartment.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param str internal_invoice_id: (required)
            The identifier of the invoice.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a
            particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.osp_gateway.models.Invoice`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ospgateway/get_invoice.py.html>`__ to see an example of how to use get_invoice API.
        """
        resource_path = "/invoices/{internalInvoiceId}"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy",
            "opc_request_id"
        ]
        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
        if extra_kwargs:
            raise ValueError(
                "get_invoice got unknown kwargs: {!r}".format(extra_kwargs))

        path_params = {
            "internalInvoiceId": internal_invoice_id
        }

        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))

        query_params = {
            "ospHomeRegion": osp_home_region,
            "compartmentId": compartment_id
        }
        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy
        )

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="Invoice")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="Invoice")

    def list_invoice_lines(self, osp_home_region, compartment_id, internal_invoice_id, **kwargs):
        """
        Returns the invoice product list by invoice id


        :param str osp_home_region: (required)
            The home region's public name of the logged in user.

        :param str compartment_id: (required)
            The `OCID`__ of the compartment.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param str internal_invoice_id: (required)
            The identifier of the invoice.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a
            particular request, please provide the request ID.

        :param str page: (optional)
            For list pagination. The value of the opc-next-page response header from the previous \"List\" call.

        :param int limit: (optional)
            For list pagination. The maximum number of results per page, or items to return in a paginated \"List\" call.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.osp_gateway.models.InvoiceLineCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ospgateway/list_invoice_lines.py.html>`__ to see an example of how to use list_invoice_lines API.
        """
        resource_path = "/invoices/{internalInvoiceId}/invoiceLines"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy",
            "opc_request_id",
            "page",
            "limit"
        ]
        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
        if extra_kwargs:
            raise ValueError(
                "list_invoice_lines got unknown kwargs: {!r}".format(extra_kwargs))

        path_params = {
            "internalInvoiceId": internal_invoice_id
        }

        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))

        query_params = {
            "ospHomeRegion": osp_home_region,
            "compartmentId": compartment_id,
            "page": kwargs.get("page", missing),
            "limit": kwargs.get("limit", missing)
        }
        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy
        )

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="InvoiceLineCollection")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                response_type="InvoiceLineCollection")

    def list_invoices(self, osp_home_region, compartment_id, **kwargs):
        """
        Returns a list of invoices


        :param str osp_home_region: (required)
            The home region's public name of the logged in user.

        :param str compartment_id: (required)
            The `OCID`__ of the compartment.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a
            particular request, please provide the request ID.

        :param str invoice_id: (optional)
            The invoice query param (not unique).

        :param list[str] type: (optional)
            A filter to only return resources that match the given type exactly.

            Allowed values are: "HARDWARE", "SUBSCRIPTION", "SUPPORT", "LICENSE", "EDUCATION", "CONSULTING", "SERVICE", "USAGE"

        :param str search_text: (optional)
            A filter to only return resources that match the given value.
            Looking for partial matches in the following fileds:
            Invoice No., Reference No. (plan number), Payment Ref, Total Amount(plan number), Balance Due(plan number)
            and Party/Customer Name

        :param datetime time_invoice_start: (optional)
            description: Start time (UTC) of the target invoice date range for which to fetch invoice data (inclusive).

        :param datetime time_invoice_end: (optional)
            description: End time (UTC) of the target invoice date range for which to fetch invoice data (exclusive).

        :param datetime time_payment_start: (optional)
            description: Start time (UTC) of the target payment date range for which to fetch invoice data (inclusive).

        :param datetime time_payment_end: (optional)
            description: End time (UTC) of the target payment date range for which to fetch invoice data (exclusive).

        :param list[str] status: (optional)
            A filter to only return resources that match one of the status elements.

            Allowed values are: "OPEN", "PAST_DUE", "PAYMENT_SUBMITTED", "CLOSED"

        :param str page: (optional)
            For list pagination. The value of the opc-next-page response header from the previous \"List\" call.

        :param int limit: (optional)
            For list pagination. The maximum number of results per page, or items to return in a paginated \"List\" call.

        :param str sort_by: (optional)
            The field to sort by. Only one field can be selected for sorting.

            Allowed values are: "INVOICE_NO", "REF_NO", "STATUS", "TYPE", "INVOICE_DATE", "DUE_DATE", "PAYM_REF", "TOTAL_AMOUNT", "BALANCE_DUE"

        :param str sort_order: (optional)
            The sort order to use (ascending or descending).

            Allowed values are: "ASC", "DESC"

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.osp_gateway.models.InvoiceCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ospgateway/list_invoices.py.html>`__ to see an example of how to use list_invoices API.
        """
        resource_path = "/invoices"
        method = "GET"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy",
            "opc_request_id",
            "invoice_id",
            "type",
            "search_text",
            "time_invoice_start",
            "time_invoice_end",
            "time_payment_start",
            "time_payment_end",
            "status",
            "page",
            "limit",
            "sort_by",
            "sort_order"
        ]
        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
        if extra_kwargs:
            raise ValueError(
                "list_invoices got unknown kwargs: {!r}".format(extra_kwargs))

        if 'type' in kwargs:
            type_allowed_values = ["HARDWARE", "SUBSCRIPTION", "SUPPORT", "LICENSE", "EDUCATION", "CONSULTING", "SERVICE", "USAGE"]
            for type_item in kwargs['type']:
                if type_item not in type_allowed_values:
                    raise ValueError(
                        "Invalid value for `type`, must be one of {0}".format(type_allowed_values)
                    )

        if 'status' in kwargs:
            status_allowed_values = ["OPEN", "PAST_DUE", "PAYMENT_SUBMITTED", "CLOSED"]
            for status_item in kwargs['status']:
                if status_item not in status_allowed_values:
                    raise ValueError(
                        "Invalid value for `status`, must be one of {0}".format(status_allowed_values)
                    )

        if 'sort_by' in kwargs:
            sort_by_allowed_values = ["INVOICE_NO", "REF_NO", "STATUS", "TYPE", "INVOICE_DATE", "DUE_DATE", "PAYM_REF", "TOTAL_AMOUNT", "BALANCE_DUE"]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(sort_by_allowed_values)
                )

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".format(sort_order_allowed_values)
                )

        query_params = {
            "ospHomeRegion": osp_home_region,
            "compartmentId": compartment_id,
            "invoiceId": kwargs.get("invoice_id", missing),
            "type": self.base_client.generate_collection_format_param(kwargs.get("type", missing), 'multi'),
            "searchText": kwargs.get("search_text", missing),
            "timeInvoiceStart": kwargs.get("time_invoice_start", missing),
            "timeInvoiceEnd": kwargs.get("time_invoice_end", missing),
            "timePaymentStart": kwargs.get("time_payment_start", missing),
            "timePaymentEnd": kwargs.get("time_payment_end", missing),
            "status": self.base_client.generate_collection_format_param(kwargs.get("status", missing), 'multi'),
            "page": kwargs.get("page", missing),
            "limit": kwargs.get("limit", missing),
            "sortBy": kwargs.get("sort_by", missing),
            "sortOrder": kwargs.get("sort_order", missing)
        }
        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy
        )

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="InvoiceCollection")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="InvoiceCollection")

    def pay_invoice(self, osp_home_region, internal_invoice_id, compartment_id, pay_invoice_details, **kwargs):
        """
        Pay an invoice


        :param str osp_home_region: (required)
            The home region's public name of the logged in user.

        :param str internal_invoice_id: (required)
            The identifier of the invoice.

        :param str compartment_id: (required)
            The `OCID`__ of the compartment.

            __ https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm

        :param oci.osp_gateway.models.PayInvoiceDetails pay_invoice_details: (required)
            Invoice payment request.

        :param str if_match: (optional)
            For optimistic concurrency control. In the PUT or DELETE call
            for a resource, set the `if-match` parameter to the value of the
            etag from a previous GET or POST response for that resource.
            The resource will be updated or deleted only if the etag you
            provide matches the resource's current etag value.

        :param str opc_retry_token: (optional)
            For requests that are not idempotent (creates being the main place of interest), THE APIs should take a header
            called opc-retry-token to identify the customer desire across requests, to introduce some level of idempotency.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a
            particular request, please provide the request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.osp_gateway.models.PayInvoiceReceipt`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ospgateway/pay_invoice.py.html>`__ to see an example of how to use pay_invoice API.
        """
        resource_path = "/invoices/{internalInvoiceId}/actions/pay"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy",
            "if_match",
            "opc_retry_token",
            "opc_request_id"
        ]
        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
        if extra_kwargs:
            raise ValueError(
                "pay_invoice got unknown kwargs: {!r}".format(extra_kwargs))

        path_params = {
            "internalInvoiceId": internal_invoice_id
        }

        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))

        query_params = {
            "ospHomeRegion": osp_home_region,
            "compartmentId": compartment_id
        }
        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "if-match": kwargs.get("if_match", missing),
            "opc-retry-token": kwargs.get("opc_retry_token", missing),
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy
        )

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_retry_token_if_needed(header_params)
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                body=pay_invoice_details,
                response_type="PayInvoiceReceipt")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                query_params=query_params,
                header_params=header_params,
                body=pay_invoice_details,
                response_type="PayInvoiceReceipt")
コード例 #6
0
class AIServiceLanguageClient(object):
    """
    OCI Language Service solutions can help enterprise customers integrate AI into their products immediately using our proven,
        pre-trained and custom models or containers, without a need to set up an house team of AI and ML experts.
        This allows enterprises to focus on business drivers and development work rather than AI and ML operations, which shortens the time to market.
    """
    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.
        """
        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':
            '/20210101',
            'service_endpoint_template':
            'https://language.aiservice.{region}.oci.{secondLevelDomain}',
            '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
        self.base_client = BaseClient("ai_service_language", config, signer,
                                      ai_language_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')

    def batch_detect_dominant_language(self,
                                       batch_detect_dominant_language_details,
                                       **kwargs):
        """
        Make a detect call to language detection pre-deployed model.


        :param oci.ai_language.models.BatchDetectDominantLanguageDetails batch_detect_dominant_language_details: (required)
            The details to make a language detection detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.BatchDetectDominantLanguageResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/batch_detect_dominant_language.py.html>`__ to see an example of how to use batch_detect_dominant_language API.
        """
        resource_path = "/actions/batchDetectDominantLanguage"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "batch_detect_dominant_language got unknown kwargs: {!r}".
                format(extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_dominant_language_details,
                response_type="BatchDetectDominantLanguageResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_dominant_language_details,
                response_type="BatchDetectDominantLanguageResult")

    def batch_detect_language_entities(self,
                                       batch_detect_language_entities_details,
                                       **kwargs):
        """
        Make a batch detect call to entity pre-deployed model


        :param oci.ai_language.models.BatchDetectLanguageEntitiesDetails batch_detect_language_entities_details: (required)
            The details to make a Entity detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.BatchDetectLanguageEntitiesResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/batch_detect_language_entities.py.html>`__ to see an example of how to use batch_detect_language_entities API.
        """
        resource_path = "/actions/batchDetectLanguageEntities"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "batch_detect_language_entities got unknown kwargs: {!r}".
                format(extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_entities_details,
                response_type="BatchDetectLanguageEntitiesResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_entities_details,
                response_type="BatchDetectLanguageEntitiesResult")

    def batch_detect_language_key_phrases(
            self, batch_detect_language_key_phrases_details, **kwargs):
        """
        Make a detect call to the keyPhrase pre-deployed model.


        :param oci.ai_language.models.BatchDetectLanguageKeyPhrasesDetails batch_detect_language_key_phrases_details: (required)
            The details to make keyPhrase detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.BatchDetectLanguageKeyPhrasesResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/batch_detect_language_key_phrases.py.html>`__ to see an example of how to use batch_detect_language_key_phrases API.
        """
        resource_path = "/actions/batchDetectLanguageKeyPhrases"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "batch_detect_language_key_phrases got unknown kwargs: {!r}".
                format(extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_key_phrases_details,
                response_type="BatchDetectLanguageKeyPhrasesResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_key_phrases_details,
                response_type="BatchDetectLanguageKeyPhrasesResult")

    def batch_detect_language_sentiments(
            self, batch_detect_language_sentiments_details, **kwargs):
        """
        Make a detect call to sentiment pre-deployed model.


        :param oci.ai_language.models.BatchDetectLanguageSentimentsDetails batch_detect_language_sentiments_details: (required)
            The details to make sentiment detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param list[str] level: (optional)
            Set this parameter for sentence and aspect level sentiment analysis.
            Allowed values are:
               - ASPECT
               - SENTENCE

            Allowed values are: "ASPECT", "SENTENCE"

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.BatchDetectLanguageSentimentsResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/batch_detect_language_sentiments.py.html>`__ to see an example of how to use batch_detect_language_sentiments API.
        """
        resource_path = "/actions/batchDetectLanguageSentiments"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id", "level"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "batch_detect_language_sentiments got unknown kwargs: {!r}".
                format(extra_kwargs))

        if 'level' in kwargs:
            level_allowed_values = ["ASPECT", "SENTENCE"]
            for level_item in kwargs['level']:
                if level_item not in level_allowed_values:
                    raise ValueError(
                        "Invalid value for `level`, must be one of {0}".format(
                            level_allowed_values))

        query_params = {
            "level":
            self.base_client.generate_collection_format_param(
                kwargs.get("level", missing), 'multi')
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                body=batch_detect_language_sentiments_details,
                response_type="BatchDetectLanguageSentimentsResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                body=batch_detect_language_sentiments_details,
                response_type="BatchDetectLanguageSentimentsResult")

    def batch_detect_language_text_classification(
            self, batch_detect_language_text_classification_details, **kwargs):
        """
        Make a detect call to text classification from the pre-deployed model.


        :param oci.ai_language.models.BatchDetectLanguageTextClassificationDetails batch_detect_language_text_classification_details: (required)
            The details to make text classification detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.BatchDetectLanguageTextClassificationResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/batch_detect_language_text_classification.py.html>`__ to see an example of how to use batch_detect_language_text_classification API.
        """
        resource_path = "/actions/batchDetectLanguageTextClassification"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "batch_detect_language_text_classification got unknown kwargs: {!r}"
                .format(extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_text_classification_details,
                response_type="BatchDetectLanguageTextClassificationResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=batch_detect_language_text_classification_details,
                response_type="BatchDetectLanguageTextClassificationResult")

    def detect_dominant_language(self, detect_dominant_language_details,
                                 **kwargs):
        """
        Make a detect call to language detection pre-deployed model.


        :param oci.ai_language.models.DetectDominantLanguageDetails detect_dominant_language_details: (required)
            The details to make a language detection detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.DetectDominantLanguageResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/detect_dominant_language.py.html>`__ to see an example of how to use detect_dominant_language API.
        """
        resource_path = "/actions/detectDominantLanguage"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "detect_dominant_language got unknown kwargs: {!r}".format(
                    extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_dominant_language_details,
                response_type="DetectDominantLanguageResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_dominant_language_details,
                response_type="DetectDominantLanguageResult")

    def detect_language_entities(self, detect_language_entities_details,
                                 **kwargs):
        """
        Make a detect call to enitiy pre-deployed model


        :param oci.ai_language.models.DetectLanguageEntitiesDetails detect_language_entities_details: (required)
            The details to make a Entity detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param str model_version: (optional)
            Named Entity Recognition model versions. By default user will get output from V2.1 implementation.

            Allowed values are: "V2.1", "V1.1"

        :param bool is_pii: (optional)
            If this parameter is set to true, you only get PII (Personally identifiable information) entities
            like PhoneNumber, Email, Person, and so on. Default value is false.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.DetectLanguageEntitiesResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/detect_language_entities.py.html>`__ to see an example of how to use detect_language_entities API.
        """
        resource_path = "/actions/detectLanguageEntities"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "retry_strategy", "opc_request_id", "model_version", "is_pii"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "detect_language_entities got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'model_version' in kwargs:
            model_version_allowed_values = ["V2.1", "V1.1"]
            if kwargs['model_version'] not in model_version_allowed_values:
                raise ValueError(
                    "Invalid value for `model_version`, must be one of {0}".
                    format(model_version_allowed_values))

        query_params = {
            "modelVersion": kwargs.get("model_version", missing),
            "isPii": kwargs.get("is_pii", missing)
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                body=detect_language_entities_details,
                response_type="DetectLanguageEntitiesResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                body=detect_language_entities_details,
                response_type="DetectLanguageEntitiesResult")

    def detect_language_key_phrases(self, detect_language_key_phrases_details,
                                    **kwargs):
        """
        Make a detect call to the keyPhrase pre-deployed model.


        :param oci.ai_language.models.DetectLanguageKeyPhrasesDetails detect_language_key_phrases_details: (required)
            The details to make keyPhrase detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.DetectLanguageKeyPhrasesResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/detect_language_key_phrases.py.html>`__ to see an example of how to use detect_language_key_phrases API.
        """
        resource_path = "/actions/detectLanguageKeyPhrases"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "detect_language_key_phrases got unknown kwargs: {!r}".format(
                    extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_key_phrases_details,
                response_type="DetectLanguageKeyPhrasesResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_key_phrases_details,
                response_type="DetectLanguageKeyPhrasesResult")

    def detect_language_sentiments(self, detect_language_sentiments_details,
                                   **kwargs):
        """
        Make a detect call to sentiment pre-deployed model.


        :param oci.ai_language.models.DetectLanguageSentimentsDetails detect_language_sentiments_details: (required)
            The details to make sentiment detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.DetectLanguageSentimentsResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/detect_language_sentiments.py.html>`__ to see an example of how to use detect_language_sentiments API.
        """
        resource_path = "/actions/detectLanguageSentiments"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "detect_language_sentiments got unknown kwargs: {!r}".format(
                    extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_sentiments_details,
                response_type="DetectLanguageSentimentsResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_sentiments_details,
                response_type="DetectLanguageSentimentsResult")

    def detect_language_text_classification(
            self, detect_language_text_classification_details, **kwargs):
        """
        Make a detect call to text classification from the pre-deployed model.


        :param oci.ai_language.models.DetectLanguageTextClassificationDetails detect_language_text_classification_details: (required)
            The details to make text classification detect call.

        :param str opc_request_id: (optional)
            The client request ID for tracing.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.ai_language.models.DetectLanguageTextClassificationResult`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/ailanguage/detect_language_text_classification.py.html>`__ to see an example of how to use detect_language_text_classification API.
        """
        resource_path = "/actions/detectLanguageTextClassification"
        method = "POST"

        # Don't accept unknown kwargs
        expected_kwargs = ["retry_strategy", "opc_request_id"]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "detect_language_text_classification got unknown kwargs: {!r}".
                format(extra_kwargs))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_text_classification_details,
                response_type="DetectLanguageTextClassificationResult")
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                header_params=header_params,
                body=detect_language_text_classification_details,
                response_type="DetectLanguageTextClassificationResult")
コード例 #7
0
class AnnouncementClient(object):
    """
    Manage Oracle Cloud Infrastructure console announcements.
    """
    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':
            '/20180904',
            'service_endpoint_template':
            'https://announcements.{region}.oci.{secondLevelDomain}',
            '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("announcement", config, signer,
                                      announcements_service_type_mapping,
                                      **base_client_init_kwargs)
        self.retry_strategy = kwargs.get('retry_strategy')
        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')

    def get_announcement(self, announcement_id, **kwargs):
        """
        Gets the details of a specific announcement.

        This call is subject to an Announcements limit that applies to the total number of requests across all read or write operations. Announcements might throttle this call to reject an otherwise valid request when the total rate of operations exceeds 20 requests per second for a given user. The service might also throttle this call to reject an otherwise valid request when the total rate of operations exceeds 100 requests per second for a given tenancy.


        :param str announcement_id: (required)
            The OCID of the announcement.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about
            a particular request, please provide the complete request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.announcements_service.models.Announcement`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/announcementsservice/get_announcement.py.html>`__ to see an example of how to use get_announcement API.
        """
        resource_path = "/announcements/{announcementId}"
        method = "GET"
        operation_name = "get_announcement"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/announcements/0.0.1/Announcement/GetAnnouncement"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_announcement got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"announcementId": announcement_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="Announcement",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="Announcement",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def get_announcement_user_status(self, announcement_id, **kwargs):
        """
        Gets information about whether a specific announcement was acknowledged by a user.

        This call is subject to an Announcements limit that applies to the total number of requests across all read or write operations. Announcements might throttle this call to reject an otherwise valid request when the total rate of operations exceeds 20 requests per second for a given user. The service might also throttle this call to reject an otherwise valid request when the total rate of operations exceeds 100 requests per second for a given tenancy.


        :param str announcement_id: (required)
            The OCID of the announcement.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about
            a particular request, please provide the complete request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.announcements_service.models.AnnouncementUserStatusDetails`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/announcementsservice/get_announcement_user_status.py.html>`__ to see an example of how to use get_announcement_user_status API.
        """
        resource_path = "/announcements/{announcementId}/userStatus"
        method = "GET"
        operation_name = "get_announcement_user_status"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/announcements/0.0.1/AnnouncementUserStatusDetails/GetAnnouncementUserStatus"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "get_announcement_user_status got unknown kwargs: {!r}".format(
                    extra_kwargs))

        path_params = {"announcementId": announcement_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="AnnouncementUserStatusDetails",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                response_type="AnnouncementUserStatusDetails",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def list_announcements(self, compartment_id, **kwargs):
        """
        Gets a list of announcements for the current tenancy.

        This call is subject to an Announcements limit that applies to the total number of requests across all read or write operations. Announcements might throttle this call to reject an otherwise valid request when the total rate of operations exceeds 20 requests per second for a given user. The service might also throttle this call to reject an otherwise valid request when the total rate of operations exceeds 100 requests per second for a given tenancy.


        :param str compartment_id: (required)
            The OCID of the compartment.

        :param int limit: (optional)
            The maximum number of items to return in a paginated \"List\" call.

        :param str page: (optional)
            The value of the `opc-next-page` response header from the previous \"List\" call.

        :param str announcement_type: (optional)
            The type of announcement.

        :param str lifecycle_state: (optional)
            The announcement's current lifecycle state.

            Allowed values are: "ACTIVE", "INACTIVE"

        :param bool is_banner: (optional)
            Whether the announcement is displayed as a console banner.

        :param str sort_by: (optional)
            The criteria to sort by. You can specify only one sort order.

            Allowed values are: "timeOneValue", "timeTwoValue", "timeCreated", "referenceTicketNumber", "summary", "announcementType"

        :param str sort_order: (optional)
            The sort order to use. (Sorting by `announcementType` orders the announcements list according to importance.)

            Allowed values are: "ASC", "DESC"

        :param datetime time_one_earliest_time: (optional)
            The boundary for the earliest `timeOneValue` date on announcements that you want to see.

        :param datetime time_one_latest_time: (optional)
            The boundary for the latest `timeOneValue` date on announcements that you want to see.

        :param str environment_name: (optional)
            A filter to return only announcements that match a specific environment name.

        :param str service: (optional)
            A filter to return only announcements affecting a specific service.

        :param str platform_type: (optional)
            A filter to return only announcements affecting a specific platform.

            Allowed values are: "IAAS", "SAAS"

        :param list[str] exclude_announcement_types: (optional)
            Exclude The type of announcement.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about
            a particular request, please provide the complete request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.announcements_service.models.AnnouncementsCollection`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/announcementsservice/list_announcements.py.html>`__ to see an example of how to use list_announcements API.
        """
        resource_path = "/announcements"
        method = "GET"
        operation_name = "list_announcements"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/announcements/0.0.1/AnnouncementsCollection/ListAnnouncements"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "limit", "page",
            "announcement_type", "lifecycle_state", "is_banner", "sort_by",
            "sort_order", "time_one_earliest_time", "time_one_latest_time",
            "environment_name", "service", "platform_type",
            "exclude_announcement_types", "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "list_announcements got unknown kwargs: {!r}".format(
                    extra_kwargs))

        if 'lifecycle_state' in kwargs:
            lifecycle_state_allowed_values = ["ACTIVE", "INACTIVE"]
            if kwargs['lifecycle_state'] not in lifecycle_state_allowed_values:
                raise ValueError(
                    "Invalid value for `lifecycle_state`, must be one of {0}".
                    format(lifecycle_state_allowed_values))

        if 'sort_by' in kwargs:
            sort_by_allowed_values = [
                "timeOneValue", "timeTwoValue", "timeCreated",
                "referenceTicketNumber", "summary", "announcementType"
            ]
            if kwargs['sort_by'] not in sort_by_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_by`, must be one of {0}".format(
                        sort_by_allowed_values))

        if 'sort_order' in kwargs:
            sort_order_allowed_values = ["ASC", "DESC"]
            if kwargs['sort_order'] not in sort_order_allowed_values:
                raise ValueError(
                    "Invalid value for `sort_order`, must be one of {0}".
                    format(sort_order_allowed_values))

        if 'platform_type' in kwargs:
            platform_type_allowed_values = ["IAAS", "SAAS"]
            if kwargs['platform_type'] not in platform_type_allowed_values:
                raise ValueError(
                    "Invalid value for `platform_type`, must be one of {0}".
                    format(platform_type_allowed_values))

        query_params = {
            "limit":
            kwargs.get("limit", missing),
            "page":
            kwargs.get("page", missing),
            "compartmentId":
            compartment_id,
            "announcementType":
            kwargs.get("announcement_type", missing),
            "lifecycleState":
            kwargs.get("lifecycle_state", missing),
            "isBanner":
            kwargs.get("is_banner", missing),
            "sortBy":
            kwargs.get("sort_by", missing),
            "sortOrder":
            kwargs.get("sort_order", missing),
            "timeOneEarliestTime":
            kwargs.get("time_one_earliest_time", missing),
            "timeOneLatestTime":
            kwargs.get("time_one_latest_time", missing),
            "environmentName":
            kwargs.get("environment_name", missing),
            "service":
            kwargs.get("service", missing),
            "platformType":
            kwargs.get("platform_type", missing),
            "excludeAnnouncementTypes":
            self.base_client.generate_collection_format_param(
                kwargs.get("exclude_announcement_types", missing), 'multi')
        }
        query_params = {
            k: v
            for (k, v) in six.iteritems(query_params)
            if v is not missing and v is not None
        }

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="AnnouncementsCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                query_params=query_params,
                header_params=header_params,
                response_type="AnnouncementsCollection",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)

    def update_announcement_user_status(self, announcement_id, status_details,
                                        **kwargs):
        """
        Updates the status of the specified announcement with regard to whether it has been marked as read.

        This call is subject to an Announcements limit that applies to the total number of requests across all read or write operations. Announcements might throttle this call to reject an otherwise valid request when the total rate of operations exceeds 20 requests per second for a given user. The service might also throttle this call to reject an otherwise valid request when the total rate of operations exceeds 100 requests per second for a given tenancy.


        :param str announcement_id: (required)
            The OCID of the announcement.

        :param oci.announcements_service.models.AnnouncementUserStatusDetails status_details: (required)
            The information to use to update the announcement's read status.

        :param str if_match: (optional)
            The locking version, used for optimistic concurrency control.

        :param str opc_request_id: (optional)
            The unique Oracle-assigned identifier for the request. If you need to contact Oracle about
            a particular request, please provide the complete request ID.

        :param obj retry_strategy: (optional)
            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.

            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.

        :param bool allow_control_chars: (optional)
            allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object.
            By default, the response will not allow control characters in strings

        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.announcements_service.models.AnnouncementUserStatusDetails`
        :rtype: :class:`~oci.response.Response`

        :example:
        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/latest/announcementsservice/update_announcement_user_status.py.html>`__ to see an example of how to use update_announcement_user_status API.
        """
        resource_path = "/announcements/{announcementId}/userStatus"
        method = "PUT"
        operation_name = "update_announcement_user_status"
        api_reference_link = "https://docs.oracle.com/iaas/api/#/en/announcements/0.0.1/AnnouncementUserStatusDetails/UpdateAnnouncementUserStatus"

        # Don't accept unknown kwargs
        expected_kwargs = [
            "allow_control_chars", "retry_strategy", "if_match",
            "opc_request_id"
        ]
        extra_kwargs = [
            _key for _key in six.iterkeys(kwargs)
            if _key not in expected_kwargs
        ]
        if extra_kwargs:
            raise ValueError(
                "update_announcement_user_status got unknown kwargs: {!r}".
                format(extra_kwargs))

        path_params = {"announcementId": announcement_id}

        path_params = {
            k: v
            for (k, v) in six.iteritems(path_params) if v is not missing
        }

        for (k, v) in six.iteritems(path_params):
            if v is None or (isinstance(v, six.string_types)
                             and len(v.strip()) == 0):
                raise ValueError(
                    'Parameter {} cannot be None, whitespace or empty string'.
                    format(k))

        header_params = {
            "accept": "application/json",
            "content-type": "application/json",
            "if-match": kwargs.get("if_match", missing),
            "opc-request-id": kwargs.get("opc_request_id", missing)
        }
        header_params = {
            k: v
            for (k, v) in six.iteritems(header_params)
            if v is not missing and v is not None
        }

        retry_strategy = self.base_client.get_preferred_retry_strategy(
            operation_retry_strategy=kwargs.get('retry_strategy'),
            client_retry_strategy=self.retry_strategy)

        if retry_strategy:
            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
                self.base_client.add_opc_client_retries_header(header_params)
                retry_strategy.add_circuit_breaker_callback(
                    self.circuit_breaker_callback)
            return retry_strategy.make_retrying_call(
                self.base_client.call_api,
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=status_details,
                response_type="AnnouncementUserStatusDetails",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)
        else:
            return self.base_client.call_api(
                resource_path=resource_path,
                method=method,
                path_params=path_params,
                header_params=header_params,
                body=status_details,
                response_type="AnnouncementUserStatusDetails",
                allow_control_chars=kwargs.get('allow_control_chars'),
                operation_name=operation_name,
                api_reference_link=api_reference_link)