Commit 972d7771 authored by Miguel Rincon's avatar Miguel Rincon Committed by Jose Vargas

Replace registration token in registration modal

This change replaces the registration token in the commands provided
in the modal, so users can easily copy-paste the contents of the
instruction and use them directly.

Changelog: changed
parent 1d53200a
...@@ -88,6 +88,7 @@ export default { ...@@ -88,6 +88,7 @@ export default {
<runner-instructions-modal <runner-instructions-modal
v-if="instructionsModalOpened" v-if="instructionsModalOpened"
ref="runnerInstructionsModal" ref="runnerInstructionsModal"
:registration-token="registrationToken"
data-testid="runner-instructions-modal" data-testid="runner-instructions-modal"
/> />
</gl-dropdown-item> </gl-dropdown-item>
......
import { GlToast } from '@gitlab/ui';
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import GroupRunnersApp from './group_runners_app.vue'; import GroupRunnersApp from './group_runners_app.vue';
Vue.use(GlToast);
Vue.use(VueApollo); Vue.use(VueApollo);
export const initGroupRunners = (selector = '#js-group-runners') => { export const initGroupRunners = (selector = '#js-group-runners') => {
......
...@@ -2,6 +2,8 @@ import { s__ } from '~/locale'; ...@@ -2,6 +2,8 @@ import { s__ } from '~/locale';
export const PLATFORMS_WITHOUT_ARCHITECTURES = ['docker', 'kubernetes']; export const PLATFORMS_WITHOUT_ARCHITECTURES = ['docker', 'kubernetes'];
export const REGISTRATION_TOKEN_PLACEHOLDER = '$REGISTRATION_TOKEN';
export const INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES = { export const INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES = {
docker: { docker: {
instructions: s__( instructions: s__(
......
...@@ -16,8 +16,9 @@ import { isEmpty } from 'lodash'; ...@@ -16,8 +16,9 @@ import { isEmpty } from 'lodash';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue'; import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import { import {
PLATFORMS_WITHOUT_ARCHITECTURES,
INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES, INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES,
PLATFORMS_WITHOUT_ARCHITECTURES,
REGISTRATION_TOKEN_PLACEHOLDER,
} from './constants'; } from './constants';
import getRunnerPlatformsQuery from './graphql/queries/get_runner_platforms.query.graphql'; import getRunnerPlatformsQuery from './graphql/queries/get_runner_platforms.query.graphql';
import getRunnerSetupInstructionsQuery from './graphql/queries/get_runner_setup.query.graphql'; import getRunnerSetupInstructionsQuery from './graphql/queries/get_runner_setup.query.graphql';
...@@ -44,6 +45,11 @@ export default { ...@@ -44,6 +45,11 @@ export default {
required: false, required: false,
default: 'runner-instructions-modal', default: 'runner-instructions-modal',
}, },
registrationToken: {
type: String,
required: false,
default: null,
},
}, },
apollo: { apollo: {
platforms: { platforms: {
...@@ -118,6 +124,15 @@ export default { ...@@ -118,6 +124,15 @@ export default {
runnerInstallationLink() { runnerInstallationLink() {
return INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES[this.selectedPlatformName]?.link; return INSTRUCTIONS_PLATFORMS_WITHOUT_ARCHITECTURES[this.selectedPlatformName]?.link;
}, },
registerInstructionsWithToken() {
const { registerInstructions } = this.instructions || {};
if (this.registrationToken) {
return registerInstructions.replace(REGISTRATION_TOKEN_PLACEHOLDER, this.registrationToken);
}
return registerInstructions;
},
}, },
methods: { methods: {
show() { show() {
...@@ -249,11 +264,11 @@ export default { ...@@ -249,11 +264,11 @@ export default {
<pre <pre
class="gl-bg-gray gl-flex-grow-1 gl-white-space-pre-line" class="gl-bg-gray gl-flex-grow-1 gl-white-space-pre-line"
data-testid="register-command" data-testid="register-command"
>{{ instructions.registerInstructions }}</pre >{{ registerInstructionsWithToken }}</pre
> >
<modal-copy-button <modal-copy-button
:title="$options.i18n.copyInstructions" :title="$options.i18n.copyInstructions"
:text="instructions.registerInstructions" :text="registerInstructionsWithToken"
:modal-id="$options.modalId" :modal-id="$options.modalId"
css-classes="gl-align-self-start gl-ml-2 gl-mt-2" css-classes="gl-align-self-start gl-ml-2 gl-mt-2"
category="tertiary" category="tertiary"
......
...@@ -9,7 +9,7 @@ module Types ...@@ -9,7 +9,7 @@ module Types
field :install_instructions, GraphQL::Types::String, null: false, field :install_instructions, GraphQL::Types::String, null: false,
description: 'Instructions for installing the runner on the specified architecture.' description: 'Instructions for installing the runner on the specified architecture.'
field :register_instructions, GraphQL::Types::String, null: true, field :register_instructions, GraphQL::Types::String, null: true,
description: 'Instructions for registering the runner.' description: 'Instructions for registering the runner. The actual registration tokens are not included in the commands. Instead, a placeholder `$REGISTRATION_TOKEN` is shown.'
end end
end end
end end
...@@ -13935,7 +13935,7 @@ Counts of requirements by their state. ...@@ -13935,7 +13935,7 @@ Counts of requirements by their state.
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="runnersetupinstallinstructions"></a>`installInstructions` | [`String!`](#string) | Instructions for installing the runner on the specified architecture. | | <a id="runnersetupinstallinstructions"></a>`installInstructions` | [`String!`](#string) | Instructions for installing the runner on the specified architecture. |
| <a id="runnersetupregisterinstructions"></a>`registerInstructions` | [`String`](#string) | Instructions for registering the runner. | | <a id="runnersetupregisterinstructions"></a>`registerInstructions` | [`String`](#string) | Instructions for registering the runner. The actual registration tokens are not included in the commands. Instead, a placeholder `$REGISTRATION_TOKEN` is shown. |
### `SastCiConfiguration` ### `SastCiConfiguration`
......
...@@ -52,7 +52,7 @@ describe('RunnerInstructionsModal component', () => { ...@@ -52,7 +52,7 @@ describe('RunnerInstructionsModal component', () => {
const findBinaryInstructions = () => wrapper.findByTestId('binary-instructions'); const findBinaryInstructions = () => wrapper.findByTestId('binary-instructions');
const findRegisterCommand = () => wrapper.findByTestId('register-command'); const findRegisterCommand = () => wrapper.findByTestId('register-command');
const createComponent = (options = {}) => { const createComponent = ({ props, ...options } = {}) => {
const requestHandlers = [ const requestHandlers = [
[getRunnerPlatformsQuery, runnerPlatformsHandler], [getRunnerPlatformsQuery, runnerPlatformsHandler],
[getRunnerSetupInstructionsQuery, runnerSetupInstructionsHandler], [getRunnerSetupInstructionsQuery, runnerSetupInstructionsHandler],
...@@ -64,6 +64,8 @@ describe('RunnerInstructionsModal component', () => { ...@@ -64,6 +64,8 @@ describe('RunnerInstructionsModal component', () => {
shallowMount(RunnerInstructionsModal, { shallowMount(RunnerInstructionsModal, {
propsData: { propsData: {
modalId: 'runner-instructions-modal', modalId: 'runner-instructions-modal',
registrationToken: 'MY_TOKEN',
...props,
}, },
localVue, localVue,
apolloProvider: fakeApollo, apolloProvider: fakeApollo,
...@@ -119,18 +121,30 @@ describe('RunnerInstructionsModal component', () => { ...@@ -119,18 +121,30 @@ describe('RunnerInstructionsModal component', () => {
expect(instructions).toBe(installInstructions); expect(instructions).toBe(installInstructions);
}); });
it('register command is shown', () => { it('register command is shown with a replaced token', () => {
const instructions = findRegisterCommand().text(); const instructions = findRegisterCommand().text();
expect(instructions).toBe(registerInstructions); expect(instructions).toBe(
'sudo gitlab-runner register --url http://gdk.test:3000/ --registration-token MY_TOKEN',
);
});
describe('when a register token is not shown', () => {
beforeEach(async () => {
createComponent({ props: { registrationToken: undefined } });
await nextTick();
});
it('register command is shown without a defined registration token', () => {
const instructions = findRegisterCommand().text();
expect(instructions).toBe(registerInstructions);
});
}); });
}); });
describe('after a platform and architecture are selected', () => { describe('after a platform and architecture are selected', () => {
const { const { installInstructions } = mockGraphqlInstructionsWindows.data.runnerSetup;
installInstructions,
registerInstructions,
} = mockGraphqlInstructionsWindows.data.runnerSetup;
beforeEach(async () => { beforeEach(async () => {
runnerSetupInstructionsHandler.mockResolvedValue(mockGraphqlInstructionsWindows); runnerSetupInstructionsHandler.mockResolvedValue(mockGraphqlInstructionsWindows);
...@@ -158,7 +172,9 @@ describe('RunnerInstructionsModal component', () => { ...@@ -158,7 +172,9 @@ describe('RunnerInstructionsModal component', () => {
it('register command is shown', () => { it('register command is shown', () => {
const command = findRegisterCommand().text(); const command = findRegisterCommand().text();
expect(command).toBe(registerInstructions); expect(command).toBe(
'./gitlab-runner.exe register --url http://gdk.test:3000/ --registration-token MY_TOKEN',
);
}); });
}); });
......
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