Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chor: change cluster name param to have datacenter.name as default value #20644

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default class HcpLinkItemComponent extends Component {

@action
onLinkToConsulCentral() {
this.hcpLinkModal.setResourceId(this.args.linkData?.resourceId);
this.hcpLinkModal.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default class LinkToHcpBannerComponent extends Component {
}
@action
onClusterLink() {
this.hcpLinkModal.setResourceId(this.args.linkData?.resourceId);
this.hcpLinkModal.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
@icon="external-link"
@iconPosition="trailing"
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"
data-test-link-to-hcp-modal-cancel-button
Expand Down
11 changes: 3 additions & 8 deletions ui/packages/consul-ui/app/helpers/hcp-authentication-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ export const HCP_PREFIX =
'https://portal.cloud.hashicorp.com/services/consul/clusters/self-managed/link-existing';
export default class hcpAuthenticationLink extends Helper {
@service('env') env;
compute([resourceId, accessMode], hash) {
compute([datacenterName, accessMode]) {
let url = new URL(HCP_PREFIX);
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 (resourceId) {
// 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 (datacenterName) {
url.searchParams.append('cluster_name', datacenterName);
}

if (clusterVersion) {
Expand Down
4 changes: 0 additions & 4 deletions ui/packages/consul-ui/app/services/hcp-link-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { tracked } from '@glimmer/tracking';

export default class HcpLinkModalService extends Service {
@tracked isModalVisible = false;
@tracked resourceId = null;

show(hcpLinkData) {
this.isModalVisible = true;
Expand All @@ -17,7 +16,4 @@ export default class HcpLinkModalService extends Service {
hide() {
this.isModalVisible = false;
}
setResourceId(resourceId) {
this.resourceId = resourceId;
}
}
11 changes: 0 additions & 11 deletions ui/packages/consul-ui/tests/acceptance/link-to-hcp-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { module, test } from 'qunit';
import { click, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import HcpLinkModalService from 'consul-ui/services/hcp-link-modal';

const bannerSelector = '[data-test-link-to-hcp-banner]';
const linkToHcpSelector = '[data-test-link-to-hcp]';
Expand All @@ -15,20 +14,10 @@ const linkToHcpModalSelector = '[data-test-link-to-hcp-modal]';
const linkToHcpModalCancelButtonSelector = '[data-test-link-to-hcp-modal-cancel-button]';
module('Acceptance | link to hcp', function (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 () {
// clear local storage so we don't have any settings
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { setupRenderingTest } from 'ember-qunit';
import { HCP_PREFIX } from 'consul-ui/helpers/hcp-authentication-link';
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 clusterVersion = '1.18.0';
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) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
Expand All @@ -29,48 +26,31 @@ module('Integration | Helper | hcp-authentication-link', function (hooks) {
);
});
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(
this.element.textContent.trim(),
`${HCP_PREFIX}?cluster_name=${clusterName}&cluster_version=${clusterVersion}`
);
});

test('it returns correct link with invalid resourceId', async function (assert) {
this.resourceId = 'invalid';
test('it returns correct link without dc name', async function (assert) {
this.dcName = null;

await render(hbs`{{hcp-authentication-link resourceId}}`);
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}}`);
await render(hbs`{{hcp-authentication-link dcName}}`);
assert.equal(
this.element.textContent.trim(),
`${HCP_PREFIX}?cluster_version=${clusterVersion}`
);
});

test('it makes a URL out of a real resourceId and accessLevel, if passed', async function (assert) {
this.resourceId = realResourceId;
test('it makes a URL out of a dc name and accessLevel, if passed', async function (assert) {
this.dcName = clusterName;
this.accessMode = accessMode;

await render(hbs`{{hcp-authentication-link resourceId accessMode}}`);
await render(hbs`{{hcp-authentication-link dcName accessMode}}`);

assert.equal(
this.element.textContent.trim(),
Expand Down
Loading