mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 13:26:07 +00:00
5fb9df1640
* Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import Serializer from './application';
|
|
import { inject as service } from '@ember/service';
|
|
import { get } from '@ember/object';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/intention';
|
|
|
|
export default class IntentionSerializer extends Serializer {
|
|
@service('encoder') encoder;
|
|
|
|
primaryKey = PRIMARY_KEY;
|
|
slugKey = SLUG_KEY;
|
|
|
|
init() {
|
|
super.init(...arguments);
|
|
this.uri = this.encoder.uriTag();
|
|
}
|
|
|
|
ensureID(item) {
|
|
if (!get(item, 'ID.length')) {
|
|
item.Legacy = false;
|
|
} else {
|
|
item.Legacy = true;
|
|
item.LegacyID = item.ID;
|
|
}
|
|
|
|
if (item.SourcePeer) {
|
|
item.ID = this
|
|
.uri`peer:${item.SourcePeer}:${item.SourceNS}:${item.SourceName}:${item.DestinationPartition}:${item.DestinationNS}:${item.DestinationName}`;
|
|
} else {
|
|
item.ID = this
|
|
.uri`${item.SourcePartition}:${item.SourceNS}:${item.SourceName}:${item.DestinationPartition}:${item.DestinationNS}:${item.DestinationName}`;
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
respondForQuery(respond, query) {
|
|
return super.respondForQuery(
|
|
(cb) =>
|
|
respond((headers, body) => {
|
|
return cb(
|
|
headers,
|
|
body.map((item) => this.ensureID(item))
|
|
);
|
|
}),
|
|
query
|
|
);
|
|
}
|
|
|
|
respondForQueryRecord(respond, query) {
|
|
return super.respondForQueryRecord(
|
|
(cb) =>
|
|
respond((headers, body) => {
|
|
body = this.ensureID(body);
|
|
return cb(headers, body);
|
|
}),
|
|
query
|
|
);
|
|
}
|
|
|
|
respondForCreateRecord(respond, serialized, data) {
|
|
const slugKey = this.slugKey;
|
|
const primaryKey = this.primaryKey;
|
|
return respond((headers, body) => {
|
|
body = data;
|
|
body.ID = this
|
|
.uri`${serialized.SourcePartition}:${serialized.SourceNS}:${serialized.SourceName}:${serialized.DestinationPartition}:${serialized.DestinationNS}:${serialized.DestinationName}`;
|
|
return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body);
|
|
});
|
|
}
|
|
|
|
respondForUpdateRecord(respond, serialized, data) {
|
|
const slugKey = this.slugKey;
|
|
const primaryKey = this.primaryKey;
|
|
return respond((headers, body) => {
|
|
body = data;
|
|
body.LegacyID = body.ID;
|
|
body.ID = serialized.ID;
|
|
return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body);
|
|
});
|
|
}
|
|
}
|