Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 0.18.0 minor release #579

Merged
merged 7 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.17.0
v0.18.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ examples/quickstart/minio/*
.terraform.lock.hcl
.terraform.tfstate.lock*
terraform.*
backend.tf
build/buz
*.build
target/*
8 changes: 6 additions & 2 deletions cmd/buz/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ func (a *App) initializeManifold() {
func (a *App) initializeRouter() {
log.Info().Msg("🟢 initializing router")
a.engine = gin.New()
a.publicRouterGroup = a.engine.Group("")
a.switchableRouterGroup = a.engine.Group("")
if err := a.engine.SetTrustedProxies(nil); err != nil {
panic(err)
}
Expand Down Expand Up @@ -147,6 +145,11 @@ func (a *App) initializeMiddleware() {
}
}

func (a *App) initializeRouterGroups() {
a.publicRouterGroup = a.engine.Group("")
a.switchableRouterGroup = a.engine.Group("")
}

// 🐝 and healthcheck route are always public
func (a *App) initializePublicRoutes() {
log.Info().Msg("🟢 initializing buz route")
Expand Down Expand Up @@ -201,6 +204,7 @@ func (a *App) Initialize() {
a.initializeRouter()
a.initializeManifold()
a.initializeMiddleware()
a.initializeRouterGroups()
a.initializePublicRoutes()
a.initializeOpsRoutes()
a.initializeSchemaCacheRoutes()
Expand Down
32 changes: 16 additions & 16 deletions deploy/terraform/aws/lambda/locals.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
locals {
domain_parts = split(".", var.buz_domain)
cookie_domain = join(".", slice(local.domain_parts, 1, length(local.domain_parts))) # Assumes Buz is running on a subdomain and the cookie should be on root
buz_debug_var = "DEBUG"
buz_config_var = "BUZ_CONFIG_PATH"
buz_config_path = "/etc/buz/config.yml"
system_env_base = "${var.system}-${var.env}-"
artifact_repository = "${local.system_env_base}img"
image = "buz:${var.buz_version}"
buz_source_image = "ghcr.io/silverton-io/${local.image}"
service_name = "${local.system_env_base}collector"
config = "${local.system_env_base}config"
schema_bucket = "${local.system_env_base}${var.schema_bucket_name}"
events_bucket = "${local.system_env_base}${var.events_bucket_name}"
default_output = "buz_events"
deadletter_output = "buz_invalid_events"
domain_parts = split(".", var.buz_domain)
cookie_domain = join(".", slice(local.domain_parts, 1, length(local.domain_parts))) # Assumes Buz is running on a subdomain and the cookie should be on root
buz_debug_var = "DEBUG"
buz_config_var = "BUZ_CONFIG_PATH"
buz_config_path = "/etc/buz/config.yml"
system_env_base = "${var.system}-${var.env}-"
artifact_repository = "${local.system_env_base}img"
image = "buz:${var.buz_version}"
buz_source_image = "${var.buz_image_repo}/${local.image}"
service_name = "${local.system_env_base}collector"
config = "${local.system_env_base}config"
schema_bucket = "${local.system_env_base}${var.schema_bucket_name}"
events_bucket = "${local.system_env_base}${var.events_bucket_name}"
default_output = "buz_events"
deadletter_output = "buz_invalid_events"
metadata_extraction_params = "{isValid:.isValid,vendor:.vendor,namespace:.namespace,version:.version}"
s3_dynamic_prefix = "isValid=!{partitionKeyFromQuery:isValid}/vendor=!{partitionKeyFromQuery:vendor}/namespace=!{partitionKeyFromQuery:namespace}/version=!{partitionKeyFromQuery:version}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
s3_dynamic_prefix = "isValid=!{partitionKeyFromQuery:isValid}/vendor=!{partitionKeyFromQuery:vendor}/namespace=!{partitionKeyFromQuery:namespace}/version=!{partitionKeyFromQuery:version}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/"
}
35 changes: 19 additions & 16 deletions deploy/terraform/aws/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ data "aws_ecr_image" "buz_image" {

resource "null_resource" "configure_docker" {
triggers = {
build_number = var.buz_version
always_run = timestamp()
}
provisioner "local-exec" {
command = "aws ecr get-login-password --region ${var.aws_region} | docker login --username AWS --password-stdin ${data.aws_caller_identity.current.account_id}.dkr.ecr.${var.aws_region}.amazonaws.com"
Expand Down Expand Up @@ -228,6 +228,14 @@ resource "aws_cloudwatch_log_group" "buz" {
}
}

data "aws_cloudfront_origin_request_policy" "buz" {
name = "Managed-AllViewerExceptHostHeader"
}

data "aws_cloudfront_cache_policy" "buz" {
name = "Managed-CachingDisabled"
}

resource "aws_cloudfront_distribution" "buz" {
enabled = true
is_ipv6_enabled = true
Expand All @@ -248,25 +256,20 @@ resource "aws_cloudfront_distribution" "buz" {
}

default_cache_behavior {
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
target_origin_id = replace(replace(aws_lambda_function_url.buz.function_url, "https://", ""), "/", "")
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["HEAD", "GET"]
forwarded_values {
query_string = true
cookies {
forward = "all"
}
}
viewer_protocol_policy = "redirect-to-https"
min_ttl = 0
default_ttl = 3600
max_ttl = 86400
target_origin_id = replace(replace(aws_lambda_function_url.buz.function_url, "https://", ""), "/", "")
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = ["HEAD", "GET"]
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.buz.id
cache_policy_id = data.aws_cloudfront_cache_policy.buz.id
}

restrictions {
geo_restriction {
restriction_type = "whitelist"
locations = ["US", "CA", "GB", "DE"]
restriction_type = "none"
}
}

Expand Down
5 changes: 3 additions & 2 deletions deploy/terraform/aws/lambda/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ terraform {
}

provider "aws" {
region = var.aws_region
}
region = var.aws_region
profile = var.aws_profile
}
14 changes: 13 additions & 1 deletion deploy/terraform/aws/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ variable "aws_region" {
default = "us-east-1"
}

variable "aws_profile" {
description = "AWS Profile"
type = string
default = "default"
}

variable "system" {
description = "The name of the Buz implementation. \n\nExample: buz"
type = string
Expand All @@ -26,10 +32,16 @@ variable "buz_domain" {
type = string
}

variable "buz_image_repo" {
description = "The Buz image repository"
type = string
default = "ghcr.io/silverton-io"
}

variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.17.0"
default = "v0.18.0"
}

variable "buz_lambda_memory_limit" {
Expand Down
2 changes: 1 addition & 1 deletion deploy/terraform/gcp/cloud_run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variable "buz_domain" {
variable "buz_version" {
description = "The version of Buz to run."
type = string
default = "v0.17.0"
default = "v0.18.0"
}

variable "buz_service_timeout_seconds" {
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ x-dependency:
services:
buz:
container_name: buz
image: ghcr.io/silverton-io/buz:v0.17.0
image: ghcr.io/silverton-io/buz:v0.18.0
volumes:
- type: bind
source: ./buz/quickstart.conf.yml
Expand Down
1 change: 1 addition & 0 deletions pkg/annotator/annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func getSchemaMetadata(schema []byte) schemaMetadata {
namespace := schemaContents.Get("self.namespace").String()
version := schemaContents.Get("self.version").String()
disableValidation := schemaContents.Get("disableValidation").Bool()
log.Debug().Msgf("🟡 vendor: %s, namespace: %s, version: %s, disableValidation: %t", vendor, namespace, version, disableValidation)
return schemaMetadata{
Vendor: vendor,
Namespace: namespace,
Expand Down
33 changes: 33 additions & 0 deletions pkg/annotator/annotator_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package annotator

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetSchemaMetadata(t *testing.T) {
testData := []struct {
name string
input []byte
expected schemaMetadata
}{
{
name: "Valid JSON",
input: []byte(`{"self":{"vendor":"testVendor","namespace":"testNamespace","version":"testVersion"},"disableValidation":true}`),
expected: schemaMetadata{
Vendor: "testVendor",
Namespace: "testNamespace",
Version: "testVersion",
DisableValidation: true,
},
},
}

for _, tc := range testData {
t.Run(tc.name, func(t *testing.T) {
result := getSchemaMetadata(tc.input)
assert.Equal(t, tc.expected, result)
})
}
}
1 change: 0 additions & 1 deletion pkg/annotator/test_annotator.go

This file was deleted.

20 changes: 18 additions & 2 deletions pkg/middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,23 @@ import (

func CORS(conf config.Cors) gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", strings.Join(conf.AllowOrigin, ", "))
c.Header("Access-Control-Allow-Credentials", strconv.FormatBool(conf.AllowCredentials))
origin := c.Request.Header.Get("Origin")

for _, domain := range conf.AllowOrigin {
if domain == "*" {
c.Header("Access-Control-Allow-Origin", origin)
break
}
if strings.HasSuffix(origin, domain) {
c.Header("Access-Control-Allow-Origin", origin)
break
}
}

if strconv.FormatBool(conf.AllowCredentials) == "true" {
c.Header("Access-Control-Allow-Credentials", strconv.FormatBool(conf.AllowCredentials))
}

c.Header("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Set-Cookie, Cookie")
c.Header("Access-Control-Allow-Methods", strings.Join(conf.AllowMethods, ", "))
c.Header("Access-Control-Max-Age", strconv.Itoa(conf.MaxAge))
Expand All @@ -25,6 +40,7 @@ func CORS(conf config.Cors) gin.HandlerFunc {
c.AbortWithStatus(http.StatusNoContent)
return
}

c.Next()
}
}
24 changes: 19 additions & 5 deletions pkg/middleware/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestCors(t *testing.T) {
u := "/test"
conf := config.Cors{
Enabled: true,
AllowOrigin: []string{"*"},
AllowCredentials: false,
AllowOrigin: []string{"http://allowed-origin.com"},
AllowCredentials: true,
AllowMethods: []string{"GET", "OPTIONS"},
MaxAge: 86400,
}
Expand All @@ -29,14 +29,28 @@ func TestCors(t *testing.T) {
ts := httptest.NewServer(r)
defer ts.Close()

t.Run("preflight", func(t *testing.T) {
t.Run("preflight success", func(t *testing.T) {
var client = &http.Client{}
req, _ := http.NewRequest(http.MethodOptions, ts.URL+u, nil)
req.Header.Set("Origin", "http://allowed-origin.com")
resp, _ := client.Do(req)

assert.Equal(t, []string{"false"}, resp.Header["Access-Control-Allow-Credentials"])
assert.Equal(t, []string{"true"}, resp.Header["Access-Control-Allow-Credentials"])
assert.Equal(t, []string{"GET, OPTIONS"}, resp.Header["Access-Control-Allow-Methods"])
assert.Equal(t, []string{"*"}, resp.Header["Access-Control-Allow-Origin"])
assert.Equal(t, []string{"http://allowed-origin.com"}, resp.Header["Access-Control-Allow-Origin"])
assert.Equal(t, []string{"86400"}, resp.Header["Access-Control-Max-Age"])
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
})

t.Run("preflight fail", func(t *testing.T) {
var client = &http.Client{}
req, _ := http.NewRequest(http.MethodOptions, ts.URL+u, nil)
req.Header.Set("Origin", "http://not-allowed-origin.com")
resp, _ := client.Do(req)

assert.Equal(t, []string{"true"}, resp.Header["Access-Control-Allow-Credentials"])
assert.Equal(t, []string{"GET, OPTIONS"}, resp.Header["Access-Control-Allow-Methods"])
assert.Equal(t, []string([]string(nil)), resp.Header["Access-Control-Allow-Origin"])
assert.Equal(t, []string{"86400"}, resp.Header["Access-Control-Max-Age"])
assert.Equal(t, http.StatusNoContent, resp.StatusCode)
})
Expand Down
Loading
Loading