ui: Move ember-data classes to use native JS classes/decorators (#9136)

* ui: Upgrade ember-data models to use native classes/decorators

* ui: Update remaining ember-data imports

* ui: Move ember-data Adapters to use native classes

* ui: Upgrade serializers to native classes/decorators

* ui: remove meta from roles, they never had it to start with
pull/9139/head
John Cowen 2020-11-09 17:29:12 +00:00 committed by GitHub
parent 2ef2723507
commit c8e40ee0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 1008 additions and 939 deletions

View File

@ -4,16 +4,17 @@ import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
// The old ACL system doesn't support the `ns=` query param // The old ACL system doesn't support the `ns=` query param
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class AclAdapter extends Adapter {
requestForQuery: function(request, { dc, index }) { requestForQuery(request, { dc, index }) {
// https://www.consul.io/api/acl.html#list-acls // https://www.consul.io/api/acl.html#list-acls
return request` return request`
GET /v1/acl/list?${{ dc }} GET /v1/acl/list?${{ dc }}
${{ index }} ${{ index }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, index, id }) {
requestForQueryRecord(request, { dc, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -23,16 +24,18 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
// https://www.consul.io/api/acl.html#create-acl-token // https://www.consul.io/api/acl.html#create-acl-token
return request` return request`
PUT /v1/acl/create?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} PUT /v1/acl/create?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }}
${serialized} ${serialized}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
// the id is in the data, don't add it into the URL // the id is in the data, don't add it into the URL
// https://www.consul.io/api/acl.html#update-acl-token // https://www.consul.io/api/acl.html#update-acl-token
return request` return request`
@ -40,20 +43,23 @@ export default Adapter.extend({
${serialized} ${serialized}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
// https://www.consul.io/api/acl.html#delete-acl-token // https://www.consul.io/api/acl.html#delete-acl-token
return request` return request`
PUT /v1/acl/destroy/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} PUT /v1/acl/destroy/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }}
`; `;
}, }
requestForCloneRecord: function(request, serialized, data) {
requestForCloneRecord(request, serialized, data) {
// https://www.consul.io/api/acl.html#clone-acl-token // https://www.consul.io/api/acl.html#clone-acl-token
return request` return request`
PUT /v1/acl/clone/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} PUT /v1/acl/clone/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }}
`; `;
}, }
clone: function(store, type, id, snapshot) {
clone(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, unserialized) { function(adapter, request, serialized, unserialized) {
return adapter.requestForCloneRecord(request, serialized, unserialized); return adapter.requestForCloneRecord(request, serialized, unserialized);
@ -64,5 +70,5 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
}); }

View File

@ -3,17 +3,20 @@ import { inject as service } from '@ember/service';
export const DATACENTER_QUERY_PARAM = 'dc'; export const DATACENTER_QUERY_PARAM = 'dc';
export const NSPACE_QUERY_PARAM = 'ns'; export const NSPACE_QUERY_PARAM = 'ns';
export default Adapter.extend({
client: service('client/http'), export default class ApplicationAdapter extends Adapter {
env: service('env'), @service('client/http') client;
formatNspace: function(nspace) { @service('env') env;
formatNspace(nspace) {
if (this.env.env('CONSUL_NSPACES_ENABLED')) { if (this.env.env('CONSUL_NSPACES_ENABLED')) {
return nspace !== '' ? { [NSPACE_QUERY_PARAM]: nspace } : undefined; return nspace !== '' ? { [NSPACE_QUERY_PARAM]: nspace } : undefined;
} }
}, }
formatDatacenter: function(dc) {
formatDatacenter(dc) {
return { return {
[DATACENTER_QUERY_PARAM]: dc, [DATACENTER_QUERY_PARAM]: dc,
}; };
}, }
}); }

View File

@ -1,12 +1,12 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class CoordinateAdapter extends Adapter {
requestForQuery: function(request, { dc, index, uri }) { requestForQuery(request, { dc, index, uri }) {
return request` return request`
GET /v1/coordinate/nodes?${{ dc }} GET /v1/coordinate/nodes?${{ dc }}
X-Request-ID: ${uri} X-Request-ID: ${uri}
${{ index }} ${{ index }}
`; `;
}, }
}); }

View File

@ -1,9 +1,9 @@
import Adapter from './application'; import Adapter from './application';
export default Adapter.extend({ export default class DcAdapter extends Adapter {
requestForQuery: function(request) { requestForQuery(request) {
return request` return request`
GET /v1/catalog/datacenters GET /v1/catalog/datacenters
`; `;
}, }
}); }

View File

@ -1,8 +1,8 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class DiscoveryChainAdapter extends Adapter {
requestForQueryRecord: function(request, { dc, ns, index, id, uri }) { requestForQueryRecord(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -15,5 +15,5 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
}); }

View File

