Skip to content

Commit

Permalink
Playground API - retrieveSample
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 7, 2022
1 parent 533da0c commit ed192b9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
40 changes: 40 additions & 0 deletions playground-api/handler.ts
Expand Up @@ -294,6 +294,45 @@ async function retrieveResult(request: HttpRequest): Promise<HttpResponse> {
}
}

async function retrieveSample(request: HttpRequest): Promise<HttpResponse> {
try {
const id = request.queryStringParameters.id;
const object = await s3.getObject({
Bucket: 'phpstan-playground',
Key: 'api/results/' + id + '.json',
}).promise();
const json = JSON.parse(object.Body as string);
const strictRules = typeof json.config.strictRules !== 'undefined' ? json.config.strictRules : false;
const bleedingEdge = typeof json.config.bleedingEdge !== 'undefined' ? json.config.bleedingEdge : false;
const treatPhpDocTypesAsCertain = typeof json.config.treatPhpDocTypesAsCertain !== 'undefined' ? json.config.treatPhpDocTypesAsCertain : true;

const bodyJson: any = {
code: json.code,
errors: json.errors,
version: json.version,
level: json.level,
config: {
strictRules,
bleedingEdge,
treatPhpDocTypesAsCertain,
},
};
if (typeof json.versionedErrors !== 'undefined') {
bodyJson.versionedErrors = json.versionedErrors;
} else {
bodyJson.versionedErrors = [{errors: json.errors, title: 'PHP 7.4'}];
}
return Promise.resolve({
statusCode: 200,
body: JSON.stringify(bodyJson),
});
} catch (e) {
console.error(e);
captureException(e);
return Promise.resolve({statusCode: 500});
}
}

async function retrieveLegacyResult(request: HttpRequest): Promise<HttpResponse> {
try {
const id = request.queryStringParameters.id;
Expand Down Expand Up @@ -343,5 +382,6 @@ const corsMiddleware = cors();
module.exports = {
analyseResult: middy(analyseResult).use(corsMiddleware),
retrieveResult: middy(retrieveResult).use(corsMiddleware),
retrieveSample: middy(retrieveSample).use(corsMiddleware),
retrieveLegacyResult: middy(retrieveLegacyResult).use(corsMiddleware),
};
9 changes: 9 additions & 0 deletions playground-api/serverless.yml
Expand Up @@ -29,6 +29,15 @@ functions:
path: /result
cors: true

retrieveSample:
handler: handler.retrieveSample
role: arn:aws:iam::928192134594:role/lambda-phpstan-playground
events:
- http:
method: get
path: /sample
cors: true

retrieveLegacyResult:
handler: handler.retrieveLegacyResult
role: arn:aws:iam::928192134594:role/lambda-phpstan-playground
Expand Down

0 comments on commit ed192b9

Please sign in to comment.