Skip to content

Instantly share code, notes, and snippets.

View mgjam's full-sized avatar

Milan Gatyás mgjam

View GitHub Profile
#set($origin = $input.params(\"Origin\"))
#if($origin == \"\")
#set($origin = $input.params(\"origin\"))
#end
#if($origin.matches(\"https://my-origin-1.com\") || $origin.matches(\"https://my-origin-2.com\")
#set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)
#end
import { Cors, Resource } from "@aws-cdk/aws-apigateway";
// existing const resource: Resource
resource.addResource('MyCorsResource', {
defaultCorsPreflightOptions: {
allowOrigins: ['https://my-origin-1.com', 'https://my-origin-2.com'],
allowHeaders: Cors.DEFAULT_HEADERS.concat(['x-api-key'])
}
});
public class LambdaProxyInput
{
//...other properties
public Dictionary<string, string[]> multiValueQueryStringParameters { get; set; }
}
public object MyHandler(LambdaProxyInput input, ILambdaContext context)
{
var myArrayValues = input.multiValueQueryStringParameters["MyQuerystringArray"];
{
...,
"multiValueQueryStringParameters": {
"parameter1": [
"value1",
"value2"
],
"parameter2": [
"value"
]
// myApiResource: Resource defined
myApiResource.addMethod(
...http_method...,
{
...lambda_integration_options...
requestTemplates: 'application/json': `{
"MyQueryStringValue": "$input.params('MyQueryStringValue')"
#if ($input.params('MyQuerystringArray') != '')
,"MyQuerystringArray": $input.params('MyQuerystringArray')
class MyDto
{
public string MyQueryStringValue { get; set; }
public string[] MyQuerystringArray { get; set; }
}
var serviceCollection = new ServiceCollection();
serviceCollection.AddTransient<IHttpService, HttpService>();
serviceCollection.AddTransient<IService, LoggingService>();
@mgjam
mgjam / unit-1.cs
Last active February 5, 2021 14:52
class Processor
{
// .. dependencies
void Process(MyInput input)
{
if (ValidateInput(input))
{
new DatabaseConnection(...).ExecuteSql("...");
}
@mgjam
mgjam / kis-6.cs
Last active November 4, 2020 18:16
class EmailValidator
{
private readonly IEnumerable<IEmailValidation> emailValidations;
/*...ctor...*/
bool IsEmailValid(string email) => emailValidations
.Aggregate(true, (acc, src) => acc ? src.IsEmailValid(email) : acc);
}
interface IEmailValidation
{
@mgjam
mgjam / kis-5.cs
Last active November 4, 2020 18:02
class EmailValidator
{
private readonly IEmailLengthValidation emailLengthValidation;
private readonly IEmailRegexValidation emailRegexValidation;
private readonly IEmailBlacklistValidation emailBlacklistValidation;
bool IsEmailValid(string email)
{
if (!emailLengthValidation.IsEmailValid(email)) return false;
if (!emailRegexValidation.IsEmailValid(email)) return false;