feat: verify hostname (load free certificate call to bunny cdn) (#271)

* feat: initialize the handler and function.

* feat: add call to the bunny cdn api.

* refactor: rename access points to apps.

* refactor: remove redundant catch and throw

Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>

---------

Co-authored-by: Felipe Mendes <zo.fmendes@gmail.com>
This commit is contained in:
Shredder 2023-06-09 22:19:10 +03:30 committed by GitHub
parent 12df937d17
commit 94313c0300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -92,4 +92,12 @@ functions:
layers:
- { Ref: TopicAwsNodeModulesLambdaLayer }
- { Ref: TopicAwsLibsLambdaLayer }
- { Ref: TopicPrismaAwsPrismaClientLambdaLayer }
- { Ref: TopicPrismaAwsPrismaClientLambdaLayer }
verifyAccessPoint:
handler: src/functions/apps/handler.verifyApp
events:
- http:
path: verifyApp
method: post
cors: true

View File

@ -7,8 +7,43 @@ import {
BunnyCdn,
BunnyCdnError,
CreatePullZoneMethodArgs,
LoadFreeCertificateMethodArgs,
} from '@libs/bunnyCDN';
export const verifyApp = async (
event: APIGatewayEvent
): Promise<APIGatewayProxyResult> => {
try {
// Check the parameters and environment variables
dotenv.config();
if (event.body === null || process.env.BUNNY_CDN_ACCESS_KEY == undefined) {
return formatJSONResponse({
status: 422,
message: 'Required parameters were not passed.',
});
}
// Set up constants
const bunnyCdn = new BunnyCdn(process.env.BUNNY_CDN_ACCESS_KEY);
const hostname = JSON.parse(event.body).hostname;
let args: LoadFreeCertificateMethodArgs = {
hostname,
};
await bunnyCdn.loadFreeCertificate(args);
return formatJSONResponse({
status: true,
});
} catch (e) {
return formatJSONResponse({
status: 500,
message: e,
});
}
};
export const submitAppInfo = async (
event: APIGatewayEvent
): Promise<APIGatewayProxyResult> => {

View File

@ -1,5 +1,17 @@
import { handlerPath } from '@libs/handler-resolver';
export const verifyApp = {
handler: `${handlerPath(__dirname)}/handler.verifyApp`,
events: [
{
http: {
method: 'post',
path: 'verifyApp',
},
},
],
};
export const submitAppInfo = {
handler: `${handlerPath(__dirname)}/handler.submitAppInfo`,
events: [