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

actions.js « store « gke_cluster « create_cluster « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8977053297a7f30528622947a0e44ebecbc52e65 (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
import * as types from './mutation_types';
import gapiLoader from '../gapi_loader';

const gapiResourceListRequest = ({ resource, params, commit, mutation, payloadKey }) =>
  new Promise((resolve, reject) => {
    const request = resource.list(params);

    return request.then(
      (resp) => {
        const { result } = resp;

        commit(mutation, result[payloadKey]);

        resolve();
      },
      (resp) => {
        reject(resp);
      },
    );
  });

export const setProject = ({ commit }, selectedProject) => {
  commit(types.SET_PROJECT, selectedProject);
};

export const setZone = ({ commit }, selectedZone) => {
  commit(types.SET_ZONE, selectedZone);
};

export const setMachineType = ({ commit }, selectedMachineType) => {
  commit(types.SET_MACHINE_TYPE, selectedMachineType);
};

export const setIsValidatingProjectBilling = ({ commit }, isValidatingProjectBilling) => {
  commit(types.SET_IS_VALIDATING_PROJECT_BILLING, isValidatingProjectBilling);
};

export const fetchProjects = ({ commit }) =>
  gapiLoader().then((gapi) =>
    gapiResourceListRequest({
      resource: gapi.client.cloudresourcemanager.projects,
      params: {},
      commit,
      mutation: types.SET_PROJECTS,
      payloadKey: 'projects',
    }),
  );

export const validateProjectBilling = ({ dispatch, commit, state }) =>
  gapiLoader()
    .then((gapi) => {
      const request = gapi.client.cloudbilling.projects.getBillingInfo({
        name: `projects/${state.selectedProject.projectId}`,
      });

      commit(types.SET_ZONE, '');
      commit(types.SET_MACHINE_TYPE, '');

      return request;
    })
    .then(
      (resp) => {
        const { billingEnabled } = resp.result;

        commit(types.SET_PROJECT_BILLING_STATUS, Boolean(billingEnabled));
        dispatch('setIsValidatingProjectBilling', false);
      },
      (errorResp) => {
        dispatch('setIsValidatingProjectBilling', false);
        return errorResp;
      },
    );

export const fetchZones = ({ commit, state }) =>
  gapiLoader().then((gapi) =>
    gapiResourceListRequest({
      resource: gapi.client.compute.zones,
      params: {
        project: state.selectedProject.projectId,
      },
      commit,
      mutation: types.SET_ZONES,
      payloadKey: 'items',
    }),
  );

export const fetchMachineTypes = ({ commit, state }) =>
  gapiLoader().then((gapi) =>
    gapiResourceListRequest({
      resource: gapi.client.compute.machineTypes,
      params: {
        project: state.selectedProject.projectId,
        zone: state.selectedZone,
      },
      commit,
      mutation: types.SET_MACHINE_TYPES,
      payloadKey: 'items',
    }),
  );