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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 03:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-12 03:07:43 +0300
commit2e3cbf7d89815e2915f77677388c49b48f8d20c3 (patch)
tree03bdbc99e829295e8077b2ec4032300c15b48e37 /app/assets/javascripts/create_cluster
parente44bb86539a8fb4cfb06dfe281632b6f206bd0a7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/create_cluster')
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue13
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue2
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/index.js22
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/services/aws_services_facade.js148
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/actions.js13
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/cluster_dropdown/index.js4
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/index.js30
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/mutation_types.js1
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/mutations.js3
-rw-r--r--app/assets/javascripts/create_cluster/eks_cluster/store/state.js2
10 files changed, 126 insertions, 112 deletions
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue b/app/assets/javascripts/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue
index 641343b8150..d04d0ff2a6d 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue
+++ b/app/assets/javascripts/create_cluster/eks_cluster/components/eks_cluster_configuration_form.vue
@@ -22,10 +22,7 @@ const {
mapState: mapSecurityGroupsState,
mapActions: mapSecurityGroupsActions,
} = createNamespacedHelpers('securityGroups');
-const {
- mapState: mapInstanceTypesState,
- mapActions: mapInstanceTypesActions,
-} = createNamespacedHelpers('instanceTypes');
+const { mapState: mapInstanceTypesState } = createNamespacedHelpers('instanceTypes');
export default {
components: {
@@ -265,12 +262,10 @@ export default {
mounted() {
this.fetchRegions();
this.fetchRoles();
- this.fetchInstanceTypes();
},
methods: {
...mapActions([
'createCluster',
- 'signOut',
'setClusterName',
'setEnvironmentScope',
'setKubernetesVersion',
@@ -290,7 +285,6 @@ export default {
...mapRolesActions({ fetchRoles: 'fetchItems' }),
...mapKeyPairsActions({ fetchKeyPairs: 'fetchItems' }),
...mapSecurityGroupsActions({ fetchSecurityGroups: 'fetchItems' }),
- ...mapInstanceTypesActions({ fetchInstanceTypes: 'fetchItems' }),
setRegionAndFetchVpcsAndKeyPairs(region) {
this.setRegion({ region });
this.setVpc({ vpc: null });
@@ -316,11 +310,6 @@ export default {
{{ s__('ClusterIntegration|Enter the details for your Amazon EKS Kubernetes cluster') }}
</h2>
<div class="mb-3" v-html="kubernetesIntegrationHelpText"></div>
- <div class="mb-3">
- <button class="btn btn-link js-sign-out" @click.prevent="signOut()">
- {{ s__('ClusterIntegration|Select a different AWS role') }}
- </button>
- </div>
<div class="form-group">
<label class="label-bold" for="eks-cluster-name">{{
s__('ClusterIntegration|Kubernetes cluster name')
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue b/app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue
index 50a23536451..1dd4c468ae6 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue
+++ b/app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue
@@ -28,7 +28,7 @@ export default {
},
data() {
return {
- roleArn: '',
+ roleArn: this.$store.state.roleArn,
};
},
computed: {
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/index.js b/app/assets/javascripts/create_cluster/eks_cluster/index.js
index 27f859d8972..fb993a7aa59 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/index.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/index.js
@@ -12,20 +12,14 @@ export default el => {
kubernetesIntegrationHelpPath,
accountAndExternalIdsHelpPath,
createRoleArnHelpPath,
- getRolesPath,
- getRegionsPath,
- getKeyPairsPath,
- getVpcsPath,
- getSubnetsPath,
- getSecurityGroupsPath,
- getInstanceTypesPath,
externalId,
accountId,
+ instanceTypes,
hasCredentials,
createRolePath,
createClusterPath,
- signOutPath,
externalLinkIcon,
+ roleArn,
} = el.dataset;
return new Vue({
@@ -35,18 +29,10 @@ export default el => {
hasCredentials: parseBoolean(hasCredentials),
externalId,
accountId,
+ instanceTypes: JSON.parse(instanceTypes),
createRolePath,
createClusterPath,
- signOutPath,
- },
- apiPaths: {
- getRolesPath,
- getRegionsPath,
- getKeyPairsPath,
- getVpcsPath,
- getSubnetsPath,
- getSecurityGroupsPath,
- getInstanceTypesPath,
+ roleArn,
},
}),
components: {
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 })),
+ );
+};
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/actions.js b/app/assets/javascripts/create_cluster/eks_cluster/store/actions.js
index 72f15263a8f..e96e6d6e4f8 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/actions.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/actions.js
@@ -1,6 +1,8 @@
import * as types from './mutation_types';
+import { setAWSConfig } from '../services/aws_services_facade';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
+import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
const getErrorMessage = data => {
const errorKey = Object.keys(data)[0];
@@ -28,7 +30,7 @@ export const createRole = ({ dispatch, state: { createRolePath } }, payload) =>
role_arn: payload.roleArn,
role_external_id: payload.externalId,
})
- .then(() => dispatch('createRoleSuccess'))
+ .then(({ data }) => dispatch('createRoleSuccess', convertObjectPropsToCamelCase(data)))
.catch(error => dispatch('createRoleError', { error }));
};
@@ -36,7 +38,8 @@ export const requestCreateRole = ({ commit }) => {
commit(types.REQUEST_CREATE_ROLE);
};
-export const createRoleSuccess = ({ commit }) => {
+export const createRoleSuccess = ({ commit }, awsCredentials) => {
+ setAWSConfig({ awsCredentials });
commit(types.CREATE_ROLE_SUCCESS);
};
@@ -117,9 +120,3 @@ export const setInstanceType = ({ commit }, payload) => {
export const setNodeCount = ({ commit }, payload) => {
commit(types.SET_NODE_COUNT, payload);
};
-
-export const signOut = ({ commit, state: { signOutPath } }) =>
- axios
- .delete(signOutPath)
- .then(() => commit(types.SIGN_OUT))
- .catch(({ response: { data } }) => createFlash(getErrorMessage(data)));
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/cluster_dropdown/index.js b/app/assets/javascripts/create_cluster/eks_cluster/store/cluster_dropdown/index.js
index 07a5821c47d..0b19589215c 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/cluster_dropdown/index.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/cluster_dropdown/index.js
@@ -3,11 +3,11 @@ import actions from './actions';
import mutations from './mutations';
import state from './state';
-const createStore = fetchFn => ({
+const createStore = ({ fetchFn, initialState }) => ({
actions: actions(fetchFn),
getters,
mutations,
- state: state(),
+ state: Object.assign(state(), initialState || {}),
});
export default createStore;
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/index.js b/app/assets/javascripts/create_cluster/eks_cluster/store/index.js
index 5982fc8a2fd..09fd560240d 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/index.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/index.js
@@ -6,12 +6,17 @@ import state from './state';
import clusterDropdownStore from './cluster_dropdown';
-import awsServicesFactory from '../services/aws_services_facade';
+import {
+ fetchRoles,
+ fetchRegions,
+ fetchKeyPairs,
+ fetchVpcs,
+ fetchSubnets,
+ fetchSecurityGroups,
+} from '../services/aws_services_facade';
-const createStore = ({ initialState, apiPaths }) => {
- const awsServices = awsServicesFactory(apiPaths);
-
- return new Vuex.Store({
+const createStore = ({ initialState }) =>
+ new Vuex.Store({
actions,
getters,
mutations,
@@ -19,34 +24,33 @@ const createStore = ({ initialState, apiPaths }) => {
modules: {
roles: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchRoles),
+ ...clusterDropdownStore({ fetchFn: fetchRoles }),
},
regions: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchRegions),
+ ...clusterDropdownStore({ fetchFn: fetchRegions }),
},
keyPairs: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchKeyPairs),
+ ...clusterDropdownStore({ fetchFn: fetchKeyPairs }),
},
vpcs: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchVpcs),
+ ...clusterDropdownStore({ fetchFn: fetchVpcs }),
},
subnets: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchSubnets),
+ ...clusterDropdownStore({ fetchFn: fetchSubnets }),
},
securityGroups: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchSecurityGroups),
+ ...clusterDropdownStore({ fetchFn: fetchSecurityGroups }),
},
instanceTypes: {
namespaced: true,
- ...clusterDropdownStore(awsServices.fetchInstanceTypes),
+ ...clusterDropdownStore({ initialState: { items: initialState.instanceTypes } }),
},
},
});
-};
export default createStore;
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/mutation_types.js b/app/assets/javascripts/create_cluster/eks_cluster/store/mutation_types.js
index f9204cc2207..9dee6abae5f 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/mutation_types.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/mutation_types.js
@@ -13,7 +13,6 @@ export const SET_GITLAB_MANAGED_CLUSTER = 'SET_GITLAB_MANAGED_CLUSTER';
export const REQUEST_CREATE_ROLE = 'REQUEST_CREATE_ROLE';
export const CREATE_ROLE_SUCCESS = 'CREATE_ROLE_SUCCESS';
export const CREATE_ROLE_ERROR = 'CREATE_ROLE_ERROR';
-export const SIGN_OUT = 'SIGN_OUT';
export const REQUEST_CREATE_CLUSTER = 'REQUEST_CREATE_CLUSTER';
export const CREATE_CLUSTER_SUCCESS = 'CREATE_CLUSTER_SUCCESS';
export const CREATE_CLUSTER_ERROR = 'CREATE_CLUSTER_ERROR';
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/mutations.js b/app/assets/javascripts/create_cluster/eks_cluster/store/mutations.js
index aa04c8f7079..c331d27d255 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/mutations.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/mutations.js
@@ -60,7 +60,4 @@ export default {
state.isCreatingCluster = false;
state.createClusterError = error;
},
- [types.SIGN_OUT](state) {
- state.hasCredentials = false;
- },
};
diff --git a/app/assets/javascripts/create_cluster/eks_cluster/store/state.js b/app/assets/javascripts/create_cluster/eks_cluster/store/state.js
index 2e3a05a9187..20434dcce98 100644
--- a/app/assets/javascripts/create_cluster/eks_cluster/store/state.js
+++ b/app/assets/javascripts/create_cluster/eks_cluster/store/state.js
@@ -12,6 +12,8 @@ export default () => ({
accountId: '',
externalId: '',
+ roleArn: '',
+
clusterName: '',
environmentScope: '*',
kubernetesVersion,