woodglue.apps.rpc¶
JSON-RPC 2.0 handler.
JSON-RPC 2.0 handler backed by a lythonic Namespace.
Dispatches JSON-RPC method calls to NamespaceNode callables, validates parameters against Method.args, and returns standard JSON-RPC 2.0 responses.
Every request runs as a woodglue.access.Caller (see woodglue.apps.authn):
- No valid credential:
-32000 "Unauthorized". - A Session-cookie request that is not
application/jsonor comes from another origin:-32003 "Cross-site request rejected". - A namespace the Caller cannot see is reported as
-32601 "Method not found", so its existence does not leak. - A visible namespace without a
callGrant:-32003 "Forbidden: ...". - DAG runs a call starts, and trigger changes it makes, record the Caller's
User id as
initiated_by(anonymouswhen auth is disabled). system.*methods check their own Grants (seewoodglue.apps.system_api) and report a missing one as-32003too.
Errors raised by a node:
RpcError(or a subclass) reports an application error to the client: the response error object is{"code": exc.code, "message": exc.message}, plus"data"whenexc.datais notNone(serialized like results). It is logged at WARNING with the method name, code and message, without a traceback, since it is an expected, client-caused failure.- Opt-in is by subclassing only. Any other exception, even one with an
integer
codeattribute (e.g.urllib.error.HTTPError), becomes-32603 "Internal error"with no message leaked to the client, and is logged at ERROR with its traceback.
RpcError
¶
Bases: Exception
Application-level JSON-RPC error that a node may raise to report a
client-visible failure. str(exc) is the message.
Construct as RpcError(code, message, data=None), or set code as a
class attribute on a subclass and construct it from just a message
(data is then keyword-only):
>>> class NotFound(RpcError):
... code = -32001
>>> e = NotFound("missing", data={"k": 1})
>>> (e.code, e.message, e.data, str(e))
(-32001, 'missing', {'k': 1}, 'missing')
>>> RpcError(-32010, "x").code
-32010
Source code in src/woodglue/apps/rpc.py
JsonRpcHandler
¶
Bases: RequestHandler
Tornado handler that speaks JSON-RPC 2.0 over HTTP POST.
Expects self.application.settings['namespaces'] to be a dict mapping
prefix strings to lythonic.compose.namespace.Namespace instances.
Source code in src/woodglue/apps/rpc.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |