okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61c43ca
main
1package daemon 2 3import ( 4"encoding/json" 5"errors" 6) 7 8// The daemon alone reads and writes creds.json. A client changes a profile's 9// api key or an MCP server's secrets through these routes and only ever learns 10// which secrets are saved, never what they are. 11 12// Credentials names the saved secrets. 13type Credentials struct { 14MCP map [string ]MCPSecretNames `json:"mcp"` 15// Providers are the profiles with a saved api key. 16Providers []string `json:"providers"` 17} 18 19// MCPSecretNames is what an MCP server has saved, by name only. 20type MCPSecretNames struct { 21Headers []string `json:"headers"` 22Env []string `json:"env"` 23BearerToken bool `json:"bearerToken"` 24} 25 26// Any reports whether the server has any secret saved. 27func (n MCPSecretNames )Any ()bool { 28return n .BearerToken || len (n .Headers )> 0 || len (n .Env )> 0 29} 30 31// MCPSecretsPatch keeps fields whose pointers or maps are nil. RemoveBearerToken 32// and the Clear flags remove whole fields; a nil map entry removes that name. 33type MCPSecretsPatch struct { 34BearerToken * string 35RemoveBearerToken bool 36Headers map [string ]* string 37ClearHeaders bool 38Env map [string ]* string 39ClearEnv bool 40} 41 42func (patch MCPSecretsPatch )MarshalJSON () ([]byte ,error ) { 43if (patch .BearerToken != nil && patch .RemoveBearerToken )|| (patch .Headers != nil && patch .ClearHeaders )|| (patch .Env != nil && patch .ClearEnv ) { 44return nil ,errors .New ("secret patch cannot replace and clear the same field" ) 45 } 46fields := make (map [string ]any ) 47if patch .BearerToken != nil { 48fields ["bearer_token" ]= * patch .BearerToken 49 }else if patch .RemoveBearerToken { 50fields ["bearer_token" ]= nil 51 } 52if patch .Headers != nil { 53fields ["headers" ]= patch .Headers 54 }else if patch .ClearHeaders { 55fields ["headers" ]= nil 56 } 57if patch .Env != nil { 58fields ["environment" ]= patch .Env 59 }else if patch .ClearEnv { 60fields ["environment" ]= nil 61 } 62return json .Marshal (fields ) 63}