2020-09-30 11:33:01 +00:00
|
|
|
import { set, get } from '@ember/object';
|
2018-10-26 16:36:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import { PRIMARY_KEY } from 'consul-ui/models/intention';
|
2020-10-26 09:30:07 +00:00
|
|
|
|
2018-10-26 16:36:15 +00:00
|
|
|
const modelName = 'intention';
|
2020-10-26 09:30:07 +00:00
|
|
|
export default class IntentionRepository extends RepositoryService {
|
|
|
|
|
|
|
|
managedByCRDs = false;
|
|
|
|
|
|
|
|
getModelName() {
|
2018-10-26 16:36:15 +00:00
|
|
|
return modelName;
|
2020-10-26 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getPrimaryKey() {
|
2018-10-26 16:36:15 +00:00
|
|
|
return PRIMARY_KEY;
|
2020-10-26 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
create(obj) {
|
2020-07-09 09:08:47 +00:00
|
|
|
delete obj.Namespace;
|
2020-10-26 09:30:07 +00:00
|
|
|
return super.create({
|
2020-09-18 10:14:06 +00:00
|
|
|
Action: 'allow',
|
|
|
|
...obj,
|
|
|
|
});
|
2020-10-26 09:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isManagedByCRDs() {
|
|
|
|
if(!this.managedByCRDs) {
|
|
|
|
this.managedByCRDs = this.store.peekAll(this.getModelName())
|
|
|
|
.toArray().some(item => item.IsManagedByCRD);
|
|
|
|
}
|
|
|
|
return this.managedByCRDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
async persist(obj) {
|
|
|
|
const res = await super.persist(...arguments);
|
|
|
|
// if Action is set it means we are an l4 type intention
|
|
|
|
// we don't delete these at a UI level incase the user
|
|
|
|
// would like to switch backwards and forwards between
|
|
|
|
// allow/deny/l7 in the forms, but once its been saved
|
|
|
|
// to the backend we then delete them
|
|
|
|
if (get(res, 'Action.length')) {
|
|
|
|
set(res, 'Permissions', []);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
async findByService(slug, dc, nspace, configuration = {}) {
|
2020-04-16 14:15:45 +00:00
|
|
|
const query = {
|
2020-10-26 09:30:07 +00:00
|
|
|
dc,
|
|
|
|
nspace,
|
2020-09-01 18:13:11 +00:00
|
|
|
filter: `SourceName == "${slug}" or DestinationName == "${slug}" or SourceName == "*" or DestinationName == "*"`,
|
2020-04-16 14:15:45 +00:00
|
|
|
};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
2020-07-17 13:42:45 +00:00
|
|
|
query.uri = configuration.uri;
|
2020-04-16 14:15:45 +00:00
|
|
|
}
|
2020-10-26 09:30:07 +00:00
|
|
|
return this.store.query(this.getModelName(), query);
|
|
|
|
}
|
|
|
|
}
|