Skip to content

Commit

Permalink
fix(demo): mirage demo fixups for 3.0 (#1257)
Browse files Browse the repository at this point in the history
* fix(demo): mirage fixups for 3.0

* fix(reports): ensure reports generation URLs are prefixed by the server authority
  • Loading branch information
andrewazores authored May 9, 2024
1 parent 2cffe0b commit 1c404d7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/app/Shared/Services/Report.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export class ReportService {
}
const headers = new Headers();
headers.append('Accept', 'application/json');
return fromFetch(recording.reportUrl, {
let url = recording.reportUrl;
if (!url.startsWith(this.login.authority)) {
url = `${this.login.authority}/${recording.reportUrl}`;
}
return fromFetch(url, {
method: 'GET',
mode: 'cors',
credentials: 'include',
Expand Down
1 change: 1 addition & 0 deletions src/mirage/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const targetFactory: FactoryDefinition<any> = Factory.extend({
alias: 'Fake Target',
connectUrl: 'http://fake-target.local:1234',
jvmId: '1234',
labels: [],
annotations: {
platform: [
{
Expand Down
31 changes: 28 additions & 3 deletions src/mirage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const startMirage = ({ environment = 'development' } = {}) => {
},
],
},
labels: [],
});
websocket.send(
JSON.stringify({
Expand Down Expand Up @@ -193,9 +194,9 @@ export const startMirage = ({ environment = 'development' } = {}) => {
const attrs = request.requestBody as any;

const recording = schema.create(Resource.RECORDING, {
// id will generated by Mirage (i.e. increment intergers)
// id will generated by Mirage (i.e. increment integers)
downloadUrl: '',
reportUrl: `beta/reports/${encodeURIComponent(request.params.targetId)}/${encodeURIComponent(
reportUrl: `api/beta/reports/${encodeURIComponent(request.params.targetId)}/${encodeURIComponent(
attrs.get('recordingName'),
)}`,
name: attrs.get('recordingName'),
Expand Down Expand Up @@ -469,7 +470,28 @@ export const startMirage = ({ environment = 'development' } = {}) => {
websocket.send(JSON.stringify(msg));
return new Response(200);
});
this.get('api/v2.2/credentials', () => ({ data: { result: [] } }));
this.post('api/v2.2/credentials', (schema, request) => {
const credential = schema.create(Resource.CREDENTIAL, {
matchExpression: (request.requestBody as any).get('matchExpression'),
numMatchingTargets: 0,
});
websocket.send(
JSON.stringify({
meta: {
category: 'CredentialsStored',
type: { type: 'application', subType: 'json' },
},
message: {
id: credential.id,
matchExpression: credential.matchExpression,
numMatchingTargets: credential.numMatchingTargets,
},
}),
);
return new Response(201);
});
this.get('api/v2.2/credentials', (schema) => ({ data: { result: schema.all(Resource.CREDENTIAL).models } }));
this.get('api/v2.2/credentials/:id', () => ({ data: { result: { matchExpression: '', targets: [] } } }));
this.post('api/v2.2/graphql', (schema, request) => {
const body = JSON.parse(request.requestBody);
const query = body.query.trim();
Expand Down Expand Up @@ -699,6 +721,9 @@ export const startMirage = ({ environment = 'development' } = {}) => {
}
return { data };
});
this.get('api/v3/tls/certs', () => {
return new Response(200, {}, ['/truststore/additional-app.crt']);
});
},
});
};
Expand Down
2 changes: 2 additions & 0 deletions src/mirage/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ const TargetModel: ModelDefinition<any> = Model.extend({});
const RecordingModel: ModelDefinition<any> = Model.extend({});
const ArchiveModel: ModelDefinition<any> = Model.extend({});
const RuleModel: ModelDefinition<any> = Model.extend({});
const CredentialModel: ModelDefinition<any> = Model.extend({});

export const models = {
[Resource.TARGET]: TargetModel,
[Resource.RECORDING]: RecordingModel,
[Resource.ARCHIVE]: ArchiveModel,
[Resource.RULE]: RuleModel,
[Resource.CREDENTIAL]: CredentialModel,
};

export default models;
1 change: 1 addition & 0 deletions src/mirage/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export enum Resource {
RECORDING = 'recording',
ARCHIVE = 'archive',
RULE = 'rule',
CREDENTIAL = 'credential',
}

0 comments on commit 1c404d7

Please sign in to comment.