@ -1,7 +1,7 @@
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import Adapter from 'ember-data/adapter'; import Adapter from '@ember-data/adapter';
import AdapterError from '@ember-data/adapter/error';
import { import {
AdapterError,
AbortError, AbortError,
TimeoutError, TimeoutError,
ServerError, ServerError,
@ -10,7 +10,7 @@ import {
NotFoundError, NotFoundError,
ConflictError, ConflictError,
InvalidError, InvalidError,
} from 'ember-data/adapters/errors'; } from '@ember-data/adapter/error';
// TODO These are now exactly the same, apart from the fact that one uses // TODO These are now exactly the same, apart from the fact that one uses
// `serialized, unserialized` and the other just `query` // `serialized, unserialized` and the other just `query`
@ -40,9 +40,10 @@ const write = function(adapter, modelName, type, snapshot) {
modelName modelName
); );
}; };
export default Adapter.extend({ export default class HttpAdapter extends Adapter {
client: service('client/http'), @service('client/http') client;
rpc: function(req, resp, obj, modelName) {
rpc(req, resp, obj, modelName) {
const client = this.client; const client = this.client;
const store = this.store; const store = this.store;
const adapter = this; const adapter = this;
@ -79,8 +80,9 @@ export default Adapter.extend({
// .catch(function(e) { // .catch(function(e) {
// return Promise.reject(e); // return Promise.reject(e);
// }); // });
}, }
error: function(err) {
error(err) {
if (err instanceof TypeError) { if (err instanceof TypeError) {
throw err; throw err;
} }
@ -132,23 +134,29 @@ export default Adapter.extend({
// Consider changing this to return the error and then // Consider changing this to return the error and then
// throw from the call site instead // throw from the call site instead
throw error; throw error;
}, }
query: function(store, type, query) {
query(store, type, query) {
return read(this, type.modelName, 'Query', query); return read(this, type.modelName, 'Query', query);
}, }
queryRecord: function(store, type, query) {
queryRecord(store, type, query) {
return read(this, type.modelName, 'QueryRecord', query); return read(this, type.modelName, 'QueryRecord', query);
}, }
findAll: function(store, type) {
findAll(store, type) {
return read(this, type.modelName, 'FindAll'); return read(this, type.modelName, 'FindAll');
}, }
createRecord: function(store, type, snapshot) {
createRecord(store, type, snapshot) {
return write(this, type.modelName, 'CreateRecord', snapshot); return write(this, type.modelName, 'CreateRecord', snapshot);
}, }
updateRecord: function(store, type, snapshot) {
updateRecord(store, type, snapshot) {
return write(this, type.modelName, 'UpdateRecord', snapshot); return write(this, type.modelName, 'UpdateRecord', snapshot);
}, }
deleteRecord: function(store, type, snapshot) {
deleteRecord(store, type, snapshot) {
return write(this, type.modelName, 'DeleteRecord', snapshot); return write(this, type.modelName, 'DeleteRecord', snapshot);
}, }
}); }

View File

@ -1,12 +1,13 @@
import Adapter, { DATACENTER_QUERY_PARAM as API_DATACENTER_KEY } from './application'; import Adapter, { DATACENTER_QUERY_PARAM as API_DATACENTER_KEY } from './application';
import { get } from '@ember/object'; import { get } from '@ember/object';
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
// Intentions use SourceNS and DestinationNS properties for namespacing
// so we don't need to add the `?ns=` anywhere here // Intentions use SourceNS and DestinationNS properties for namespacing so we
// don't need to add the `?ns=` anywhere here
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class IntentionAdapter extends Adapter {
requestForQuery: function(request, { dc, filter, index, uri }) { requestForQuery(request, { dc, filter, index, uri }) {
return request` return request`
GET /v1/connect/intentions?${{ dc }} GET /v1/connect/intentions?${{ dc }}
X-Request-ID: ${uri}${ X-Request-ID: ${uri}${
@ -21,13 +22,15 @@ export default Adapter.extend({
filter, filter,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, index, id }) {
requestForQueryRecord(request, { dc, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
// get the information we need from the id, which has been previously encoded // get the information we need from the id, which has been previously
// encoded
const [SourceNS, SourceName, DestinationNS, DestinationName] = id const [SourceNS, SourceName, DestinationNS, DestinationName] = id
.split(':') .split(':')
.map(decodeURIComponent); .map(decodeURIComponent);
@ -42,8 +45,9 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
const body = { const body = {
SourceNS: serialized.SourceNS, SourceNS: serialized.SourceNS,
DestinationNS: serialized.DestinationNS, DestinationNS: serialized.DestinationNS,
@ -72,14 +76,16 @@ export default Adapter.extend({
${body} ${body}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
// you can no longer save Destinations // you can no longer save Destinations
delete serialized.DestinationNS; delete serialized.DestinationNS;
delete serialized.DestinationName; delete serialized.DestinationName;
return this.requestForCreateRecord(...arguments); return this.requestForCreateRecord(...arguments);
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
return request` return request`
DELETE /v1/connect/intentions/exact?${{ DELETE /v1/connect/intentions/exact?${{
source: `${data.SourceNS}/${data.SourceName}`, source: `${data.SourceNS}/${data.SourceName}`,
@ -87,5 +93,5 @@ export default Adapter.extend({
[API_DATACENTER_KEY]: data[DATACENTER_KEY], [API_DATACENTER_KEY]: data[DATACENTER_KEY],
}} }}
`; `;
}, }
}); }

View File

@ -1,16 +1,15 @@
import Adapter from './application'; import Adapter from './application';
import isFolder from 'consul-ui/utils/isFolder'; import isFolder from 'consul-ui/utils/isFolder';
import keyToArray from 'consul-ui/utils/keyToArray'; import keyToArray from 'consul-ui/utils/keyToArray';
import { SLUG_KEY } from 'consul-ui/models/kv'; import { SLUG_KEY } from 'consul-ui/models/kv';
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
const API_KEYS_KEY = 'keys'; const API_KEYS_KEY = 'keys';
export default Adapter.extend({
requestForQuery: function(request, { dc, ns, index, id, separator }) { export default class KvAdapter extends Adapter {
requestForQuery(request, { dc, ns, index, id, separator }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -22,8 +21,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id }) {
requestForQueryRecord(request, { dc, ns, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -35,10 +35,11 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
// TODO: Should we replace text/plain here with x-www-form-encoded?
// See https://github.com/hashicorp/consul/issues/3804 // TODO: Should we replace text/plain here with x-www-form-encoded? See
requestForCreateRecord: function(request, serialized, data) { // https://github.com/hashicorp/consul/issues/3804
requestForCreateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
...this.formatNspace(data[NSPACE_KEY]), ...this.formatNspace(data[NSPACE_KEY]),
@ -49,8 +50,9 @@ export default Adapter.extend({
${serialized} ${serialized}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
flags: data.Flags, flags: data.Flags,
@ -62,8 +64,9 @@ export default Adapter.extend({
${serialized} ${serialized}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
let recurse; let recurse;
if (isFolder(data[SLUG_KEY])) { if (isFolder(data[SLUG_KEY])) {
recurse = null; recurse = null;
@ -76,5 +79,5 @@ export default Adapter.extend({
return request` return request`
DELETE /v1/kv/${keyToArray(data[SLUG_KEY])}?${params} DELETE /v1/kv/${keyToArray(data[SLUG_KEY])}?${params}
`; `;
}, }
}); }

View File

@ -1,15 +1,18 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({
requestForQuery: function(request, { dc, index, id, uri }) { export default class NodeAdapter extends Adapter {
requestForQuery(request, { dc, index, id, uri }) {
return request` return request`
GET /v1/internal/ui/nodes?${{ dc }} GET /v1/internal/ui/nodes?${{ dc }}
X-Request-ID: ${uri} X-Request-ID: ${uri}
${{ index }} ${{ index }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, index, id, uri }) {
requestForQueryRecord(request, { dc, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -19,15 +22,17 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
requestForQueryLeader: function(request, { dc, uri }) {
requestForQueryLeader(request, { dc, uri }) {
return request` return request`
GET /v1/status/leader?${{ dc }} GET /v1/status/leader?${{ dc }}
X-Request-ID: ${uri} X-Request-ID: ${uri}
Refresh: 30 Refresh: 30
`; `;
}, }
queryLeader: function(store, type, id, snapshot) {
queryLeader(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, unserialized) { function(adapter, request, serialized, unserialized) {
return adapter.requestForQueryLeader(request, serialized, unserialized); return adapter.requestForQueryLeader(request, serialized, unserialized);
@ -38,5 +43,5 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
}); }

View File

@ -2,16 +2,17 @@ import Adapter from './application';
import { SLUG_KEY } from 'consul-ui/models/nspace'; import { SLUG_KEY } from 'consul-ui/models/nspace';
// namespaces aren't categorized by datacenter, therefore no dc // namespaces aren't categorized by datacenter, therefore no dc
export default Adapter.extend({ export default class NspaceAdapter extends Adapter {
requestForQuery: function(request, { index, uri }) { requestForQuery(request, { index, uri }) {
return request` return request`
GET /v1/namespaces GET /v1/namespaces
X-Request-ID: ${uri} X-Request-ID: ${uri}
${{ index }} ${{ index }}
`; `;
}, }
requestForQueryRecord: function(request, { index, id }) {
requestForQueryRecord(request, { index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an name'); throw new Error('You must specify an name');
} }
@ -20,8 +21,9 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
return request` return request`
PUT /v1/namespace/${data[SLUG_KEY]} PUT /v1/namespace/${data[SLUG_KEY]}
@ -34,8 +36,9 @@ export default Adapter.extend({
}, },
}} }}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
return request` return request`
PUT /v1/namespace/${data[SLUG_KEY]} PUT /v1/namespace/${data[SLUG_KEY]}
@ -47,13 +50,15 @@ export default Adapter.extend({
}, },
}} }}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
return request` return request`
DELETE /v1/namespace/${data[SLUG_KEY]} DELETE /v1/namespace/${data[SLUG_KEY]}
`; `;
}, }
requestForAuthorize: function(request, { dc, ns, index }) {
requestForAuthorize(request, { dc, ns, index }) {
return request` return request`
POST /v1/internal/acl/authorize?${{ dc, ns, index }} POST /v1/internal/acl/authorize?${{ dc, ns, index }}
@ -64,8 +69,9 @@ export default Adapter.extend({
}, },
]} ]}
`; `;
}, }
authorize: function(store, type, id, snapshot) {
authorize(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, unserialized) { function(adapter, request, serialized, unserialized) {
return adapter.requestForAuthorize(request, serialized, unserialized); return adapter.requestForAuthorize(request, serialized, unserialized);
@ -79,5 +85,5 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
}); }

View File

@ -1,6 +1,5 @@
import Adapter from './application'; import Adapter from './application';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { env } from 'consul-ui/env'; import { env } from 'consul-ui/env';
import nonEmptySet from 'consul-ui/utils/non-empty-set'; import nonEmptySet from 'consul-ui/utils/non-empty-set';
@ -10,9 +9,11 @@ if (env('CONSUL_NSPACES_ENABLED')) {
} else { } else {
Namespace = () => ({}); Namespace = () => ({});
} }
export default Adapter.extend({
env: service('env'), export default class OidcProviderAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, uri }) { @service('env') env;
requestForQuery(request, { dc, ns, index, uri }) {
return request` return request`
GET /v1/internal/ui/oidc-auth-methods?${{ dc }} GET /v1/internal/ui/oidc-auth-methods?${{ dc }}
X-Request-ID: ${uri} X-Request-ID: ${uri}
@ -22,8 +23,9 @@ export default Adapter.extend({
...this.formatNspace(ns), ...this.formatNspace(ns),
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, id }) {
requestForQueryRecord(request, { dc, ns, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -37,8 +39,9 @@ export default Adapter.extend({
RedirectURI: `${this.env.var('CONSUL_BASE_UI_URL')}/oidc/callback`, RedirectURI: `${this.env.var('CONSUL_BASE_UI_URL')}/oidc/callback`,
}} }}
`; `;
}, }
requestForAuthorize: function(request, { dc, ns, id, code, state }) {
requestForAuthorize(request, { dc, ns, id, code, state }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -59,8 +62,9 @@ export default Adapter.extend({
State: state, State: state,
}} }}
`; `;
}, }
requestForLogout: function(request, { id }) {
requestForLogout(request, { id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -69,8 +73,9 @@ export default Adapter.extend({
Cache-Control: no-store Cache-Control: no-store
X-Consul-Token: ${id} X-Consul-Token: ${id}
`; `;
}, }
authorize: function(store, type, id, snapshot) {
authorize(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, unserialized) { function(adapter, request, serialized, unserialized) {
return adapter.requestForAuthorize(request, serialized, unserialized); return adapter.requestForAuthorize(request, serialized, unserialized);
@ -81,8 +86,9 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
logout: function(store, type, id, snapshot) {
logout(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, unserialized) { function(adapter, request, serialized, unserialized) {
return adapter.requestForLogout(request, serialized, unserialized); return adapter.requestForLogout(request, serialized, unserialized);
@ -94,5 +100,5 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
}); }

View File

@ -1,9 +1,7 @@
import Adapter from './application'; import Adapter from './application';
import { SLUG_KEY } from 'consul-ui/models/policy'; import { SLUG_KEY } from 'consul-ui/models/policy';
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
import { env } from 'consul-ui/env'; import { env } from 'consul-ui/env';
import nonEmptySet from 'consul-ui/utils/non-empty-set'; import nonEmptySet from 'consul-ui/utils/non-empty-set';
@ -15,8 +13,8 @@ if (env('CONSUL_NSPACES_ENABLED')) {
} }
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class PolicyAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, id }) { requestForQuery(request, { dc, ns, index, id }) {
return request` return request`
GET /v1/acl/policies?${{ dc }} GET /v1/acl/policies?${{ dc }}
@ -25,8 +23,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id }) {
requestForQueryRecord(request, { dc, ns, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -38,8 +37,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
}; };
@ -54,8 +54,9 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
}; };
@ -70,8 +71,9 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
...this.formatNspace(data[NSPACE_KEY]), ...this.formatNspace(data[NSPACE_KEY]),
@ -79,5 +81,5 @@ export default Adapter.extend({
return request` return request`
DELETE /v1/acl/policy/${data[SLUG_KEY]}?${params} DELETE /v1/acl/policy/${data[SLUG_KEY]}?${params}
`; `;
}, }
}); }

View File

@ -1,7 +1,7 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class ProxyAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, id, uri }) { requestForQuery(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -15,5 +15,5 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
}); }

View File

@ -1,9 +1,7 @@
import Adapter from './application'; import Adapter from './application';
import { SLUG_KEY } from 'consul-ui/models/role'; import { SLUG_KEY } from 'consul-ui/models/role';
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
import { env } from 'consul-ui/env'; import { env } from 'consul-ui/env';
import nonEmptySet from 'consul-ui/utils/non-empty-set'; import nonEmptySet from 'consul-ui/utils/non-empty-set';
@ -13,9 +11,10 @@ if (env('CONSUL_NSPACES_ENABLED')) {
} else { } else {
Namespace = () => ({}); Namespace = () => ({});
} }
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class RoleAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, id }) { requestForQuery(request, { dc, ns, index, id }) {
return request` return request`
GET /v1/acl/roles?${{ dc }} GET /v1/acl/roles?${{ dc }}
@ -24,8 +23,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id }) {
requestForQueryRecord(request, { dc, ns, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -37,8 +37,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
}; };
@ -54,8 +55,9 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
requestForUpdateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
}; };
@ -71,8 +73,9 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
...this.formatNspace(data[NSPACE_KEY]), ...this.formatNspace(data[NSPACE_KEY]),
@ -80,5 +83,5 @@ export default Adapter.extend({
return request` return request`
DELETE /v1/acl/role/${data[SLUG_KEY]}?${params} DELETE /v1/acl/role/${data[SLUG_KEY]}?${params}
`; `;
}, }
}); }

View File

@ -1,7 +1,8 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class ServiceInstanceAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, id, uri }) { requestForQuery(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -15,10 +16,11 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id, uri }) {
requestForQueryRecord(request, { dc, ns, index, id, uri }) {
// query and queryRecord both use the same endpoint // query and queryRecord both use the same endpoint
// they are just serialized differently // they are just serialized differently
return this.requestForQuery(...arguments); return this.requestForQuery(...arguments);
}, }
}); }

View File

@ -1,7 +1,8 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class ServiceAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, gateway, uri }) { requestForQuery(request, { dc, ns, index, gateway, uri }) {
if (typeof gateway !== 'undefined') { if (typeof gateway !== 'undefined') {
return request` return request`
GET /v1/internal/ui/gateway-services-nodes/${gateway}?${{ dc }} GET /v1/internal/ui/gateway-services-nodes/${gateway}?${{ dc }}
@ -24,8 +25,9 @@ export default Adapter.extend({
}} }}
`; `;
} }
}, }
requestForQueryRecord: function(request, { dc, ns, index, id, uri }) {
requestForQueryRecord(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -38,5 +40,5 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
}); }

View File

