Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js')
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js148
1 files changed, 94 insertions, 54 deletions
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js b/app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js
index 21b87d525cf..601ff6f9adc 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js
@@ -1,58 +1,98 @@
-import axios from '~/lib/utils/axios_utils';
-
-export default apiPaths => ({
- fetchRoles() {
- return axios
- .get(apiPaths.getRolesPath)
- .then(({ data: { roles } }) =>
- roles.map(({ role_name: name, arn: value }) => ({ name, value })),
- );
- },
- fetchKeyPairs({ region }) {
- return axios
- .get(apiPaths.getKeyPairsPath, { params: { region } })
- .then(({ data: { key_pairs: keyPairs } }) =>
- keyPairs.map(({ key_name }) => ({ name: key_name, value: key_name })),
- );
- },
- fetchRegions() {
- return axios.get(apiPaths.getRegionsPath).then(({ data: { regions } }) =>
- regions.map(({ region_name }) => ({
- name: region_name,
- value: region_name,
+import AWS from 'aws-sdk/global';
+import EC2 from 'aws-sdk/clients/ec2';
+import IAM from 'aws-sdk/clients/iam';
+
+const lookupVpcName = ({ Tags: tags, VpcId: id }) => {
+ const nameTag = tags.find(({ Key: key }) => key === 'Name');
+
+ return nameTag ? nameTag.Value : id;
+};
+
+export const DEFAULT_REGION = 'us-east-2';
+
+export const setAWSConfig = ({ awsCredentials }) => {
+ AWS.config = {
+ ...awsCredentials,
+ region: DEFAULT_REGION,
+ };
+};
+
+export const fetchRoles = () => {
+ const iam = new IAM();
+
+ return iam
+ .listRoles()
+ .promise()
+ .then(({ Roles: roles }) => roles.map(({ RoleName: name, Arn: value }) => ({ name, value })));
+};
+
+export const fetchRegions = () => {
+ const ec2 = new EC2();
+
+ return ec2
+ .describeRegions()
+ .promise()
+ .then(({ Regions: regions }) =>
+ regions.map(({ RegionName: name }) => ({
+ name,
+ value: name,
})),
);
- },
- fetchVpcs({ region }) {
- return axios.get(apiPaths.getVpcsPath, { params: { region } }).then(({ data: { vpcs } }) =>
- vpcs.map(({ vpc_id }) => ({
- value: vpc_id,
- name: vpc_id,
+};
+
+export const fetchKeyPairs = ({ region }) => {
+ const ec2 = new EC2({ region });
+
+ return ec2
+ .describeKeyPairs()
+ .promise()
+ .then(({ KeyPairs: keyPairs }) => keyPairs.map(({ KeyName: name }) => ({ name, value: name })));
+};
+
+export const fetchVpcs = ({ region }) => {
+ const ec2 = new EC2({ region });
+
+ return ec2
+ .describeVpcs()
+ .promise()
+ .then(({ Vpcs: vpcs }) =>
+ vpcs.map(vpc => ({
+ value: vpc.VpcId,
+ name: lookupVpcName(vpc),
})),
);
- },
- fetchSubnets({ vpc, region }) {
- return axios
- .get(apiPaths.getSubnetsPath, { params: { vpc_id: vpc, region } })
- .then(({ data: { subnets } }) =>
- subnets.map(({ subnet_id }) => ({ name: subnet_id, value: subnet_id })),
- );
- },
- fetchSecurityGroups({ vpc, region }) {
- return axios
- .get(apiPaths.getSecurityGroupsPath, { params: { vpc_id: vpc, region } })
- .then(({ data: { security_groups: securityGroups } }) =>
- securityGroups.map(({ group_name: name, group_id: value }) => ({ name, value })),
- );
- },
- fetchInstanceTypes() {
- return axios
- .get(apiPaths.getInstanceTypesPath)
- .then(({ data: { instance_types: instanceTypes } }) =>
- instanceTypes.map(({ instance_type_name }) => ({
- name: instance_type_name,
- value: instance_type_name,
- })),
- );
- },
-});
+};
+
+export const fetchSubnets = ({ vpc, region }) => {
+ const ec2 = new EC2({ region });
+
+ return ec2
+ .describeSubnets({
+ Filters: [
+ {
+ Name: 'vpc-id',
+ Values: [vpc],
+ },
+ ],
+ })
+ .promise()
+ .then(({ Subnets: subnets }) => subnets.map(({ SubnetId: id }) => ({ value: id, name: id })));
+};
+
+export const fetchSecurityGroups = ({ region, vpc }) => {
+ const ec2 = new EC2({ region });
+
+ return ec2
+ .describeSecurityGroups({
+ Filters: [
+ {
+ Name: 'vpc-id',
+ Values: [vpc],
+ },
+ ],
+ })
+ .promise()
+ .then(({ SecurityGroups: securityGroups }) =>
+ securityGroups.map(({ GroupName: name, GroupId: value }) => ({ name, value })),
+ );
+};