feat: centralize send message production gate

This commit is contained in:
zhaoyilun
2026-07-10 20:35:46 +08:00
parent 2a7087218b
commit b08b0e01bd
7 changed files with 187 additions and 22 deletions

View File

@@ -0,0 +1,47 @@
package tools
import "strings"
const EnvSendMessageProductionEnabled = "ISPHERE_SEND_PRODUCTION_ENABLED"
type SendMessageGatePolicy struct {
ProductionAllowed bool
ReasonCode string
ReasonMessage string
EvidenceGatePass bool
ConnectorConfigured bool
}
func LoadSendMessageGatePolicy(env map[string]string, evidenceGatePass bool, connectorConfigured bool) SendMessageGatePolicy {
policy := SendMessageGatePolicy{
EvidenceGatePass: evidenceGatePass,
ConnectorConfigured: connectorConfigured,
}
if !sendMessageProductionEnabled(env) {
policy.ReasonCode = "send_disabled_by_default"
policy.ReasonMessage = "production send is disabled by default; set ISPHERE_SEND_PRODUCTION_ENABLED=1 only after the evidence and connector gates pass"
return policy
}
if !evidenceGatePass {
policy.ReasonCode = "send_evidence_missing"
policy.ReasonMessage = "production send is blocked until dynamic observation, idempotency audit, and one approved sandbox send gate pass"
return policy
}
if !connectorConfigured {
policy.ReasonCode = "send_connector_missing"
policy.ReasonMessage = "production send is blocked because no validated send connector is configured"
return policy
}
policy.ProductionAllowed = true
policy.ReasonCode = "send_gate_passed"
policy.ReasonMessage = "production send gate passed"
return policy
}
func sendMessageProductionEnabled(env map[string]string) bool {
if env == nil {
return false
}
value := strings.TrimSpace(strings.ToLower(env[EnvSendMessageProductionEnabled]))
return value == "1" || value == "true" || value == "yes"
}