|
| 1 | +# coding: utf-8 |
| 2 | +# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
| 3 | + |
| 4 | +from __future__ import absolute_import |
| 5 | + |
| 6 | +import six |
| 7 | + |
| 8 | +from ..base_client import BaseClient |
| 9 | +from ..config import get_config_value_or_default, validate_config |
| 10 | +from ..signer import Signer |
| 11 | +from ..util import Sentinel |
| 12 | +from .models import audit_type_mapping |
| 13 | +missing = Sentinel("Missing") |
| 14 | + |
| 15 | + |
| 16 | +class AuditClient(object): |
| 17 | + |
| 18 | + def __init__(self, config): |
| 19 | + validate_config(config) |
| 20 | + signer = Signer( |
| 21 | + tenancy=config["tenancy"], |
| 22 | + user=config["user"], |
| 23 | + fingerprint=config["fingerprint"], |
| 24 | + private_key_file_location=config.get("key_file"), |
| 25 | + pass_phrase=get_config_value_or_default(config, "pass_phrase"), |
| 26 | + private_key_content=config.get("key_content") |
| 27 | + ) |
| 28 | + self.base_client = BaseClient("audit", config, signer, audit_type_mapping) |
| 29 | + |
| 30 | + def get_configuration(self, compartment_id, **kwargs): |
| 31 | + """ |
| 32 | + GetConfiguration |
| 33 | + Get the configuration |
| 34 | +
|
| 35 | +
|
| 36 | + :param str compartment_id: (required) |
| 37 | + ID of the root compartment (tenancy) |
| 38 | +
|
| 39 | + :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.audit.models.Configuration` |
| 40 | + :rtype: :class:`~oci.response.Response` |
| 41 | + """ |
| 42 | + resource_path = "/configuration" |
| 43 | + method = "GET" |
| 44 | + |
| 45 | + if kwargs: |
| 46 | + raise ValueError( |
| 47 | + "get_configuration got unknown kwargs: {!r}".format(kwargs)) |
| 48 | + |
| 49 | + query_params = { |
| 50 | + "compartmentId": compartment_id |
| 51 | + } |
| 52 | + query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing} |
| 53 | + |
| 54 | + header_params = { |
| 55 | + "accept": "application/json", |
| 56 | + "content-type": "application/json" |
| 57 | + } |
| 58 | + |
| 59 | + return self.base_client.call_api( |
| 60 | + resource_path=resource_path, |
| 61 | + method=method, |
| 62 | + query_params=query_params, |
| 63 | + header_params=header_params, |
| 64 | + response_type="Configuration") |
| 65 | + |
| 66 | + def list_events(self, compartment_id, start_time, end_time, **kwargs): |
| 67 | + """ |
| 68 | + ListEvents |
| 69 | + Returns all audit events for the specified compartment that were processed within the specified time range. |
| 70 | +
|
| 71 | +
|
| 72 | + :param str compartment_id: (required) |
| 73 | + The OCID of the compartment. |
| 74 | +
|
| 75 | + :param datetime start_time: (required) |
| 76 | + Returns events that were processed at or after this start date and time, expressed in `RFC 3339`__ timestamp format. |
| 77 | + For example, a start value of `2017-01-15T11:30:00Z` will retrieve a list of all events processed since 30 minutes after the 11th hour of January 15, 2017, in Coordinated Universal Time (UTC). |
| 78 | + You can specify a value with granularity to the minute. Seconds (and milliseconds, if included) must be set to `0`. |
| 79 | +
|
| 80 | + __ https://tools.ietf.org/html/rfc3339 |
| 81 | +
|
| 82 | + :param datetime end_time: (required) |
| 83 | + Returns events that were processed before this end date and time, expressed in `RFC 3339`__ timestamp format. For example, a start value of `2017-01-01T00:00:00Z` and an end value of `2017-01-02T00:00:00Z` will retrieve a list of all events processed on January 1, 2017. |
| 84 | + Similarly, a start value of `2017-01-01T00:00:00Z` and an end value of `2017-02-01T00:00:00Z` will result in a list of all events processed between January 1, 2017 and January 31, 2017. |
| 85 | + You can specify a value with granularity to the minute. Seconds (and milliseconds, if included) must be set to `0`. |
| 86 | +
|
| 87 | + __ https://tools.ietf.org/html/rfc3339 |
| 88 | +
|
| 89 | + :param str page: (optional) |
| 90 | + The value of the `opc-next-page` response header from the previous list query. |
| 91 | +
|
| 92 | + :param str opc_request_id: (optional) |
| 93 | + Unique Oracle-assigned identifier for the request. |
| 94 | + If you need to contact Oracle about a particular request, please provide the request ID. |
| 95 | +
|
| 96 | + :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.audit.models.AuditEvent` |
| 97 | + :rtype: :class:`~oci.response.Response` |
| 98 | + """ |
| 99 | + resource_path = "/auditEvents" |
| 100 | + method = "GET" |
| 101 | + |
| 102 | + # Don't accept unknown kwargs |
| 103 | + expected_kwargs = [ |
| 104 | + "page", |
| 105 | + "opc_request_id" |
| 106 | + ] |
| 107 | + extra_kwargs = [key for key in six.iterkeys(kwargs) if key not in expected_kwargs] |
| 108 | + if extra_kwargs: |
| 109 | + raise ValueError( |
| 110 | + "list_events got unknown kwargs: {!r}".format(extra_kwargs)) |
| 111 | + |
| 112 | + query_params = { |
| 113 | + "compartmentId": compartment_id, |
| 114 | + "startTime": start_time, |
| 115 | + "endTime": end_time, |
| 116 | + "page": kwargs.get("page", missing) |
| 117 | + } |
| 118 | + query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing} |
| 119 | + |
| 120 | + header_params = { |
| 121 | + "accept": "application/json", |
| 122 | + "content-type": "application/json", |
| 123 | + "opc-request-id": kwargs.get("opc_request_id", missing) |
| 124 | + } |
| 125 | + header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing} |
| 126 | + |
| 127 | + return self.base_client.call_api( |
| 128 | + resource_path=resource_path, |
| 129 | + method=method, |
| 130 | + query_params=query_params, |
| 131 | + header_params=header_params, |
| 132 | + response_type="list[AuditEvent]") |
| 133 | + |
| 134 | + def update_configuration(self, compartment_id, update_configuration_details, **kwargs): |
| 135 | + """ |
| 136 | + UpdateConfiguration |
| 137 | + Update the configuration |
| 138 | +
|
| 139 | +
|
| 140 | + :param str compartment_id: (required) |
| 141 | + ID of the root compartment (tenancy) |
| 142 | +
|
| 143 | + :param UpdateConfigurationDetails update_configuration_details: (required) |
| 144 | + The configuration properties |
| 145 | +
|
| 146 | + :return: A :class:`~oci.response.Response` object with data of type None |
| 147 | + :rtype: :class:`~oci.response.Response` |
| 148 | + """ |
| 149 | + resource_path = "/configuration" |
| 150 | + method = "PUT" |
| 151 | + |
| 152 | + if kwargs: |
| 153 | + raise ValueError( |
| 154 | + "update_configuration got unknown kwargs: {!r}".format(kwargs)) |
| 155 | + |
| 156 | + query_params = { |
| 157 | + "compartmentId": compartment_id |
| 158 | + } |
| 159 | + query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing} |
| 160 | + |
| 161 | + header_params = { |
| 162 | + "accept": "application/json", |
| 163 | + "content-type": "application/json" |
| 164 | + } |
| 165 | + |
| 166 | + return self.base_client.call_api( |
| 167 | + resource_path=resource_path, |
| 168 | + method=method, |
| 169 | + query_params=query_params, |
| 170 | + header_params=header_params, |
| 171 | + body=update_configuration_details) |
0 commit comments