Skip to content

Commit

Permalink
Merge pull request #36 from OpenCHAMI/lritzdorf/bootscript-notify
Browse files Browse the repository at this point in the history
Routers: implement POST notification for bootscript requests
  • Loading branch information
travisbcotton authored Jun 28, 2024
2 parents 14b5745 + 2ada9d8 commit a0e1caa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/boot-script-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ var (
spireServiceURL = "https://spire-tokens.spire:54440"
oauth2AdminBaseURL = "http://127.0.0.1:3333"
oauth2PublicBaseURL = "http://127.0.0.1:3333"
bootscriptNotifyURL = ""
)

func parseEnv(evar string, v interface{}) (ret error) {
Expand Down Expand Up @@ -324,6 +325,10 @@ func parseEnvVars() error {
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_OAUTH2_PUBLIC_BASE_URL: %q", parseErr))
}
parseErr = parseEnv("BSS_BOOTSCRIPT_NOTIFY_URL", &bootscriptNotifyURL)
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_BOOTSCRIPT_NOTIFY_URL: %q", parseErr))
}

//
// Etcd environment variables
Expand Down Expand Up @@ -421,6 +426,7 @@ func parseCmdLine() {
flag.StringVar(&jwksURL, "jwks-url", jwksURL, "(BSS_JWKS_URL) Set the JWKS URL to fetch the public key for authorization (enables authentication)")
flag.StringVar(&oauth2AdminBaseURL, "oauth2-admin-base-url", oauth2AdminBaseURL, "(BSS_OAUTH2_ADMIN_BASE_URL) Base URL of the OAUTH2 server admin endpoints for client authorizations")
flag.StringVar(&oauth2PublicBaseURL, "oauth2-public-base-url", oauth2PublicBaseURL, "(BSS_OAUTH2_PUBLIC_BASE_URL) Base URL of the OAUTH2 server public endpoints (e.g. for token grants)")
flag.StringVar(&bootscriptNotifyURL, "bootscript-notify-url", bootscriptNotifyURL, "(BSS_BOOTSCRIPT_NOTIFY_URL) Full URL to which newly-booted node IPs should be POSTed (e.g. TPM-manager server)")
flag.BoolVar(&insecure, "insecure", insecure, "(BSS_INSECURE) Don't enforce https certificate security")
flag.BoolVar(&debugFlag, "debug", debugFlag, "(BSS_DEBUG) Enable debug output")
flag.BoolVar(&useSQL, "postgres", useSQL, "(BSS_USESQL) Use Postgres instead of ETCD")
Expand Down
15 changes: 15 additions & 0 deletions cmd/boot-script-service/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ package main

import (
"fmt"
"log"
"net/http"
net_url "net/url"
"time"

base "github.com/Cray-HPE/hms-base"
"github.com/OpenCHAMI/jwtauth/v5"
"github.com/go-chi/chi/middleware"
"github.com/go-chi/chi/v5"
"github.com/hashicorp/go-retryablehttp"
)

const (
Expand Down Expand Up @@ -130,6 +133,9 @@ func bootParameters(w http.ResponseWriter, r *http.Request) {
}

func bootScript(w http.ResponseWriter, r *http.Request) {
if bootscriptNotifyURL != "" {
go notifyTarget(bootscriptNotifyURL, r.RemoteAddr)
}
switch r.Method {
case http.MethodGet:
BootscriptGet(w, r)
Expand Down Expand Up @@ -211,3 +217,12 @@ func endpointHistoryGet(w http.ResponseWriter, r *http.Request) {
sendAllowable(w, "GET")
}
}

func notifyTarget(url string, data string) {
resp, err := retryablehttp.PostForm(url, net_url.Values{"data": {data}})
if err != nil {
log.Printf("WARNING: HTTP POST of \"%v\" failed: %v\n", data, err)
return
}
defer resp.Body.Close()
}

0 comments on commit a0e1caa

Please sign in to comment.