mirror of https://github.com/status-im/consul.git
chor: change cluster name param to have datacenter.name as default value (#20644)
* chor: change cluster name param to have datacenter.name as default value
This commit is contained in:
parent
14efb28086
commit
8425cd0f90
|
@ -52,7 +52,6 @@ export default class HcpLinkItemComponent extends Component {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onLinkToConsulCentral() {
|
onLinkToConsulCentral() {
|
||||||
this.hcpLinkModal.setResourceId(this.args.linkData?.resourceId);
|
|
||||||
this.hcpLinkModal.show();
|
this.hcpLinkModal.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ export default class LinkToHcpBannerComponent extends Component {
|
||||||
}
|
}
|
||||||
@action
|
@action
|
||||||
onClusterLink() {
|
onClusterLink() {
|
||||||
this.hcpLinkModal.setResourceId(this.args.linkData?.resourceId);
|
|
||||||
this.hcpLinkModal.show();
|
this.hcpLinkModal.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
</Hds::Form::Radio::Group>
|
</Hds::Form::Radio::Group>
|
||||||
{{#if (and this.isReadOnlyAccessLevelSelected (can "read acls") (can "create tokens"))}}
|
{{#if (and this.isReadOnlyAccessLevelSelected (can "read acls") (can "create tokens"))}}
|
||||||
<div class="link-to-hcp-modal__generate-token">
|
<div class="link-to-hcp-modal__generate-token">
|
||||||
{{#if globalReadonlyPolicy.data}}
|
{{#if (and globalReadonlyPolicy globalReadonlyPolicy.data)}}
|
||||||
<p class="hds-typography-display-100 hds-font-weight-medium font-family-sans-display">
|
<p class="hds-typography-display-100 hds-font-weight-medium font-family-sans-display">
|
||||||
Generate a read-only ACL token now (preferred) or copy an existing token’s secret ID
|
Generate a read-only ACL token now (preferred) or copy an existing token’s secret ID
|
||||||
</p>
|
</p>
|
||||||
|
@ -97,7 +97,7 @@
|
||||||
@icon="external-link"
|
@icon="external-link"
|
||||||
@iconPosition="trailing"
|
@iconPosition="trailing"
|
||||||
data-test-link-to-hcp-modal-next-button
|
data-test-link-to-hcp-modal-next-button
|
||||||
@href={{hcp-authentication-link this.hcpLinkModal.resourceId this.accessLevel}}
|
@href={{hcp-authentication-link @dc this.accessLevel}}
|
||||||
/>
|
/>
|
||||||
<Hds::Button type="button" @text="Cancel" @color="secondary"
|
<Hds::Button type="button" @text="Cancel" @color="secondary"
|
||||||
data-test-link-to-hcp-modal-cancel-button
|
data-test-link-to-hcp-modal-cancel-button
|
||||||
|
|
|
@ -27,6 +27,12 @@ export default class LinkToHcpModalComponent extends Component {
|
||||||
isGeneratingToken = false;
|
isGeneratingToken = false;
|
||||||
AccessLevel = ACCESS_LEVEL;
|
AccessLevel = ACCESS_LEVEL;
|
||||||
|
|
||||||
|
constructor(args, owner) {
|
||||||
|
super(...arguments);
|
||||||
|
// it is needed for .lookup to not flakey in tests
|
||||||
|
this.hideModal = this.hcpLinkModal.hide.bind(this.hcpLinkModal);
|
||||||
|
}
|
||||||
|
|
||||||
get isReadOnlyAccessLevelSelected() {
|
get isReadOnlyAccessLevelSelected() {
|
||||||
return this.accessLevel === this.AccessLevel.GLOBALREADONLY;
|
return this.accessLevel === this.AccessLevel.GLOBALREADONLY;
|
||||||
}
|
}
|
||||||
|
@ -35,10 +41,6 @@ export default class LinkToHcpModalComponent extends Component {
|
||||||
return this.token && this.token.length > 0;
|
return this.token && this.token.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivateModal = () => {
|
|
||||||
this.hcpLinkModal.hide();
|
|
||||||
};
|
|
||||||
|
|
||||||
onGenerateTokenClicked = (policy) => {
|
onGenerateTokenClicked = (policy) => {
|
||||||
this.isGeneratingToken = true;
|
this.isGeneratingToken = true;
|
||||||
let token = this.tokenRepo.create({
|
let token = this.tokenRepo.create({
|
||||||
|
@ -53,12 +55,12 @@ export default class LinkToHcpModalComponent extends Component {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@action
|
|
||||||
onCancel() {
|
|
||||||
this.deactivateModal();
|
|
||||||
}
|
|
||||||
@action
|
@action
|
||||||
onAccessModeChanged({ target }) {
|
onAccessModeChanged({ target }) {
|
||||||
this.accessLevel = target.value;
|
this.accessLevel = target.value;
|
||||||
}
|
}
|
||||||
|
@action
|
||||||
|
deactivateModal() {
|
||||||
|
this.hideModal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,6 @@ import Helper from '@ember/component/helper';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A resourceId Looks like:
|
|
||||||
* organization/b4432207-bb9c-438e-a160-b98923efa979/project/4b09958c-fa91-43ab-8029-eb28d8cee9d4/hashicorp.consul.global-network-manager.cluster/test-from-api
|
|
||||||
* organization/${organizationId}/project/${projectId}/hashicorp.consul.global-network-manager.cluster/${clusterName}
|
|
||||||
*
|
|
||||||
* A HCP URL looks like:
|
* A HCP URL looks like:
|
||||||
* https://portal.cloud.hashicorp.com/services/consul/clusters/self-managed/link-existing?cluster_name=test-from-api&cluster_version=1.18.0&cluster_access_mode=CONSUL_ACCESS_LEVEL_GLOBAL_READ_WRITE&redirect_url=localhost:8500/services
|
* https://portal.cloud.hashicorp.com/services/consul/clusters/self-managed/link-existing?cluster_name=test-from-api&cluster_version=1.18.0&cluster_access_mode=CONSUL_ACCESS_LEVEL_GLOBAL_READ_WRITE&redirect_url=localhost:8500/services
|
||||||
*/
|
*/
|
||||||
|
@ -18,17 +14,12 @@ export const HCP_PREFIX =
|
||||||
'https://portal.cloud.hashicorp.com/services/consul/clusters/self-managed/link-existing';
|
'https://portal.cloud.hashicorp.com/services/consul/clusters/self-managed/link-existing';
|
||||||
export default class hcpAuthenticationLink extends Helper {
|
export default class hcpAuthenticationLink extends Helper {
|
||||||
@service('env') env;
|
@service('env') env;
|
||||||
compute([resourceId, accessMode], hash) {
|
compute([datacenterName, accessMode]) {
|
||||||
let url = new URL(HCP_PREFIX);
|
let url = new URL(HCP_PREFIX);
|
||||||
const clusterVersion = this.env.var('CONSUL_VERSION');
|
const clusterVersion = this.env.var('CONSUL_VERSION');
|
||||||
|
|
||||||
// if resourceId is empty, we still might want the user to get to the HCP sign-in page
|
if (datacenterName) {
|
||||||
if (resourceId) {
|
url.searchParams.append('cluster_name', datacenterName);
|
||||||
// Array looks like: ["organization", organizationId, "project", projectId, "hashicorp.consul.global-network-manager.cluster", "Cluster Id"]
|
|
||||||
const [, , , , , clusterName] = resourceId.split('/');
|
|
||||||
if (clusterName) {
|
|
||||||
url.searchParams.append('cluster_name', clusterName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clusterVersion) {
|
if (clusterVersion) {
|
||||||
|
|
|
@ -8,16 +8,12 @@ import { tracked } from '@glimmer/tracking';
|
||||||
|
|
||||||
export default class HcpLinkModalService extends Service {
|
export default class HcpLinkModalService extends Service {
|
||||||
@tracked isModalVisible = false;
|
@tracked isModalVisible = false;
|
||||||
@tracked resourceId = null;
|
|
||||||
|
|
||||||
show(hcpLinkData) {
|
show() {
|
||||||
this.isModalVisible = true;
|
this.isModalVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
hide() {
|
hide() {
|
||||||
this.isModalVisible = false;
|
this.isModalVisible = false;
|
||||||
}
|
}
|
||||||
setResourceId(resourceId) {
|
|
||||||
this.resourceId = resourceId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
import { module, test } from 'qunit';
|
import { module, test } from 'qunit';
|
||||||
import { click, visit } from '@ember/test-helpers';
|
import { click, visit } from '@ember/test-helpers';
|
||||||
import { setupApplicationTest } from 'ember-qunit';
|
import { setupApplicationTest } from 'ember-qunit';
|
||||||
import HcpLinkModalService from 'consul-ui/services/hcp-link-modal';
|
|
||||||
|
|
||||||
const bannerSelector = '[data-test-link-to-hcp-banner]';
|
const bannerSelector = '[data-test-link-to-hcp-banner]';
|
||||||
const linkToHcpSelector = '[data-test-link-to-hcp]';
|
const linkToHcpSelector = '[data-test-link-to-hcp]';
|
||||||
|
@ -15,20 +14,10 @@ const linkToHcpModalSelector = '[data-test-link-to-hcp-modal]';
|
||||||
const linkToHcpModalCancelButtonSelector = '[data-test-link-to-hcp-modal-cancel-button]';
|
const linkToHcpModalCancelButtonSelector = '[data-test-link-to-hcp-modal-cancel-button]';
|
||||||
module('Acceptance | link to hcp', function (hooks) {
|
module('Acceptance | link to hcp', function (hooks) {
|
||||||
setupApplicationTest(hooks);
|
setupApplicationTest(hooks);
|
||||||
const correctResourceId =
|
|
||||||
'organization/b4432207-bb9c-438e-a160-b98923efa979/project/4b09958c-fa91-43ab-8029-eb28d8cee9d4/hashicorp.consul.global-network-manager.cluster/test-from-api';
|
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
// clear local storage so we don't have any settings
|
// clear local storage so we don't have any settings
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
this.owner.register(
|
|
||||||
'service:hcp-link-modal',
|
|
||||||
class extends HcpLinkModalService {
|
|
||||||
setResourceId(resourceId) {
|
|
||||||
super.setResourceId(correctResourceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('the banner and nav item are initially displayed on services page', async function (assert) {
|
test('the banner and nav item are initially displayed on services page', async function (assert) {
|
||||||
|
|
|
@ -27,8 +27,6 @@ const modalGenerateTokenMissedPolicyAlertSelector =
|
||||||
'[data-test-link-to-hcp-modal-missed-policy-alert]';
|
'[data-test-link-to-hcp-modal-missed-policy-alert]';
|
||||||
const modalNextButtonSelector = '[data-test-link-to-hcp-modal-next-button]';
|
const modalNextButtonSelector = '[data-test-link-to-hcp-modal-next-button]';
|
||||||
const modalCancelButtonSelector = '[data-test-link-to-hcp-modal-cancel-button]';
|
const modalCancelButtonSelector = '[data-test-link-to-hcp-modal-cancel-button]';
|
||||||
const resourceId =
|
|
||||||
'organization/b4432207-bb9c-438e-a160-b98923efa979/project/4b09958c-fa91-43ab-8029-eb28d8cee9d4/hashicorp.consul.global-network-manager.cluster/test-from-api';
|
|
||||||
|
|
||||||
module('Integration | Component | link-to-hcp-modal', function (hooks) {
|
module('Integration | Component | link-to-hcp-modal', function (hooks) {
|
||||||
let originalClipboardWriteText;
|
let originalClipboardWriteText;
|
||||||
|
@ -71,7 +69,6 @@ module('Integration | Component | link-to-hcp-modal', function (hooks) {
|
||||||
this.owner.register(
|
this.owner.register(
|
||||||
'service:hcp-link-modal',
|
'service:hcp-link-modal',
|
||||||
class Stub extends Service {
|
class Stub extends Service {
|
||||||
resourceId = resourceId;
|
|
||||||
hide = hideModal;
|
hide = hideModal;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,12 +10,9 @@ import { setupRenderingTest } from 'ember-qunit';
|
||||||
import { HCP_PREFIX } from 'consul-ui/helpers/hcp-authentication-link';
|
import { HCP_PREFIX } from 'consul-ui/helpers/hcp-authentication-link';
|
||||||
import { EnvStub } from 'consul-ui/services/env';
|
import { EnvStub } from 'consul-ui/services/env';
|
||||||
|
|
||||||
// organization/b4432207-bb9c-438e-a160-b98923efa979/project/4b09958c-fa91-43ab-8029-eb28d8cee9d4/hashicorp.consul.global-network-manager.cluster/test-from-api
|
|
||||||
const clusterName = 'hello';
|
const clusterName = 'hello';
|
||||||
const clusterVersion = '1.18.0';
|
const clusterVersion = '1.18.0';
|
||||||
const accessMode = 'CONSUL_ACCESS_LEVEL_GLOBAL_READ_WRITE';
|
const accessMode = 'CONSUL_ACCESS_LEVEL_GLOBAL_READ_WRITE';
|
||||||
const projectId = '4b09958c-fa91-43ab-8029-eb28d8cee9d4';
|
|
||||||
const realResourceId = `organization/b4432207-bb9c-438e-a160-b98923efa979/project/${projectId}/hashicorp.consul.global-network-manager.cluster/${clusterName}`;
|
|
||||||
module('Integration | Helper | hcp-authentication-link', function (hooks) {
|
module('Integration | Helper | hcp-authentication-link', function (hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
hooks.beforeEach(function () {
|
hooks.beforeEach(function () {
|
||||||
|
@ -29,9 +26,9 @@ module('Integration | Helper | hcp-authentication-link', function (hooks) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('it makes a URL out of a real resourceId', async function (assert) {
|
test('it makes a URL out of a real resourceId', async function (assert) {
|
||||||
this.resourceId = realResourceId;
|
this.dcName = clusterName;
|
||||||
|
|
||||||
await render(hbs`{{hcp-authentication-link resourceId}}`);
|
await render(hbs`{{hcp-authentication-link dcName}}`);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
this.element.textContent.trim(),
|
this.element.textContent.trim(),
|
||||||
|
@ -39,38 +36,21 @@ module('Integration | Helper | hcp-authentication-link', function (hooks) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it returns correct link with invalid resourceId', async function (assert) {
|
test('it returns correct link without dc name', async function (assert) {
|
||||||
this.resourceId = 'invalid';
|
this.dcName = null;
|
||||||
|
|
||||||
await render(hbs`{{hcp-authentication-link resourceId}}`);
|
await render(hbs`{{hcp-authentication-link dcName}}`);
|
||||||
assert.equal(
|
|
||||||
this.element.textContent.trim(),
|
|
||||||
`${HCP_PREFIX}?cluster_version=${clusterVersion}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// not enough items in id
|
|
||||||
this.resourceId =
|
|
||||||
'`organization/b4432207-bb9c-438e-a160-b98923efa979/project/${projectId}/hashicorp.consul.global-network-manager.cluster`';
|
|
||||||
await render(hbs`{{hcp-authentication-link resourceId}}`);
|
|
||||||
assert.equal(
|
|
||||||
this.element.textContent.trim(),
|
|
||||||
`${HCP_PREFIX}?cluster_version=${clusterVersion}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// value is null
|
|
||||||
this.resourceId = null;
|
|
||||||
await render(hbs`{{hcp-authentication-link resourceId}}`);
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
this.element.textContent.trim(),
|
this.element.textContent.trim(),
|
||||||
`${HCP_PREFIX}?cluster_version=${clusterVersion}`
|
`${HCP_PREFIX}?cluster_version=${clusterVersion}`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it makes a URL out of a real resourceId and accessLevel, if passed', async function (assert) {
|
test('it makes a URL out of a dc name and accessLevel, if passed', async function (assert) {
|
||||||
this.resourceId = realResourceId;
|
this.dcName = clusterName;
|
||||||
this.accessMode = accessMode;
|
this.accessMode = accessMode;
|
||||||
|
|
||||||
await render(hbs`{{hcp-authentication-link resourceId accessMode}}`);
|
await render(hbs`{{hcp-authentication-link dcName accessMode}}`);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
this.element.textContent.trim(),
|
this.element.textContent.trim(),
|
||||||
|
|
Loading…
Reference in New Issue