Skip to content

Instantly share code, notes, and snippets.

View liavyona's full-sized avatar

Liav Yona liavyona

View GitHub Profile
@liavyona
liavyona / opa.go
Last active January 4, 2022 15:54
opa
package opa
import (
"context"
"encoding/json"
"fmt"
"sync"
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/rego"
@liavyona
liavyona / main.go
Last active October 12, 2021 18:36
compare
func compareToPrevRunNodes(
vaccinationsData map[string]api.VaccinationStatus,
currentRun string,
prevRunNodes map[string]interface{},
) (map[string][]interface{}, error) {
var vaccinationNodes = map[string][]interface{}{
"new": {},
"old": {},
"changed": {},
}
@liavyona
liavyona / arango.go
Last active October 12, 2021 18:37
arango 1
type ArangoDB struct {
db driver.Database
}
type VaccinationEdge struct {
From string `json:"_from"`
To string `json:"_to"`
Collection string `json:"collection"`
}
@liavyona
liavyona / api.go
Created August 31, 2021 07:29
vaccination status
package api
import (
"encoding/json"
"fmt"
"net/http"
"time"
)
type VaccinationStatusEntity struct {
@liavyona
liavyona / add_trigger.sql
Created July 31, 2021 12:31
add_trigger.sql
CREATE EXTENSION IF NOT EXISTS aws_lambda CASCADE;
CREATE OR REPLACE FUNCTION respond_with_lambda()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
BEGIN
IF cardinality(TG_ARGV)!=2 THEN
RAISE EXCEPTION 'Expected 2 parameters to respond_with_lambda function but got %', cardinality(TG_ARGV);
ELSEIF TG_ARGV[0]='' THEN
# Built-ins
from os import getenv
from json import dumps
from typing import Any, Dict
from http import HTTPStatus
# Third party
from aws_lambda_powertools.utilities.typing import LambdaContext
from aws_lambda_powertools.utilities.parser import event_parser, BaseModel
import boto3
@liavyona
liavyona / example.py
Created May 7, 2021 11:25
K8S HTTP proxy
def _proxy_http_request_kubernetes_service(service: str, port: int, path: str, namespace: str,
method: str, headers: dict,
body: Any, timeout: int) -> HTTPResponse:
api_client = ApiClient()
full_path = f"/api/v1/namespaces/{namespace}/services/{service}:{port}/proxy/{path}"
logger.info(f"Sending {method} request to {full_path} with body {body}")
response: HTTPResponse = api_client.call_api(
resource_path=full_path,
method=method,
header_params={"Accept": "*/*"}.update(headers),
@liavyona
liavyona / example.py
Created May 7, 2021 11:24
EKS- STS token authenticaton
def _authenticate_to_eks_cluster(cluster_endpoint: str, ca_cert_path: str, sts_token: str) -> None:
configuration = kube_client.Configuration()
configuration.host = cluster_endpoint
configuration.verify_ssl = True
configuration.debug = False
configuration.ssl_ca_cert = ca_cert_path
configuration.api_key = {"authorization": "Bearer " + sts_token}
kube_client.Configuration.set_default(configuration)
@liavyona
liavyona / example.py
Last active May 7, 2021 11:26
EKS - STS token fetching
EKS_CLUSTER_NAME_PARAMETER = 'x-k8s-aws-id'
EKS_TOKEN_PREFIX = 'k8s-aws-v1.'
STS_URL = 'https://sts.{}.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15'
DEFAULT_REGION = 'eu-central-1'
def _get_bearer_token(cluster_name: str, region: str = DEFAULT_REGION) -> str:
session = Session()
client = session.client('sts', region_name=region)
print(f"Lambda's AWS identity: {client.get_caller_identity()}")