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
|
|
|
*/
|
|
|
|
|
2019-05-01 18:09:29 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2021-09-15 18:50:11 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2019-05-01 18:09:29 +00:00
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/role';
|
2021-02-23 08:56:42 +00:00
|
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
2019-05-01 18:09:29 +00:00
|
|
|
|
|
|
|
const MODEL_NAME = 'role';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class RoleService extends RepositoryService {
|
2021-09-15 18:50:11 +00:00
|
|
|
@service('form') form;
|
2020-11-09 09:25:35 +00:00
|
|
|
getModelName() {
|
2019-05-01 18:09:29 +00:00
|
|
|
return MODEL_NAME;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrimaryKey() {
|
2019-05-01 18:09:29 +00:00
|
|
|
return PRIMARY_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getSlugKey() {
|
2019-05-01 18:09:29 +00:00
|
|
|
return SLUG_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/roles')
|
|
|
|
async findAll() {
|
|
|
|
return super.findAll(...arguments);
|
2021-02-23 08:56:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
@dataSource('/:partition/:ns/:dc/role/:id')
|
|
|
|
async findBySlug(params) {
|
|
|
|
let item;
|
|
|
|
if (params.id === '') {
|
|
|
|
item = await this.create({
|
|
|
|
Datacenter: params.dc,
|
|
|
|
Partition: params.partition,
|
|
|
|
Namespace: params.ns,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
item = await super.findBySlug(...arguments);
|
|
|
|
}
|
2022-09-15 08:43:17 +00:00
|
|
|
return this.form.form(this.getModelName()).setData(item).getData();
|
2021-02-23 08:56:42 +00:00
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|