laceworksdk.api.v1.token
Lacework Agent Access Token API wrapper.
1# -*- coding: utf-8 -*- 2""" 3Lacework Agent Access Token API wrapper. 4""" 5 6import logging 7 8logger = logging.getLogger(__name__) 9 10 11class TokenAPI: 12 """ 13 Lacework Agent Access Token API. 14 """ 15 16 def __init__(self, session): 17 """ 18 Initializes the TokenAPI object. 19 20 :param session: An instance of the HttpSession class 21 22 :return TokenAPI object. 23 """ 24 25 super().__init__() 26 27 self._session = session 28 29 def create(self, 30 alias=None, 31 enabled=True, 32 description=None): 33 """ 34 A method to create a new agent access token. 35 36 :param alias: A string representing the alias for the agent access token. 37 :param enabled: A boolean representing whether the agent access token should be enabled. 38 :param description: A string representing a description for the agent access token. 39 40 :return response json 41 """ 42 43 logger.info("Creating agent access token in Lacework...") 44 45 data = {} 46 47 if alias: 48 data["TOKEN_ALIAS"] = alias 49 if enabled is not None: 50 data["TOKEN_ENABLED"] = int(bool(enabled)) 51 if description: 52 data["PROPS"]["DESCRIPTION"]: description 53 54 # Build the Token API URI 55 api_uri = "/api/v1/external/tokens" 56 57 response = self._session.post(api_uri, data=data) 58 59 return response.json() 60 61 def get(self, 62 access_token=None): 63 """ 64 A method to get a list of enabled agent access tokens. 65 66 :return response json 67 """ 68 69 logger.info("Getting agent access tokens from Lacework...") 70 71 # Build the Token API URI 72 api_uri = "/api/v1/external/tokens" 73 74 if access_token: 75 api_uri += f"/{access_token}" 76 77 response = self._session.get(api_uri) 78 79 return response.json() 80 81 def get_enabled(self): 82 """ 83 A method to get a list of enabled agent access tokens. 84 85 :return response json 86 """ 87 88 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 89 90 return self.get() 91 92 def get_token(self, 93 access_token): 94 """ 95 A method to get details about an agent access token. 96 97 :param access_token: A string representing the agent access token to get. 98 99 :return response json 100 """ 101 102 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 103 104 return self.get(access_token=access_token) 105 106 def update(self, 107 access_token, 108 alias=None, 109 enabled=True, 110 description=None): 111 """ 112 A method to update the details about an agent access token. 113 114 :param access_token: A string representing the agent access token to update. 115 :param alias: A string representing the alias for the agent access token. 116 :param enabled: A boolean representing whether the agent access token should be enabled. 117 :param description: A string representing a description for the agent access token. 118 119 :return response json 120 """ 121 122 logger.info("Updating agent access token details in Lacework...") 123 124 data = {} 125 126 if alias: 127 data["TOKEN_ALIAS"] = alias 128 if enabled is not None: 129 data["TOKEN_ENABLED"] = int(bool(enabled)) 130 if description: 131 data["PROPS"]["DESCRIPTION"]: description 132 133 # Build the Token API URI 134 api_uri = f"/api/v1/external/tokens/{access_token}" 135 136 response = self._session.put(api_uri, data=data) 137 138 return response.json() 139 140 def update_token(self, 141 access_token, 142 token_alias=None, 143 token_enabled=False, 144 token_description=None): 145 """ 146 A method to update the details about an agent access token. 147 148 :param access_token: A string representing the agent access token to update. 149 :param token_alias: A string representing the alias for the agent access token. 150 :param token_enalbed: A boolean representing whether the agent access token should be enabled. 151 :param token_description: A string representing a description for the agent access token. 152 153 :return response json 154 """ 155 156 logger.warning("The 'update_token' function may be deprecated shortly, please consider switching to 'update'.") 157 158 return self.update(access_token=access_token, 159 alias=token_alias, 160 enabled=token_enabled, 161 description=token_description)
class
TokenAPI:
12class TokenAPI: 13 """ 14 Lacework Agent Access Token API. 15 """ 16 17 def __init__(self, session): 18 """ 19 Initializes the TokenAPI object. 20 21 :param session: An instance of the HttpSession class 22 23 :return TokenAPI object. 24 """ 25 26 super().__init__() 27 28 self._session = session 29 30 def create(self, 31 alias=None, 32 enabled=True, 33 description=None): 34 """ 35 A method to create a new agent access token. 36 37 :param alias: A string representing the alias for the agent access token. 38 :param enabled: A boolean representing whether the agent access token should be enabled. 39 :param description: A string representing a description for the agent access token. 40 41 :return response json 42 """ 43 44 logger.info("Creating agent access token in Lacework...") 45 46 data = {} 47 48 if alias: 49 data["TOKEN_ALIAS"] = alias 50 if enabled is not None: 51 data["TOKEN_ENABLED"] = int(bool(enabled)) 52 if description: 53 data["PROPS"]["DESCRIPTION"]: description 54 55 # Build the Token API URI 56 api_uri = "/api/v1/external/tokens" 57 58 response = self._session.post(api_uri, data=data) 59 60 return response.json() 61 62 def get(self, 63 access_token=None): 64 """ 65 A method to get a list of enabled agent access tokens. 66 67 :return response json 68 """ 69 70 logger.info("Getting agent access tokens from Lacework...") 71 72 # Build the Token API URI 73 api_uri = "/api/v1/external/tokens" 74 75 if access_token: 76 api_uri += f"/{access_token}" 77 78 response = self._session.get(api_uri) 79 80 return response.json() 81 82 def get_enabled(self): 83 """ 84 A method to get a list of enabled agent access tokens. 85 86 :return response json 87 """ 88 89 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 90 91 return self.get() 92 93 def get_token(self, 94 access_token): 95 """ 96 A method to get details about an agent access token. 97 98 :param access_token: A string representing the agent access token to get. 99 100 :return response json 101 """ 102 103 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 104 105 return self.get(access_token=access_token) 106 107 def update(self, 108 access_token, 109 alias=None, 110 enabled=True, 111 description=None): 112 """ 113 A method to update the details about an agent access token. 114 115 :param access_token: A string representing the agent access token to update. 116 :param alias: A string representing the alias for the agent access token. 117 :param enabled: A boolean representing whether the agent access token should be enabled. 118 :param description: A string representing a description for the agent access token. 119 120 :return response json 121 """ 122 123 logger.info("Updating agent access token details in Lacework...") 124 125 data = {} 126 127 if alias: 128 data["TOKEN_ALIAS"] = alias 129 if enabled is not None: 130 data["TOKEN_ENABLED"] = int(bool(enabled)) 131 if description: 132 data["PROPS"]["DESCRIPTION"]: description 133 134 # Build the Token API URI 135 api_uri = f"/api/v1/external/tokens/{access_token}" 136 137 response = self._session.put(api_uri, data=data) 138 139 return response.json() 140 141 def update_token(self, 142 access_token, 143 token_alias=None, 144 token_enabled=False, 145 token_description=None): 146 """ 147 A method to update the details about an agent access token. 148 149 :param access_token: A string representing the agent access token to update. 150 :param token_alias: A string representing the alias for the agent access token. 151 :param token_enalbed: A boolean representing whether the agent access token should be enabled. 152 :param token_description: A string representing a description for the agent access token. 153 154 :return response json 155 """ 156 157 logger.warning("The 'update_token' function may be deprecated shortly, please consider switching to 'update'.") 158 159 return self.update(access_token=access_token, 160 alias=token_alias, 161 enabled=token_enabled, 162 description=token_description)
Lacework Agent Access Token API.
TokenAPI(session)
17 def __init__(self, session): 18 """ 19 Initializes the TokenAPI object. 20 21 :param session: An instance of the HttpSession class 22 23 :return TokenAPI object. 24 """ 25 26 super().__init__() 27 28 self._session = session
Initializes the TokenAPI object.
Parameters
- session: An instance of the HttpSession class
:return TokenAPI object.
def
create(self, alias=None, enabled=True, description=None):
30 def create(self, 31 alias=None, 32 enabled=True, 33 description=None): 34 """ 35 A method to create a new agent access token. 36 37 :param alias: A string representing the alias for the agent access token. 38 :param enabled: A boolean representing whether the agent access token should be enabled. 39 :param description: A string representing a description for the agent access token. 40 41 :return response json 42 """ 43 44 logger.info("Creating agent access token in Lacework...") 45 46 data = {} 47 48 if alias: 49 data["TOKEN_ALIAS"] = alias 50 if enabled is not None: 51 data["TOKEN_ENABLED"] = int(bool(enabled)) 52 if description: 53 data["PROPS"]["DESCRIPTION"]: description 54 55 # Build the Token API URI 56 api_uri = "/api/v1/external/tokens" 57 58 response = self._session.post(api_uri, data=data) 59 60 return response.json()
A method to create a new agent access token.
Parameters
- alias: A string representing the alias for the agent access token.
- enabled: A boolean representing whether the agent access token should be enabled.
- description: A string representing a description for the agent access token.
:return response json
def
get(self, access_token=None):
62 def get(self, 63 access_token=None): 64 """ 65 A method to get a list of enabled agent access tokens. 66 67 :return response json 68 """ 69 70 logger.info("Getting agent access tokens from Lacework...") 71 72 # Build the Token API URI 73 api_uri = "/api/v1/external/tokens" 74 75 if access_token: 76 api_uri += f"/{access_token}" 77 78 response = self._session.get(api_uri) 79 80 return response.json()
A method to get a list of enabled agent access tokens.
:return response json
def
get_enabled(self):
82 def get_enabled(self): 83 """ 84 A method to get a list of enabled agent access tokens. 85 86 :return response json 87 """ 88 89 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 90 91 return self.get()
A method to get a list of enabled agent access tokens.
:return response json
def
get_token(self, access_token):
93 def get_token(self, 94 access_token): 95 """ 96 A method to get details about an agent access token. 97 98 :param access_token: A string representing the agent access token to get. 99 100 :return response json 101 """ 102 103 logger.warning("The 'get_enabled' function may be deprecated shortly, please consider switching to 'get'.") 104 105 return self.get(access_token=access_token)
A method to get details about an agent access token.
Parameters
- access_token: A string representing the agent access token to get.
:return response json
def
update(self, access_token, alias=None, enabled=True, description=None):
107 def update(self, 108 access_token, 109 alias=None, 110 enabled=True, 111 description=None): 112 """ 113 A method to update the details about an agent access token. 114 115 :param access_token: A string representing the agent access token to update. 116 :param alias: A string representing the alias for the agent access token. 117 :param enabled: A boolean representing whether the agent access token should be enabled. 118 :param description: A string representing a description for the agent access token. 119 120 :return response json 121 """ 122 123 logger.info("Updating agent access token details in Lacework...") 124 125 data = {} 126 127 if alias: 128 data["TOKEN_ALIAS"] = alias 129 if enabled is not None: 130 data["TOKEN_ENABLED"] = int(bool(enabled)) 131 if description: 132 data["PROPS"]["DESCRIPTION"]: description 133 134 # Build the Token API URI 135 api_uri = f"/api/v1/external/tokens/{access_token}" 136 137 response = self._session.put(api_uri, data=data) 138 139 return response.json()
A method to update the details about an agent access token.
Parameters
- access_token: A string representing the agent access token to update.
- alias: A string representing the alias for the agent access token.
- enabled: A boolean representing whether the agent access token should be enabled.
- description: A string representing a description for the agent access token.
:return response json
def
update_token( self, access_token, token_alias=None, token_enabled=False, token_description=None):
141 def update_token(self, 142 access_token, 143 token_alias=None, 144 token_enabled=False, 145 token_description=None): 146 """ 147 A method to update the details about an agent access token. 148 149 :param access_token: A string representing the agent access token to update. 150 :param token_alias: A string representing the alias for the agent access token. 151 :param token_enalbed: A boolean representing whether the agent access token should be enabled. 152 :param token_description: A string representing a description for the agent access token. 153 154 :return response json 155 """ 156 157 logger.warning("The 'update_token' function may be deprecated shortly, please consider switching to 'update'.") 158 159 return self.update(access_token=access_token, 160 alias=token_alias, 161 enabled=token_enabled, 162 description=token_description)
A method to update the details about an agent access token.
Parameters
- access_token: A string representing the agent access token to update.
- token_alias: A string representing the alias for the agent access token.
- token_enalbed: A boolean representing whether the agent access token should be enabled.
- token_description: A string representing a description for the agent access token.
:return response json