Autogen the Origin of the log and use it to replace the hardcoded ct.ipng.ch strings in gen-html and gen-env
This commit is contained in:
@@ -32,7 +32,7 @@ func generateEnv(yamlFile string, wantDiff bool, allowWrite bool, useColor bool)
|
|||||||
// Build TESSERACT_ARGS string
|
// Build TESSERACT_ARGS string
|
||||||
args := []string{
|
args := []string{
|
||||||
fmt.Sprintf("--private_key=%s", logEntry.Secret),
|
fmt.Sprintf("--private_key=%s", logEntry.Secret),
|
||||||
fmt.Sprintf("--origin=%s.log.ct.ipng.ch", logEntry.ShortName),
|
fmt.Sprintf("--origin=%s", logEntry.Origin),
|
||||||
fmt.Sprintf("--storage_dir=%s", logEntry.LocalDirectory),
|
fmt.Sprintf("--storage_dir=%s", logEntry.LocalDirectory),
|
||||||
fmt.Sprintf("--roots_pem_file=%s", rootsPemPath),
|
fmt.Sprintf("--roots_pem_file=%s", rootsPemPath),
|
||||||
}
|
}
|
||||||
|
@@ -74,7 +74,7 @@ const htmlTemplate = `<!DOCTYPE html>
|
|||||||
|
|
||||||
{{range .Logs}}
|
{{range .Logs}}
|
||||||
|
|
||||||
<h2>{{.ShortName}}.log.ct.ipng.ch</h2>
|
<h2>{{.Origin}}</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Log ID: <code>{{.LogID}}</code><br>
|
Log ID: <code>{{.LogID}}</code><br>
|
||||||
@@ -211,7 +211,7 @@ func computeKeyInfo(logEntry *Log) error {
|
|||||||
|
|
||||||
func generateLogJSONWithStatus(logEntry Log, outputPath string, wantDiff bool, allowWrite bool, useColor bool) error {
|
func generateLogJSONWithStatus(logEntry Log, outputPath string, wantDiff bool, allowWrite bool, useColor bool) error {
|
||||||
logJSON := LogV3JSON{
|
logJSON := LogV3JSON{
|
||||||
Description: fmt.Sprintf("%s.log.ct.ipng.ch", logEntry.ShortName),
|
Description: logEntry.Origin,
|
||||||
SubmissionURL: fmt.Sprintf("%s/", logEntry.SubmissionPrefix),
|
SubmissionURL: fmt.Sprintf("%s/", logEntry.SubmissionPrefix),
|
||||||
MonitoringURL: fmt.Sprintf("%s/", logEntry.MonitoringPrefix),
|
MonitoringURL: fmt.Sprintf("%s/", logEntry.MonitoringPrefix),
|
||||||
TemporalInterval: TemporalInterval{
|
TemporalInterval: TemporalInterval{
|
||||||
|
@@ -41,6 +41,7 @@ type Log struct {
|
|||||||
PublicKeyPEM string
|
PublicKeyPEM string
|
||||||
PublicKeyDERB64 string
|
PublicKeyDERB64 string
|
||||||
PublicKeyBase64 string
|
PublicKeyBase64 string
|
||||||
|
Origin string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -99,6 +100,15 @@ func loadConfig(yamlFile string) Config {
|
|||||||
if config.Logs[i].Period == 0 {
|
if config.Logs[i].Period == 0 {
|
||||||
config.Logs[i].Period = 200
|
config.Logs[i].Period = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract hostname from SubmissionPrefix to set Origin
|
||||||
|
if config.Logs[i].SubmissionPrefix != "" {
|
||||||
|
hostname, err := extractHostname(config.Logs[i].SubmissionPrefix)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to parse SubmissionPrefix URL for %s: %v", config.Logs[i].ShortName, err)
|
||||||
|
}
|
||||||
|
config.Logs[i].Origin = hostname
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@@ -151,14 +151,10 @@ func extractPort(listenAddr string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extractHostname(urlStr string) (string, error) {
|
func extractHostname(urlStr string) (string, error) {
|
||||||
if !strings.HasPrefix(urlStr, "http://") && !strings.HasPrefix(urlStr, "https://") {
|
|
||||||
urlStr = "https://" + urlStr
|
|
||||||
}
|
|
||||||
|
|
||||||
parsedURL, err := url.Parse(urlStr)
|
parsedURL, err := url.Parse(urlStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsedURL.Hostname(), nil
|
return parsedURL.Host, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user