Skip to content

Commit

Permalink
main: add optional dedicated owntracks listener
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jan 5, 2024
1 parent 0d5cc47 commit a470753
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func main() {
disableAuth bool
secureKeyFlag string
basicAuth bool
otListen string
otUsername string
otPassword string
requireSubject string
Expand All @@ -85,6 +86,7 @@ func main() {
fs.StringVar(&secureKeyFlag, "secure-key", "", "Key used to encrypt/verify information like cookies")
fs.StringVar(&baseURL, "base-url", getEnvDefault("BASE_URL", "http://localhost:8080"), "Base URL this service runs on")

fs.StringVar(&otListen, "ot-listen", getEnvDefault("OT_LISTEN", ""), "Optional address to listen on for the owntracks publish endpoint.")
fs.StringVar(&otUsername, "ot-username", getEnvDefault("OT_PUBLISH_USERNAME", ""), "Username for the owntracks publish endpoint (required)")
fs.StringVar(&otPassword, "ot-password", "", "Password for the owntracks publish endpoint (required)")

Expand Down Expand Up @@ -197,7 +199,6 @@ func main() {

mux := http.NewServeMux()

mux.Handle("/pub", wrapBasicAuth(otUsername, otPassword, http.HandlerFunc(ots.HandlePublish)))
if disableAuth {
mux.Handle("/", ws)
} else if basicAuth {
Expand All @@ -223,6 +224,25 @@ func main() {

var g run.Group

if otListen == "" {
mux.Handle("/pub", wrapBasicAuth(otUsername, otPassword, http.HandlerFunc(ots.HandlePublish)))
} else {
otmux := http.NewServeMux()
otmux.Handle("/pub", wrapBasicAuth(otUsername, otPassword, http.HandlerFunc(ots.HandlePublish)))
srv := http.Server{Addr: otListen, Handler: otmux}

g.Add(func() error {
l.Printf("owntracks publisher listing on %s", listen)
return srv.ListenAndServe()
}, func(error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
l.Printf("shutting down owntracks publisher: %v", err)
}
})
}

if !disable4sqSync {
if ws.fsqOauthConfig.ClientID == "" || ws.fsqOauthConfig.ClientSecret == "" {
l.Fatal("foursquare oauth2 config not set")
Expand Down

0 comments on commit a470753

Please sign in to comment.