Skip to content

Commit

Permalink
Add get jwt (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickduran committed Nov 8, 2022
1 parent 5e2a6ba commit 72f7951
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
17 changes: 17 additions & 0 deletions confidant_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,23 @@ def update_credential(
ret['result'] = True
return ret

def get_jwt(self, environment):
ret = {'result': False}
try:
response = self._execute_request(
'get',
'{0}/v1/jwks/token'.format(self.config['url'], id),
params={'environment': environment},
)
data = response.json()
ret.update(data)
except RequestExecutionError:
logging.exception('Error with executing request: ')
return ret

ret['result'] = True
return ret

def _decrypt_blind_credentials(self, blind_credentials):
_blind_credentials = []
for blind_credential in blind_credentials:
Expand Down
15 changes: 15 additions & 0 deletions confidant_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ def _parse_args():
required=True,
)

get_jwt = subparsers.add_parser(
'get_jwt',
help='Generate a JWT for the authenticated user',
)
get_jwt.add_argument(
'--environment',
type=str,
dest='environment',
required=True,
)
return parser.parse_args()


Expand Down Expand Up @@ -777,6 +787,11 @@ def main():
)
except Exception:
logging.exception('An unexpected general error occurred.')
elif args.subcommand == 'get_jwt':
try:
ret = client.get_jwt(args.environment)
except Exception:
logging.exception('An unexpected general error occurred.')

print(json.dumps(ret, sort_keys=True, indent=4, separators=(',', ': ')))
if not ret['result']:
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.4.0",
version="2.5.0",
packages=find_packages(exclude=["test*"]),
install_requires=[
# Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK)
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/confidant_client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,3 +862,28 @@ def test_update_service(self):
'blind_credentials': ['x', 'y', 'z']
}
)

def test_get_jwt(self):
client = confidant_client.ConfidantClient(
'http://localhost',
'alias/authnz-testing',
{'from': 'confidant-unittest',
'to': 'test',
'user_type': 'service'},
)
token_mock = MagicMock()
client._get_token = token_mock
client.request_session.request = mock_200

self.assertEqual(
client.get_jwt('development'),
{'result': True}
)
client.request_session.request.assert_called_with(
'GET',
'http://localhost/v1/jwks/token',
auth=('2/service/confidant-unittest', token_mock()),
allow_redirects=False,
timeout=5,
params={'environment': 'development'},
)

0 comments on commit 72f7951

Please sign in to comment.