|
| 1 | +""" |
| 2 | +Tenable Attack Surface Management |
| 3 | +================================= |
| 4 | +
|
| 5 | +This package covers the Tenable ASM application. |
| 6 | +
|
| 7 | +.. autoclass:: TenableASM |
| 8 | + :members: |
| 9 | +
|
| 10 | +
|
| 11 | +.. toctree:: |
| 12 | + :hidden: |
| 13 | + :glob: |
| 14 | +
|
| 15 | + inventory |
| 16 | + smart_folders |
| 17 | +
|
| 18 | +""" |
| 19 | +from tenable.base.platform import APIPlatform |
| 20 | +from .inventory import InventoryAPI |
| 21 | +from .smart_folders import SmartFoldersAPI |
| 22 | + |
| 23 | + |
| 24 | +class TenableASM(APIPlatform): |
| 25 | + """ |
| 26 | + The TenableASM class is the primary interaction point for users to interface with |
| 27 | + Tenable Attack Surface Management via the pyTenable library. All the API endpoint |
| 28 | + classes that wrap the various aspects of ASM will be attached to this base class. |
| 29 | +
|
| 30 | + Args: |
| 31 | + api_key (str, optional): |
| 32 | + The user's API key to interface into Tenable ASM. If the key isn't |
| 33 | + specified, then the library will attempt to read the environment |
| 34 | + variable `TASM_API_KEY` to get the key. |
| 35 | + url (str, optional): |
| 36 | + The base URL that the paths will be appended onto. The default is |
| 37 | + ``https://asm.cloud.tenable.com`` If the url isn't specified, then the |
| 38 | + library will attempt to read the environment variable `TASM_URL`. |
| 39 | + retries (int, optional): |
| 40 | + The number of retries to make before failing a request. The |
| 41 | + default is ``5``. |
| 42 | + backoff (float, optional): |
| 43 | + If a 429 response is returned, how much do we want to backoff |
| 44 | + if the response didn't send a Retry-After header. The default |
| 45 | + backoff is ``1`` second. |
| 46 | + vendor (str, optional): |
| 47 | + The vendor name for the User-Agent string. |
| 48 | + product (str, optional): |
| 49 | + The product name for the User-Agent string. |
| 50 | + build (str, optional): |
| 51 | + The version or build identifier for the User-Agent string. |
| 52 | + timeout (int, optional): |
| 53 | + The connection timeout parameter informing the library how long to |
| 54 | + wait in seconds for a stalled response before terminating the |
| 55 | + connection. If unspecified, the default is 120 seconds. |
| 56 | +
|
| 57 | + Examples: |
| 58 | +
|
| 59 | + Basic example: |
| 60 | +
|
| 61 | + >>> from tenable.asm import TenableASM |
| 62 | + >>> tasm = TenableASM(api_key='abcdef1234567890') |
| 63 | +
|
| 64 | + Another example with proper identification: |
| 65 | +
|
| 66 | + >>> tasm = TenableASM(api_key='abcdef1234567890', |
| 67 | + ... vendor='Company Name', |
| 68 | + ... product='My Awesome Widget', |
| 69 | + ... build='1.0.0' |
| 70 | + ... ) |
| 71 | +
|
| 72 | + Yet another example thats leveraging the `TASM_API_KEY` environment variable: |
| 73 | +
|
| 74 | + >>> tasm = TenableASM(vendor='Company Name', |
| 75 | + ... product='My Awesome Widget', |
| 76 | + ... build='1.0.0' |
| 77 | + ... ) |
| 78 | + """ |
| 79 | + _url = 'https://asm.cloud.tenable.com' |
| 80 | + _base_path = 'api/1.0' |
| 81 | + _env_base = 'TASM' |
| 82 | + _box = True |
| 83 | + _allowed_auth_mech_priority = ['key'] |
| 84 | + _allowed_auth_mech_params = {'key': ['api_key']} |
| 85 | + |
| 86 | + def _key_auth(self, api_key, **kwargs): |
| 87 | + """ |
| 88 | + API Key authorization mechanism for Tenable ASM. |
| 89 | + """ |
| 90 | + self._session.headers.update({'Authorization': api_key}) |
| 91 | + self._auth_meth = 'key' |
| 92 | + |
| 93 | + @property |
| 94 | + def inventory(self): |
| 95 | + """ |
| 96 | + The interface object for the |
| 97 | + :doc:`Tenable ASM Inventory API <inventory>` |
| 98 | + """ |
| 99 | + return InventoryAPI(self) |
| 100 | + |
| 101 | + @property |
| 102 | + def smart_folders(self): |
| 103 | + """ |
| 104 | + The interface object for the |
| 105 | + :doc:`Tenable ASM Smart Folders API <smart_folders>` |
| 106 | + """ |
| 107 | + return SmartFoldersAPI(self) |
0 commit comments