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: support TLS in metrics-api #104

Merged
merged 2 commits into from
Feb 1, 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
3 changes: 2 additions & 1 deletion e2e/images/metrics-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ RUN go build -o /go/bin/server .
FROM gcr.io/distroless/base
COPY --from=build-env /go/bin/server /
EXPOSE 8080
EXPOSE 4333

CMD ["/server"]
ENTRYPOINT ["/server"]
18 changes: 15 additions & 3 deletions e2e/images/metrics-api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

const (
PORT = 8080
PORT = 8080
TLS_PORT = 4333
)

var value int
Expand Down Expand Up @@ -90,8 +91,7 @@ func setValue(w http.ResponseWriter, r *http.Request) {
}

func main() {
fmt.Printf("Running server on port: %d", PORT)

fmt.Printf("Running server on port: %d\n", PORT)
app := new(application)
app.auth.basic.username = os.Getenv("AUTH_USERNAME")
app.auth.basic.password = os.Getenv("AUTH_PASSWORD")
Expand All @@ -106,5 +106,17 @@ func main() {
r.HandleFunc("/api/value/{number:[0-9]+}", setValue).Methods("POST")

http.Handle("/", r)

value, found := os.LookupEnv("USE_TLS")
if found && value == "true" {
go func() {
fmt.Printf("Running tls server on port: %d\n", TLS_PORT)
err := http.ListenAndServeTLS(fmt.Sprintf(":%d", TLS_PORT), "/certs/tls.crt", "/certs/tls.key", nil)
if err != nil {
fmt.Println(err.Error())
}
}()
}

http.ListenAndServe(fmt.Sprintf(":%d", PORT), nil)
}