Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
#19 Search entitlement by access key
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries committed Jul 21, 2019
1 parent b76d095 commit 24dc4f9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
32 changes: 32 additions & 0 deletions bintray/bintray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3696,3 +3696,35 @@ def update_entitlement(self, subject, entitlement_id, repo=None, package=None, v
response = self._requester.patch(url, json=json_data)
self._logger.info("Update successfully")
return response

def search_entitlement_by_access_key(self, access_key=None, scope=None, product=None,
deep=False):
""" Search for entitlements for a specific access key in the specified scope.
The minimal scope is a subject.
You can optionally add a sub-scope of product, repo, package and version.
If deep equals true (default is false), will return all entitlements under the given
scope, for example, if scope is repository, existing package and version entitlements
under the given repository will be returned.
Security: Authenticated user with 'admin' permission.
:param access_key: specific access key to be searched
:param scope: specified scope to be used in the search
:param product: products name associated to the access key
:param deep: return all entitlements under the given scope
:return: entitlement found
"""
url = "{}/search/entitlements".format(Bintray.BINTRAY_URL)
params = {"deep": bool_to_number(deep)}
if access_key:
params["access_key"] = access_key
if scope:
params["scope"] = scope
if product:
params["product"] = product

response = self._requester.get(url, params=params)
self._logger.info("Get successfully")
return response
11 changes: 11 additions & 0 deletions tests/test_entitlements.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ def test_update_entitlement():
error_message = str(error)

assert "Could not PATCH (403): forbidden" == error_message


def test_search_entitlement_by_access_key():
bintray = Bintray()
error_message = ""
try:
bintray.search_entitlement_by_access_key("uilianries", "foobar", "generic/statistics/test")
except Exception as error:
error_message = str(error)

assert "Could not GET (403): Forbidden" == error_message

0 comments on commit 24dc4f9

Please sign in to comment.