diff --git a/app/models/cloudcredential.js b/app/models/cloudcredential.js index 91d3d849d..2a4b3def2 100644 --- a/app/models/cloudcredential.js +++ b/app/models/cloudcredential.js @@ -18,21 +18,23 @@ const cloudCredential = Resource.extend({ isAmazon: notEmpty('amazonec2credentialConfig'), isAzure: notEmpty('azurecredentialConfig'), isDo: notEmpty('digitaloceancredentialConfig'), + isGoogle: notEmpty('googlecredentialConfig'), isLinode: notEmpty('linodecredentialConfig'), isOCI: notEmpty('ocicredentialConfig'), isPNAP: notEmpty('pnapcredentialConfig'), isVMware: notEmpty('vmwarevspherecredentialConfig'), - displayType: computed('amazonec2credentialConfig', 'azurecredentialConfig', 'digitaloceancredentialConfig', 'linodecredentialConfig', 'ocicredentialConfig', 'pnapcredentialConfig', 'vmwarevspherecredentialConfig', function() { + displayType: computed('amazonec2credentialConfig', 'azurecredentialConfig', 'digitaloceancredentialConfig', 'googlecredentialConfig', 'linodecredentialConfig', 'ocicredentialConfig', 'pnapcredentialConfig', 'vmwarevspherecredentialConfig', function() { const { isAmazon, isAzure, isDo, + isGoogle, isLinode, isOCI, isPNAP, - isVMware + isVMware, } = this; if (isAmazon) { @@ -41,6 +43,8 @@ const cloudCredential = Resource.extend({ return 'Azure'; } else if (isDo) { return 'Digital Ocean'; + } else if (isGoogle) { + return 'Google'; } else if (isLinode) { return 'Linode'; } else if (isOCI) { diff --git a/lib/global-admin/addon/components/cru-cloud-credential/component.js b/lib/global-admin/addon/components/cru-cloud-credential/component.js index d4f3fc259..73a9183c6 100644 --- a/lib/global-admin/addon/components/cru-cloud-credential/component.js +++ b/lib/global-admin/addon/components/cru-cloud-credential/component.js @@ -27,6 +27,18 @@ const CRED_CONFIG_CHOICES = [ driver: 'digitalocean', configField: 'digitaloceancredentialConfig', }, + { + name: 'google', + displayName: 'Google', + driver: 'google', + configField: 'googlecredentialConfig', + }, + { + name: 'linode', + displayName: 'Linode', + driver: 'linode', + configField: 'linodecredentialConfig', + }, { name: 'oci', displayName: 'OCI', @@ -39,12 +51,6 @@ const CRED_CONFIG_CHOICES = [ driver: 'pnap', configField: 'pnapcredentialConfig', }, - { - name: 'linode', - displayName: 'Linode', - driver: 'linode', - configField: 'linodecredentialConfig', - }, { name: 'vmware', displayName: 'VMware vSphere', @@ -152,6 +158,7 @@ export default Component.extend(ViewNewEdit, { case 'amazon': case 'digitalOcean': case 'linode': + case 'google': return 'modalAddCloudKey.saving.validating'; case 'oci': case 'pnap': @@ -191,7 +198,7 @@ export default Component.extend(ViewNewEdit, { } const { cloudCredentialType } = this; - const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci']; + const keysThatWeCanValidate = ['amazon', 'digitalOcean', 'linode', 'oci', 'google']; const auth = { type: 'validate', token: null, @@ -268,6 +275,16 @@ export default Component.extend(ViewNewEdit, { return this.setError(`${ err.message }`); }); } + + if (cloudCredentialType === 'google') { + return this.fetchZones().then(() => { + set(this, 'validatingKeys', false); + + return true; + }).catch((err) => { + return this.setError(`${ err.message }`); + }); + } } set(this, 'validatingKeys', false); @@ -331,6 +348,24 @@ export default Component.extend(ViewNewEdit, { parseAndCollectErrors() { throw new Error('parseAndCollectErrors action is required!'); - } + }, + fetchZones() { + const credentials = get(this, 'config.authEncodedJson'); + const config = JSON.parse(credentials || '{}'); + const { project_id: projectId } = config; + + return get(this, 'globalStore').rawRequest({ + url: '/meta/gkeZones', + method: 'POST', + data: { + credentials, + projectId, + } + }).then(() => { + return Promise.resolve(); + }).catch((xhr) => { + return Promise.reject({ message: xhr?.body?.error }); + }); + }, }); diff --git a/lib/global-admin/addon/components/cru-cloud-credential/template.hbs b/lib/global-admin/addon/components/cru-cloud-credential/template.hbs index 723a240d0..372e5566b 100644 --- a/lib/global-admin/addon/components/cru-cloud-credential/template.hbs +++ b/lib/global-admin/addon/components/cru-cloud-credential/template.hbs @@ -145,11 +145,35 @@
+ {{else if (eq cloudCredentialType "google")}} +