Skip to content

Commit 68b72d1

Browse files
authored
Merge pull request #140 from britive/fix/itsm-details
v4.0.1
2 parents 9f0331e + 0b9693a commit 68b72d1

5 files changed

Lines changed: 52 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Change Log (v2.8.1+)
22

3+
## v4.0.1 [2025-01-29]
4+
5+
__What's New:__
6+
7+
* None
8+
9+
__Enhancements:__
10+
11+
* None
12+
13+
__Bug Fixes:__
14+
15+
* Withdrawn request now returns `withdrawn` status instead of `cancelled`.
16+
* Always include ITSM `ticket_type` and/or `ticket_id` if they are provided.
17+
* Failing `my_resources.checkout` due to 404 after approval.
18+
19+
__Dependencies:__
20+
21+
* None
22+
23+
__Other:__
24+
25+
* None
26+
327
## v4.0.0 [2025-01-17]
428

529
__What's New:__

src/britive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '4.0.0'
1+
__version__ = '4.0.1'

src/britive/my_access.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'rejected': ProfileApprovalRejected(),
2323
'cancelled': ProfileApprovalWithdrawn(),
2424
'timeout': ProfileApprovalTimedOut(),
25+
'withdrawn': ProfileApprovalWithdrawn(),
2526
}
2627

2728

@@ -202,7 +203,13 @@ def _checkout(
202203
) -> dict:
203204
params = {'accessType': 'PROGRAMMATIC' if programmatic else 'CONSOLE'}
204205

205-
data = {'justification': justification}
206+
data = {}
207+
if justification:
208+
data['justification'] = justification
209+
if ticket_type:
210+
data['ticketType'] = ticket_type
211+
if ticket_id:
212+
data['ticketId'] = ticket_id
206213

207214
transaction = None
208215

@@ -577,7 +584,7 @@ def create_filter(self, filter_name: str, filter_properties: str) -> dict:
577584

578585
data = {'name': filter_name, 'filter': filter_properties}
579586

580-
return self.britive.post(f"{self.base_url}/{self.whoami()['userId']}/filters", json=data)
587+
return self.britive.post(f'{self.base_url}/{self.whoami()["userId"]}/filters', json=data)
581588

582589
def list_filters(self) -> list:
583590
"""
@@ -586,7 +593,7 @@ def list_filters(self) -> list:
586593
:return: List of filters.
587594
"""
588595

589-
return self.britive.get(f"{self.base_url}/{self.whoami()['userId']}/filters")
596+
return self.britive.get(f'{self.base_url}/{self.whoami()["userId"]}/filters')
590597

591598
def update_filter(self, filter_id: str, filter_name: str, filter_properties: str) -> dict:
592599
"""
@@ -619,7 +626,7 @@ def update_filter(self, filter_id: str, filter_name: str, filter_properties: str
619626

620627
data = {'name': filter_name, 'filter': filter_properties}
621628

622-
return self.britive.put(f"{self.base_url}/{self.whoami()['userId']}/filters/{filter_id}", json=data)
629+
return self.britive.put(f'{self.base_url}/{self.whoami()["userId"]}/filters/{filter_id}', json=data)
623630

624631
def delete_filter(self, filter_id: str) -> None:
625632
"""
@@ -629,4 +636,4 @@ def delete_filter(self, filter_id: str) -> None:
629636
:return: None.
630637
"""
631638

632-
return self.britive.delete(f"{self.base_url}/{self.whoami()['userId']}/filters/{filter_id}")
639+
return self.britive.delete(f'{self.base_url}/{self.whoami()["userId"]}/filters/{filter_id}')

src/britive/my_requests.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import sys
21
import time
32
from typing import Any, Callable
43

54
from .exceptions import (
65
ProfileApprovalMaxBlockTimeExceeded,
6+
ProfileApprovalWithdrawn,
77
ProfileCheckoutAlreadyApproved,
88
)
99
from .helpers import HelperMethods
@@ -102,15 +102,14 @@ def _request_approval(
102102
# status == timeout or approved or rejected or cancelled
103103
return status
104104
raise ProfileApprovalMaxBlockTimeExceeded
105-
except KeyboardInterrupt: # handle Ctrl+C (^C)
106-
# the first ^C we get we will try to withdraw the request
105+
except KeyboardInterrupt as e: # handle Ctrl+C (^C)
107106
try:
107+
# the first ^C we get we will try to withdraw the request
108108
time.sleep(1) # give the caller a small window to ^C again
109-
self.withdraw_approval_request(request_id=request_id)
110-
sys.exit()
109+
self._withdraw_approval_request(request_id=request_id)
110+
raise ProfileApprovalWithdrawn('user interrupt.') from e
111111
except KeyboardInterrupt:
112-
sys.exit()
113-
112+
raise e from None
114113
else:
115114
return request
116115

src/britive/my_resources.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'rejected': ProfileApprovalRejected(),
2020
'cancelled': ProfileApprovalWithdrawn(),
2121
'timeout': ProfileApprovalTimedOut(),
22+
'withdrawn': ProfileApprovalWithdrawn(),
2223
}
2324

2425

@@ -125,7 +126,13 @@ def _checkout(
125126
ticket_type: str = None,
126127
wait_time: int = 60,
127128
) -> dict:
128-
data = {'justification': justification}
129+
data = {}
130+
if justification:
131+
data['justification'] = justification
132+
if ticket_type:
133+
data['ticketType'] = ticket_type
134+
if ticket_id:
135+
data['ticketId'] = ticket_id
129136

130137
transaction = None
131138

@@ -185,7 +192,7 @@ def _checkout(
185192
# handle the response based on the value of status
186193
if status == 'approved':
187194
transaction = self.britive.post(
188-
f'{self.base_url}/{profile_id}/resources/{resource_id}/checkout', json=data
195+
f'{self.base_url}/profiles/{profile_id}/resources/{resource_id}/checkout', json=data
189196
)
190197
else:
191198
raise approval_exceptions[status](e) from e

0 commit comments

Comments
 (0)