Skip to content

Instantly share code, notes, and snippets.

View brachi-wernick's full-sized avatar

Brachi Packter brachi-wernick

  • moonactive
  • Israel
View GitHub Profile
@brachi-wernick
brachi-wernick / AddAwsGatewayResource.java
Last active March 8, 2018 13:33
AddAwsGatewayResource
//find the root resource
List<Resource> resources = gateway
.getResources(new GetResourcesRequest().withRestApiId(targetRestApi.getId())).getItems();
Resource rootResource = resources.stream().filter(resource -> resource.getPath().equals(File.separator)).findFirst().orElseThrow(RuntimeException::new);
// add our resource with a path and save its id
String resourceId=gateway.createResource(new CreateResourceRequest().withParentId(rootResourceId).withRestApiId(targetRestApiId)
.withPathPart(pathPart)).getId();
@brachi-wernick
brachi-wernick / CreateAwsInputModel.java
Last active March 8, 2018 13:33
CreateAwsInputModel.java
/* our model variable should include some json schema model like
{
"type":"object",
"properties":{
"a":{"type":"integer"},
"b":{"type":"integer"},
"op":{"type":"string"}
},
"title":"Input"
}
@brachi-wernick
brachi-wernick / AddMethodRequestWithModelName.java
Last active March 8, 2018 13:34
AddMethodRequestWithModelName
Map<String, String> modelName = new HashMap<String, String>() {{
put("application/json", inputModelName);
}};
gateway.putMethod(new PutMethodRequest().withResourceId(resourceId)
.withRestApiId(targetRestApiId)
.withAuthorizationType("NONE")
.withRequestModels(modelName)
.withHttpMethod("POST"));
@brachi-wernick
brachi-wernick / AddAwsGatewayResourceMethodResponse.java
Last active March 8, 2018 13:35
AddAwsGatewayResourceMethodResponse.java
Map<String, String> modelName = new HashMap<String, String>() {{
put("application/json", outputModelName);
}};
//rootResource was found previously
gateway.putMethodResponse(new PutMethodResponseRequest()
.withHttpMethod("POST")
.withResponseModels(modelName)
.withRestApiId(targetRestApiId)
.withResourceId(rootResource)
AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion(region).build();
FunctionConfiguration targetFunction = awsLambda.getFunction(new GetFunctionRequest().withFunctionName(lambdaName)).getConfiguration();
gateway.putIntegration(new PutIntegrationRequest()
.withCredentials(lambdaExecutionRole)
.withIntegrationHttpMethod("POST")
.withHttpMethod("POST")
.withType(IntegrationType.AWS)
.withRestApiId(targetRestApiId)
.withResourceId(rootResourceId)
.withPassthroughBehavior("WHEN_NO_MATCH")
.withUri(String.format(URI_TEMPLATE, targetFunction.getFunctionArn())));
gateway.putIntegrationResponse(new PutIntegrationResponseRequest().withRestApiId(targetRestApiId)
.withResourceId(rootResourceId)
.withHttpMethod("POST")
.withStatusCode("200"));
gateway.createDeployment(new CreateDeploymentRequest()
.withRestApiId(targetRestApi.getId())
.withStageName(deploymentStageName));
@brachi-wernick
brachi-wernick / maxLengthValidatorFn.ts
Last active April 10, 2018 19:36
maxLengthValidatorFn.ts
export function requiredIf(requiredIf:boolean): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
let value = c.value;
if ((value == null || value == undefined || value == "") && requiredIf) {
return {
requiredIf: {condition:requiredIf}
};
@brachi-wernick
brachi-wernick / requiredIfValidatorFnMutableInput.ts
Last active June 11, 2018 19:39
requiredIfValidatorFnMutableInput
export function requiredIf(requiredIf:{value:boolean}): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
let value = control.value;
if ((value == null || value == undefined || value == "") && requiredIf.value) {
return {
requiredIf: {condition:requiredIf.value}
};
}