Skip to content

Commit

Permalink
Release/0.6.12 (#61)
Browse files Browse the repository at this point in the history
* Add API Mode.
  Add support of the SQLite DB for storing OpenAPI schemas, and support for multiple specs.

* Add TRACE debug log level

* Update Shadow API. Add unknown parameters detection

* Add Japanese translations

* Update dependencies

* Bug fixes
  • Loading branch information
afr1ka authored and Nikolay Tkachenko committed Aug 8, 2023
1 parent efdb5b6 commit 1f115e3
Show file tree
Hide file tree
Showing 53 changed files with 7,483 additions and 552 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resources/dev/wallarm_api.db
17 changes: 8 additions & 9 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
needs:
- draft-release
env:
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.19.5.linux-amd64.tar.gz"
X_GO_DISTRIBUTION: "https://go.dev/dl/go1.20.7.linux-amd64.tar.gz"
strategy:
matrix:
include:
Expand All @@ -78,6 +78,7 @@ jobs:
apt-get update -y && \
apt-get install --no-install-recommends -y \
build-essential \
binutils \
ca-certificates \
curl \
Expand Down Expand Up @@ -159,7 +160,7 @@ jobs:
needs:
- draft-release
env:
X_GO_VERSION: "1.19.5-r0"
X_GO_VERSION: "1.20.7-r0"
strategy:
matrix:
include:
Expand All @@ -177,7 +178,7 @@ jobs:
-
uses: addnab/docker-run-action@v3
with:
image: alpine:3.17
image: alpine:3.18
options: >
--volume ${{ github.workspace }}:/build
--workdir /build
Expand Down Expand Up @@ -261,18 +262,16 @@ jobs:
runs-on: ubuntu-latest
needs:
- draft-release
env:
X_GO_VERSION: "1.19.5-r0"
strategy:
matrix:
include:
- arch: armv6
distro: bullseye
go_distribution: https://go.dev/dl/go1.19.5.linux-armv6l.tar.gz
go_distribution: https://go.dev/dl/go1.20.7.linux-armv6l.tar.gz
artifact: armv6-libc
- arch: aarch64
distro: bullseye
go_distribution: https://go.dev/dl/go1.19.5.linux-arm64.tar.gz
go_distribution: https://go.dev/dl/go1.20.7.linux-arm64.tar.gz
artifact: arm64-libc
- arch: armv6
distro: alpine_latest
Expand Down Expand Up @@ -328,10 +327,10 @@ jobs:
git \
gzip \
make \
go=${{ env.X_GO_VERSION }}
go
;;
esac
go version
run: |-
export PATH=${PATH}:/usr/local/go/bin && \
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
vendor/
.DS_Store
.idea/
dev/
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS build
FROM golang:1.20-alpine3.18 AS build

ARG APIFIREWALL_VERSION
ENV APIFIREWALL_VERSION=${APIFIREWALL_VERSION}
Expand All @@ -10,7 +10,7 @@ RUN apk add --no-cache \
musl-dev

WORKDIR /build
COPY . .
COPY .. .

RUN go mod download -x && \
go build \
Expand All @@ -22,17 +22,17 @@ RUN go mod download -x && \
# Smoke test
RUN ./api-firewall -v

FROM alpine:3.17 AS composer
FROM alpine:3.18 AS composer

WORKDIR /output

COPY --from=build /build/api-firewall ./usr/local/bin/
COPY ./docker-entrypoint.sh ./usr/local/bin/docker-entrypoint.sh
COPY docker-entrypoint.sh ./usr/local/bin/docker-entrypoint.sh

RUN chmod 755 ./usr/local/bin/* && \
chown root:root ./usr/local/bin/*

FROM alpine:3.17
FROM alpine:3.18

RUN adduser -u 1000 -H -h /opt -D -s /bin/sh api-firewall

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.6.11
VERSION := 0.6.12

.DEFAULT_GOAL := build

Expand All @@ -13,11 +13,12 @@ tidy:
go mod vendor

test:
go test ./... -count=1
go test ./... -count=1 -race -cover

genmocks:
mockgen -source ./internal/platform/proxy/chainpool.go -destination ./internal/platform/proxy/httppool_mock.go -package proxy
mockgen -source ./internal/platform/shadowAPI/shadowAPI.go -destination ./internal/platform/shadowAPI/shadowAPI_mock.go -package shadowAPI
mockgen -source ./internal/platform/database/database.go -destination ./internal/platform/database/database_mock.go -package database
mockgen -source ./cmd/api-firewall/internal/updater/updater.go -destination ./cmd/api-firewall/internal/updater/updater_mock.go -package updater

update:
go get -u ./...
Expand Down
68 changes: 68 additions & 0 deletions cmd/api-firewall/internal/handlers/api/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package api

import (
"os"

"github.com/sirupsen/logrus"
"github.com/valyala/fasthttp"
"github.com/wallarm/api-firewall/internal/platform/database"
"github.com/wallarm/api-firewall/internal/platform/web"
)

type Health struct {
Build string
Logger *logrus.Logger
OpenAPIDB database.DBOpenAPILoader
}

// Readiness checks if the Fasthttp connection pool is ready to handle new requests.
func (h *Health) Readiness(ctx *fasthttp.RequestCtx) error {

status := "ok"
statusCode := fasthttp.StatusOK

if len(h.OpenAPIDB.SchemaIDs()) == 0 {
status = "not ready"
statusCode = fasthttp.StatusInternalServerError
}

data := struct {
Status string `json:"status"`
}{
Status: status,
}

return web.Respond(ctx, data, statusCode)
}

// Liveness returns simple status info if the service is alive. If the
// app is deployed to a Kubernetes cluster, it will also return pod, node, and
// namespace details via the Downward API. The Kubernetes environment variables
// need to be set within your Pod/Deployment manifest.
func (h *Health) Liveness(ctx *fasthttp.RequestCtx) error {
host, err := os.Hostname()
if err != nil {
host = "unavailable"
}

data := struct {
Status string `json:"status,omitempty"`
Build string `json:"build,omitempty"`
Host string `json:"host,omitempty"`
Pod string `json:"pod,omitempty"`
PodIP string `json:"podIP,omitempty"`
Node string `json:"node,omitempty"`
Namespace string `json:"namespace,omitempty"`
}{
Status: "up",
Build: h.Build,
Host: host,
Pod: os.Getenv("KUBERNETES_PODNAME"),
PodIP: os.Getenv("KUBERNETES_NAMESPACE_POD_IP"),
Node: os.Getenv("KUBERNETES_NODENAME"),
Namespace: os.Getenv("KUBERNETES_NAMESPACE"),
}

statusCode := fasthttp.StatusOK
return web.Respond(ctx, data, statusCode)
}
Loading

0 comments on commit 1f115e3

Please sign in to comment.