Skip to content

Instantly share code, notes, and snippets.

View ivamluz's full-sized avatar

Ivam Luz ivamluz

  • Appnovation
  • Campinas
View GitHub Profile
@ivamluz
ivamluz / gist:5366568970701ccfb09282378124574a
Created May 16, 2020 21:49
Test Cloud Run endpoint - 200 response
$ curl -i \
> -H 'x-api-key: 1234' \
> 'https://pipeline-demo-pmrwyqmvha-uc.a.run.app/hello'
HTTP/2 200
content-type: application/json
date: Sat, 16 May 2020 21:48:45 GMT
server: Google Frontend
content-length: 18
alt-svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
$ ./hash_value.py --value "1234"
d404559f602eab6fd602ac7680dacbfaadd13630335e951f097af3900e9de176b6db28512f2e000b9d04fba5133e8b1c6e8df59db3a8ab9d60be4b97cc9e81db
@ivamluz
ivamluz / gist:60f982bf4744aa887354e13207d6742d
Last active May 17, 2020 16:32
Test Cloud Run endpoint - 401 response
$ curl -i \
> -H 'x-api-key: 1234' \
> 'https://pipeline-demo-pmrwyqmvha-uc.a.run.app/hello'
HTTP/2 401
content-type: text/html; charset=utf-8
date: Sat, 16 May 2020 19:59:36 GMT
server: Google Frontend
content-length: 338
alt-svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
@ivamluz
ivamluz / gist:1cf160ad935942d99be5ce115fcbf1d8
Created May 16, 2020 19:57
Test a Google Cloud Run endpoint
$ curl -i 'https://pipeline-demo-pmrwyqmvha-uc.a.run.app/health'
HTTP/2 200
content-type: text/html; charset=utf-8
date: Sat, 16 May 2020 19:56:20 GMT
server: Google Frontend
content-length: 13
alt-svc: h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
It is alive!
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
from functools import wraps
from flask import request, abort
import hashlib
import os
def require_apikey(view_function):
@wraps(view_function)
def decorated_function(*args, **kwargs):
API_KEY_HEADER_NAME = 'x-api-key'
steps:
- name: gcr.io/cloud-builders/docker
args:
["build", "-t", "gcr.io/$PROJECT_ID/${_SERVICE_NAME}:${SHORT_SHA}", "."]
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/${_SERVICE_NAME}"]
- name: "gcr.io/cloud-builders/gcloud"
args:
# serverless.yml
service: service-name
provider: aws
functions:
hello:
handler: handler.hello
vpc:
securityGroupIds:
- ${cf:<STACK-NAME>.PrivateLambdaSecurityGroup}
@ivamluz
ivamluz / delete-cnf-stack.sh
Created April 25, 2020 21:32
Sample command for deleting a Cloud Formation Stack
aws cloudformation delete-stack --stack-name <stack-name>
./deploy-cfn-stack.sh \
<stack-name> \
<path-to-cfn-template-file> \
<path-to-cfn-params-file>