|
64 | 64 | ZipChallengePhaseSplitSerializer,)
|
65 | 65 | from .utils import (get_file_content,
|
66 | 66 | get_or_create_ecr_repository,
|
67 |
| - convert_to_aws_ecr_compatible_format,) |
| 67 | + convert_to_aws_ecr_compatible_format, |
| 68 | + create_federated_user,) |
68 | 69 |
|
69 | 70 | logger = logging.getLogger(__name__)
|
70 | 71 |
|
@@ -1376,3 +1377,37 @@ def get_broker_url_by_challenge_pk(request, challenge_pk):
|
1376 | 1377 |
|
1377 | 1378 | response_data = [challenge.queue]
|
1378 | 1379 | return Response(response_data, status=status.HTTP_200_OK)
|
| 1380 | + |
| 1381 | + |
| 1382 | +@api_view(['GET']) |
| 1383 | +@throttle_classes([UserRateThrottle]) |
| 1384 | +@permission_classes((permissions.IsAuthenticated, HasVerifiedEmail)) |
| 1385 | +@authentication_classes((ExpiringTokenAuthentication,)) |
| 1386 | +def get_aws_credentials_for_participant_team(request, phase_pk): |
| 1387 | + """ |
| 1388 | + Returns: |
| 1389 | + Dictionary containing AWS credentials for the participant team for a particular challenge |
| 1390 | + """ |
| 1391 | + |
| 1392 | + challenge_phase = get_challenge_phase_model(phase_pk) |
| 1393 | + |
| 1394 | + challenge = challenge_phase.challenge |
| 1395 | + participant_team_pk = get_participant_team_id_of_user_for_a_challenge( |
| 1396 | + request.user, challenge.pk) |
| 1397 | + |
| 1398 | + if not challenge.is_docker_based: |
| 1399 | + response_data = {'error': 'Sorry, this is not a docker based challenge.'} |
| 1400 | + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) |
| 1401 | + |
| 1402 | + if participant_team_pk is None: |
| 1403 | + response_data = {'error': 'You have not participated in this challenge.'} |
| 1404 | + return Response(response_data, status=status.HTTP_400_BAD_REQUEST) |
| 1405 | + |
| 1406 | + participant_team = ParticipantTeam.objects.get(id=participant_team_pk) |
| 1407 | + federated_user = create_federated_user(participant_team.team_name, participant_team.get_docker_repository_name()) |
| 1408 | + data = { |
| 1409 | + 'federated_user': federated_user, |
| 1410 | + 'docker_repository_uri': participant_team.docker_repository_uri |
| 1411 | + } |
| 1412 | + response_data = {'success': data} |
| 1413 | + return Response(response_data, status=status.HTTP_200_OK) |
0 commit comments