Skip to content

Commit

Permalink
enable server config with env vars (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris authored Oct 7, 2024
1 parent 0719a07 commit 362df4f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/proxy-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func runClient(cCtx *cli.Context) error {

proxyHandler := proxy.NewProxy(targetAddr, validators).WithTransport(&http.Transport{TLSClientConfig: tlsConfig})

log.With("listenAddr", listenAddr).Info("about to start proxy")
log.With("listenAddr", listenAddr).Info("Starting proxy client")
err = http.ListenAndServe(listenAddr, proxyHandler)
if err != nil {
log.Error("stopping proxy", "server error", err)
Expand Down
60 changes: 34 additions & 26 deletions cmd/proxy-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,55 @@ import (

var flags []cli.Flag = []cli.Flag{
&cli.StringFlag{
Name: "listen-addr",
Value: "127.0.0.1:8080",
Usage: "address to listen on",
Name: "listen-addr",
EnvVars: []string{"LISTEN_ADDR"},
Value: "127.0.0.1:8080",
Usage: "address to listen on",
},
&cli.StringFlag{
Name: "target-addr",
Value: "https://localhost:80",
Usage: "address to proxy requests to",
Name: "target-addr",
EnvVars: []string{"TARGET_ADDR"},
Value: "https://localhost:80",
Usage: "address to proxy requests to",
},
&cli.StringFlag{
Name: "server-attestation-type",
Value: string(proxy.AttestationAzureTDX),
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
Name: "server-attestation-type",
EnvVars: []string{"SERVER_ATTESTATION_TYPE"},
Value: string(proxy.AttestationAzureTDX),
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
},
&cli.StringFlag{
Name: "tls-certificate",
Usage: "Certificate to present (PEM). Only valid for --server-attestation-type=none and with --tls-private-key.",
Name: "tls-certificate",
EnvVars: []string{"TLS_CERTIFICATE"},
Usage: "Certificate to present (PEM). Only valid for --server-attestation-type=none and with --tls-private-key.",
},
&cli.StringFlag{
Name: "tls-private-key",
Usage: "Private key for the certificate (PEM). Only valid with --tls-certificate.",
Name: "tls-private-key",
EnvVars: []string{"TLS_PRIVATE_KEY"},
Usage: "Private key for the certificate (PEM). Only valid with --tls-certificate.",
},
&cli.StringFlag{
Name: "client-attestation-type",
Value: string(proxy.AttestationNone),
Usage: "type of attestation to expect and verify (" + proxy.AvailableAttestationTypes + ")",
Name: "client-attestation-type",
EnvVars: []string{"CLIENT_ATTESTATION_TYPE"},
Value: string(proxy.AttestationNone),
Usage: "type of attestation to expect and verify (" + proxy.AvailableAttestationTypes + ")",
},
&cli.StringFlag{
Name: "client-measurements",
Usage: "optional path to JSON measurements enforced on the client",
Name: "client-measurements",
EnvVars: []string{"CLIENT_MEASUREMENTS"},
Usage: "optional path to JSON measurements enforced on the client",
},
&cli.BoolFlag{
Name: "log-json",
Value: false,
Usage: "log in JSON format",
Name: "log-json",
EnvVars: []string{"LOG_JSON"},
Value: false,
Usage: "log in JSON format",
},
&cli.BoolFlag{
Name: "log-debug",
Value: false,
Usage: "log debug messages",
Name: "log-debug",
EnvVars: []string{"LOG_DEBUG"},
Value: false,
Usage: "log debug messages",
},
}

Expand Down Expand Up @@ -155,7 +164,6 @@ func runServer(cCtx *cli.Context) error {
ogClientConfig.Certificates = []tls.Certificate{cert}
ogClientConfig.GetCertificate = nil
return ogClientConfig, nil

},
}
}
Expand Down Expand Up @@ -188,7 +196,7 @@ func runServer(cCtx *cli.Context) error {
}
}()

log.With("listenAddr", listenAddr).Info("about to start proxy")
log.With("listenAddr", listenAddr).Info("Starting proxy server")
err = server.Serve(tlsListener)
if err != nil {
log.Error("stopping proxy", "server error", err)
Expand Down

0 comments on commit 362df4f

Please sign in to comment.