Skip to content

Commit

Permalink
feat: support TLS in metrics-api (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
JorTurFer authored Feb 1, 2023
1 parent 8287344 commit cceaad3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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)
}

0 comments on commit cceaad3

Please sign in to comment.