|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""Webex Admin Audit Events API wrapper. |
| 3 | +
|
| 4 | +Copyright (c) 2016-2019 Cisco and/or its affiliates. |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | + |
| 26 | +from __future__ import ( |
| 27 | + absolute_import, |
| 28 | + division, |
| 29 | + print_function, |
| 30 | + unicode_literals, |
| 31 | +) |
| 32 | + |
| 33 | +from builtins import * |
| 34 | + |
| 35 | +from past.builtins import basestring |
| 36 | + |
| 37 | +from webexteamssdk.generator_containers import generator_container |
| 38 | +from webexteamssdk.restsession import RestSession |
| 39 | +from webexteamssdk.utils import check_type, dict_from_items_with_values |
| 40 | + |
| 41 | + |
| 42 | +API_ENDPOINT = 'adminAudit/events' |
| 43 | +OBJECT_TYPE = 'admin_audit_event' |
| 44 | + |
| 45 | + |
| 46 | +class AdminAuditEventsAPI(object): |
| 47 | + """Admin Audit Events API. |
| 48 | +
|
| 49 | + Wraps the Webex Teams Admin Audit Events API and exposes the API as native |
| 50 | + Python methods that return native Python objects. |
| 51 | +
|
| 52 | + """ |
| 53 | + |
| 54 | + def __init__(self, session, object_factory): |
| 55 | + """Init a new AdminAuditEventsAPI object with the provided RestSession. |
| 56 | +
|
| 57 | + Args: |
| 58 | + session(RestSession): The RESTful session object to be used for |
| 59 | + API calls to the Webex Teams service. |
| 60 | +
|
| 61 | + Raises: |
| 62 | + TypeError: If the parameter types are incorrect. |
| 63 | +
|
| 64 | + """ |
| 65 | + check_type(session, RestSession) |
| 66 | + |
| 67 | + super(AdminAuditEventsAPI, self).__init__() |
| 68 | + |
| 69 | + self._session = session |
| 70 | + self._object_factory = object_factory |
| 71 | + |
| 72 | + @generator_container |
| 73 | + def list(self, orgId, _from, to, actorId=None, max=100, offset=0, |
| 74 | + **request_parameters): |
| 75 | + """List Organizations. |
| 76 | +
|
| 77 | + This method supports Webex Teams's implementation of RFC5988 Web |
| 78 | + Linking to provide pagination support. It returns a generator |
| 79 | + container that incrementally yields all audit events returned by the |
| 80 | + query. The generator will automatically request additional 'pages' of |
| 81 | + responses from Webex as needed until all responses have been returned. |
| 82 | + The container makes the generator safe for reuse. A new API call will |
| 83 | + be made, using the same parameters that were specified when the |
| 84 | + generator was created, every time a new iterator is requested from the |
| 85 | + container. |
| 86 | +
|
| 87 | + Args: |
| 88 | + orgId(basestring): List events in this organization, by ID. |
| 89 | + _from(basestring): List events which occurred after a specific |
| 90 | + date and time. |
| 91 | + to(basestring): List events which occurred before a specific date |
| 92 | + and time. |
| 93 | + actorId(basestring): List events performed by this person, by ID. |
| 94 | + max(int): Limit the maximum number of events in the response. The |
| 95 | + maximum value is 200. |
| 96 | + offset(int): Offset from the first result that you want to fetch. |
| 97 | + **request_parameters: Additional request parameters (provides |
| 98 | + support for parameters that may be added in the future). |
| 99 | +
|
| 100 | + Returns: |
| 101 | + GeneratorContainer: A GeneratorContainer which, when iterated, |
| 102 | + yields the organizations returned by the Webex Teams query. |
| 103 | +
|
| 104 | + Raises: |
| 105 | + TypeError: If the parameter types are incorrect. |
| 106 | + ApiError: If the Webex Teams cloud returns an error. |
| 107 | + """ |
| 108 | + check_type(orgId, basestring) |
| 109 | + check_type(_from, basestring) |
| 110 | + check_type(to, basestring) |
| 111 | + check_type(actorId, basestring, optional=True) |
| 112 | + check_type(max, int) |
| 113 | + check_type(offset, int) |
| 114 | + |
| 115 | + params = dict_from_items_with_values( |
| 116 | + request_parameters, |
| 117 | + orgId=orgId, |
| 118 | + _from=_from, |
| 119 | + to=to, |
| 120 | + actorId=actorId, |
| 121 | + max=max, |
| 122 | + offset=offset, |
| 123 | + ) |
| 124 | + |
| 125 | + if _from: |
| 126 | + params["from"] = params.pop("_from") |
| 127 | + |
| 128 | + # API request - get items |
| 129 | + items = self._session.get_items(API_ENDPOINT, params=params) |
| 130 | + |
| 131 | + # Yield AdminAuditEvent objects created from the returned JSON objects |
| 132 | + for item in items: |
| 133 | + yield self._object_factory(OBJECT_TYPE, item) |
0 commit comments