Commit 629fd9a3 authored by Enrique Alcantara's avatar Enrique Alcantara Committed by Tiger

Code review feedback

- Remove extra space in before endLink
- Remove handleAuthenticate and call createRole directly
- Call createRole as a form submission.
- Store api paths in the store state
parent dd841d54
...@@ -46,7 +46,7 @@ export default { ...@@ -46,7 +46,7 @@ export default {
return sprintf( return sprintf(
s__( s__(
'ClusterIntegration|Create a provision role on %{startAwsLink}Amazon Web Services %{externalLinkIcon} %{endLink} using the account and external ID above. %{startMoreInfoLink}More information%{endLink}', 'ClusterIntegration|Create a provision role on %{startAwsLink}Amazon Web Services %{externalLinkIcon}%{endLink} using the account and external ID above. %{startMoreInfoLink}More information%{endLink}',
), ),
{ {
startAwsLink: startAwsLink:
...@@ -63,7 +63,7 @@ export default { ...@@ -63,7 +63,7 @@ export default {
return sprintf( return sprintf(
s__( s__(
'ClusterIntegration|The Amazon Resource Name (ARN) associated with your role. If you do not have a provision role, first create one on %{startAwsLink}Amazon Web Services %{externalLinkIcon} %{endLink} using the above account and external IDs. %{startMoreInfoLink}More information%{endLink}', 'ClusterIntegration|The Amazon Resource Name (ARN) associated with your role. If you do not have a provision role, first create one on %{startAwsLink}Amazon Web Services %{externalLinkIcon}%{endLink} using the above account and external IDs. %{startMoreInfoLink}More information%{endLink}',
), ),
{ {
startAwsLink: startAwsLink:
...@@ -78,16 +78,11 @@ export default { ...@@ -78,16 +78,11 @@ export default {
}, },
methods: { methods: {
...mapActions(['createRole']), ...mapActions(['createRole']),
handleAuthenticate() {
const { roleArn, externalId } = this;
this.createRole({ roleArn, externalId });
},
}, },
}; };
</script> </script>
<template> <template>
<form name="service-credentials-form"> <form name="service-credentials-form" @submit.prevent="createRole({ roleArn, externalId })">
<h2>{{ s__('ClusterIntegration|Authenticate with Amazon Web Services') }}</h2> <h2>{{ s__('ClusterIntegration|Authenticate with Amazon Web Services') }}</h2>
<p> <p>
{{ {{
...@@ -137,10 +132,10 @@ export default { ...@@ -137,10 +132,10 @@ export default {
</div> </div>
<loading-button <loading-button
class="js-submit-service-credentials" class="js-submit-service-credentials"
type="submit"
:disabled="submitButtonDisabled" :disabled="submitButtonDisabled"
:loading="isCreatingRole" :loading="isCreatingRole"
:label="submitButtonLabel" :label="submitButtonLabel"
@click="handleAuthenticate($event)"
/> />
</form> </form>
</template> </template>
...@@ -26,8 +26,6 @@ export default el => { ...@@ -26,8 +26,6 @@ export default el => {
hasCredentials: parseBoolean(hasCredentials), hasCredentials: parseBoolean(hasCredentials),
externalId, externalId,
accountId, accountId,
},
apiPaths: {
createRolePath, createRolePath,
}, },
}), }),
......
import * as types from './mutation_types'; import * as types from './mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
export default apiPaths => ({ export const setClusterName = ({ commit }, payload) => {
setClusterName({ commit }, payload) { commit(types.SET_CLUSTER_NAME, payload);
commit(types.SET_CLUSTER_NAME, payload); };
},
setEnvironmentScope({ commit }, payload) { export const setEnvironmentScope = ({ commit }, payload) => {
commit(types.SET_ENVIRONMENT_SCOPE, payload); commit(types.SET_ENVIRONMENT_SCOPE, payload);
}, };
setKubernetesVersion({ commit }, payload) {
commit(types.SET_KUBERNETES_VERSION, payload); export const setKubernetesVersion = ({ commit }, payload) => {
}, commit(types.SET_KUBERNETES_VERSION, payload);
createRole({ dispatch }, payload) { };
dispatch('requestCreateRole');
export const createRole = ({ dispatch, state: { createRolePath } }, payload) => {
return axios dispatch('requestCreateRole');
.post(apiPaths.createRolePath, {
role_arn: payload.roleArn, return axios
role_external_id: payload.externalId, .post(createRolePath, {
}) role_arn: payload.roleArn,
.then(() => dispatch('createRoleSuccess')) role_external_id: payload.externalId,
.catch(error => dispatch('createRoleError', { error })); })
}, .then(() => dispatch('createRoleSuccess'))
requestCreateRole({ commit }) { .catch(error => dispatch('createRoleError', { error }));
commit(types.REQUEST_CREATE_ROLE); };
},
createRoleSuccess({ commit }) { export const requestCreateRole = ({ commit }) => {
commit(types.CREATE_ROLE_SUCCESS); commit(types.REQUEST_CREATE_ROLE);
}, };
createRoleError({ commit }, payload) {
commit(types.CREATE_ROLE_ERROR, payload); export const createRoleSuccess = ({ commit }) => {
}, commit(types.CREATE_ROLE_SUCCESS);
setRegion({ commit }, payload) { };
commit(types.SET_REGION, payload);
}, export const createRoleError = ({ commit }, payload) => {
setKeyPair({ commit }, payload) { commit(types.CREATE_ROLE_ERROR, payload);
commit(types.SET_KEY_PAIR, payload); };
},
setVpc({ commit }, payload) { export const setRegion = ({ commit }, payload) => {
commit(types.SET_VPC, payload); commit(types.SET_REGION, payload);
}, };
setSubnet({ commit }, payload) {
commit(types.SET_SUBNET, payload); export const setKeyPair = ({ commit }, payload) => {
}, commit(types.SET_KEY_PAIR, payload);
setRole({ commit }, payload) { };
commit(types.SET_ROLE, payload);
}, export const setVpc = ({ commit }, payload) => {
setSecurityGroup({ commit }, payload) { commit(types.SET_VPC, payload);
commit(types.SET_SECURITY_GROUP, payload); };
},
setGitlabManagedCluster({ commit }, payload) { export const setSubnet = ({ commit }, payload) => {
commit(types.SET_GITLAB_MANAGED_CLUSTER, payload); commit(types.SET_SUBNET, payload);
}, };
});
export const setRole = ({ commit }, payload) => {
commit(types.SET_ROLE, payload);
};
export const setSecurityGroup = ({ commit }, payload) => {
commit(types.SET_SECURITY_GROUP, payload);
};
export const setGitlabManagedCluster = ({ commit }, payload) => {
commit(types.SET_GITLAB_MANAGED_CLUSTER, payload);
};
import Vuex from 'vuex'; import Vuex from 'vuex';
import actions from './actions'; import * as actions from './actions';
import * as getters from './getters'; import * as getters from './getters';
import mutations from './mutations'; import mutations from './mutations';
import state from './state'; import state from './state';
...@@ -8,9 +8,9 @@ import clusterDropdownStore from './cluster_dropdown'; ...@@ -8,9 +8,9 @@ import clusterDropdownStore from './cluster_dropdown';
import * as awsServices from '../services/aws_services_facade'; import * as awsServices from '../services/aws_services_facade';
const createStore = ({ initialState, apiPaths }) => const createStore = ({ initialState }) =>
new Vuex.Store({ new Vuex.Store({
actions: actions(apiPaths), actions,
getters, getters,
mutations, mutations,
state: Object.assign(state(), initialState), state: Object.assign(state(), initialState),
......
import { KUBERNETES_VERSIONS } from '../constants'; import { KUBERNETES_VERSIONS } from '../constants';
export default () => ({ export default () => ({
createRolePath: null,
isCreatingRole: false, isCreatingRole: false,
roleCreated: false, roleCreated: false,
createRoleError: false, createRoleError: false,
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- last = local_assigns.fetch(:last, false) - last = local_assigns.fetch(:last, false)
- classes = ['btn btn-light btn-outline flex-fill d-inline-flex flex-column justify-content-center align-items-center', ('mr-3' unless last)] - classes = ['btn btn-light btn-outline flex-fill d-inline-flex flex-column justify-content-center align-items-center', ('mr-3' unless last)]
= link_to clusterable.new_path(provider: provider), class: 'btn btn-light btn-outline flex-fill d-inline-flex flex-column mr-3 justify-content-center align-items-center' do = link_to clusterable.new_path(provider: provider), class: classes do
.svg-content.p-2= image_tag logo_path, alt: label, class: 'gl-w-64 gl-h-64' .svg-content.p-2= image_tag logo_path, alt: label, class: 'gl-w-64 gl-h-64'
%span %span
= label = label
...@@ -1489,7 +1489,7 @@ msgstr "" ...@@ -1489,7 +1489,7 @@ msgstr ""
msgid "Amazon EKS integration allows you to provision EKS clusters from GitLab." msgid "Amazon EKS integration allows you to provision EKS clusters from GitLab."
msgstr "" msgstr ""
msgid "Amazon authentication is not %{link_start}property configured%{link_end}. Ask your GitLab administrator if you want to use this service." msgid "Amazon authentication is not %{link_start}correctly configured%{link_end}. Ask your GitLab administrator if you want to use this service."
msgstr "" msgstr ""
msgid "Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication" msgid "Amount of time (in hours) that users are allowed to skip forced configuration of two-factor authentication"
...@@ -2173,6 +2173,9 @@ msgstr "" ...@@ -2173,6 +2173,9 @@ msgstr ""
msgid "Authenticate with GitHub" msgid "Authenticate with GitHub"
msgstr "" msgstr ""
msgid "Authenticating"
msgstr ""
msgid "Authentication Log" msgid "Authentication Log"
msgstr "" msgstr ""
...@@ -3607,7 +3610,7 @@ msgstr "" ...@@ -3607,7 +3610,7 @@ msgstr ""
msgid "ClusterIntegration|Create Kubernetes cluster" msgid "ClusterIntegration|Create Kubernetes cluster"
msgstr "" msgstr ""
msgid "ClusterIntegration|Create a provision role on %{startAwsLink}Amazon Web Services %{externalLinkIcon} %{endLink} using the account and external ID above. %{startMoreInfoLink}More information%{endLink}" msgid "ClusterIntegration|Create a provision role on %{startAwsLink}Amazon Web Services %{externalLinkIcon}%{endLink} using the account and external ID above. %{startMoreInfoLink}More information%{endLink}"
msgstr "" msgstr ""
msgid "ClusterIntegration|Create cluster on" msgid "ClusterIntegration|Create cluster on"
...@@ -4045,7 +4048,7 @@ msgstr "" ...@@ -4045,7 +4048,7 @@ msgstr ""
msgid "ClusterIntegration|Subnet" msgid "ClusterIntegration|Subnet"
msgstr "" msgstr ""
msgid "ClusterIntegration|The Amazon Resource Name (ARN) associated with your role. If you do not have a provision role, first create one on %{startAwsLink}Amazon Web Services %{externalLinkIcon} %{endLink} using the above account and external IDs. %{startMoreInfoLink}More information%{endLink}" msgid "ClusterIntegration|The Amazon Resource Name (ARN) associated with your role. If you do not have a provision role, first create one on %{startAwsLink}Amazon Web Services %{externalLinkIcon}%{endLink} using the above account and external IDs. %{startMoreInfoLink}More information%{endLink}"
msgstr "" msgstr ""
msgid "ClusterIntegration|The Kubernetes certificate used to authenticate to the cluster." msgid "ClusterIntegration|The Kubernetes certificate used to authenticate to the cluster."
......
...@@ -47,6 +47,7 @@ describe('ServiceCredentialsForm', () => { ...@@ -47,6 +47,7 @@ describe('ServiceCredentialsForm', () => {
const findCopyExternalIdButton = () => vm.find('.js-copy-external-id-button'); const findCopyExternalIdButton = () => vm.find('.js-copy-external-id-button');
const findInvalidCredentials = () => vm.find('.js-invalid-credentials'); const findInvalidCredentials = () => vm.find('.js-invalid-credentials');
const findSubmitButton = () => vm.find(LoadingButton); const findSubmitButton = () => vm.find(LoadingButton);
const findForm = () => vm.find('form[name="service-credentials-form"]');
it('displays provided account id', () => { it('displays provided account id', () => {
expect(findAccountIdInput().attributes('value')).toBe(accountId); expect(findAccountIdInput().attributes('value')).toBe(accountId);
...@@ -74,8 +75,8 @@ describe('ServiceCredentialsForm', () => { ...@@ -74,8 +75,8 @@ describe('ServiceCredentialsForm', () => {
expect(findSubmitButton().attributes('disabled')).toBeFalsy(); expect(findSubmitButton().attributes('disabled')).toBeFalsy();
}); });
it('dispatches authenticate action when submit button is clicked', () => { it('dispatches createRole action when form is submitted', () => {
findSubmitButton().vm.$emit('click'); findForm().trigger('submit');
expect(createRoleAction).toHaveBeenCalled(); expect(createRoleAction).toHaveBeenCalled();
}); });
......
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import createState from '~/create_cluster/eks_cluster/store/state'; import createState from '~/create_cluster/eks_cluster/store/state';
import actionsFactory from '~/create_cluster/eks_cluster/store/actions'; import * as actions from '~/create_cluster/eks_cluster/store/actions';
import { import {
SET_CLUSTER_NAME, SET_CLUSTER_NAME,
SET_ENVIRONMENT_SCOPE, SET_ENVIRONMENT_SCOPE,
...@@ -31,9 +31,8 @@ describe('EKS Cluster Store Actions', () => { ...@@ -31,9 +31,8 @@ describe('EKS Cluster Store Actions', () => {
let keyPair; let keyPair;
let securityGroup; let securityGroup;
let gitlabManagedCluster; let gitlabManagedCluster;
let actions;
let apiPaths;
let mock; let mock;
let state;
beforeEach(() => { beforeEach(() => {
clusterName = 'my cluster'; clusterName = 'my cluster';
...@@ -47,11 +46,10 @@ describe('EKS Cluster Store Actions', () => { ...@@ -47,11 +46,10 @@ describe('EKS Cluster Store Actions', () => {
securityGroup = { name: 'default group' }; securityGroup = { name: 'default group' };
gitlabManagedCluster = true; gitlabManagedCluster = true;
apiPaths = { state = {
...createState(),
createRolePath: '/clusters/roles/', createRolePath: '/clusters/roles/',
}; };
actions = actionsFactory(apiPaths);
}); });
beforeEach(() => { beforeEach(() => {
...@@ -77,7 +75,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -77,7 +75,7 @@ describe('EKS Cluster Store Actions', () => {
`(`$action commits $mutation with $payloadDescription payload`, data => { `(`$action commits $mutation with $payloadDescription payload`, data => {
const { action, mutation, payload } = data; const { action, mutation, payload } = data;
testAction(actions[action], payload, createState(), [{ type: mutation, payload }]); testAction(actions[action], payload, state, [{ type: mutation, payload }]);
}); });
describe('createRole', () => { describe('createRole', () => {
...@@ -89,7 +87,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -89,7 +87,7 @@ describe('EKS Cluster Store Actions', () => {
describe('when request succeeds', () => { describe('when request succeeds', () => {
beforeEach(() => { beforeEach(() => {
mock mock
.onPost(apiPaths.createRolePath, { .onPost(state.createRolePath, {
role_arn: payload.roleArn, role_arn: payload.roleArn,
role_external_id: payload.externalId, role_external_id: payload.externalId,
}) })
...@@ -100,7 +98,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -100,7 +98,7 @@ describe('EKS Cluster Store Actions', () => {
testAction( testAction(
actions.createRole, actions.createRole,
payload, payload,
createState(), state,
[], [],
[{ type: 'requestCreateRole' }, { type: 'createRoleSuccess' }], [{ type: 'requestCreateRole' }, { type: 'createRoleSuccess' }],
)); ));
...@@ -112,7 +110,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -112,7 +110,7 @@ describe('EKS Cluster Store Actions', () => {
beforeEach(() => { beforeEach(() => {
error = new Error('Request failed with status code 400'); error = new Error('Request failed with status code 400');
mock mock
.onPost(apiPaths.createRolePath, { .onPost(state.createRolePath, {
role_arn: payload.roleArn, role_arn: payload.roleArn,
role_external_id: payload.externalId, role_external_id: payload.externalId,
}) })
...@@ -123,7 +121,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -123,7 +121,7 @@ describe('EKS Cluster Store Actions', () => {
testAction( testAction(
actions.createRole, actions.createRole,
payload, payload,
createState(), state,
[], [],
[{ type: 'requestCreateRole' }, { type: 'createRoleError', payload: { error } }], [{ type: 'requestCreateRole' }, { type: 'createRoleError', payload: { error } }],
)); ));
...@@ -132,13 +130,13 @@ describe('EKS Cluster Store Actions', () => { ...@@ -132,13 +130,13 @@ describe('EKS Cluster Store Actions', () => {
describe('requestCreateRole', () => { describe('requestCreateRole', () => {
it('commits requestCreaterole mutation', () => { it('commits requestCreaterole mutation', () => {
testAction(actions.requestCreateRole, null, createState(), [{ type: REQUEST_CREATE_ROLE }]); testAction(actions.requestCreateRole, null, state, [{ type: REQUEST_CREATE_ROLE }]);
}); });
}); });
describe('createRoleSuccess', () => { describe('createRoleSuccess', () => {
it('commits createRoleSuccess mutation', () => { it('commits createRoleSuccess mutation', () => {
testAction(actions.createRoleSuccess, null, createState(), [{ type: CREATE_ROLE_SUCCESS }]); testAction(actions.createRoleSuccess, null, state, [{ type: CREATE_ROLE_SUCCESS }]);
}); });
}); });
...@@ -148,9 +146,7 @@ describe('EKS Cluster Store Actions', () => { ...@@ -148,9 +146,7 @@ describe('EKS Cluster Store Actions', () => {
error: new Error(), error: new Error(),
}; };
testAction(actions.createRoleError, payload, createState(), [ testAction(actions.createRoleError, payload, state, [{ type: CREATE_ROLE_ERROR, payload }]);
{ type: CREATE_ROLE_ERROR, payload },
]);
}); });
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment