mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-15 19:17:02 +02:00
* Update browserslist * Add browserslistrc * ember-cli-update --to 3.26, fix conflicts * Run codemodes that start with ember-* * More codemods - before cp* * More codemods (curly data-test-*) * WIP ember-basic-dropdown template errors * updates ember-basic-dropdown and related deps to fix build issues * updates basic dropdown instances to new version API * updates more deps -- ember-template-lint is working again * runs no-implicit-this codemod * creates and runs no-quoteless-attributes codemod * runs angle brackets codemod * updates lint:hbs globs to only touch hbs files * removes yield only templates * creates and runs deprecated args transform * supresses lint error for invokeAction on LinkTo component * resolves remaining ambiguous path lint errors * resolves simple-unless lint errors * adds warnings for deprecated tagName arg on LinkTo components * adds warnings for remaining curly component invocation * updates global template lint rules * resolves remaining template lint errors * disables some ember specfic lint rules that target pre octane patterns * js lint fix run * resolves remaining js lint errors * fixes test run * adds npm-run-all dep * fixes test attribute issues * fixes console acceptance tests * fixes tests * adds yield only wizard/tutorial-active template * fixes more tests * attempts to fix more flaky tests * removes commented out settled in transit test * updates deprecations workflow and adds initializer to filter by version * updates flaky policies acl old test * updates to flaky transit test * bumps ember deps down to LTS version * runs linters after main merge * fixes client count tests after bad merge conflict fixes * fixes client count history test * more updates to lint config * another round of hbs lint fixes after extending stylistic rule * updates lint-staged commands * removes indent eslint rule since it seems to break things * fixes bad attribute in transform-edit-form template * test fixes * fixes enterprise tests * adds changelog * removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters * flaky test fix Co-authored-by: hashishaw <cshaw@hashicorp.com>
105 lines
3.8 KiB
JavaScript
105 lines
3.8 KiB
JavaScript
import Component from '@ember/component';
|
|
import { inject as service } from '@ember/service';
|
|
import parseURL from 'core/utils/parse-url';
|
|
import config from 'open-api-explorer/config/environment';
|
|
|
|
const { APP } = config;
|
|
|
|
const SearchFilterPlugin = () => {
|
|
return {
|
|
fn: {
|
|
opsFilter: (taggedOps, phrase) => {
|
|
// map over the options and filter out operations where the path doesn't match what's typed
|
|
return (
|
|
taggedOps
|
|
.map((tagObj) => {
|
|
let operations = tagObj.get('operations').filter((operationObj) => {
|
|
return operationObj.get('path').includes(phrase);
|
|
});
|
|
return tagObj.set('operations', operations);
|
|
})
|
|
// then traverse again and remove the top level item if there are no operations left after filtering
|
|
.filter((tagObj) => !!tagObj.get('operations').size)
|
|
);
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
const CONFIG = (SwaggerUIBundle, componentInstance, initialFilter) => {
|
|
return {
|
|
dom_id: `#${componentInstance.elementId}-swagger`,
|
|
url: '/v1/sys/internal/specs/openapi',
|
|
deepLinking: false,
|
|
presets: [SwaggerUIBundle.presets.apis],
|
|
plugins: [SwaggerUIBundle.plugins.DownloadUrl, SearchFilterPlugin],
|
|
// 'list' expands tags, but not operations
|
|
docExpansion: 'list',
|
|
operationsSorter: 'alpha',
|
|
filter: initialFilter || true,
|
|
// this makes sure we show the x-vault- options
|
|
showExtensions: true,
|
|
// we don't have any models defined currently
|
|
defaultModelsExpandDepth: -1,
|
|
defaultModelExpandDepth: 1,
|
|
requestInterceptor: (req) => {
|
|
// we need to add vault authorization header
|
|
// and namepace headers for things to work properly
|
|
req.headers['X-Vault-Token'] = componentInstance.auth.currentToken;
|
|
|
|
let namespace = componentInstance.namespaceService.path;
|
|
if (namespace && !APP.NAMESPACE_ROOT_URLS.some((str) => req.url.includes(str))) {
|
|
req.headers['X-Vault-Namespace'] = namespace;
|
|
}
|
|
// we want to link to the right JSON in swagger UI so
|
|
// it's already been pre-pended
|
|
if (!req.loadSpec) {
|
|
let { protocol, host, pathname } = parseURL(req.url);
|
|
//paths in the spec don't have /v1 in them, so we need to add that here
|
|
// http(s): vlt.io:4200 /sys/mounts
|
|
req.url = `${protocol}//${host}/v1${pathname}`;
|
|
}
|
|
return req;
|
|
},
|
|
onComplete: () => {
|
|
componentInstance.set('swaggerLoading', false);
|
|
},
|
|
};
|
|
};
|
|
|
|
export default Component.extend({
|
|
auth: service(),
|
|
namespaceService: service('namespace'),
|
|
initialFilter: null,
|
|
onFilterChange() {},
|
|
swaggerLoading: true,
|
|
|
|
async didInsertElement() {
|
|
const { default: SwaggerUIBundle } = await import('swagger-ui-dist/swagger-ui-bundle.js');
|
|
this._super(...arguments);
|
|
// trim any initial slashes
|
|
let initialFilter = this.initialFilter.replace(/^(\/)+/, '');
|
|
SwaggerUIBundle(CONFIG(SwaggerUIBundle, this, initialFilter));
|
|
},
|
|
|
|
actions: {
|
|
// sets the filter so the query param is updated so we get sharable URLs
|
|
updateFilter(e) {
|
|
this.onFilterChange(e.target.value || '');
|
|
},
|
|
proxyEvent(e) {
|
|
let swaggerInput = this.element.querySelector('.operation-filter-input');
|
|
// if this breaks because of a react upgrade,
|
|
// change this to
|
|
//let originalSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
//originalSetter.call(swaggerInput, e.target.value);
|
|
// see post on triggering react events externally for an explanation of
|
|
// why this works: https://stackoverflow.com/a/46012210
|
|
let evt = new Event('input', { bubbles: true });
|
|
evt.simulated = true;
|
|
swaggerInput.value = e.target.value.replace(/^(\/)+/, '');
|
|
swaggerInput.dispatchEvent(evt);
|
|
},
|
|
},
|
|
});
|