Report the backend host as the source fact value
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-09 23:46:21 +11:00
parent 0aff1746e2
commit a43e5481f0
9 changed files with 146 additions and 64 deletions
+12 -3
View File
@@ -13,6 +13,8 @@ import (
// callers need no branch.
type sourceInjector struct {
name string
// hosts maps backend name to the value emitted; an unmapped name is emitted as-is.
hosts map[string]string
// inject is false when the query shape rules synthesis out. Suppression of an
// upstream fact of the same name does not depend on it.
inject bool
@@ -25,7 +27,7 @@ func (s *Server) newSourceInjector(query string, factEntity bool) *sourceInjecto
if !s.cfg.SourceFactEnabled || s.cfg.SourceFact == "" {
return nil
}
return &sourceInjector{name: s.cfg.SourceFact, inject: injectable(query, factEntity)}
return &sourceInjector{name: s.cfg.SourceFact, hosts: s.hosts, inject: injectable(query, factEntity)}
}
// claims reports whether an upstream record carries the name pdbmux owns, and is
@@ -36,6 +38,13 @@ func (si *sourceInjector) claims(factName string) bool {
return si != nil && factName != "" && factName == si.name
}
func (si *sourceInjector) value(backend string) string {
if h, ok := si.hosts[backend]; ok {
return h
}
return backend
}
// injects reports whether this response may carry the synthetic record.
func (si *sourceInjector) injects() bool {
return si != nil && si.inject
@@ -70,7 +79,7 @@ func (si *sourceInjector) factRecord(certname, backend, environment string) json
Environment string `json:"environment"`
Name string `json:"name"`
Value string `json:"value"`
}{Certname: certname, Environment: environment, Name: si.name, Value: backend})
}{Certname: certname, Environment: environment, Name: si.name, Value: si.value(backend)})
if err != nil {
return nil
}
@@ -87,7 +96,7 @@ func (si *sourceInjector) stamp(raw json.RawMessage, backend string) json.RawMes
if json.Unmarshal(raw, &obj) != nil || obj == nil {
return raw
}
value, err := json.Marshal(backend)
value, err := json.Marshal(si.value(backend))
if err != nil {
return raw
}