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

runner_registration_token_reset.vue « components « runner « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2335faa4f859d5c496f3aa1996d168b3ade02b7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script>
import { GlButton } from '@gitlab/ui';
import createFlash, { FLASH_TYPES } from '~/flash';
import { __, s__ } from '~/locale';
import runnersRegistrationTokenResetMutation from '~/runner/graphql/runners_registration_token_reset.mutation.graphql';
import { captureException } from '~/runner/sentry_utils';
import { INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE } from '../constants';

export default {
  name: 'RunnerRegistrationTokenReset',
  components: {
    GlButton,
  },
  props: {
    type: {
      type: String,
      required: true,
      validator(type) {
        return [INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE].includes(type);
      },
    },
  },
  data() {
    return {
      loading: false,
    };
  },
  computed: {},
  methods: {
    async resetToken() {
      // TODO Replace confirmation with gl-modal
      // See: https://gitlab.com/gitlab-org/gitlab/-/issues/333810
      // eslint-disable-next-line no-alert
      if (!window.confirm(__('Are you sure you want to reset the registration token?'))) {
        return;
      }

      this.loading = true;
      try {
        const {
          data: {
            runnersRegistrationTokenReset: { token, errors },
          },
        } = await this.$apollo.mutate({
          mutation: runnersRegistrationTokenResetMutation,
          variables: {
            // TODO Currently INTANCE_TYPE only is supported
            // In future iterations this component will support
            // other registration token types.
            // See: https://gitlab.com/gitlab-org/gitlab/-/issues/19819
            input: {
              type: this.type,
            },
          },
        });
        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;
      createFlash({ message });

      this.reportToSentry(error);
    },
    onSuccess(token) {
      createFlash({
        message: s__('Runners|New registration token generated!'),
        type: FLASH_TYPES.SUCCESS,
      });
      this.$emit('tokenReset', token);
    },
    reportToSentry(error) {
      captureException({ error, component: this.$options.name });
    },
  },
};
</script>
<template>
  <gl-button :loading="loading" @click="resetToken">
    {{ __('Reset registration token') }}
  </gl-button>
</template>