2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-15 15:34:54 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { get } from '@ember/object';
|
2020-10-09 20:31:15 +00:00
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class UiConfigService extends Service {
|
2020-12-15 15:34:54 +00:00
|
|
|
@service('env') env;
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:nspace/:dc/ui-config/:path')
|
|
|
|
async findByPath(params) {
|
|
|
|
return get(this.get(), params.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
@dataSource('/:partition/:nspace/:dc/notfound/:path')
|
|
|
|
async parsePath(params) {
|
|
|
|
return params.path.split('/').reduce((prev, item, i) => {
|
|
|
|
switch (true) {
|
|
|
|
case item.startsWith('~'):
|
|
|
|
prev.nspace = item.substr(1);
|
|
|
|
break;
|
2021-12-13 15:39:56 +00:00
|
|
|
case item.startsWith('_'):
|
2021-09-15 18:50:11 +00:00
|
|
|
prev.partition = item.substr(1);
|
|
|
|
break;
|
|
|
|
case typeof prev.dc === 'undefined':
|
|
|
|
prev.dc = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return prev;
|
|
|
|
}, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
@dataSource('/:partition/:nspace/:dc/ui-config')
|
|
|
|
async get() {
|
|
|
|
return this.env.var('CONSUL_UI_CONFIG');
|
2020-12-15 15:34:54 +00:00
|
|
|
}
|
2020-10-09 20:31:15 +00:00
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
// @deprecated
|
|
|
|
getSync() {
|
2020-12-15 15:34:54 +00:00
|
|
|
return this.env.var('CONSUL_UI_CONFIG');
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|