Skip to content

Commit

Permalink
Adding get services function and bump to 2.3.1 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickduran authored Sep 2, 2022
1 parent 8c56735 commit 47cdbf8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install apt dependencies
run: sudo apt-get install -y python3-dev openssl libssl-dev gcc pkg-config libffi-dev libxml2-dev libxmlsec1-dev
run: sudo apt-get update && sudo apt-get install -y python3-dev openssl libssl-dev gcc pkg-config libffi-dev libxml2-dev libxmlsec1-dev
- name: Install dependencies
run: pip install -r requirements.txt && pip install -e .
- name: Run python tests
Expand Down
38 changes: 38 additions & 0 deletions confidant_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,44 @@ def get_credential(self, id):
ret['result'] = True
return ret

def get_credential_services(self, id):
"""
Get the list of services that currently use this credential
and whether they are enabled or not
"""
# Return a dict, always with an attribute that specifies whether or not
# the function was able to successfully get a result.
ret = {'result': False}

# Make a request to confidant with the provided url, to fetch the
# services using the credential providing the credential id and
# base64 encoded token for authentication.
try:
response = self._execute_request(
'get',
'{0}/v1/credentials/{1}/services'.format(self.config['url'],
id),
expected_return_codes=[200, 404]
)
except RequestExecutionError:
logging.exception('Error with executing request')
return ret

if response.status_code == 404:
logging.debug('Credential not found in confidant.')
ret['result'] = False
return ret

try:
data = response.json()
except ValueError:
logging.error('Received badly formatted json data from confidant.')
return ret

ret['data'] = data
ret['result'] = True
return ret

def update_credential(
self,
id,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name="confidant-client",
version="2.3.0",
version="2.3.1",
packages=find_packages(exclude=["test*"]),
install_requires=[
# Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK)
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/confidant_client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,48 @@ def test_get_credential_not_found(self):
{'result': False}
)

@patch(
'confidant_client.services.get_boto_client',
MagicMock()
)
def test_get_credential_services(self):
client = confidant_client.ConfidantClient(
'http://localhost/',
'alias/authnz-testing',
{'from': 'confidant-unittest',
'to': 'test',
'user_type': 'service'},
)
client._get_token = MagicMock()
client.request_session.request = mock_200
self.assertEqual(
client.get_credential_services(
'confidant-development'
),
{'result': True, 'data': {}}
)

@patch(
'confidant_client.services.get_boto_client',
MagicMock()
)
def test_get_credential_services_not_found(self):
client = confidant_client.ConfidantClient(
'http://localhost/',
'alias/authnz-testing',
{'from': 'confidant-unittest',
'to': 'test',
'user_type': 'service'},
)
client._get_token = MagicMock()
client.request_session.request = mock_404
self.assertEqual(
client.get_credential_services(
'confidant-development',
),
{'result': False}
)

@patch(
'confidant_client.services.get_boto_client',
MagicMock()
Expand Down

0 comments on commit 47cdbf8

Please sign in to comment.