@ -5,8 +5,8 @@ import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class SessionAdapter extends Adapter {
requestForQuery: function(request, { dc, ns, index, id, uri }) { requestForQuery(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -19,8 +19,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id }) {
requestForQueryRecord(request, { dc, ns, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -32,8 +33,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
...this.formatNspace(data[NSPACE_KEY]), ...this.formatNspace(data[NSPACE_KEY]),
@ -41,5 +43,5 @@ export default Adapter.extend({
return request` return request`
PUT /v1/session/destroy/${data[SLUG_KEY]}?${params} PUT /v1/session/destroy/${data[SLUG_KEY]}?${params}
`; `;
}, }
}); }

View File

@ -1,10 +1,8 @@
import Adapter from './application'; import Adapter from './application';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { SLUG_KEY } from 'consul-ui/models/token'; import { SLUG_KEY } from 'consul-ui/models/token';
import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc'; import { FOREIGN_KEY as DATACENTER_KEY } from 'consul-ui/models/dc';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
import { env } from 'consul-ui/env'; import { env } from 'consul-ui/env';
import nonEmptySet from 'consul-ui/utils/non-empty-set'; import nonEmptySet from 'consul-ui/utils/non-empty-set';
@ -14,11 +12,12 @@ if (env('CONSUL_NSPACES_ENABLED')) {
} else { } else {
Namespace = () => ({}); Namespace = () => ({});
} }
// TODO: Update to use this.formatDatacenter()
export default Adapter.extend({
store: service('store'),
requestForQuery: function(request, { dc, ns, index, role, policy }) { // TODO: Update to use this.formatDatacenter()
export default class TokenAdapter extends Adapter {
@service('store') store;
requestForQuery(request, { dc, ns, index, role, policy }) {
return request` return request`
GET /v1/acl/tokens?${{ role, policy, dc }} GET /v1/acl/tokens?${{ role, policy, dc }}
@ -27,8 +26,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForQueryRecord: function(request, { dc, ns, index, id }) {
requestForQueryRecord(request, { dc, ns, index, id }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -40,8 +40,9 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
requestForCreateRecord: function(request, serialized, data) {
requestForCreateRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
}; };
@ -58,11 +59,12 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForUpdateRecord: function(request, serialized, data) {
// TODO: here we check data['Rules'] not serialized['Rules'] requestForUpdateRecord(request, serialized, data) {
// data.Rules is not undefined, and serialized.Rules is not null // TODO: here we check data['Rules'] not serialized['Rules'] data.Rules is
// revisit this at some point we should probably use serialized here // not undefined, and serialized.Rules is not null revisit this at some
// point we should probably use serialized here
// If a token has Rules, use the old API // If a token has Rules, use the old API
if (typeof data['Rules'] !== 'undefined') { if (typeof data['Rules'] !== 'undefined') {
@ -90,8 +92,9 @@ export default Adapter.extend({
...Namespace(serialized.Namespace), ...Namespace(serialized.Namespace),
}} }}
`; `;
}, }
requestForDeleteRecord: function(request, serialized, data) {
requestForDeleteRecord(request, serialized, data) {
const params = { const params = {
...this.formatDatacenter(data[DATACENTER_KEY]), ...this.formatDatacenter(data[DATACENTER_KEY]),
...this.formatNspace(data[NSPACE_KEY]), ...this.formatNspace(data[NSPACE_KEY]),
@ -99,8 +102,9 @@ export default Adapter.extend({
return request` return request`
DELETE /v1/acl/token/${data[SLUG_KEY]}?${params} DELETE /v1/acl/token/${data[SLUG_KEY]}?${params}
`; `;
}, }
requestForSelf: function(request, serialized, { dc, index, secret }) {
requestForSelf(request, serialized, { dc, index, secret }) {
// TODO: Change here and elsewhere to use Authorization Bearer Token // TODO: Change here and elsewhere to use Authorization Bearer Token
// https://github.com/hashicorp/consul/pull/4502 // https://github.com/hashicorp/consul/pull/4502
return request` return request`
@ -110,8 +114,9 @@ export default Adapter.extend({
${{ index }} ${{ index }}
`; `;
}, }
requestForCloneRecord: function(request, serialized, data) {
requestForCloneRecord(request, serialized, data) {
// this uses snapshots // this uses snapshots
const id = data[SLUG_KEY]; const id = data[SLUG_KEY];
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
@ -124,12 +129,13 @@ export default Adapter.extend({
return request` return request`
PUT /v1/acl/token/${id}/clone?${params} PUT /v1/acl/token/${id}/clone?${params}
`; `;
}, }
// TODO: self doesn't get passed a snapshot right now
// ideally it would just for consistency // TODO: self doesn't get passed a snapshot right now ideally it would just
// thing is its probably not the same shape as a 'Token', // for consistency thing is its probably not the same shape as a
// plus we can't create Snapshots as they are private, see services/store.js // 'Token', plus we can't create Snapshots as they are private, see
self: function(store, type, id, unserialized) { // services/store.js
self(store, type, id, unserialized) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, data) { function(adapter, request, serialized, data) {
return adapter.requestForSelf(request, serialized, data); return adapter.requestForSelf(request, serialized, data);
@ -140,8 +146,9 @@ export default Adapter.extend({
unserialized, unserialized,
type.modelName type.modelName
); );
}, }
clone: function(store, type, id, snapshot) {
clone(store, type, id, snapshot) {
return this.rpc( return this.rpc(
function(adapter, request, serialized, data) { function(adapter, request, serialized, data) {
return adapter.requestForCloneRecord(request, serialized, data); return adapter.requestForCloneRecord(request, serialized, data);
@ -159,5 +166,5 @@ export default Adapter.extend({
snapshot, snapshot,
type.modelName type.modelName
); );
}, }
}); }

View File

@ -1,7 +1,8 @@
import Adapter from './application'; import Adapter from './application';
// TODO: Update to use this.formatDatacenter() // TODO: Update to use this.formatDatacenter()
export default Adapter.extend({ export default class TopologyAdapter extends Adapter {
requestForQueryRecord: function(request, { dc, ns, index, id, uri, kind }) { requestForQueryRecord(request, { dc, ns, index, id, uri, kind }) {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
throw new Error('You must specify an id'); throw new Error('You must specify an id');
} }
@ -14,5 +15,5 @@ export default Adapter.extend({
index, index,
}} }}
`; `;
}, }
}); }

View File

@ -1,21 +1,19 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({ export default class Acl extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') ID;
Name: attr('string', {
// TODO: Why didn't I have to do this for KV's? @attr('string') Datacenter;
// this is to ensure that Name is '' and not null when creating // TODO: Why didn't I have to do this for KV's? This is to ensure that Name
// maybe its due to the fact that `Key` is the primaryKey in Kv's // is '' and not null when creating maybe its due to the fact that `Key` is
defaultValue: '', // the primaryKey in Kv's
}), @attr('string', { defaultValue: () => '' }) Name;
Type: attr('string'), @attr('string') Type;
Rules: attr('string'), @attr('string') Rules;
CreateIndex: attr('number'), @attr('number') CreateIndex;
ModifyIndex: attr('number'), @attr('number') ModifyIndex;
Datacenter: attr('string'), }
});

View File

@ -1,14 +1,14 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Node'; export const SLUG_KEY = 'Node';
export default Model.extend({ export default class Coordinate extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') Node;
Coord: attr(),
Segment: attr('string'), @attr() Coord; // {Vec, Error, Adjustment, Height}
Datacenter: attr('string'), @attr('string') Segment;
SyncTime: attr('number'), @attr('string') Datacenter;
}); @attr('number') SyncTime;
}

View File

@ -1,16 +1,12 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const FOREIGN_KEY = 'Datacenter'; export const FOREIGN_KEY = 'Datacenter';
export const SLUG_KEY = 'Name'; export const SLUG_KEY = 'Name';
export default Model.extend({ export default class Datacenter extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') Name;
// TODO: Are these required?
Services: hasMany('service'), @attr('boolean', { defaultValue: () => true }) MeshEnabled;
Nodes: hasMany('node'), }
MeshEnabled: attr('boolean', { defaultValue: true }),
});

View File

@ -1,12 +1,13 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ServiceName'; export const SLUG_KEY = 'ServiceName';
export default Model.extend({
[PRIMARY_KEY]: attr('string'), export default class DiscoveryChain extends Model {
[SLUG_KEY]: attr('string'), @attr('string') uid;
Datacenter: attr('string'), @attr('string') ServiceName;
Chain: attr(),
meta: attr(), @attr('string') Datacenter;
}); @attr() Chain; // {}
@attr() meta; // {}
}

View File

@ -1,8 +1,7 @@
import Fragment from 'ember-data-model-fragments/fragment';
import { attr } from '@ember-data/model';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { or } from '@ember/object/computed'; import { or } from '@ember/object/computed';
import attr from 'ember-data/attr';
import Fragment from 'ember-data-model-fragments/fragment';
export const schema = { export const schema = {
Name: { Name: {
@ -13,17 +12,20 @@ export const schema = {
}, },
}; };
export default Fragment.extend({ export default class IntentionPermission extends Fragment {
Name: attr('string'), @attr('string') Name;
Exact: attr('string'), @attr('string') Exact;
Prefix: attr('string'), @attr('string') Prefix;
Suffix: attr('string'), @attr('string') Suffix;
Regex: attr('string'), @attr('string') Regex;
Present: attr(), // this is a boolean but we don't want it to automatically be set to false // this is a boolean but we don't want it to automatically be set to false
@attr() Present;
Value: or(...schema.HeaderType.allowedValues), @or(...schema.HeaderType.allowedValues) Value;
HeaderType: computed(...schema.HeaderType.allowedValues, function() {
@computed(...schema.HeaderType.allowedValues)
get HeaderType() {
return schema.HeaderType.allowedValues.find(prop => typeof this[prop] !== 'undefined'); return schema.HeaderType.allowedValues.find(prop => typeof this[prop] !== 'undefined');
}), }
}); }

View File

@ -1,9 +1,8 @@
import attr from 'ember-data/attr';
import { computed } from '@ember/object';
import { or } from '@ember/object/computed';
import Fragment from 'ember-data-model-fragments/fragment'; import Fragment from 'ember-data-model-fragments/fragment';
import { fragmentArray, array } from 'ember-data-model-fragments/attributes'; import { fragmentArray, array } from 'ember-data-model-fragments/attributes';
import { attr } from '@ember-data/model';
import { computed } from '@ember/object';
import { or } from '@ember/object/computed';
export const schema = { export const schema = {
PathType: { PathType: {
@ -14,16 +13,18 @@ export const schema = {
}, },
}; };
export default Fragment.extend({ export default class IntentionPermissionHttp extends Fragment {
PathExact: attr('string'), @attr('string') PathExact;
PathPrefix: attr('string'), @attr('string') PathPrefix;
PathRegex: attr('string'), @attr('string') PathRegex;
Header: fragmentArray('intention-permission-http-header'), @fragmentArray('intention-permission-http-header') Header;
Methods: array('string'), @array('string') Methods;
Path: or(...schema.PathType.allowedValues), @or(...schema.PathType.allowedValues) Path;
PathType: computed(...schema.PathType.allowedValues, function() {
@computed(...schema.PathType.allowedValues)
get PathType() {
return schema.PathType.allowedValues.find(prop => typeof this[prop] === 'string'); return schema.PathType.allowedValues.find(prop => typeof this[prop] === 'string');
}), }
}); }

View File

@ -1,7 +1,6 @@
import attr from 'ember-data/attr';
import Fragment from 'ember-data-model-fragments/fragment'; import Fragment from 'ember-data-model-fragments/fragment';
import { fragment } from 'ember-data-model-fragments/attributes'; import { fragment } from 'ember-data-model-fragments/attributes';
import { attr } from '@ember-data/model';
export const schema = { export const schema = {
Action: { Action: {
@ -10,9 +9,7 @@ export const schema = {
}, },
}; };
export default Fragment.extend({ export default class IntentionPermission extends Fragment {
Action: attr('string', { @attr('string', { defaultValue: () => schema.Action.defaultValue }) Action;
defaultValue: schema.Action.defaultValue, @fragment('intention-permission-http') HTTP;
}), }
HTTP: fragment('intention-permission-http'),
});

View File

@ -1,40 +1,43 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { fragmentArray } from 'ember-data-model-fragments/attributes'; import { fragmentArray } from 'ember-data-model-fragments/attributes';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({
[PRIMARY_KEY]: attr('string'),
[SLUG_KEY]: attr('string'),
Description: attr('string'),
SourceNS: attr('string', { defaultValue: 'default' }),
SourceName: attr('string', { defaultValue: '*' }),
DestinationName: attr('string', { defaultValue: '*' }),
DestinationNS: attr('string', { defaultValue: 'default' }),
Precedence: attr('number'),
Permissions: fragmentArray('intention-permission'),
SourceType: attr('string', { defaultValue: 'consul' }),
Action: attr('string'),
Meta: attr(),
LegacyID: attr('string'),
Legacy: attr('boolean', { defaultValue: true }),
IsManagedByCRD: computed('Meta', function() { export default class Intention extends Model {
@attr('string') uid;
@attr('string') ID;
@attr('string') Datacenter;
@attr('string') Description;
@attr('string', { defaultValue: () => 'default' }) SourceNS;
@attr('string', { defaultValue: () => '*' }) SourceName;
@attr('string', { defaultValue: () => 'default' }) DestinationNS;
@attr('string', { defaultValue: () => '*' }) DestinationName;
@attr('number') Precedence;
@attr('string', { defaultValue: () => 'consul' }) SourceType;
@attr('string') Action;
@attr('string') LegacyID;
@attr('boolean', { defaultValue: () => true }) Legacy;
@attr('number') SyncTime;
@attr('date') CreatedAt;
@attr('date') UpdatedAt;
@attr('number') CreateIndex;
@attr('number') ModifyIndex;
@attr() Meta; // {}
@fragmentArray('intention-permission') Permissions;
@computed('Meta')
get IsManagedByCRD() {
const meta = Object.entries(this.Meta || {}).find( const meta = Object.entries(this.Meta || {}).find(
([key, value]) => key === 'external-source' && value === 'kubernetes' ([key, value]) => key === 'external-source' && value === 'kubernetes'
); );
return typeof meta !== 'undefined'; return typeof meta !== 'undefined';
}), }
IsEditable: computed('Legacy', 'IsManagedByCRD', function() {
@computed('IsManagedByCRD')
get IsEditable() {
return !this.IsManagedByCRD; return !this.IsManagedByCRD;
}), }
SyncTime: attr('number'), }
Datacenter: attr('string'),
CreatedAt: attr('date'),
UpdatedAt: attr('date'),
CreateIndex: attr('number'),
ModifyIndex: attr('number'),
});

View File

@ -1,30 +1,32 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr'; import { computed } from '@ember/object';
import { computed, get } from '@ember/object';
import isFolder from 'consul-ui/utils/isFolder'; import isFolder from 'consul-ui/utils/isFolder';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
// not really a slug as it contains slashes but all intents and purposes // not really a slug as it contains slashes but all intents and purposes its
// its my 'slug' // my 'slug'
export const SLUG_KEY = 'Key'; export const SLUG_KEY = 'Key';
export default Model.extend({ export default class Kv extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') Key;
LockIndex: attr('number'),
Flags: attr('number'),
// TODO: Consider defaulting all strings to '' because `typeof null !== 'string'`
// look into what other transformers do with `null` also
// preferably removeNull would be done in this layer also as if a property is `null`
// default Values don't kick in, which also explains `Tags` elsewhere
Value: attr('string'), //, {defaultValue: function() {return '';}}
CreateIndex: attr('number'),
ModifyIndex: attr('number'),
Session: attr('string'),
Datacenter: attr('string'),
Namespace: attr('string'),
isFolder: computed('Key', function() { @attr('string') Datacenter;
return isFolder(get(this, 'Key') || ''); @attr('string') Namespace;
}), @attr('number') LockIndex;
}); @attr('number') Flags;
// TODO: Consider defaulting all strings to '' because `typeof null !==
// 'string'` look into what other transformers do with `null` also
// preferably removeNull would be done in this layer also as if a property
// is `null` default Values don't kick in, which also explains `Tags`
// elsewhere
@attr('string') Value; //, {defaultValue: function() {return '';}}
@attr('number') CreateIndex;
@attr('number') ModifyIndex;
@attr('string') Session;
@computed('Key')
get isFolder() {
return isFolder(this.Key || '');
}
}

View File

@ -1,27 +1,27 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({ export default class Node extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') ID;
Address: attr('string'),
Node: attr('string'), @attr('string') Datacenter;
Meta: attr(), @attr('string') Address;
Services: attr(), @attr('string') Node;
Checks: attr(), @attr('number') SyncTime;
CreateIndex: attr('number'), @attr('number') CreateIndex;
ModifyIndex: attr('number'), @attr('number') ModifyIndex;
TaggedAddresses: attr(), @attr() meta; // {}
Datacenter: attr('string'), @attr() Meta; // {}
Segment: attr(), @attr() TaggedAddresses; // {lan, wan}
Coord: attr(), @attr() Services; // ServiceInstances[]
SyncTime: attr('number'), @attr() Checks; // Checks[]
meta: attr(),
Status: computed('Checks.[]', 'ChecksCritical', 'ChecksPassing', 'ChecksWarning', function() { @computed('Checks.[]', 'ChecksCritical', 'ChecksPassing', 'ChecksWarning')
get Status() {
switch (true) { switch (true) {
case this.ChecksCritical !== 0: case this.ChecksCritical !== 0:
return 'critical'; return 'critical';
@ -32,14 +32,20 @@ export default Model.extend({
default: default:
return 'empty'; return 'empty';
} }
}), }
ChecksCritical: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksCritical() {
return this.Checks.filter(item => item.Status === 'critical').length; return this.Checks.filter(item => item.Status === 'critical').length;
}), }
ChecksPassing: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksPassing() {
return this.Checks.filter(item => item.Status === 'passing').length; return this.Checks.filter(item => item.Status === 'passing').length;
}), }
ChecksWarning: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksWarning() {
return this.Checks.filter(item => item.Status === 'warning').length; return this.Checks.filter(item => item.Status === 'warning').length;
}), }
}); }

View File

@ -1,20 +1,22 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'Name'; export const PRIMARY_KEY = 'Name';
// keep this for consistency
export const SLUG_KEY = 'Name'; export const SLUG_KEY = 'Name';
export const NSPACE_KEY = 'Namespace'; export const NSPACE_KEY = 'Namespace';
export default Model.extend({
[PRIMARY_KEY]: attr('string'),
[SLUG_KEY]: attr('string'),
Description: attr('string', { defaultValue: '' }), export default class Nspace extends Model {
@attr('string') uid;
@attr('string') Name;
@attr('number') SyncTime;
@attr('string', { defaultValue: () => '' }) Description;
// TODO: Is there some sort of date we can use here // TODO: Is there some sort of date we can use here
DeletedAt: attr('string'), @attr('string') DeletedAt;
ACLs: attr(undefined, function() { @attr({
return { defaultValue: { PolicyDefaults: [], RoleDefaults: [] } }; defaultValue: () => ({
}), PolicyDefaults: [],
RoleDefaults: [],
SyncTime: attr('number'), }),
}); })
ACLs;
}

View File

@ -1,15 +1,16 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Name'; export const SLUG_KEY = 'Name';
export default Model.extend({
[PRIMARY_KEY]: attr('string'), export default class OidcProvider extends Model {
[SLUG_KEY]: attr('string'), @attr('string') uid;
meta: attr(), @attr('string') Name;
Datacenter: attr('string'),
DisplayName: attr('string'), @attr('string') Datacenter;
Kind: attr('string'), @attr('string') Namespace;
Namespace: attr('string'), @attr('string') Kind;
AuthURL: attr('string'), @attr('string') AuthURL;
}); @attr('string') DisplayName;
@attr() meta; // {}
}

View File

@ -1,43 +1,31 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
export const MANAGEMENT_ID = '00000000-0000-0000-0000-000000000001';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export const MANAGEMENT_ID = '00000000-0000-0000-0000-000000000001'; export default class Policy extends Model {
@attr('string') uid;
@attr('string') ID;
export default Model.extend({ @attr('string') Datacenter;
[PRIMARY_KEY]: attr('string'), @attr('string') Namespace;
[SLUG_KEY]: attr('string'), @attr('string', { defaultValue: () => '' }) Name;
Name: attr('string', { @attr('string', { defaultValue: () => '' }) Description;
defaultValue: '', @attr('string', { defaultValue: () => '' }) Rules;
}), @attr('number') SyncTime;
Description: attr('string', { @attr('number') CreateIndex;
defaultValue: '', @attr('number') ModifyIndex;
}), @attr() Datacenters; // string[]
Rules: attr('string', { @attr() meta; // {}
defaultValue: '', // frontend only for templated policies (Identities)
}), @attr('string', { defaultValue: () => '' }) template;
// frontend only for ordering where CreateIndex can't be used // frontend only for ordering where CreateIndex can't be used
CreateTime: attr('number', { @attr('number', { defaultValue: () => new Date().getTime() }) CreateTime;
defaultValue: function() {
return new Date().getTime();
},
}),
//
isGlobalManagement: computed('ID', function() {
return this.ID === MANAGEMENT_ID;
}),
Datacenter: attr('string'),
Namespace: attr('string'),
SyncTime: attr('number'),
meta: attr(),
Datacenters: attr(),
CreateIndex: attr('number'),
ModifyIndex: attr('number'),
template: attr('string', { @computed('ID')
defaultValue: '', get isGlobalManagement() {
}), return this.ID === MANAGEMENT_ID;
}); }
}

View File

@ -1,16 +1,18 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Node,ServiceID'; export const SLUG_KEY = 'Node,ServiceID';
export default Model.extend({
[PRIMARY_KEY]: attr('string'), // TODO: This should be changed to ProxyInstance
ID: attr('string'), export default class Proxy extends Model {
ServiceName: attr('string'), @attr('string') uid;
ServiceID: attr('string'), @attr('string') ID;
Node: attr('string'),
ServiceProxy: attr(), @attr('string') Datacenter;
SyncTime: attr('number'), @attr('string') Namespace;
Datacenter: attr('string'), @attr('string') ServiceName;
Namespace: attr('string'), @attr('string') ServiceID;
}); @attr('string') Node;
@attr('number') SyncTime;
@attr() ServiceProxy; // {}
}

View File

@ -1,41 +1,25 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({
[PRIMARY_KEY]: attr('string'), export default class Role extends Model {
[SLUG_KEY]: attr('string'), @attr('string') uid;
Name: attr('string', { @attr('string') ID;
defaultValue: '',
}), @attr('string') Datacenter;
Description: attr('string', { @attr('string') Namespace;
defaultValue: '', @attr('string', { defaultValue: () => '' }) Name;
}), @attr('string', { defaultValue: () => '' }) Description;
Policies: attr({ @attr({ defaultValue: () => [] }) Policies;
defaultValue: function() { @attr({ defaultValue: () => [] }) ServiceIdentities;
return []; @attr({ defaultValue: () => [] }) NodeIdentities;
}, @attr('number') SyncTime;
}), @attr('number') CreateIndex;
ServiceIdentities: attr({ @attr('number') ModifyIndex;
defaultValue: function() {
return [];
},
}),
NodeIdentities: attr({
defaultValue: function() {
return [];
},
}),
// frontend only for ordering where CreateIndex can't be used // frontend only for ordering where CreateIndex can't be used
CreateTime: attr('date'), @attr('number') CreateTime;
//
Datacenter: attr('string'),
Namespace: attr('string'),
SyncTime: attr('number'),
// TODO: Figure out whether we need this or not // TODO: Figure out whether we need this or not
Datacenters: attr(), @attr() Datacenters; // string[]
Hash: attr('string'), @attr('string') Hash;
CreateIndex: attr('number'), }
ModifyIndex: attr('number'),
});

View File

@ -1,44 +1,43 @@
import Model from 'ember-data/model'; import Model, { attr, belongsTo } from '@ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo } from 'ember-data/relationships';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { or, filter, alias } from '@ember/object/computed'; import { or, filter, alias } from '@ember/object/computed';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Node.Node,Service.ID'; export const SLUG_KEY = 'Node.Node,Service.ID';
export default Model.extend({ export default class ServiceInstance extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'),
Datacenter: attr('string'), @attr('string') Datacenter;
// ProxyInstance is the ember-data model relationship // ProxyInstance is the ember-data model relationship
ProxyInstance: belongsTo('Proxy'), @belongsTo('Proxy') ProxyInstance;
// Proxy is the actual JSON api response // Proxy is the actual JSON api response
Proxy: attr(), @attr() Proxy;
Node: attr(), @attr() Node;
Service: attr(), @attr() Service;
Checks: attr(), @attr() Checks;
SyncTime: attr('number'), @attr('number') SyncTime;
meta: attr(), @attr() meta;
Name: or('Service.ID', 'Service.Service'),
Tags: alias('Service.Tags'), @or('Service.ID', 'Service.Service') Name;
Meta: alias('Service.Meta'), @alias('Service.Tags') Tags;
Namespace: alias('Service.Namespace'), @alias('Service.Meta') Meta;
ExternalSources: computed('Service.Meta', function() { @alias('Service.Namespace') Namespace;
@filter('Checks.[]', (item, i, arr) => item.ServiceID !== '') ServiceChecks;
@filter('Checks.[]', (item, i, arr) => item.ServiceID === '') NodeChecks;
@computed('Service.Meta')
get ExternalSources() {
const sources = Object.entries(this.Service.Meta || {}) const sources = Object.entries(this.Service.Meta || {})
.filter(([key, value]) => key === 'external-source') .filter(([key, value]) => key === 'external-source')
.map(([key, value]) => { .map(([key, value]) => {
return value; return value;
}); });
return [...new Set(sources)]; return [...new Set(sources)];
}), }
ServiceChecks: filter('Checks.[]', function(item, i, arr) {
return item.ServiceID !== ''; @computed('ChecksPassing', 'ChecksWarning', 'ChecksCritical')
}), get Status() {
NodeChecks: filter('Checks.[]', function(item, i, arr) {
return item.ServiceID === '';
}),
Status: computed('ChecksPassing', 'ChecksWarning', 'ChecksCritical', function() {
switch (true) { switch (true) {
case this.ChecksCritical.length !== 0: case this.ChecksCritical.length !== 0:
return 'critical'; return 'critical';
@ -49,23 +48,35 @@ export default Model.extend({
default: default:
return 'empty'; return 'empty';
} }
}), }
ChecksPassing: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksPassing() {
return this.Checks.filter(item => item.Status === 'passing'); return this.Checks.filter(item => item.Status === 'passing');
}), }
ChecksWarning: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksWarning() {
return this.Checks.filter(item => item.Status === 'warning'); return this.Checks.filter(item => item.Status === 'warning');
}), }
ChecksCritical: computed('Checks.[]', function() {
@computed('Checks.[]')
get ChecksCritical() {
return this.Checks.filter(item => item.Status === 'critical'); return this.Checks.filter(item => item.Status === 'critical');
}), }
PercentageChecksPassing: computed('Checks.[]', 'ChecksPassing', function() {
@computed('Checks.[]', 'ChecksPassing')
get PercentageChecksPassing() {
return (this.ChecksPassing.length / this.Checks.length) * 100; return (this.ChecksPassing.length / this.Checks.length) * 100;
}), }
PercentageChecksWarning: computed('Checks.[]', 'ChecksWarning', function() {
@computed('Checks.[]', 'ChecksWarning')
get PercentageChecksWarning() {
return (this.ChecksWarning.length / this.Checks.length) * 100; return (this.ChecksWarning.length / this.Checks.length) * 100;
}), }
PercentageChecksCritical: computed('Checks.[]', 'ChecksCritical', function() {
@computed('Checks.[]', 'ChecksCritical')
get PercentageChecksCritical() {
return (this.ChecksCritical.length / this.Checks.length) * 100; return (this.ChecksCritical.length / this.Checks.length) * 100;
}), }
}); }

View File

@ -1,52 +1,48 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { computed, get } from '@ember/object'; import { computed, get } from '@ember/object';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Name'; export const SLUG_KEY = 'Name';
export default Model.extend({ export default class Service extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') Name;
Tags: attr({
defaultValue: function() { @attr('string') Datacenter;
return []; @attr('string') Namespace;
}, @attr('string') Kind;
}), @attr('number') ChecksPassing;
InstanceCount: attr('number'), @attr('number') ChecksCritical;
ConnectedWithGateway: attr(), @attr('number') ChecksWarning;
ConnectedWithProxy: attr(), @attr('number') InstanceCount;
Proxy: attr(), @attr('boolean') ConnectedWithGateway;
GatewayConfig: attr(), @attr('boolean') ConnectedWithProxy;
Kind: attr('string'), @attr('number') SyncTime;
ExternalSources: attr(), @attr('number') CreateIndex;
Meta: attr(), @attr('number') ModifyIndex;
Address: attr('string'), @attr({ defaultValue: () => [] }) Tags;
TaggedAddresses: attr(),
Port: attr('number'), @attr() Nodes; // array
EnableTagOverride: attr('boolean'), @attr() Proxy; // Service
CreateIndex: attr('number'), @attr() GatewayConfig; // {AssociatedServiceCount: 0}
ModifyIndex: attr('number'), @attr() ExternalSources; // array
// TODO: These should be typed @attr() Meta; // {}
ChecksPassing: attr(),
ChecksCritical: attr(), @attr() meta; // {}
ChecksWarning: attr(),
Nodes: attr(),
Datacenter: attr('string'),
Namespace: attr('string'),
Node: attr(),
Service: attr(),
Checks: attr(),
SyncTime: attr('number'),
meta: attr(),
/* Mesh properties involve both the service and the associated proxy */ /* Mesh properties involve both the service and the associated proxy */
MeshEnabled: computed('ConnectedWithProxy', 'ConnectedWithGateway', function() { @computed('ConnectedWithProxy', 'ConnectedWithGateway')
get MeshEnabled() {
return this.ConnectedWithProxy || this.ConnectedWithGateway; return this.ConnectedWithProxy || this.ConnectedWithGateway;
}), }
InMesh: computed('Kind', function() {
@computed('MeshEnabled', 'Kind')
get InMesh() {
return this.MeshEnabled || (this.Kind || '').length > 0; return this.MeshEnabled || (this.Kind || '').length > 0;
}), }
MeshStatus: computed('MeshChecksPassing', 'MeshChecksWarning', 'MeshChecksCritical', function() {
@computed('MeshChecksPassing', 'MeshChecksWarning', 'MeshChecksCritical')
get MeshStatus() {
switch (true) { switch (true) {
case this.MeshChecksCritical !== 0: case this.MeshChecksCritical !== 0:
return 'critical'; return 'critical';
@ -57,57 +53,33 @@ export default Model.extend({
default: default:
return 'empty'; return 'empty';
} }
}), }
MeshChecksPassing: computed('ChecksPassing', 'Proxy.ChecksPassing', function() {
@computed('ChecksPassing', 'Proxy.ChecksPassing')
get MeshChecksPassing() {
let proxyCount = 0; let proxyCount = 0;
if (typeof this.Proxy !== 'undefined') { if (typeof this.Proxy !== 'undefined') {
proxyCount = this.Proxy.ChecksPassing; proxyCount = this.Proxy.ChecksPassing;
} }
return this.ChecksPassing + proxyCount; return this.ChecksPassing + proxyCount;
}), }
MeshChecksWarning: computed('ChecksWarning', 'Proxy.ChecksWarning', function() {
@computed('ChecksWarning', 'Proxy.ChecksWarning')
get MeshChecksWarning() {
let proxyCount = 0; let proxyCount = 0;
if (typeof this.Proxy !== 'undefined') { if (typeof this.Proxy !== 'undefined') {
proxyCount = this.Proxy.ChecksWarning; proxyCount = this.Proxy.ChecksWarning;
} }
return this.ChecksWarning + proxyCount; return this.ChecksWarning + proxyCount;
}), }
MeshChecksCritical: computed('ChecksCritical', 'Proxy.ChecksCritical', function() {
@computed('ChecksCritical', 'Proxy.ChecksCritical')
get MeshChecksCritical() {
let proxyCount = 0; let proxyCount = 0;
if (typeof this.Proxy !== 'undefined') { if (typeof this.Proxy !== 'undefined') {
proxyCount = this.Proxy.ChecksCritical; proxyCount = this.Proxy.ChecksCritical;
} }
return this.ChecksCritical + proxyCount; return this.ChecksCritical + proxyCount;
}), }
/**/ /**/
passing: computed('ChecksPassing', 'Checks', function() { }
let num = 0;
// TODO: use typeof
if (get(this, 'ChecksPassing') !== undefined) {
num = get(this, 'ChecksPassing');
} else {
num = get(get(this, 'Checks').filterBy('Status', 'passing'), 'length');
}
return {
length: num,
};
}),
hasStatus: function(status) {
let num = 0;
switch (status) {
case 'passing':
num = get(this, 'ChecksPassing');
break;
case 'critical':
num = get(this, 'ChecksCritical');
break;
case 'warning':
num = get(this, 'ChecksWarning');
break;
case '': // all
num = 1;
break;
}
return num > 0;
},
});

View File

@ -1,25 +1,22 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID'; export const SLUG_KEY = 'ID';
export default Model.extend({ export default class Session extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') ID;
Name: attr('string'),
Node: attr('string'), @attr('string') Name;
CreateIndex: attr('number'), @attr('string') Datacenter;
ModifyIndex: attr('number'), @attr('string') Namespace;
LockDelay: attr('number'), @attr('string') Node;
Behavior: attr('string'), @attr('string') Behavior;
TTL: attr('string'), @attr('string') TTL;
Checks: attr({ @attr('number') LockDelay;
defaultValue: function() { @attr('number') SyncTime;
return []; @attr('number') CreateIndex;
}, @attr('number') ModifyIndex;
}),
Datacenter: attr('string'), @attr({ defaultValue: () => [] }) Checks;
Namespace: attr('string'), }
SyncTime: attr('number'),
});

View File

@ -1,56 +1,41 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { MANAGEMENT_ID } from 'consul-ui/models/policy'; import { MANAGEMENT_ID } from 'consul-ui/models/policy';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'AccessorID'; export const SLUG_KEY = 'AccessorID';
export default Model.extend({ export default class Token extends Model {
[PRIMARY_KEY]: attr('string'), @attr('string') uid;
[SLUG_KEY]: attr('string'), @attr('string') AccessorID;
IDPName: attr('string'),
SecretID: attr('string'), @attr('string') Datacenter;
@attr('string') Namespace;
@attr('string') IDPName;
@attr('string') SecretID;
@attr('boolean') Legacy;
@attr('boolean') Local;
@attr('string', { defaultValue: () => '' }) Description;
@attr() meta; // {}
@attr({ defaultValue: () => [] }) Policies;
@attr({ defaultValue: () => [] }) Roles;
@attr({ defaultValue: () => [] }) ServiceIdentities;
@attr({ defaultValue: () => [] }) NodeIdentities;
@attr('date') CreateTime;
@attr('string') Hash;
@attr('number') CreateIndex;
@attr('number') ModifyIndex;
// Legacy // Legacy
Type: attr('string'), @attr('string') Type;
Name: attr('string', { @attr('string', { defaultValue: () => '' }) Name;
defaultValue: '', @attr('string') Rules;
}),
Rules: attr('string'),
// End Legacy // End Legacy
Legacy: attr('boolean'),
Description: attr('string', { @computed('Policies.[]')
defaultValue: '', get isGlobalManagement() {
}),
meta: attr(),
Datacenter: attr('string'),
Namespace: attr('string'),
Local: attr('boolean'),
isGlobalManagement: computed('Policies.[]', function() {
return (this.Policies || []).find(item => item.ID === MANAGEMENT_ID); return (this.Policies || []).find(item => item.ID === MANAGEMENT_ID);
}), }
Policies: attr({ }
defaultValue: function() {
return [];
},
}),
Roles: attr({
defaultValue: function() {
return [];
},
}),
ServiceIdentities: attr({
defaultValue: function() {
return [];
},
}),
NodeIdentities: attr({
defaultValue: function() {
return [];
},
}),
CreateTime: attr('date'),
Hash: attr('string'),
CreateIndex: attr('number'),
ModifyIndex: attr('number'),
});

View File

@ -1,16 +1,17 @@
import Model from 'ember-data/model'; import Model, { attr } from '@ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid'; export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ServiceName'; export const SLUG_KEY = 'ServiceName';
export default Model.extend({
[PRIMARY_KEY]: attr('string'), export default class Topology extends Model {
[SLUG_KEY]: attr('string'), @attr('string') uid;
Datacenter: attr('string'), @attr('string') ServiceName;
Namespace: attr('string'),
Upstreams: attr(), @attr('string') Datacenter;
Downstreams: attr(), @attr('string') Namespace;
Protocol: attr(), @attr('string') Protocol;
FilteredByACLs: attr(), @attr('boolean') FilteredByACLs;
meta: attr(), @attr() Upstreams; // Service[]
}); @attr() Downstreams; // Service[],
@attr() meta; // {}
}

View File

@ -1,10 +1,14 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/acl'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/acl';
export default Serializer.extend({ export default class AclSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQueryRecord: function(respond, query) {
return this._super(cb => respond((headers, body) => cb(headers, body[0])), query); respondForQueryRecord(respond, query) {
}, return super.respondForQueryRecord(
}); cb => respond((headers, body) => cb(headers, body[0])),
query
);
}
}

