summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js
blob: d982e4db4c16bcb3c0d7b9b48f7078f2cb948b09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import EC2 from 'aws-sdk/clients/ec2';
import IAM from 'aws-sdk/clients/iam';

export const fetchRoles = () => {
  const iam = new IAM();

  return iam
    .listRoles()
    .promise()
    .then(({ Roles: roles }) => roles.map(({ RoleName: name }) => ({ name })));
};

export const fetchKeyPairs = () => {
  const ec2 = new EC2();

  return ec2
    .describeKeyPairs()
    .promise()
    .then(({ KeyPairs: keyPairs }) => keyPairs.map(({ RegionName: name }) => ({ name })));
};

export const fetchRegions = () => {
  const ec2 = new EC2();

  return ec2
    .describeRegions()
    .promise()
    .then(({ Regions: regions }) =>
      regions.map(({ RegionName: name }) => ({
        name,
        value: name,
      })),
    );
};

export const fetchVpcs = () => {
  const ec2 = new EC2();

  return ec2
    .describeVpcs()
    .promise()
    .then(({ Vpcs: vpcs }) =>
      vpcs.map(({ VpcId: id }) => ({
        value: id,
        name: id,
      })),
    );
};

export const fetchSubnets = ({ vpc }) => {
  const ec2 = new EC2();

  return ec2
    .describeSubnets({
      Filters: [
        {
          Name: 'vpc-id',
          Values: [vpc],
        },
      ],
    })
    .promise()
    .then(({ Subnets: subnets }) => subnets.map(({ SubnetId: id }) => ({ id, name: id })));
};

export const fetchSecurityGroups = ({ vpc }) => {
  const ec2 = new EC2();

  return ec2
    .describeSecurityGroups({
      Filters: [
        {
          Name: 'vpc-id',
          Values: [vpc],
        },
      ],
    })
    .promise()
    .then(({ SecurityGroups: securityGroups }) =>
      securityGroups.map(({ GroupName: name, GroupId: value }) => ({ name, value })),
    );
};

export default () => {};