nsmcp::HttpTransport method questionKeyFromCredential (protected)

 <instance of nsmcp::HttpTransport[i]> questionKeyFromCredential \
    authorization context

Defined in /usr/local/ns/tcl/nsmcp/transport.tcl

A Codex bridge may omit the run header while still using the dedicated question credential. Bind it only when one live run has that exact credential; concurrent runs require the explicit observer header.

Parameters:
authorization (required)
context (required)

Testcases:
No testcase defined.
Source code:
if {![regexp {^Bearer ([A-Za-z0-9._~+/-]+=*)$} $authorization -> token]} {
    return {}
}
set digest [ns_crypto::md string -digest sha256 -- $token]
set matches {}
set known false
foreach key [nsv_array names nsmcp:question-observers] {
    if {![nsv_get nsmcp:question-observers $key observer]
        || ![dict exists $observer credentialDigest]
        || [dict get $observer credentialDigest] ne $digest} {
        continue
    }
    set known true
    if {![dict exists $observer principal] || ![dict exists $observer server]
        || ![dict exists $observer deadline]
        || [dict get $observer principal] ne [$context principal]
        || [dict get $observer server] ne [$context server]
        || [dict get $observer deadline]<=[clock milliseconds]} {
        continue
    }
    lappend matches $key
    if {[llength $matches]>1} {
        error "Concurrent question runs require X-Nsmcp-Question"
    }
}
if {$known && $matches eq {}} {
    error "Question policy expired or unavailable"
}
return [lindex $matches 0]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: