From 9fdea17b1a8a18fe4df551ccf303d874ea2a0335 Mon Sep 17 00:00:00 2001
From: Westly Wright
Date: Tue, 16 Mar 2021 14:06:03 -0700
Subject: [PATCH 1/2] Google GCP cloud credentials
rancher/rancher#31346
---
.../cru-cloud-credential/component.js | 51 ++++++++++--
.../cru-cloud-credential/template.hbs | 26 ++++++-
.../components/input-text-file/template.hbs | 78 +++++++++++++------
3 files changed, 122 insertions(+), 33 deletions(-)
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")}}
+
+
+ {{#input-text-file
+ label="clusterNew.googlegke.credential.label"
+ value=config.authEncodedJson
+ accept="text/*, .json"
+ minHeight=60
+ canChangeName=false
+ nameRequired=true
+ placeholder="clusterNew.googlegke.credential.placeholder"
+ concealValue=true as |section|
+ }}
+ {{#if (eq section "description")}}
+
+
+ {{t "clusterNew.googlegke.credential.helpText" htmlSafe=true}}
+
+
+ {{/if}}
+ {{/input-text-file}}
+
+
{{else if (eq cloudCredentialType "linode")}}
{{input
type="password"
diff --git a/lib/shared/addon/components/input-text-file/template.hbs b/lib/shared/addon/components/input-text-file/template.hbs
index d88634ede..d4edbcc95 100644
--- a/lib/shared/addon/components/input-text-file/template.hbs
+++ b/lib/shared/addon/components/input-text-file/template.hbs
@@ -1,38 +1,63 @@
- {{!--
--}}
- {{#if (and canChangeName shouldChangeName)}}
- {{input value=name placeholder=(if namePlaceholder (t namePlaceholder) "")}}
- {{else}}
-
- {{#if label}}
- {{t label}}
- {{else}}
- {{name}}
- {{/if}}
- {{#if nameRequired}}{{field-required}}{{/if}}
- {{#if canChangeName}}
-
- {{/if}}
-
- {{/if}}
- {{!-- --}}
{{#if canUpload}}
{{#if showUploadLabel}}
-
+
+ {{#if (and canChangeName shouldChangeName)}}
+ {{input value=name placeholder=(if namePlaceholder (t namePlaceholder) "")}}
+ {{else}}
+
+ {{#if label}}
+ {{t label}}
+ {{else}}
+ {{name}}
+ {{/if}}
+ {{#if nameRequired}}
+ {{field-required}}
+ {{/if}}
+ {{#if canChangeName}}
+
+ {{t "action.edit"}}
+
+ {{/if}}
+
+ {{/if}}
+
-
+
{{textarea-autogrow
@@ -47,4 +72,9 @@
{{yield "description"}}
-
+
\ No newline at end of file
From 7046e4cf339dbf89e56ee916e09b765fb9f25027 Mon Sep 17 00:00:00 2001
From: Westly Wright
Date: Wed, 17 Mar 2021 11:29:52 -0700
Subject: [PATCH 2/2] add google cc to display type on cc model
---
app/models/cloudcredential.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
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) {