Skip to content

Commit 362df4f

Browse files
authored
enable server config with env vars (#14)
1 parent 0719a07 commit 362df4f

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

cmd/proxy-client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func runClient(cCtx *cli.Context) error {
152152

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

155-
log.With("listenAddr", listenAddr).Info("about to start proxy")
155+
log.With("listenAddr", listenAddr).Info("Starting proxy client")
156156
err = http.ListenAndServe(listenAddr, proxyHandler)
157157
if err != nil {
158158
log.Error("stopping proxy", "server error", err)

cmd/proxy-server/main.go

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,55 @@ import (
1919

2020
var flags []cli.Flag = []cli.Flag{
2121
&cli.StringFlag{
22-
Name: "listen-addr",
23-
Value: "127.0.0.1:8080",
24-
Usage: "address to listen on",
22+
Name: "listen-addr",
23+
EnvVars: []string{"LISTEN_ADDR"},
24+
Value: "127.0.0.1:8080",
25+
Usage: "address to listen on",
2526
},
2627
&cli.StringFlag{
27-
Name: "target-addr",
28-
Value: "https://localhost:80",
29-
Usage: "address to proxy requests to",
28+
Name: "target-addr",
29+
EnvVars: []string{"TARGET_ADDR"},
30+
Value: "https://localhost:80",
31+
Usage: "address to proxy requests to",
3032
},
3133
&cli.StringFlag{
32-
Name: "server-attestation-type",
33-
Value: string(proxy.AttestationAzureTDX),
34-
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
34+
Name: "server-attestation-type",
35+
EnvVars: []string{"SERVER_ATTESTATION_TYPE"},
36+
Value: string(proxy.AttestationAzureTDX),
37+
Usage: "type of attestation to present (" + proxy.AvailableAttestationTypes + ")",
3538
},
3639
&cli.StringFlag{
37-
Name: "tls-certificate",
38-
Usage: "Certificate to present (PEM). Only valid for --server-attestation-type=none and with --tls-private-key.",
40+
Name: "tls-certificate",
41+
EnvVars: []string{"TLS_CERTIFICATE"},
42+
Usage: "Certificate to present (PEM). Only valid for --server-attestation-type=none and with --tls-private-key.",
3943
},
4044
&cli.StringFlag{
41-
Name: "tls-private-key",
42-
Usage: "Private key for the certificate (PEM). Only valid with --tls-certificate.",
45+
Name: "tls-private-key",
46+
EnvVars: []string{"TLS_PRIVATE_KEY"},
47+
Usage: "Private key for the certificate (PEM). Only valid with --tls-certificate.",
4348
},
4449
&cli.StringFlag{
45-
Name: "client-attestation-type",
46-
Value: string(proxy.AttestationNone),
47-
Usage: "type of attestation to expect and verify (" + proxy.AvailableAttestationTypes + ")",
50+
Name: "client-attestation-type",
51+
EnvVars: []string{"CLIENT_ATTESTATION_TYPE"},
52+
Value: string(proxy.AttestationNone),
53+
Usage: "type of attestation to expect and verify (" + proxy.AvailableAttestationTypes + ")",
4854
},
4955
&cli.StringFlag{
50-
Name: "client-measurements",
51-
Usage: "optional path to JSON measurements enforced on the client",
56+
Name: "client-measurements",
57+
EnvVars: []string{"CLIENT_MEASUREMENTS"},
58+
Usage: "optional path to JSON measurements enforced on the client",
5259
},
5360
&cli.BoolFlag{
54-
Name: "log-json",
55-
Value: false,
56-
Usage: "log in JSON format",
61+
Name: "log-json",
62+
EnvVars: []string{"LOG_JSON"},
63+
Value: false,
64+
Usage: "log in JSON format",
5765
},
5866
&cli.BoolFlag{
59-
Name: "log-debug",
60-
Value: false,
61-
Usage: "log debug messages",
67+
Name: "log-debug",
68+
EnvVars: []string{"LOG_DEBUG"},
69+
Value: false,
70+
Usage: "log debug messages",
6271
},
6372
}
6473

@@ -155,7 +164,6 @@ func runServer(cCtx *cli.Context) error {
155164
ogClientConfig.Certificates = []tls.Certificate{cert}
156165
ogClientConfig.GetCertificate = nil
157166
return ogClientConfig, nil
158-
159167
},
160168
}
161169
}
@@ -188,7 +196,7 @@ func runServer(cCtx *cli.Context) error {
188196
}
189197
}()
190198

191-
log.With("listenAddr", listenAddr).Info("about to start proxy")
199+
log.With("listenAddr", listenAddr).Info("Starting proxy server")
192200
err = server.Serve(tlsListener)
193201
if err != nil {
194202
log.Error("stopping proxy", "server error", err)

0 commit comments

Comments
 (0)