View File

@ -1,5 +1,4 @@
import Serializer from './http'; import Serializer from './http';
import { set } from '@ember/object'; import { set } from '@ember/object';
import { import {
HEADERS_SYMBOL as HTTP_HEADERS_SYMBOL, HEADERS_SYMBOL as HTTP_HEADERS_SYMBOL,
@ -27,9 +26,9 @@ const attachHeaders = function(headers, body, query = {}) {
Object.keys(headers).forEach(function(key) { Object.keys(headers).forEach(function(key) {
lower[key.toLowerCase()] = headers[key]; lower[key.toLowerCase()] = headers[key];
}); });
// Add a 'pretend' Datacenter/Nspace header, they are not headers // Add a 'pretend' Datacenter/Nspace header, they are not headers the come
// the come from the request but we add them here so we can use them later // from the request but we add them here so we can use them later for store
// for store reconciliation // reconciliation
if (typeof query.dc !== 'undefined') { if (typeof query.dc !== 'undefined') {
lower[HTTP_HEADERS_DATACENTER.toLowerCase()] = query.dc; lower[HTTP_HEADERS_DATACENTER.toLowerCase()] = query.dc;
} }
@ -40,10 +39,11 @@ const attachHeaders = function(headers, body, query = {}) {
return body; return body;
}; };
export default Serializer.extend({ export default class ApplicationSerializer extends Serializer {
attachHeaders: attachHeaders, attachHeaders = attachHeaders;
fingerprint: createFingerprinter(DATACENTER_KEY, NSPACE_KEY), fingerprint = createFingerprinter(DATACENTER_KEY, NSPACE_KEY);
respondForQuery: function(respond, query) {
respondForQuery(respond, query) {
return respond((headers, body) => return respond((headers, body) =>
attachHeaders( attachHeaders(
headers, headers,
@ -51,13 +51,15 @@ export default Serializer.extend({
query query
) )
); );
}, }
respondForQueryRecord: function(respond, query) {
respondForQueryRecord(respond, query) {
return respond((headers, body) => return respond((headers, body) =>
attachHeaders(headers, this.fingerprint(this.primaryKey, this.slugKey, query.dc)(body), query) attachHeaders(headers, this.fingerprint(this.primaryKey, this.slugKey, query.dc)(body), query)
); );
}, }
respondForCreateRecord: function(respond, serialized, data) {
respondForCreateRecord(respond, serialized, data) {
const slugKey = this.slugKey; const slugKey = this.slugKey;
const primaryKey = this.primaryKey; const primaryKey = this.primaryKey;
return respond((headers, body) => { return respond((headers, body) => {
@ -68,29 +70,32 @@ export default Serializer.extend({
// Creates need a primaryKey adding // Creates need a primaryKey adding
return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body); return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body);
}); });
}, }
respondForUpdateRecord: function(respond, serialized, data) {
respondForUpdateRecord(respond, serialized, data) {
const slugKey = this.slugKey; const slugKey = this.slugKey;
const primaryKey = this.primaryKey; const primaryKey = this.primaryKey;
return respond((headers, body) => { return respond((headers, body) => {
// If updates are true use the info we already have // If updates are true use the info we already have
// TODO: We may aswell avoid re-fingerprinting here if we are just // TODO: We may aswell avoid re-fingerprinting here if we are just going
// going to reuse data then its already fingerprinted and as the response // to reuse data then its already fingerprinted and as the response is
// is true we don't have anything changed so the old fingerprint stays the same // true we don't have anything changed so the old fingerprint stays the
// as long as nothing in the fingerprint has been edited (the namespace?) // same as long as nothing in the fingerprint has been edited (the
// namespace?)
if (body === true) { if (body === true) {
body = data; body = data;
} }
return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body); return this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])(body);
}); });
}, }
respondForDeleteRecord: function(respond, serialized, data) {
respondForDeleteRecord(respond, serialized, data) {
const slugKey = this.slugKey; const slugKey = this.slugKey;
const primaryKey = this.primaryKey; const primaryKey = this.primaryKey;
return respond((headers, body) => { return respond((headers, body) => {
// Deletes only need the primaryKey/uid returning // Deletes only need the primaryKey/uid returning and they need the slug
// and they need the slug key AND potential namespace in order to // key AND potential namespace in order to create the correct
// create the correct uid/fingerprint // uid/fingerprint
return { return {
[primaryKey]: this.fingerprint( [primaryKey]: this.fingerprint(
primaryKey, primaryKey,
@ -102,24 +107,25 @@ export default Serializer.extend({
})[primaryKey], })[primaryKey],
}; };
}); });
}, }
// this could get confusing if you tried to override
// say `normalizeQueryResponse` // this could get confusing if you tried to override say
// TODO: consider creating a method for each one of the `normalize...Response` family // `normalizeQueryResponse`
normalizeResponse: function(store, modelClass, payload, id, requestType) { // TODO: consider creating a method for each one of the
// `normalize...Response` family
normalizeResponse(store, modelClass, payload, id, requestType) {
const normalizedPayload = this.normalizePayload(payload, id, requestType); const normalizedPayload = this.normalizePayload(payload, id, requestType);
// put the meta onto the response, here this is ok // put the meta onto the response, here this is ok as JSON-API allows this
// as JSON-API allows this and our specific data is now in // and our specific data is now in response[primaryModelClass.modelName]
// response[primaryModelClass.modelName] // so we aren't in danger of overwriting anything (which was the reason
// so we aren't in danger of overwriting anything // for the Symbol-like property earlier) use a method modelled on
// (which was the reason for the Symbol-like property earlier) // ember-data methods so we have the opportunity to do this on a per-model
// use a method modelled on ember-data methods so we have the opportunity to // level
// do this on a per-model level
const meta = this.normalizeMeta(store, modelClass, normalizedPayload, id, requestType); const meta = this.normalizeMeta(store, modelClass, normalizedPayload, id, requestType);
if (requestType !== 'query') { if (requestType !== 'query') {
normalizedPayload.meta = meta; normalizedPayload.meta = meta;
} }
const res = this._super( const res = super.normalizeResponse(
store, store,
modelClass, modelClass,
{ {
@ -129,22 +135,24 @@ export default Serializer.extend({
id, id,
requestType requestType
); );
// If the result of the super normalizeResponse is undefined // If the result of the super normalizeResponse is undefined its because
// its because the JSONSerializer (which REST inherits from) // the JSONSerializer (which REST inherits from) doesn't recognise the
// doesn't recognise the requestType, in this case its likely to be an 'action' // requestType, in this case its likely to be an 'action' request rather
// request rather than a specific 'load me some data' one. // than a specific 'load me some data' one. Therefore its ok to bypass the
// Therefore its ok to bypass the store here for the moment // store here for the moment we currently use this for self, but it also
// we currently use this for self, but it also would affect any custom // would affect any custom methods that use a serializer in our custom
// methods that use a serializer in our custom service/store // service/store
if (typeof res === 'undefined') { if (typeof res === 'undefined') {
return payload; return payload;
} }
return res; return res;
}, }
timestamp: function() {
timestamp() {
return new Date().getTime(); return new Date().getTime();
}, }
normalizeMeta: function(store, modelClass, payload, id, requestType) {
normalizeMeta(store, modelClass, payload, id, requestType) {
// Pick the meta/headers back off the payload and cleanup // Pick the meta/headers back off the payload and cleanup
const headers = payload[HTTP_HEADERS_SYMBOL] || {}; const headers = payload[HTTP_HEADERS_SYMBOL] || {};
delete payload[HTTP_HEADERS_SYMBOL]; delete payload[HTTP_HEADERS_SYMBOL];
@ -167,8 +175,9 @@ export default Serializer.extend({
}); });
} }
return meta; return meta;
}, }
normalizePayload: function(payload, id, requestType) {
normalizePayload(payload, id, requestType) {
return payload; return payload;
}, }
}); }

View File

@ -1,7 +1,7 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/coordinate'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/coordinate';
export default Serializer.extend({ export default class CoordinateSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
}); }

