diff --git a/conjur_api/client.py b/conjur_api/client.py index 9c9b67d..6017a0a 100644 --- a/conjur_api/client.py +++ b/conjur_api/client.py @@ -200,23 +200,23 @@ async def set(self, variable_id: str, value: str) -> str: """ await self._api.set_variable(variable_id, value) - async def load_policy_file(self, policy_name: str, policy_file: str) -> dict: + async def load_policy_file(self, policy_name: str, policy_file: str, dry_run: False) -> dict: """ Applies a file-based policy to the Conjur instance """ - return await self._api.load_policy_file(policy_name, policy_file) + return await self._api.load_policy_file(policy_name, policy_file, dry_run) - async def replace_policy_file(self, policy_name: str, policy_file: str) -> dict: + async def replace_policy_file(self, policy_name: str, policy_file: str, dry_run: False) -> dict: """ Replaces a file-based policy defined in the Conjur instance """ - return await self._api.replace_policy_file(policy_name, policy_file) + return await self._api.replace_policy_file(policy_name, policy_file, dry_run) - async def update_policy_file(self, policy_name: str, policy_file: str) -> dict: + async def update_policy_file(self, policy_name: str, policy_file: str, dry_run: False) -> dict: """ Replaces a file-based policy defined in the Conjur instance """ - return await self._api.update_policy_file(policy_name, policy_file) + return await self._api.update_policy_file(policy_name, policy_file, dry_run) async def rotate_other_api_key(self, resource: Resource) -> str: """ diff --git a/conjur_api/http/api.py b/conjur_api/http/api.py index 1b1fa41..0228cf3 100644 --- a/conjur_api/http/api.py +++ b/conjur_api/http/api.py @@ -487,7 +487,7 @@ async def set_variable(self, variable_id: str, value: str) -> str: async def _load_policy_file( self, policy_id: str, policy_file: str, - http_verb: HttpVerb) -> dict: + http_verb: HttpVerb, dry_run: bool) -> dict: """ This method is used to load, replace or update a file-based policy into the desired name. @@ -504,32 +504,37 @@ async def _load_policy_file( if api_token is None: raise MissingApiTokenException() + query = {} + if dry_run: + query = { 'dryRun': 'true' } + response = await invoke_endpoint(http_verb, ConjurEndpoint.POLICIES, params, policy_data, api_token=api_token, ssl_verification_metadata=self.ssl_verification_data, + query=query, proxy_params=self._connection_info.proxy_params) return response.json - async def load_policy_file(self, policy_id: str, policy_file: str) -> dict: + async def load_policy_file(self, policy_id: str, policy_file: str, dry_run: bool) -> dict: """ This method is used to load a file-based policy into the desired name. """ - return await self._load_policy_file(policy_id, policy_file, HttpVerb.POST) + return await self._load_policy_file(policy_id, policy_file, HttpVerb.POST, dry_run) - async def replace_policy_file(self, policy_id: str, policy_file: str) -> dict: + async def replace_policy_file(self, policy_id: str, policy_file: str, dry_run: bool) -> dict: """ This method is used to replace a file-based policy into the desired policy ID. """ - return await self._load_policy_file(policy_id, policy_file, HttpVerb.PUT) + return await self._load_policy_file(policy_id, policy_file, HttpVerb.PUT, dry_run) - async def update_policy_file(self, policy_id: str, policy_file: str) -> dict: + async def update_policy_file(self, policy_id: str, policy_file: str, dry_run: bool) -> dict: """ This method is used to update a file-based policy into the desired policy ID. """ - return await self._load_policy_file(policy_id, policy_file, HttpVerb.PATCH) + return await self._load_policy_file(policy_id, policy_file, HttpVerb.PATCH, dry_run) async def rotate_other_api_key(self, resource: Resource) -> str: """