laceworksdk.api.v1.integrations
Lacework Integrations API wrapper.
1# -*- coding: utf-8 -*- 2""" 3Lacework Integrations API wrapper. 4""" 5 6import logging 7 8logger = logging.getLogger(__name__) 9 10 11class IntegrationsAPI: 12 """ 13 Lacework Integrations API. 14 """ 15 16 def __init__(self, session): 17 """ 18 Initializes the IntegrationsAPI object. 19 20 :param session: An instance of the HttpSession class 21 22 :return IntegrationsAPI object. 23 """ 24 25 super().__init__() 26 27 self._session = session 28 29 def create(self, 30 name, 31 type, 32 enabled, 33 data): 34 """ 35 A method to create a new cloud integration. 36 37 :param name: A string representing the integration name. 38 :param type: A string representing the integration type. 39 :param enabled: An integer representing whether the integration is enabled. 40 (0 or 1) 41 :param data: A JSON object matching the schema for the specified type. 42 43 :return response json 44 """ 45 46 logger.info("Creating cloud integration in Lacework...") 47 48 # Build the Integrations request URI 49 api_uri = "/api/v1/external/integrations" 50 51 data = { 52 "NAME": name, 53 "TYPE": type, 54 "ENABLED": int(bool(enabled)), 55 "DATA": data 56 } 57 58 response = self._session.post(api_uri, data=data) 59 60 return response.json() 61 62 def get(self, 63 guid=None, 64 schema=None, 65 type=None): 66 """ 67 A generic method to get cloud integrations. 68 69 :param guid: A string representing the integration GUID. 70 :param schema: A string representing the schema type. 71 :param type: A string representing the integration type. 72 73 :return response json 74 """ 75 76 logger.info("Getting cloud integrations from Lacework...") 77 78 # Build the Integrations request URI 79 if guid: 80 api_uri = f"/api/v1/external/integrations/{guid}" 81 elif type: 82 api_uri = f"/api/v1/external/integrations/type/{type}" 83 elif schema: 84 api_uri = f"/api/v1/external/integrations/schema/{schema}" 85 else: 86 api_uri = "/api/v1/external/integrations" 87 88 response = self._session.get(api_uri) 89 90 return response.json() 91 92 def get_all(self): 93 """ 94 A method to get a list of all cloud integrations. 95 96 :return response json 97 """ 98 99 logger.warning("The 'get_all' function may be deprecated shortly, please consider switching to 'get'.") 100 101 return self.get() 102 103 def get_by_id(self, 104 id): 105 """ 106 A method to get the specified cloud integration. 107 108 :param id: A string representing the Lacework integration GUID. 109 110 :return response json 111 """ 112 113 logger.warning("The 'get_by_id' function may be deprecated shortly, please consider switching to 'get'.") 114 115 return self.get(guid=id) 116 117 def get_by_type(self, 118 type): 119 """ 120 A method to get the specified cloud integration. 121 122 :param type: A string representing the integration type. 123 124 :return response json 125 """ 126 127 logger.warning("The 'get_by_type' function may be deprecated shortly, please consider switching to 'get'.") 128 129 return self.get(type=type) 130 131 def update(self, 132 guid, 133 name=None, 134 type=None, 135 enabled=None, 136 data=None): 137 """ 138 A method to update the specified cloud integration. 139 140 :param guid: A string representing the Lacework integration GUID. 141 :param name: A string representing the integration name. 142 :param type: A string representing the integration type. 143 :param enabled: An integer representing whether the integration is enabled. 144 (0 or 1) 145 :param data: A JSON object matching the schema for the specified type. 146 147 :return response json 148 """ 149 150 logger.info("Updating cloud integration in Lacework...") 151 152 # Build the Integrations request URI 153 api_uri = f"/api/v1/external/integrations/{guid}" 154 155 tmp_data = {} 156 157 if name: 158 tmp_data["NAME"] = name 159 if type: 160 tmp_data["TYPE"] = type 161 if enabled is not None: 162 tmp_data["ENABLED"] = int(bool(enabled)) 163 if data: 164 tmp_data["DATA"] = data 165 166 response = self._session.patch(api_uri, data=tmp_data) 167 168 return response.json() 169 170 def update_by_id(self, 171 id, 172 name=None, 173 type=None, 174 enabled=None, 175 data=None): 176 """ 177 A method to update the specified cloud integration. 178 179 :param id: A string representing the Lacework integration GUID. 180 :param name: A string representing the integration name. 181 :param type: A string representing the integration type. 182 :param enabled: An integer representing whether the integration is enabled. (0 or 1) 183 :param data: A JSON object matching the schema for the specified type. 184 185 :return response json 186 """ 187 188 logger.warning("The 'update_by_id' function may be deprecated shortly, please consider switching to 'update'.") 189 190 return self.update(guid=id, name=name, type=type, enabled=enabled, data=data) 191 192 def update_status(self, 193 id, 194 enabled): 195 """ 196 A method to update the status of a specified cloud integration. 197 198 :param id: A string representing the Lacework integration GUID. 199 :param enabled: A boolean representing whether the integration is enabled. 200 201 :return response json 202 """ 203 204 logger.warning("The 'update_status' function may be deprecated shortly, please consider switching to 'update'.") 205 206 return self.update(guid=id, enabled=enabled) 207 208 def delete(self, 209 guid): 210 """ 211 A method to delete the specified cloud integration. 212 213 :param guid: A string representing the Lacework integration GUID. 214 215 :return response json 216 """ 217 218 logger.info("Deleting cloud integration in Lacework...") 219 220 # Build the Integrations request URI 221 api_uri = f"/api/v1/external/integrations/{guid}" 222 223 response = self._session.delete(api_uri) 224 225 return response.json() 226 227 def delete_by_id(self, 228 id): 229 """ 230 A method to delete the specified cloud integration. 231 232 :param id: A string representing the Lacework integration GUID. 233 234 :return response json 235 236 **** Needs to be deprecated 237 """ 238 239 logger.warning("The 'delete_by_id' function may be deprecated shortly, please consider switching to 'delete'.") 240 241 return self.delete(guid=id) 242 243 def get_schema(self, type): 244 """ 245 A method to get the schema for a specified cloud integration type. 246 247 :param type: A string representing the integration type. 248 249 :return response json 250 """ 251 252 logger.info("Getting cloud integration schema from Lacework...") 253 254 return self.get(schema=type)
12class IntegrationsAPI: 13 """ 14 Lacework Integrations API. 15 """ 16 17 def __init__(self, session): 18 """ 19 Initializes the IntegrationsAPI object. 20 21 :param session: An instance of the HttpSession class 22 23 :return IntegrationsAPI object. 24 """ 25 26 super().__init__() 27 28 self._session = session 29 30 def create(self, 31 name, 32 type, 33 enabled, 34 data): 35 """ 36 A method to create a new cloud integration. 37 38 :param name: A string representing the integration name. 39 :param type: A string representing the integration type. 40 :param enabled: An integer representing whether the integration is enabled. 41 (0 or 1) 42 :param data: A JSON object matching the schema for the specified type. 43 44 :return response json 45 """ 46 47 logger.info("Creating cloud integration in Lacework...") 48 49 # Build the Integrations request URI 50 api_uri = "/api/v1/external/integrations" 51 52 data = { 53 "NAME": name, 54 "TYPE": type, 55 "ENABLED": int(bool(enabled)), 56 "DATA": data 57 } 58 59 response = self._session.post(api_uri, data=data) 60 61 return response.json() 62 63 def get(self, 64 guid=None, 65 schema=None, 66 type=None): 67 """ 68 A generic method to get cloud integrations. 69 70 :param guid: A string representing the integration GUID. 71 :param schema: A string representing the schema type. 72 :param type: A string representing the integration type. 73 74 :return response json 75 """ 76 77 logger.info("Getting cloud integrations from Lacework...") 78 79 # Build the Integrations request URI 80 if guid: 81 api_uri = f"/api/v1/external/integrations/{guid}" 82 elif type: 83 api_uri = f"/api/v1/external/integrations/type/{type}" 84 elif schema: 85 api_uri = f"/api/v1/external/integrations/schema/{schema}" 86 else: 87 api_uri = "/api/v1/external/integrations" 88 89 response = self._session.get(api_uri) 90 91 return response.json() 92 93 def get_all(self): 94 """ 95 A method to get a list of all cloud integrations. 96 97 :return response json 98 """ 99 100 logger.warning("The 'get_all' function may be deprecated shortly, please consider switching to 'get'.") 101 102 return self.get() 103 104 def get_by_id(self, 105 id): 106 """ 107 A method to get the specified cloud integration. 108 109 :param id: A string representing the Lacework integration GUID. 110 111 :return response json 112 """ 113 114 logger.warning("The 'get_by_id' function may be deprecated shortly, please consider switching to 'get'.") 115 116 return self.get(guid=id) 117 118 def get_by_type(self, 119 type): 120 """ 121 A method to get the specified cloud integration. 122 123 :param type: A string representing the integration type. 124 125 :return response json 126 """ 127 128 logger.warning("The 'get_by_type' function may be deprecated shortly, please consider switching to 'get'.") 129 130 return self.get(type=type) 131 132 def update(self, 133 guid, 134 name=None, 135 type=None, 136 enabled=None, 137 data=None): 138 """ 139 A method to update the specified cloud integration. 140 141 :param guid: A string representing the Lacework integration GUID. 142 :param name: A string representing the integration name. 143 :param type: A string representing the integration type. 144 :param enabled: An integer representing whether the integration is enabled. 145 (0 or 1) 146 :param data: A JSON object matching the schema for the specified type. 147 148 :return response json 149 """ 150 151 logger.info("Updating cloud integration in Lacework...") 152 153 # Build the Integrations request URI 154 api_uri = f"/api/v1/external/integrations/{guid}" 155 156 tmp_data = {} 157 158 if name: 159 tmp_data["NAME"] = name 160 if type: 161 tmp_data["TYPE"] = type 162 if enabled is not None: 163 tmp_data["ENABLED"] = int(bool(enabled)) 164 if data: 165 tmp_data["DATA"] = data 166 167 response = self._session.patch(api_uri, data=tmp_data) 168 169 return response.json() 170 171 def update_by_id(self, 172 id, 173 name=None, 174 type=None, 175 enabled=None, 176 data=None): 177 """ 178 A method to update the specified cloud integration. 179 180 :param id: A string representing the Lacework integration GUID. 181 :param name: A string representing the integration name. 182 :param type: A string representing the integration type. 183 :param enabled: An integer representing whether the integration is enabled. (0 or 1) 184 :param data: A JSON object matching the schema for the specified type. 185 186 :return response json 187 """ 188 189 logger.warning("The 'update_by_id' function may be deprecated shortly, please consider switching to 'update'.") 190 191 return self.update(guid=id, name=name, type=type, enabled=enabled, data=data) 192 193 def update_status(self, 194 id, 195 enabled): 196 """ 197 A method to update the status of a specified cloud integration. 198 199 :param id: A string representing the Lacework integration GUID. 200 :param enabled: A boolean representing whether the integration is enabled. 201 202 :return response json 203 """ 204 205 logger.warning("The 'update_status' function may be deprecated shortly, please consider switching to 'update'.") 206 207 return self.update(guid=id, enabled=enabled) 208 209 def delete(self, 210 guid): 211 """ 212 A method to delete the specified cloud integration. 213 214 :param guid: A string representing the Lacework integration GUID. 215 216 :return response json 217 """ 218 219 logger.info("Deleting cloud integration in Lacework...") 220 221 # Build the Integrations request URI 222 api_uri = f"/api/v1/external/integrations/{guid}" 223 224 response = self._session.delete(api_uri) 225 226 return response.json() 227 228 def delete_by_id(self, 229 id): 230 """ 231 A method to delete the specified cloud integration. 232 233 :param id: A string representing the Lacework integration GUID. 234 235 :return response json 236 237 **** Needs to be deprecated 238 """ 239 240 logger.warning("The 'delete_by_id' function may be deprecated shortly, please consider switching to 'delete'.") 241 242 return self.delete(guid=id) 243 244 def get_schema(self, type): 245 """ 246 A method to get the schema for a specified cloud integration type. 247 248 :param type: A string representing the integration type. 249 250 :return response json 251 """ 252 253 logger.info("Getting cloud integration schema from Lacework...") 254 255 return self.get(schema=type)
Lacework Integrations API.
17 def __init__(self, session): 18 """ 19 Initializes the IntegrationsAPI object. 20 21 :param session: An instance of the HttpSession class 22 23 :return IntegrationsAPI object. 24 """ 25 26 super().__init__() 27 28 self._session = session
Initializes the IntegrationsAPI object.
Parameters
- session: An instance of the HttpSession class
:return IntegrationsAPI object.
30 def create(self, 31 name, 32 type, 33 enabled, 34 data): 35 """ 36 A method to create a new cloud integration. 37 38 :param name: A string representing the integration name. 39 :param type: A string representing the integration type. 40 :param enabled: An integer representing whether the integration is enabled. 41 (0 or 1) 42 :param data: A JSON object matching the schema for the specified type. 43 44 :return response json 45 """ 46 47 logger.info("Creating cloud integration in Lacework...") 48 49 # Build the Integrations request URI 50 api_uri = "/api/v1/external/integrations" 51 52 data = { 53 "NAME": name, 54 "TYPE": type, 55 "ENABLED": int(bool(enabled)), 56 "DATA": data 57 } 58 59 response = self._session.post(api_uri, data=data) 60 61 return response.json()
A method to create a new cloud integration.
Parameters
- name: A string representing the integration name.
- type: A string representing the integration type.
- enabled: An integer representing whether the integration is enabled. (0 or 1)
- data: A JSON object matching the schema for the specified type.
:return response json
63 def get(self, 64 guid=None, 65 schema=None, 66 type=None): 67 """ 68 A generic method to get cloud integrations. 69 70 :param guid: A string representing the integration GUID. 71 :param schema: A string representing the schema type. 72 :param type: A string representing the integration type. 73 74 :return response json 75 """ 76 77 logger.info("Getting cloud integrations from Lacework...") 78 79 # Build the Integrations request URI 80 if guid: 81 api_uri = f"/api/v1/external/integrations/{guid}" 82 elif type: 83 api_uri = f"/api/v1/external/integrations/type/{type}" 84 elif schema: 85 api_uri = f"/api/v1/external/integrations/schema/{schema}" 86 else: 87 api_uri = "/api/v1/external/integrations" 88 89 response = self._session.get(api_uri) 90 91 return response.json()
A generic method to get cloud integrations.
Parameters
- guid: A string representing the integration GUID.
- schema: A string representing the schema type.
- type: A string representing the integration type.
:return response json
93 def get_all(self): 94 """ 95 A method to get a list of all cloud integrations. 96 97 :return response json 98 """ 99 100 logger.warning("The 'get_all' function may be deprecated shortly, please consider switching to 'get'.") 101 102 return self.get()
A method to get a list of all cloud integrations.
:return response json
104 def get_by_id(self, 105 id): 106 """ 107 A method to get the specified cloud integration. 108 109 :param id: A string representing the Lacework integration GUID. 110 111 :return response json 112 """ 113 114 logger.warning("The 'get_by_id' function may be deprecated shortly, please consider switching to 'get'.") 115 116 return self.get(guid=id)
A method to get the specified cloud integration.
Parameters
- id: A string representing the Lacework integration GUID.
:return response json
118 def get_by_type(self, 119 type): 120 """ 121 A method to get the specified cloud integration. 122 123 :param type: A string representing the integration type. 124 125 :return response json 126 """ 127 128 logger.warning("The 'get_by_type' function may be deprecated shortly, please consider switching to 'get'.") 129 130 return self.get(type=type)
A method to get the specified cloud integration.
Parameters
- type: A string representing the integration type.
:return response json
132 def update(self, 133 guid, 134 name=None, 135 type=None, 136 enabled=None, 137 data=None): 138 """ 139 A method to update the specified cloud integration. 140 141 :param guid: A string representing the Lacework integration GUID. 142 :param name: A string representing the integration name. 143 :param type: A string representing the integration type. 144 :param enabled: An integer representing whether the integration is enabled. 145 (0 or 1) 146 :param data: A JSON object matching the schema for the specified type. 147 148 :return response json 149 """ 150 151 logger.info("Updating cloud integration in Lacework...") 152 153 # Build the Integrations request URI 154 api_uri = f"/api/v1/external/integrations/{guid}" 155 156 tmp_data = {} 157 158 if name: 159 tmp_data["NAME"] = name 160 if type: 161 tmp_data["TYPE"] = type 162 if enabled is not None: 163 tmp_data["ENABLED"] = int(bool(enabled)) 164 if data: 165 tmp_data["DATA"] = data 166 167 response = self._session.patch(api_uri, data=tmp_data) 168 169 return response.json()
A method to update the specified cloud integration.
Parameters
- guid: A string representing the Lacework integration GUID.
- name: A string representing the integration name.
- type: A string representing the integration type.
- enabled: An integer representing whether the integration is enabled. (0 or 1)
- data: A JSON object matching the schema for the specified type.
:return response json
171 def update_by_id(self, 172 id, 173 name=None, 174 type=None, 175 enabled=None, 176 data=None): 177 """ 178 A method to update the specified cloud integration. 179 180 :param id: A string representing the Lacework integration GUID. 181 :param name: A string representing the integration name. 182 :param type: A string representing the integration type. 183 :param enabled: An integer representing whether the integration is enabled. (0 or 1) 184 :param data: A JSON object matching the schema for the specified type. 185 186 :return response json 187 """ 188 189 logger.warning("The 'update_by_id' function may be deprecated shortly, please consider switching to 'update'.") 190 191 return self.update(guid=id, name=name, type=type, enabled=enabled, data=data)
A method to update the specified cloud integration.
Parameters
- id: A string representing the Lacework integration GUID.
- name: A string representing the integration name.
- type: A string representing the integration type.
- enabled: An integer representing whether the integration is enabled. (0 or 1)
- data: A JSON object matching the schema for the specified type.
:return response json
193 def update_status(self, 194 id, 195 enabled): 196 """ 197 A method to update the status of a specified cloud integration. 198 199 :param id: A string representing the Lacework integration GUID. 200 :param enabled: A boolean representing whether the integration is enabled. 201 202 :return response json 203 """ 204 205 logger.warning("The 'update_status' function may be deprecated shortly, please consider switching to 'update'.") 206 207 return self.update(guid=id, enabled=enabled)
A method to update the status of a specified cloud integration.
Parameters
- id: A string representing the Lacework integration GUID.
- enabled: A boolean representing whether the integration is enabled.
:return response json
209 def delete(self, 210 guid): 211 """ 212 A method to delete the specified cloud integration. 213 214 :param guid: A string representing the Lacework integration GUID. 215 216 :return response json 217 """ 218 219 logger.info("Deleting cloud integration in Lacework...") 220 221 # Build the Integrations request URI 222 api_uri = f"/api/v1/external/integrations/{guid}" 223 224 response = self._session.delete(api_uri) 225 226 return response.json()
A method to delete the specified cloud integration.
Parameters
- guid: A string representing the Lacework integration GUID.
:return response json
228 def delete_by_id(self, 229 id): 230 """ 231 A method to delete the specified cloud integration. 232 233 :param id: A string representing the Lacework integration GUID. 234 235 :return response json 236 237 **** Needs to be deprecated 238 """ 239 240 logger.warning("The 'delete_by_id' function may be deprecated shortly, please consider switching to 'delete'.") 241 242 return self.delete(guid=id)
A method to delete the specified cloud integration.
Parameters
- id: A string representing the Lacework integration GUID.
:return response json
** Needs to be deprecated
244 def get_schema(self, type): 245 """ 246 A method to get the schema for a specified cloud integration type. 247 248 :param type: A string representing the integration type. 249 250 :return response json 251 """ 252 253 logger.info("Getting cloud integration schema from Lacework...") 254 255 return self.get(schema=type)
A method to get the schema for a specified cloud integration type.
Parameters
- type: A string representing the integration type.
:return response json