Files
threshold-ui/ui/desktop/app/routes/scopes.js
T
CyberCoveandClaude Sonnet 5.5 89089dbb9a Rebrand Boundary UI to Threshold; neutralize HashiCorp update/phone-home endpoints
- Product name, app id, installer names, translations, titles -> Threshold
- Desktop: look for threshold CLI first, then boundary; migrate legacy
  Boundary user-data dir; updater/release lookups disabled unless configured
- Remove HashiCorp/IBM logos and art (plain placeholder mark), GitHub
  release workflows and HashiCorp release metadata
- Add NOTICE and README 'About this fork'

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 12:24:16 -07:00

108 lines
3.5 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { TrackedArray } from 'tracked-built-ins';
import config from 'desktop/config/environment';
export default class ScopesRoute extends Route {
// =services
@service store;
// =methods
async beforeModel() {
this.isPaginationSupported = false;
const adapter = this.store.adapterFor('application');
const scopeSchema = this.store.modelFor('scope');
try {
const scopesCheck = await adapter.query(this.store, scopeSchema, {
page_size: 1,
});
// we use the response_type to determine if pagination is supported
// and this will still pass even if there are no scopes returned
if (scopesCheck.response_type) {
this.isPaginationSupported = true;
}
} catch {
// no op
}
}
/**
* Attempt to load all scopes from the API. This is allowed
* to fail, since in some cases the user may not have permission to read a
* scope directly, but may have permission to read resources under it.
* If scopes fails to load, we still proceed using an empty array.
* @param {object} params
* @param {string} params.scope_id
* @return {Promise{[ScopeModel]}}
*/
async model() {
// NOTE: In the absence of a `scope_id` query parameter, this endpoint is
// expected to default to the global scope, thus returning org scopes.
return this.store.query('scope', {}).catch(() => new TrackedArray([]));
}
/**
* Adds `isPaginationSupported`, `downloadLink`, and
* `downloadError` to the controller.
* @param {Controller} controller
*/
async setupController(controller) {
super.setupController(...arguments);
controller.set('isPaginationSupported', this.isPaginationSupported);
let downloadLink;
let downloadError = false;
if (!this.isPaginationSupported) {
// Threshold has no default release metadata API (the upstream
// HashiCorp releases API is intentionally not contacted). When
// `config.releases.metadataUrl` is empty we skip the request and direct
// the user to the releases page instead.
const metaDataUrl = config.releases?.metadataUrl;
const { isWindows, isMac, isLinux } =
await window.desktop.system.checkOS();
try {
if (!metaDataUrl) throw new Error('No release metadata URL');
const metaDataResponse = await fetch(metaDataUrl);
const metaData = await metaDataResponse.json();
if (isWindows) {
downloadLink = this.extractOsSpecificUrl(metaData, 'windows', '.zip');
} else if (isMac) {
downloadLink = this.extractOsSpecificUrl(metaData, 'darwin', '.dmg');
} else if (isLinux) {
downloadLink = this.extractOsSpecificUrl(metaData, 'linux', '.deb');
}
if (!downloadLink) throw new Error('No build found');
} catch {
// this is a catch for any errors that may occur and shows the user
// an error alert directing them to the releases page
downloadError = true;
}
}
controller.set('releasesPageUrl', config.releases?.releasesPageUrl);
controller.set('downloadLink', downloadLink);
controller.set('downloadError', downloadError);
}
extractOsSpecificUrl(metaData, os, fileExtension) {
const build = metaData.builds.find(
(build) => build.os === os && build.url.endsWith(fileExtension),
);
return build?.url;
}
}