Коммит 8f29549f создал по автору Miguel Rincon's avatar Miguel Rincon
Просмотр файлов

Add registration token reset in registration modal

This change allows users that are still using the legacy runner
registration process to reset (rotate) their registration token in
the modal with the registration instructions.
владелец 9375beff
import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import { INSTANCE_TYPE } from '../constants';
import AdminNewRunnerApp from './admin_new_runner_app.vue';
Vue.use(VueApollo);
Vue.use(GlToast);
export const initAdminNewRunner = (selector = '#js-admin-new-runner') => {
const el = document.querySelector(selector);
......@@ -21,6 +24,9 @@ export const initAdminNewRunner = (selector = '#js-admin-new-runner') => {
return new Vue({
el,
apolloProvider,
provide: {
legacyTokenResetRunnerType: INSTANCE_TYPE,
},
render(h) {
return h(AdminNewRunnerApp, {
props: {
......
<script>
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { TYPENAME_GROUP, TYPENAME_PROJECT } from '~/graphql_shared/constants';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { __, s__ } from '~/locale';
import runnersRegistrationTokenResetMutation from '~/ci/runner/graphql/list/runners_registration_token_reset.mutation.graphql';
import { captureException } from '~/ci/runner/sentry_utils';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '../../constants';
const i18n = {
modalAction: s__('Runners|Reset token'),
modalCancel: __('Cancel'),
modalCopy: __('Are you sure you want to reset the registration token?'),
modalTitle: __('Reset registration token'),
};
export default {
name: 'RunnerRegistrationTokenResetButton',
i18n,
components: {
GlButton,
GlModal,
},
directives: {
GlModal: GlModalDirective,
},
inject: {
legacyTokenResetRunnerType: {
default: null,
},
legacyTokenResetGroupId: {
default: null,
},
legacyTokenResetProjectId: {
default: null,
},
},
modalId: 'token-reset-modal',
data() {
return {
loading: false,
};
},
computed: {
resetTokenInput() {
const type = this.legacyTokenResetRunnerType;
switch (type) {
case INSTANCE_TYPE:
return {
type,
};
case GROUP_TYPE:
return {
id: convertToGraphQLId(TYPENAME_GROUP, this.legacyTokenResetGroupId),
type,
};
case PROJECT_TYPE:
return {
id: convertToGraphQLId(TYPENAME_PROJECT, this.legacyTokenResetProjectId),
type,
};
default:
return null;
}
},
isAvailable() {
return Boolean(this.resetTokenInput);
},
actionPrimary() {
return {
text: i18n.modalAction,
attributes: { variant: 'danger' },
};
},
actionSecondary() {
return {
text: i18n.modalCancel,
attributes: { variant: 'default' },
};
},
},
methods: {
handleModalPrimary() {
this.resetToken();
},
async resetToken() {
this.loading = true;
try {
const {
data: {
runnersRegistrationTokenReset: { token, errors },
},
} = await this.$apollo.mutate({
mutation: runnersRegistrationTokenResetMutation,
variables: {
input: this.resetTokenInput,
},
});
if (errors && errors.length) {
throw new Error(errors.join(' '));
}
this.onSuccess(token);
} catch (e) {
this.onError(e);
} finally {
this.loading = false;
}
},
onError(error) {
const { message } = error;
createAlert({ message });
captureException({ error, component: this.$options.name });
},
onSuccess(token) {
this.$toast?.show(s__('Runners|New registration token generated!'));
this.$emit('tokenReset', token);
},
},
};
</script>
<template>
<gl-button v-if="isAvailable" v-gl-modal="$options.modalId" :loading="loading">
{{ __('Reset registration token') }}
<gl-modal
size="sm"
:modal-id="$options.modalId"
:action-primary="actionPrimary"
:action-secondary="actionSecondary"
:title="$options.i18n.modalTitle"
@primary="handleModalPrimary"
>
<p>{{ $options.i18n.modalCopy }}</p>
</gl-modal>
</gl-button>
</template>
import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import { GROUP_TYPE } from '../constants';
import GroupNewRunnerApp from './group_new_runner_app.vue';
Vue.use(VueApollo);
Vue.use(GlToast);
export const initGroupNewRunner = (selector = '#js-group-new-runner') => {
const el = document.querySelector(selector);
......@@ -21,6 +24,10 @@ export const initGroupNewRunner = (selector = '#js-group-new-runner') => {
return new Vue({
el,
apolloProvider,
provide: {
legacyTokenResetRunnerType: GROUP_TYPE,
legacyTokenResetGroupId: groupId,
},
render(h) {
return h(GroupNewRunnerApp, {
props: {
......
import Vue from 'vue';
import { GlToast } from '@gitlab/ui';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
import { PROJECT_TYPE } from '../constants';
import ProjectNewRunnerApp from './project_new_runner_app.vue';
Vue.use(VueApollo);
Vue.use(GlToast);
export const initProjectNewRunner = (selector = '#js-project-new-runner') => {
const el = document.querySelector(selector);
......@@ -21,6 +24,10 @@ export const initProjectNewRunner = (selector = '#js-project-new-runner') => {
return new Vue({
el,
apolloProvider,
provide: {
legacyTokenResetRunnerType: PROJECT_TYPE,
legacyTokenResetProjectId: projectId,
},
render(h) {
return h(ProjectNewRunnerApp, {
props: {
......
......@@ -2,6 +2,7 @@
import { GlButton, GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import LegacyRegistrationTokenResetButton from '~/ci/runner/components/registration/legacy_registration_token_reset_button.vue';
import { REGISTRATION_TOKEN_PLACEHOLDER } from '../constants';
import getRunnerSetupInstructionsQuery from '../graphql/get_runner_setup.query.graphql';
......@@ -12,6 +13,7 @@ export default {
GlDropdownItem,
GlLoadingIcon,
ModalCopyButton,
LegacyRegistrationTokenResetButton,
},
props: {
platform: {
......@@ -28,6 +30,7 @@ export default {
data() {
return {
selectedArchitecture: this.platform?.architectures[0] || null,
currentRegistrationToken: this.registrationToken,
instructions: null,
};
},
......@@ -61,10 +64,10 @@ export default {
registerInstructionsWithToken() {
const { registerInstructions } = this.instructions || {};
if (this.registrationToken) {
if (this.currentRegistrationToken) {
return registerInstructions?.replace(
REGISTRATION_TOKEN_PLACEHOLDER,
this.registrationToken,
this.currentRegistrationToken,
);
}
return registerInstructions;
......@@ -83,6 +86,9 @@ export default {
selectArchitecture(architecture) {
this.selectedArchitecture = architecture;
},
onTokenReset(token) {
this.currentRegistrationToken = token;
},
onClose() {
this.$emit('close');
},
......@@ -145,7 +151,11 @@ export default {
category="tertiary"
/>
</div>
<h5 class="gl-mb-3">{{ $options.i18n.registerRunnerCommand }}</h5>
<div class="gl-sm-display-flex gl-align-items-center gl-mb-3">
<h5 class="gl-mb-3">{{ $options.i18n.registerRunnerCommand }}</h5>
<legacy-registration-token-reset-button class="gl-ml-auto" @tokenReset="onTokenReset" />
</div>
<div class="gl-display-flex">
<pre
class="gl-bg-gray gl-flex-grow-1 gl-white-space-pre-line"
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать