Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(demo): mirage demo fixups for 3.0 #1257

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
}
Loading