Skip to content

Commit 4d13e6e

Browse files
committed
Implement setSupervisorAuthHeader for setting bearer token
1 parent d99bfc9 commit 4d13e6e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func httpSupervisorProxy(w http.ResponseWriter, r *http.Request) {
112112
proxy := httputil.NewSingleHostReverseProxy(u)
113113

114114
// Add authorization header
115-
r.Header.Add("Authorization", "Bearer "+os.Getenv("SUPERVISOR_TOKEN"))
115+
setSupervisorAuthHeader(r)
116116

117117
switch cleanPath {
118118
case "/logs":

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ func getSupervisorHost() string {
2424
return supervisorHost
2525
}
2626

27+
func setSupervisorAuthHeader(r *http.Request) {
28+
token := os.Getenv("SUPERVISOR_TOKEN")
29+
if token != "" {
30+
r.Header.Add("Authorization", "Bearer "+token)
31+
} else {
32+
log.Println("No SUPERVISOR_TOKEN set, request will be unauthenticated")
33+
}
34+
}
35+
2736
func main() {
2837
development = (os.Getenv("DEVELOPMENT") == "True")
2938

mdns.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"log"
88
"net"
99
"net/http"
10-
"os"
1110
"time"
1211

1312
"github.com/grandcat/zeroconf"
@@ -91,7 +90,7 @@ func getOutboundIP() (net.IP, error) {
9190
return nil, fmt.Errorf("can't create request to Supervisor: %s", err)
9291
}
9392

94-
req.Header.Add("Authorization", "Bearer "+os.Getenv("SUPERVISOR_TOKEN"))
93+
setSupervisorAuthHeader(req)
9594

9695
response, err := client.Do(req)
9796
if err == nil {

0 commit comments

Comments
 (0)