Commit 89fbcb36 authored by Ryo Yamashita's avatar Ryo Yamashita Committed by Yas Naoi
Browse files

Issue #3301955 by Ryo Yamashita, yas: Add the function to import AWS Cloud key pair in the SPA

parent 4eb4240f
Loading
Loading
Loading
Loading
+15 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/aws_cloud/key_pair.ts: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -44,6 +44,21 @@ const AWS_CLOUD_KEY_PAIR_TEMPLATE: EntityFormTemplate[] = [
      }
    ],
  },
  {
    cloudServiceProvider: 'aws_cloud',
    entityName: 'key_pair',
    actionType: 'import',
    entityRecords: [
      {
        type: 'panel',
        panelName: 'Key pair',
        keyValueRecords: [
          { type: 'file', labelName: 'Public Key', name: 'key_pair_public_key' },
          { type: 'default', labelName: 'Key pair name', name: 'key_pair_name', defaultValue: '', required: true },
        ]
      }
    ]
  },
]

export default AWS_CLOUD_KEY_PAIR_TEMPLATE;
+15 −0
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.routing.yml: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1100,6 +1100,21 @@ entity.aws_cloud_key_pair.edit:
  options:
      perm: 'edit any aws cloud key pair+edit own aws cloud key pair'

entity.aws_cloud_key_pair.import:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_key_pair/import'
  defaults:
    _controller: '\Drupal\aws_cloud\Controller\Ec2\ApiController::operateEntity'
    entity_type_id: aws_cloud_key_pair
    entity_id: ''
    command: import
  methods: [POST]
  requirements:
    # Use custom access that will check for cloud_context and the desired permission.
    # Desired permission is passed as an option in the "perm" variable
    _custom_access: '\Drupal\cloud\Controller\CloudConfigController::access'
  options:
      perm: 'add aws cloud key pair'

entity.aws_cloud_security_group.create:
  path: '/cloud_dashboard/aws_cloud/{cloud_context}/aws_cloud_security_group/{entity_id}/create'
  defaults:
+15 −0
Changes for modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -904,6 +904,21 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
          $method_name = 'editKeyPair';
          break;

        case 'import_aws_cloud_key_pair':
          /** @var \Drupal\aws_cloud\Entity\Ec2\KeyPairInterface $entity */
          $entity->set('key_pair_name', $request->get('key_pair_name', ''));
          /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
          $file = $request->files->get('key_pair_public_key');
          if (empty($file)) {
            return new JsonResponse([
              'result' => 'NG',
              'reason' => 'Internal Server Error',
            ], 500);
          }
          $form_state->setValue('key_pair_public_key', $file->getRealPath());
          $method_name = 'importKeyPair';
          break;

        case 'reboot_aws_cloud_instance':
          $method_name = 'rebootInstance';
          break;
+1 −1
Changes for modules/cloud_service_providers/openstack/src/Controller/ApiController.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -621,7 +621,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
        $entity->set('key_pair_name', $request->get('key_pair_name', ''));
        /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
        $file = $request->files->get('key_pair_public_key');
        if (!$file) {
        if (empty($file)) {
          return new JsonResponse([
            'result' => 'NG',
            'reason' => 'Internal Server Error',