summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/create_cluster/eks_cluster/components/service_credentials_form.vue
blob: a3f76241bf2bfde5f6439e1a9f7e96a2abf084c2 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<script>
/* eslint-disable vue/no-v-html */
import { GlButton, GlFormGroup, GlFormInput, GlIcon, GlLink, GlSprintf } from '@gitlab/ui';
import { escape } from 'lodash';
import { mapState, mapActions } from 'vuex';
import { DEFAULT_REGION } from '../constants';
import { sprintf, s__, __ } from '~/locale';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';

export default {
  components: {
    GlButton,
    GlFormGroup,
    GlFormInput,
    GlIcon,
    GlLink,
    GlSprintf,
    ClipboardButton,
  },
  props: {
    accountAndExternalIdsHelpPath: {
      type: String,
      required: true,
    },
    createRoleArnHelpPath: {
      type: String,
      required: true,
    },
    externalLinkIcon: {
      type: String,
      required: true,
    },
  },
  i18n: {
    regionInputLabel: s__('ClusterIntegration|Cluster Region'),
    regionHelpPath: 'https://aws.amazon.com/about-aws/global-infrastructure/regions_az/',
    regionHelpText: s__(
      'ClusterIntegration|Select the region you want to create the new cluster in. Make sure you have access to this region for your role to be able to authenticate. If no region is selected, we will use %{codeStart}DEFAULT_REGION%{codeEnd}. Learn more about %{linkStart}Regions%{linkEnd}.',
    ),
    regionHelpTextDefaultRegion: DEFAULT_REGION,
  },
  data() {
    return {
      roleArn: this.$store.state.roleArn,
      selectedRegion: this.$store.state.selectedRegion,
    };
  },
  computed: {
    ...mapState(['accountId', 'externalId', 'isCreatingRole', 'createRoleError']),
    submitButtonDisabled() {
      return this.isCreatingRole || !this.roleArn;
    },
    submitButtonLabel() {
      return this.isCreatingRole
        ? __('Authenticating')
        : s__('ClusterIntegration|Authenticate with AWS');
    },
    accountAndExternalIdsHelpText() {
      const escapedUrl = escape(this.accountAndExternalIdsHelpPath);

      return sprintf(
        s__(
          'ClusterIntegration|Create a provision role on %{startAwsLink}Amazon Web Services %{externalLinkIcon}%{endLink} using the account and external ID above. %{startMoreInfoLink}More information%{endLink}',
        ),
        {
          startAwsLink:
            '<a href="https://console.aws.amazon.com/iam/home?#roles" target="_blank" rel="noopener noreferrer">',
          startMoreInfoLink: `<a href="${escapedUrl}" target="_blank" rel="noopener noreferrer">`,
          externalLinkIcon: this.externalLinkIcon,
          endLink: '</a>',
        },
        false,
      );
    },
    provisionRoleArnHelpText() {
      const escapedUrl = escape(this.createRoleArnHelpPath);

      return sprintf(
        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}',
        ),
        {
          startAwsLink:
            '<a href="https://console.aws.amazon.com/iam/home?#roles" target="_blank" rel="noopener noreferrer">',
          startMoreInfoLink: `<a href="${escapedUrl}" target="_blank" rel="noopener noreferrer">`,
          externalLinkIcon: this.externalLinkIcon,
          endLink: '</a>',
        },
        false,
      );
    },
  },
  methods: {
    ...mapActions(['createRole']),
  },
};
</script>
<template>
  <form name="service-credentials-form">
    <h4>{{ s__('ClusterIntegration|Authenticate with Amazon Web Services') }}</h4>
    <p>
      {{
        s__(
          'ClusterIntegration|You must grant access to your organization’s AWS resources in order to create a new EKS cluster. To grant access, create a provision role using the account and external ID below and provide us the ARN.',
        )
      }}
    </p>
    <div v-if="createRoleError" class="js-invalid-credentials bs-callout bs-callout-danger">
      {{ createRoleError }}
    </div>
    <div class="form-row">
      <div class="form-group col-md-6">
        <label for="gitlab-account-id">{{ __('Account ID') }}</label>
        <div class="input-group">
          <gl-form-input id="gitlab-account-id" type="text" readonly :value="accountId" />
          <div class="input-group-append">
            <clipboard-button
              :text="accountId"
              :title="__('Copy Account ID to clipboard')"
              class="input-group-text js-copy-account-id-button"
            />
          </div>
        </div>
      </div>
      <div class="form-group col-md-6">
        <label for="eks-external-id">{{ __('External ID') }}</label>
        <div class="input-group">
          <gl-form-input id="eks-external-id" type="text" readonly :value="externalId" />
          <div class="input-group-append">
            <clipboard-button
              :text="externalId"
              :title="__('Copy External ID to clipboard')"
              class="input-group-text js-copy-external-id-button"
            />
          </div>
        </div>
      </div>
      <div class="col-12 mb-3 mt-n3">
        <p class="form-text text-muted" v-html="accountAndExternalIdsHelpText"></p>
      </div>
    </div>
    <div class="form-group">
      <label for="eks-provision-role-arn">{{ s__('ClusterIntegration|Provision Role ARN') }}</label>
      <gl-form-input id="eks-provision-role-arn" v-model="roleArn" />
      <p class="form-text text-muted" v-html="provisionRoleArnHelpText"></p>
    </div>

    <gl-form-group :label="$options.i18n.regionInputLabel">
      <gl-form-input id="eks-region" v-model="selectedRegion" type="text" />

      <template #description>
        <gl-sprintf :message="$options.i18n.regionHelpText">
          <template #code>
            <code>{{ $options.i18n.regionHelpTextDefaultRegion }}</code>
          </template>

          <template #link="{ content }">
            <gl-link :href="$options.i18n.regionHelpPath" target="_blank">
              {{ content }}
              <gl-icon name="external-link" />
            </gl-link>
          </template>
        </gl-sprintf>
      </template>
    </gl-form-group>

    <gl-button
      variant="success"
      category="primary"
      type="submit"
      :disabled="submitButtonDisabled"
      :loading="isCreatingRole"
      @click.prevent="createRole({ roleArn, selectedRegion, externalId })"
    >
      {{ submitButtonLabel }}
    </gl-button>
  </form>
</template>