Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Change Log (v2.8.1+)

## v4.1.0 [2025-02-28]

__What's New:__

* `my_resources.list` akin to `my_access.list` allowing the use of `size`.

__Enhancements:__

* None

__Bug Fixes:__

* `managed_permissions` added to the `application_management` init.
* `Britive.parse_tenant` still referenced in `aws` federation provider.

__Dependencies:__

* None

__Other:__

* None

## v4.0.1 [2025-01-29]

__What's New:__
Expand Down
2 changes: 1 addition & 1 deletion src/britive/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '4.0.1'
__version__ = '4.1.0'
2 changes: 2 additions & 0 deletions src/britive/application_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .environment_groups import EnvironmentGroups
from .environments import Environments
from .groups import Groups
from .managed_permissions import ManagedPermissions
from .permissions import Permissions
from .profiles import Profiles
from .scans import Scans
Expand All @@ -17,6 +18,7 @@ def __init__(self, britive) -> None:
self.environment_groups = EnvironmentGroups(britive)
self.environments = Environments(britive)
self.groups = Groups(britive)
self.managed_permissions = ManagedPermissions(britive)
self.permissions = Permissions(britive)
self.profiles = Profiles(britive)
self.scans = Scans(britive)
4 changes: 4 additions & 0 deletions src/britive/britive.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def __request(self, method, url, params=None, data=None, json=None) -> dict:

# load the result as a dict
result = handle_response(response)

if url.endswith('my-resources') and method == 'get' and params.get('page') == 0 and params.get('size'):
return result

_pagination_type = _pagination_type or pagination_type(response.headers, result)

# check on the pagination and iterate if required - we only need to check on this after the first
Expand Down
4 changes: 2 additions & 2 deletions src/britive/federation_providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class AwsFederationProvider(FederationProvider):
def __init__(self, profile: str, tenant: str, duration: int = 900) -> None:
from britive.britive import Britive # doing import here to avoid circular dependency
from britive.helpers.utils import parse_tenant # doing import here to avoid circular dependency

self.profile = profile
self.duration = duration
Expand All @@ -21,7 +21,7 @@ def __init__(self, profile: str, tenant: str, duration: int = 900) -> None:
raise TenantMissingError(
'Error: the aws federation provider requires the britive tenant as part of the signing algorithm'
)
self.tenant = Britive.parse_tenant(temp_tenant).split(':')[0] # remove the port if it exists
self.tenant = parse_tenant(temp_tenant).split(':')[0] # remove the port if it exists
super().__init__()

@staticmethod
Expand Down
5 changes: 2 additions & 3 deletions src/britive/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def check_response_for_error(status_code, content) -> None:
if status_code in allowed_exceptions:
if isinstance(content, dict):
error_code = content.get('errorCode', 'E0000')
message = f"{status_code} - {error_code} - {content.get('message', 'no message available')}"
message = f'{status_code} - {error_code} - {content.get("message", "no message available")}'
if content.get('details'):
message += f" - {content.get('details')}"
message += f' - {content.get("details")}'
else:
message = f'{status_code} - {content}'
raise unauthorized_code_map.get(
Expand All @@ -39,7 +39,6 @@ def check_response_for_error(status_code, content) -> None:
def handle_response(response):
try:
return response.json()
# Can likely drop to just the `requests` exception, with `>=2.32.0`, but leaving both for now.
except requests.exceptions.JSONDecodeError:
return response.content.decode('utf-8')

Expand Down
26 changes: 25 additions & 1 deletion src/britive/my_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,36 @@ def __init__(self, britive) -> None:
self.withdraw_approval_request = __my_requests.withdraw_approval_request
self.withdraw_approval_request_by_name = __my_requests.withdraw_approval_request_by_name

# Let's just mimic my_access.list functionality for now.
def list(self, filter_text: str = None, list_type: str = None, search_text: str = None, size: int = None) -> list:
"""
List the resource details for the current user.

:param filter_text: filter resource by key, e.g. `filter_text='key eq env'`
:param list_type: filter resources by type, e.g. `list_type='frequently-used'`
:param search_text: filter resources by search text.
:param size: reduce the size of the response to the specified limit.
:return: List of profiles.
"""

params = {}
if filter_text:
params['filter'] = filter_text
if list_type:
params['type'] = list_type
if search_text:
params['searchText'] = search_text
if size:
params.update(page=0, size=size)

return self.britive.get(self.base_url, params=params)

def list_profiles(self, filter_text: str = None, list_type: str = None, search_text: str = None) -> list:
"""
List the profiles for which the user has access.

:param filter_text: filter resource by key, e.g. `filter_text='key eq env'`
:param list_type: filter resources by type, e.g. `list_type='frequentlyUsed'`
:param list_type: filter resources by type, e.g. `list_type='frequently-used'`
:param search_text: filter resources by search text.
:return: List of profiles.
"""
Expand Down