View File

@ -1,13 +1,15 @@
import Serializer from './application'; import Serializer from './application';
export default Serializer.extend({ export default class DcSerializer extends Serializer {
primaryKey: 'Name', primaryKey = 'Name';
respondForQuery: function(respond, query) {
respondForQuery(respond, query) {
return respond(function(headers, body) { return respond(function(headers, body) {
return body; return body;
}); });
}, }
normalizePayload: function(payload, id, requestType) {
normalizePayload(payload, id, requestType) {
switch (requestType) { switch (requestType) {
case 'query': case 'query':
return payload.map(item => { return payload.map(item => {
@ -17,5 +19,5 @@ export default Serializer.extend({
}); });
} }
return payload; return payload;
}, }
}); }

View File

@ -1,11 +1,12 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/discovery-chain'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/discovery-chain';
export default Serializer.extend({ export default class DiscoveryChainSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQueryRecord: function(respond, query) {
return this._super(function(cb) { respondForQueryRecord(respond, query) {
return super.respondForQueryRecord(function(cb) {
return respond(function(headers, body) { return respond(function(headers, body) {
return cb(headers, { return cb(headers, {
...body, ...body,
@ -13,5 +14,5 @@ export default Serializer.extend({
}); });
}); });
}, query); }, query);
}, }
}); }

View File

@ -1,25 +1,31 @@
import Serializer from 'ember-data/serializers/rest'; import Serializer from '@ember-data/serializer/rest';
export default Serializer.extend({ export default class HttpSerializer extends Serializer {
respondForQuery: function(respond, query) { respondForQuery(respond, query) {
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
respondForQueryRecord: function(respond, query) {
respondForQueryRecord(respond, query) {
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
respondForFindAll: function(respond, query) {
respondForFindAll(respond, query) {
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
respondForCreateRecord: function(respond, data) {
respondForCreateRecord(respond, data) {
// TODO: Creates may need a primaryKey adding (remove from application) // TODO: Creates may need a primaryKey adding (remove from application)
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
respondForUpdateRecord: function(respond, data) {
// TODO: Updates only need the primaryKey/uid returning (remove from application) respondForUpdateRecord(respond, data) {
// TODO: Updates only need the primaryKey/uid returning (remove from
// application)
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
respondForDeleteRecord: function(respond, data) {
respondForDeleteRecord(respond, data) {
// TODO: Deletes only need the primaryKey/uid returning (remove from application) // TODO: Deletes only need the primaryKey/uid returning (remove from application)
return respond((headers, body) => body); return respond((headers, body) => body);
}, }
}); }

View File

@ -4,15 +4,18 @@ import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/intention'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/intention';
import removeNull from 'consul-ui/utils/remove-null'; import removeNull from 'consul-ui/utils/remove-null';
export default Serializer.extend({ export default class IntentionSerializer extends Serializer {
primaryKey: PRIMARY_KEY, @service('encoder') encoder;
slugKey: SLUG_KEY,
encoder: service('encoder'), primaryKey = PRIMARY_KEY;
init: function() { slugKey = SLUG_KEY;
this._super();
init() {
super.init(...arguments);
this.uri = this.encoder.uriTag(); this.uri = this.encoder.uriTag();
}, }
ensureID: function(item) {
ensureID(item) {
if (!get(item, 'ID.length')) { if (!get(item, 'ID.length')) {
item.Legacy = false; item.Legacy = false;
} else { } else {
@ -22,9 +25,10 @@ export default Serializer.extend({
item.ID = this item.ID = this
.uri`${item.SourceNS}:${item.SourceName}:${item.DestinationNS}:${item.DestinationName}`; .uri`${item.SourceNS}:${item.SourceName}:${item.DestinationNS}:${item.DestinationName}`;
return item; return item;
}, }
respondForQuery: function(respond, query) {
return this._super( respondForQuery(respond, query) {
return super.respondForQuery(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
return cb( return cb(
@ -34,9 +38,10 @@ export default Serializer.extend({
}), }),
query query
); );
}, }
respondForQueryRecord: function(respond, query) {
return this._super( respondForQueryRecord(respond, query) {
return super.respondForQueryRecord(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
body = this.ensureID(removeNull(body)); body = this.ensureID(removeNull(body));
@ -44,8 +49,9 @@ export default Serializer.extend({
}), }),
query query
); );
}, }
respondForCreateRecord: function(respond, serialized, data) {
respondForCreateRecord(respond, serialized, data) {
const slugKey = this.slugKey; const slugKey = this.slugKey;
const primaryKey = this.primaryKey; const primaryKey = this.primaryKey;
return respond((headers, body) => { return respond((headers, body) => {
@ -54,8 +60,9 @@ export default Serializer.extend({
.uri`${serialized.SourceNS}:${serialized.SourceName}:${serialized.DestinationNS}:${serialized.DestinationName}`; .uri`${serialized.SourceNS}:${serialized.SourceName}:${serialized.DestinationNS}:${serialized.DestinationName}`;
return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body); return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body);
}); });
}, }
respondForUpdateRecord: function(respond, serialized, data) {
respondForUpdateRecord(respond, serialized, data) {
const slugKey = this.slugKey; const slugKey = this.slugKey;
const primaryKey = this.primaryKey; const primaryKey = this.primaryKey;
return respond((headers, body) => { return respond((headers, body) => {
@ -64,5 +71,5 @@ export default Serializer.extend({
body.ID = serialized.ID; body.ID = serialized.ID;
return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body); return this.fingerprint(primaryKey, slugKey, body.Datacenter)(body);
}); });
}, }
}); }

View File

@ -1,25 +1,31 @@
import Serializer from './application'; import Serializer from './application';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/kv'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/kv';
import { NSPACE_KEY } from 'consul-ui/models/nspace'; import { NSPACE_KEY } from 'consul-ui/models/nspace';
import { NSPACE_QUERY_PARAM as API_NSPACE_KEY } from 'consul-ui/adapters/application'; import { NSPACE_QUERY_PARAM as API_NSPACE_KEY } from 'consul-ui/adapters/application';
import removeNull from 'consul-ui/utils/remove-null'; import removeNull from 'consul-ui/utils/remove-null';
export default Serializer.extend({ export default class KvSerializer extends Serializer {
primaryKey: PRIMARY_KEY, @service('atob') decoder;
slugKey: SLUG_KEY,
decoder: service('atob'), primaryKey = PRIMARY_KEY;
slugKey = SLUG_KEY;
// TODO: Would undefined be better instead of null? // TODO: Would undefined be better instead of null?
serialize: function(snapshot, options) { serialize(snapshot, options) {
const value = snapshot.attr('Value'); const value = snapshot.attr('Value');
return typeof value === 'string' ? this.decoder.execute(value) : null; return typeof value === 'string' ? this.decoder.execute(value) : null;
}, }
respondForQueryRecord: function(respond, query) {
return this._super(cb => respond((headers, body) => cb(headers, removeNull(body[0]))), query); respondForQueryRecord(respond, query) {
}, return super.respondForQueryRecord(
respondForQuery: function(respond, query) { cb => respond((headers, body) => cb(headers, removeNull(body[0]))),
return this._super( query
);
}
respondForQuery(respond, query) {
return super.respondForQuery(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
return cb( return cb(
@ -34,5 +40,5 @@ export default Serializer.extend({
}), }),
query query
); );
}, }
}); }

View File

@ -1,8 +1,8 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/node'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/node';
// TODO: Looks like ID just isn't used at all // TODO: Looks like ID just isn't used at all consider just using .Node for
// consider just using .Node for the SLUG_KEY // the SLUG_KEY
const fillSlug = function(item) { const fillSlug = function(item) {
if (item[SLUG_KEY] === '') { if (item[SLUG_KEY] === '') {
item[SLUG_KEY] = item['Node']; item[SLUG_KEY] = item['Node'];
@ -10,22 +10,28 @@ const fillSlug = function(item) {
return item; return item;
}; };
export default Serializer.extend({ export default class NodeSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQuery: function(respond, query) {
return this._super(cb => respond((headers, body) => cb(headers, body.map(fillSlug))), query); respondForQuery(respond, query) {
}, return super.respondForQuery(
respondForQueryRecord: function(respond, query) { cb => respond((headers, body) => cb(headers, body.map(fillSlug))),
return this._super( query
);
}
respondForQueryRecord(respond, query) {
return super.respondForQueryRecord(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
return cb(headers, fillSlug(body)); return cb(headers, fillSlug(body));
}), }),
query query
); );
}, }
respondForQueryLeader: function(respond, query) {
respondForQueryLeader(respond, query) {
// don't call super here we don't care about // don't call super here we don't care about
// ids/fingerprinting // ids/fingerprinting
return respond((headers, body) => { return respond((headers, body) => {
@ -45,5 +51,5 @@ export default Serializer.extend({
query query
); );
}); });
}, }
}); }

View File

@ -2,10 +2,11 @@ import Serializer from './application';
import { get } from '@ember/object'; import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
export default Serializer.extend({ export default class NspaceSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQuery: function(respond, serialized, data) {
respondForQuery(respond, serialized, data) {
return respond((headers, body) => { return respond((headers, body) => {
return this.attachHeaders( return this.attachHeaders(
headers, headers,
@ -16,9 +17,9 @@ export default Serializer.extend({
return item; return item;
}); });
} }
// Both of these might come though unset so we make sure // Both of these might come though unset so we make sure we at least
// we at least have an empty array here so we can add // have an empty array here so we can add children to them if we
// children to them if we need to whilst saving nspaces // need to whilst saving nspaces
['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) { ['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) {
if (typeof item.ACLs === 'undefined') { if (typeof item.ACLs === 'undefined') {
item.ACLs = []; item.ACLs = [];
@ -31,33 +32,36 @@ export default Serializer.extend({
}) })
); );
}); });
}, }
respondForQueryRecord: function(respond, serialized, data) {
// We don't attachHeaders here yet, mainly because we don't use respondForQueryRecord(respond, serialized, data) {
// blocking queries on form views yet, and by the time we do // We don't attachHeaders here yet, mainly because we don't use blocking
// Serializers should have been refactored to not use attachHeaders // queries on form views yet, and by the time we do Serializers should
// have been refactored to not use attachHeaders
return respond((headers, body) => { return respond((headers, body) => {
return body; return body;
}); });
}, }
respondForCreateRecord: function(respond, serialized, data) {
respondForCreateRecord(respond, serialized, data) {
return respond((headers, body) => { return respond((headers, body) => {
// The data properties sent to be saved in the backend // The data properties sent to be saved in the backend or the same ones
// or the same ones that we receive back if its successfull // that we receive back if its successfull therefore we can just ignore
// therefore we can just ignore the result and avoid ember-data // the result and avoid ember-data syncing problems
// syncing problems
return {}; return {};
}); });
}, }
respondForUpdateRecord: function(respond, serialized, data) {
respondForUpdateRecord(respond, serialized, data) {
return respond((headers, body) => { return respond((headers, body) => {
return body; return body;
}); });
}, }
respondForDeleteRecord: function(respond, serialized, data) {
respondForDeleteRecord(respond, serialized, data) {
return respond((headers, body) => { return respond((headers, body) => {
// Deletes only need the primaryKey/uid returning // Deletes only need the primaryKey/uid returning
return body; return body;
}); });
}, }
}); }

View File

@ -1,21 +1,22 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/oidc-provider'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/oidc-provider';
export default Serializer.extend({ export default class OidcSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForAuthorize: function(respond, serialized, data) {
// we avoid the parent serializer here as it tries to create a respondForAuthorize(respond, serialized, data) {
// fingerprint for an 'action' request // we avoid the parent serializer here as it tries to create a fingerprint
// but we still need to pass the headers through // for an 'action' request but we still need to pass the headers through
return respond((headers, body) => { return respond((headers, body) => {
return this.attachHeaders(headers, body, data); return this.attachHeaders(headers, body, data);
}); });
}, }
respondForQueryRecord: function(respond, query) {
respondForQueryRecord(respond, query) {
// add the name and nspace here so we can merge this // add the name and nspace here so we can merge this
// TODO: Look to see if we always want the merging functionality // TODO: Look to see if we always want the merging functionality
return this._super( return super.respondForQueryRecord(
cb => cb =>
respond((headers, body) => respond((headers, body) =>
cb(headers, { cb(headers, {
@ -26,5 +27,5 @@ export default Serializer.extend({
), ),
query query
); );
}, }
}); }

View File

@ -1,7 +1,7 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy';
export default Serializer.extend({ export default class PolicySerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
}); }

View File

@ -1,7 +1,7 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/proxy'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/proxy';
export default Serializer.extend({ export default class ProxySerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
}); }

View File

@ -1,7 +1,8 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/role'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/role';
import WithPolicies from 'consul-ui/mixins/policy/as-many'; import WithPolicies from 'consul-ui/mixins/policy/as-many';
export default Serializer.extend(WithPolicies, {
primaryKey: PRIMARY_KEY, export default class RoleSerializer extends Serializer.extend(WithPolicies) {
slugKey: SLUG_KEY, primaryKey = PRIMARY_KEY;
}); slugKey = SLUG_KEY;
}

View File

@ -1,11 +1,12 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service-instance'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service-instance';
export default Serializer.extend({ export default class ServiceInstanceSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQuery: function(respond, query) {
return this._super(function(cb) { respondForQuery(respond, query) {
return super.respondForQuery(function(cb) {
return respond(function(headers, body) { return respond(function(headers, body) {
if (body.length === 0) { if (body.length === 0) {
const e = new Error(); const e = new Error();
@ -20,9 +21,10 @@ export default Serializer.extend({
return cb(headers, body); return cb(headers, body);
}); });
}, query); }, query);
}, }
respondForQueryRecord: function(respond, query) {
return this._super(function(cb) { respondForQueryRecord(respond, query) {
return super.respondForQueryRecord(function(cb) {
return respond(function(headers, body) { return respond(function(headers, body) {
body = body.find(function(item) { body = body.find(function(item) {
return item.Node.Node === query.node && item.Service.ID === query.serviceId; return item.Node.Node === query.node && item.Service.ID === query.serviceId;
@ -41,5 +43,5 @@ export default Serializer.extend({
return cb(headers, body); return cb(headers, body);
}); });
}, query); }, query);
}, }
}); }

View File

@ -2,15 +2,16 @@ import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/service';
import { get } from '@ember/object'; import { get } from '@ember/object';
export default Serializer.extend({ export default class ServiceSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQuery: function(respond, query) {
return this._super( respondForQuery(respond, query) {
return super.respondForQuery(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
// Services and proxies all come together in the same list // Services and proxies all come together in the same list. Here we
// Here we map the proxies to their related services on a Service.Proxy // map the proxies to their related services on a Service.Proxy
// property for easy access later on // property for easy access later on
const services = {}; const services = {};
body body
@ -25,8 +26,8 @@ export default Serializer.extend({
return item.Kind === 'connect-proxy'; return item.Kind === 'connect-proxy';
}) })
.forEach(item => { .forEach(item => {
// Iterating to cover the usecase of a proxy being // Iterating to cover the usecase of a proxy being used by more
// used by more than one service // than one service
if (item.ProxyFor) { if (item.ProxyFor) {
item.ProxyFor.forEach(service => { item.ProxyFor.forEach(service => {
if (typeof services[service] !== 'undefined') { if (typeof services[service] !== 'undefined') {
@ -39,11 +40,12 @@ export default Serializer.extend({
}), }),
query query
); );
}, }
respondForQueryRecord: function(respond, query) {
respondForQueryRecord(respond, query) {
// Name is added here from the query, which is used to make the uid // Name is added here from the query, which is used to make the uid
// Datacenter gets added in the ApplicationSerializer // Datacenter gets added in the ApplicationSerializer
return this._super( return super.respondForQueryRecord(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
return cb(headers, { return cb(headers, {
@ -54,5 +56,5 @@ export default Serializer.extend({
}), }),
query query
); );
}, }
}); }

View File

@ -1,10 +1,14 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/session'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/session';
export default Serializer.extend({ export default class SessionSerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQueryRecord: function(respond, query) {
return this._super(cb => respond((headers, body) => cb(headers, body[0])), query); respondForQueryRecord(respond, query) {
}, return super.respondForQueryRecord(
}); cb => respond((headers, body) => cb(headers, body[0])),
query
);
}
}

View File

@ -1,18 +1,18 @@
import Serializer from './application'; import Serializer from './application';
import { get } from '@ember/object'; import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token';
import WithPolicies from 'consul-ui/mixins/policy/as-many'; import WithPolicies from 'consul-ui/mixins/policy/as-many';
import WithRoles from 'consul-ui/mixins/role/as-many'; import WithRoles from 'consul-ui/mixins/role/as-many';
export default Serializer.extend(WithPolicies, WithRoles, { export default class TokenSerializer extends Serializer.extend(WithPolicies, WithRoles) {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
serialize: function(snapshot, options) {
let data = this._super(...arguments); serialize(snapshot, options) {
// If a token has Rules, use the old API shape let data = super.serialize(...arguments);
// notice we use a null check here (not an undefined check) // If a token has Rules, use the old API shape notice we use a null check
// as we are dealing with the serialized model not raw user data // here (not an undefined check) as we are dealing with the serialized
// model not raw user data
if (data['Rules'] !== null) { if (data['Rules'] !== null) {
data = { data = {
ID: data.SecretID, ID: data.SecretID,
@ -22,20 +22,22 @@ export default Serializer.extend(WithPolicies, WithRoles, {
}; };
} }
// make sure we never send the SecretID // make sure we never send the SecretID
// TODO: If we selectively format the request payload in the adapter // TODO: If we selectively format the request payload in the adapter we
// we won't have to do this here // won't have to do this here see side note in
// see side note in https://github.com/hashicorp/consul/pull/6285 // https://github.com/hashicorp/consul/pull/6285 which will mean most if
// which will mean most if not all of this method can go // not all of this method can go
if (data) { if (data) {
delete data['SecretID']; delete data['SecretID'];
} }
return data; return data;
}, }
respondForSelf: function(respond, query) {
respondForSelf(respond, query) {
return this.respondForQueryRecord(respond, query); return this.respondForQueryRecord(respond, query);
}, }
respondForUpdateRecord: function(respond, serialized, data) {
return this._super( respondForUpdateRecord(respond, serialized, data) {
return super.respondForUpdateRecord(
cb => cb =>
respond((headers, body) => { respond((headers, body) => {
// Sometimes we get `Policies: null`, make null equal an empty array // Sometimes we get `Policies: null`, make null equal an empty array
@ -55,5 +57,5 @@ export default Serializer.extend(WithPolicies, WithRoles, {
serialized, serialized,
data data
); );
}, }
}); }

View File

@ -1,11 +1,12 @@
import Serializer from './application'; import Serializer from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/topology'; import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/topology';
export default Serializer.extend({ export default class TopologySerializer extends Serializer {
primaryKey: PRIMARY_KEY, primaryKey = PRIMARY_KEY;
slugKey: SLUG_KEY, slugKey = SLUG_KEY;
respondForQueryRecord: function(respond, query) {
return this._super(function(cb) { respondForQueryRecord(respond, query) {
return super.respondForQueryRecord(function(cb) {
return respond(function(headers, body) { return respond(function(headers, body) {
return cb(headers, { return cb(headers, {
...body, ...body,
@ -13,5 +14,5 @@ export default Serializer.extend({
}); });
}); });
}, query); }, query);
}, }
}); }

View File

@ -1,5 +1,5 @@
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import Store from 'ember-data/store'; import Store from '@ember-data/store';
export default class StoreService extends Store { export default class StoreService extends Store {
@service('data-source/service') @service('data-source/service')