From 5eae62884bd8ae3e85becc917b0ed99c2c2ce08e Mon Sep 17 00:00:00 2001 From: theborch Date: Wed, 29 Jan 2025 15:50:07 -0600 Subject: [PATCH 1/4] fix:`cancelled` replaced with `withdrawn` --- src/britive/my_access.py | 1 + src/britive/my_requests.py | 13 ++++++------- src/britive/my_resources.py | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/britive/my_access.py b/src/britive/my_access.py index 28da3a4..7f17786 100644 --- a/src/britive/my_access.py +++ b/src/britive/my_access.py @@ -22,6 +22,7 @@ 'rejected': ProfileApprovalRejected(), 'cancelled': ProfileApprovalWithdrawn(), 'timeout': ProfileApprovalTimedOut(), + 'withdrawn': ProfileApprovalWithdrawn(), } diff --git a/src/britive/my_requests.py b/src/britive/my_requests.py index 5197b6c..69dacce 100644 --- a/src/britive/my_requests.py +++ b/src/britive/my_requests.py @@ -1,9 +1,9 @@ -import sys import time from typing import Any, Callable from .exceptions import ( ProfileApprovalMaxBlockTimeExceeded, + ProfileApprovalWithdrawn, ProfileCheckoutAlreadyApproved, ) from .helpers import HelperMethods @@ -102,15 +102,14 @@ def _request_approval( # status == timeout or approved or rejected or cancelled return status raise ProfileApprovalMaxBlockTimeExceeded - except KeyboardInterrupt: # handle Ctrl+C (^C) - # the first ^C we get we will try to withdraw the request + except KeyboardInterrupt as e: # handle Ctrl+C (^C) try: + # the first ^C we get we will try to withdraw the request time.sleep(1) # give the caller a small window to ^C again - self.withdraw_approval_request(request_id=request_id) - sys.exit() + self._withdraw_approval_request(request_id=request_id) + raise ProfileApprovalWithdrawn from e except KeyboardInterrupt: - sys.exit() - + raise e from None else: return request diff --git a/src/britive/my_resources.py b/src/britive/my_resources.py index 28eec94..31afa94 100644 --- a/src/britive/my_resources.py +++ b/src/britive/my_resources.py @@ -19,6 +19,7 @@ 'rejected': ProfileApprovalRejected(), 'cancelled': ProfileApprovalWithdrawn(), 'timeout': ProfileApprovalTimedOut(), + 'withdrawn': ProfileApprovalWithdrawn(), } From 9de1387a8389470b72b959f392c415e589c2a52c Mon Sep 17 00:00:00 2001 From: theborch Date: Wed, 29 Jan 2025 15:50:38 -0600 Subject: [PATCH 2/4] fix:always supply ticket_* details if provided --- src/britive/my_access.py | 16 +++++++++++----- src/britive/my_resources.py | 8 +++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/britive/my_access.py b/src/britive/my_access.py index 7f17786..51c0853 100644 --- a/src/britive/my_access.py +++ b/src/britive/my_access.py @@ -203,7 +203,13 @@ def _checkout( ) -> dict: params = {'accessType': 'PROGRAMMATIC' if programmatic else 'CONSOLE'} - data = {'justification': justification} + data = {} + if justification: + data['justification'] = justification + if ticket_type: + data['ticketType'] = ticket_type + if ticket_id: + data['ticketId'] = ticket_id transaction = None @@ -578,7 +584,7 @@ def create_filter(self, filter_name: str, filter_properties: str) -> dict: data = {'name': filter_name, 'filter': filter_properties} - return self.britive.post(f"{self.base_url}/{self.whoami()['userId']}/filters", json=data) + return self.britive.post(f'{self.base_url}/{self.whoami()["userId"]}/filters', json=data) def list_filters(self) -> list: """ @@ -587,7 +593,7 @@ def list_filters(self) -> list: :return: List of filters. """ - return self.britive.get(f"{self.base_url}/{self.whoami()['userId']}/filters") + return self.britive.get(f'{self.base_url}/{self.whoami()["userId"]}/filters') def update_filter(self, filter_id: str, filter_name: str, filter_properties: str) -> dict: """ @@ -620,7 +626,7 @@ def update_filter(self, filter_id: str, filter_name: str, filter_properties: str data = {'name': filter_name, 'filter': filter_properties} - return self.britive.put(f"{self.base_url}/{self.whoami()['userId']}/filters/{filter_id}", json=data) + return self.britive.put(f'{self.base_url}/{self.whoami()["userId"]}/filters/{filter_id}', json=data) def delete_filter(self, filter_id: str) -> None: """ @@ -630,4 +636,4 @@ def delete_filter(self, filter_id: str) -> None: :return: None. """ - return self.britive.delete(f"{self.base_url}/{self.whoami()['userId']}/filters/{filter_id}") + return self.britive.delete(f'{self.base_url}/{self.whoami()["userId"]}/filters/{filter_id}') diff --git a/src/britive/my_resources.py b/src/britive/my_resources.py index 31afa94..844b277 100644 --- a/src/britive/my_resources.py +++ b/src/britive/my_resources.py @@ -126,7 +126,13 @@ def _checkout( ticket_type: str = None, wait_time: int = 60, ) -> dict: - data = {'justification': justification} + data = {} + if justification: + data['justification'] = justification + if ticket_type: + data['ticketType'] = ticket_type + if ticket_id: + data['ticketId'] = ticket_id transaction = None From 189da53b23aa2e5df7d6c8eaa0dca1fb58568ff8 Mon Sep 17 00:00:00 2001 From: theborch Date: Thu, 30 Jan 2025 10:18:01 -0600 Subject: [PATCH 3/4] fix:my_resources checkout after approval 404 --- src/britive/my_requests.py | 2 +- src/britive/my_resources.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/britive/my_requests.py b/src/britive/my_requests.py index 69dacce..657c64d 100644 --- a/src/britive/my_requests.py +++ b/src/britive/my_requests.py @@ -107,7 +107,7 @@ def _request_approval( # the first ^C we get we will try to withdraw the request time.sleep(1) # give the caller a small window to ^C again self._withdraw_approval_request(request_id=request_id) - raise ProfileApprovalWithdrawn from e + raise ProfileApprovalWithdrawn('user interrupt.') from e except KeyboardInterrupt: raise e from None else: diff --git a/src/britive/my_resources.py b/src/britive/my_resources.py index 844b277..8c80c77 100644 --- a/src/britive/my_resources.py +++ b/src/britive/my_resources.py @@ -192,7 +192,7 @@ def _checkout( # handle the response based on the value of status if status == 'approved': transaction = self.britive.post( - f'{self.base_url}/{profile_id}/resources/{resource_id}/checkout', json=data + f'{self.base_url}/profiles/{profile_id}/resources/{resource_id}/checkout', json=data ) else: raise approval_exceptions[status](e) from e From 0b9693af65a63edc05702e51e7ebf166501cb511 Mon Sep 17 00:00:00 2001 From: theborch Date: Wed, 29 Jan 2025 15:54:23 -0600 Subject: [PATCH 4/4] v4.0.1 --- CHANGELOG.md | 24 ++++++++++++++++++++++++ src/britive/__init__.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ac7d8..8eb8ad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,29 @@ # Change Log (v2.8.1+) +## v4.0.1 [2025-01-29] + +__What's New:__ + +* None + +__Enhancements:__ + +* None + +__Bug Fixes:__ + +* Withdrawn request now returns `withdrawn` status instead of `cancelled`. +* Always include ITSM `ticket_type` and/or `ticket_id` if they are provided. +* Failing `my_resources.checkout` due to 404 after approval. + +__Dependencies:__ + +* None + +__Other:__ + +* None + ## v4.0.0 [2025-01-17] __What's New:__ diff --git a/src/britive/__init__.py b/src/britive/__init__.py index d6497a8..1a3bef5 100644 --- a/src/britive/__init__.py +++ b/src/britive/__init__.py @@ -1 +1 @@ -__version__ = '4.0.0' +__version__ = '4.0.1'