Skip to content

Commit 3088ae1

Browse files
committed
Add testbench
1 parent cfa1692 commit 3088ae1

File tree

11 files changed

+263
-3
lines changed

11 files changed

+263
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
static/

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM golang:1.21-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache gcc musl-dev
7+
8+
# Copy go mod files
9+
COPY go.mod go.sum ./
10+
RUN go mod download
11+
12+
# Copy source code
13+
COPY . .
14+
15+
# Build the application
16+
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
17+
18+
# Final stage
19+
FROM alpine:latest
20+
21+
WORKDIR /app
22+
23+
# Copy the binary from builder
24+
COPY --from=builder /app/main .
25+
COPY views/ views/
26+
COPY static/ static/
27+
28+
# Run as non-root user
29+
RUN adduser -D appuser
30+
USER appuser
31+
32+
EXPOSE 8080
33+
34+
CMD ["./main"]

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,17 @@ reload:
88
kubectl delete namespace tesla
99
kubectl create namespace tesla
1010
make apply
11+
12+
run:
13+
docker compose up
14+
15+
pull-secrets:
16+
@echo "Creating static directory if it doesn't exist..."
17+
@mkdir -p ./static
18+
@echo "Pulling secrets from tesla-fleet-api..."
19+
kubectl get secret tesla-fleet-api -n tesla -o jsonpath='{.data}' | jq -r 'to_entries[] | "echo \"Extracting \(.key)...\"; echo \(.value) | base64 -d > \"./static/\(.key)\""' | sh
20+
@echo "Pulling secrets from tesla-raj-tls..."
21+
kubectl get secret tesla-raj-tls -n tesla -o jsonpath='{.data}' | jq -r 'to_entries[] | "echo \"Extracting \(.key)...\"; echo \(.value) | base64 -d > \"./static/\(.key)\""' | sh
22+
@echo "Done pulling secrets!"
23+
24+

config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"host": "0.0.0.0",
3+
"port": 4443,
4+
"log_level": "debug",
5+
"tls": {
6+
"server_cert": "/etc/ssl/certs/tls.crt",
7+
"server_key": "/etc/ssl/certs/tls.key"
8+
},
9+
"fleet": {
10+
"private_key": "/etc/vehicle-command/private-key.pem"
11+
}
12+
}

docker-compose.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: '3.8'
2+
3+
services:
4+
tesla-http-proxy:
5+
image: tesla/vehicle-command:latest
6+
ports:
7+
- "4443:4443"
8+
environment:
9+
- TESLA_HTTP_PROXY_TLS_CERT=/config/tls.crt
10+
- TESLA_HTTP_PROXY_TLS_KEY=/config/tls.key
11+
- TESLA_HTTP_PROXY_HOST=0.0.0.0
12+
- TESLA_HTTP_PROXY_PORT=4443
13+
- TESLA_HTTP_PROXY_TIMEOUT=10s
14+
- TESLA_KEY_FILE=/secret/private-key.pem
15+
- TESLA_VERBOSE=true
16+
volumes:
17+
- ./static/tls.crt:/config/tls.crt:ro
18+
- ./static/tls.key:/config/tls.key:ro
19+
- ./static/private-key.pem:/secret/private-key.pem:ro
20+
21+
22+
23+
fleet-telemetry-consumer:
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
ports:
28+
- "3000:3000"
29+
# environment:
30+
# - TESLA_PROXY_URL=https://localhost:4443
31+
depends_on:
32+
- tesla-http-proxy
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
apiVersion: cert-manager.io/v1
22
kind: Certificate
33
metadata:
4-
name: fleet-telemetry-tesla-tls
4+
name: tesla-raj-tls
55
spec:
6+
privateKey:
7+
algorithm: ECDSA
8+
size: 256
9+
rotationPolicy: Always
610
dnsNames:
711
- fleet-telemetry.tesla.rajsingh.info
12+
- tesla.rajsingh.info
813
issuerRef:
914
group: cert-manager.io
1015
kind: ClusterIssuer
1116
name: raj-issuer
12-
secretName: fleet-telemetry-tesla-raj-tls
17+
secretName: tesla-raj-tls
1318
usages:
1419
- digital signature
1520
- key encipherment

examples/kustomization/fleet-telemetry.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spec:
3838
name: fleet-telemetry-config
3939
- name: certs
4040
secret:
41-
secretName: fleet-telemetry-tesla-raj-tls
41+
secretName: tesla-raj-tls
4242
---
4343
apiVersion: v1
4444
kind: Service

go.mod

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module fleet-telemetry-consumer
2+
3+
go 1.21
4+
5+
require (
6+
github.com/gofiber/fiber/v2 v2.52.0
7+
github.com/gofiber/template/html/v2 v2.1.0
8+
)
9+
10+
require (
11+
github.com/andybalholm/brotli v1.0.5 // indirect
12+
github.com/gofiber/template v1.8.2 // indirect
13+
github.com/gofiber/utils v1.1.0 // indirect
14+
github.com/google/uuid v1.5.0 // indirect
15+
github.com/klauspost/compress v1.17.0 // indirect
16+
github.com/mattn/go-colorable v0.1.13 // indirect
17+
github.com/mattn/go-isatty v0.0.20 // indirect
18+
github.com/mattn/go-runewidth v0.0.15 // indirect
19+
github.com/rivo/uniseg v0.2.0 // indirect
20+
github.com/valyala/bytebufferpool v1.0.0 // indirect
21+
github.com/valyala/fasthttp v1.51.0 // indirect
22+
github.com/valyala/tcplisten v1.0.0 // indirect
23+
golang.org/x/sys v0.15.0 // indirect
24+
)

go.sum

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
2+
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/gofiber/fiber/v2 v2.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/UE=
6+
github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
7+
github.com/gofiber/template v1.8.2 h1:PIv9s/7Uq6m+Fm2MDNd20pAFFKt5wWs7ZBd8iV9pWwk=
8+
github.com/gofiber/template v1.8.2/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
9+
github.com/gofiber/template/html/v2 v2.1.0 h1:FjwzqhhdJpnhyCvav60Z1ytnBqOUr5sGO/aTeob9/ng=
10+
github.com/gofiber/template/html/v2 v2.1.0/go.mod h1:txXsRQN/G7Fr2cqGfr6zhVHgreCfpsBS+9+DJyrddJc=
11+
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
12+
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
13+
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
14+
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
15+
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
16+
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
17+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
18+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
19+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
20+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
21+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
22+
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
23+
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
24+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
25+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
26+
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
27+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
28+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
29+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
30+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
31+
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
32+
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
33+
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
34+
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
35+
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
36+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
37+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
38+
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
39+
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
40+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
41+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/gofiber/fiber/v2"
7+
"github.com/gofiber/template/html/v2"
8+
)
9+
10+
func main() {
11+
// Create a new engine
12+
engine := html.New("./views", ".html")
13+
14+
// Create new Fiber app with template engine
15+
app := fiber.New(fiber.Config{
16+
Views: engine,
17+
})
18+
19+
// Serve static files
20+
app.Static("/static", "./static")
21+
22+
// Serve the public key at the specified path
23+
app.Get("/.well-known/appspecific/com.tesla.3p.public-key.pem", func(c *fiber.Ctx) error {
24+
return c.SendFile("./static/public-key.pem")
25+
})
26+
27+
// Serve the main page
28+
app.Get("/", func(c *fiber.Ctx) error {
29+
return c.Render("index", fiber.Map{
30+
"Title": "Tesla Fleet Telemetry",
31+
})
32+
})
33+
34+
log.Fatal(app.Listen(":3000"))
35+
}

0 commit comments

Comments
 (0)