Closed cdent closed 3 years ago
@jd I suspect you might have some input on this if you can cast (ha!) your mind back to gnocchi time.
I think we mostly used ENVIRON
in headers not in data, so we were cool with strings only.
Now I understand why you'd need this feature in data. I did not check the implementation, but the principle LGTM.
@taget have you had a chance to try this out?
@taget I'm still hoping you can verify that this solves the problems you were trying to solve
@cdent hi Chris, sorry to not response you for long time.
I tried in my test environment, works for me when cast a integer to string
yaml:
POST: /api/cgi
request_headers:
content-type: application/json
data:
params:
content:
requestInfo:
requestKey: mx_ksdionuj3djfk
caller: vs-api
seqId: ''
requestId: ''
version: '1.0'
type: json
requestItem:
data:
detail:
- uuid: $ENVIRON['VS_UUID']
hostIpList:
- $ENVIRON['VS_HOSTIP']
migrateBandwidth: 20
migrateTimeout: 3600
pauseTime: $ENVIRON:str['PAUSE_TIME']
schedulerDebug: 'on'
compression:
compression: mt
method: instance_live_migrate
VS_HOSTIP="101" VS_UUID="100" PAUSE_TIME=122 gabbi-run http://127.0.0.1:8000 < a.yaml
result
{
"params": {
"content": {
"type": "json",
"requestInfo": {
"seqId": "",
"requestId": "",
"caller": "vs-api",
"requestKey": "mx_ksdionuj3djfk"
},
"requestItem": {
"method": "instance_live_migrate",
"data": {
"detail": [
{
"schedulerDebug": "on",
"migrateBandwidth": 20,
"uuid": 100,
"compression": {
"compression": "mt"
},
"pauseTime": "122",
"migrateTimeout": 3600,
"hostIpList": [
101
]
}
]
}
},
"version": "1.0"
}
}
}
thanks for your help :)
This is an effort to provide the functionality described in #270 by implementing optional "casts" on the $ENVIRON and $REPLACER replacers by appending a :cast (int, str, bool, float) to the replacer name (e.g.,
$ENVIRON:int['FOOBAR']
).This only works when the replacer is the entirety of the message being replaced:
not mixed in:
We can't do this for two reasons:
repl
function inre.sub
works, they can only return strings, thus the casting has to happen after the re.subWhile the code is present to make it possible to do casts of other replacers, for the moment any cast will be ignored, mostly because it doesn't make sense for most of them.
It might, however, make sense for
$COOKIE
so input on that desired.This isn't done, it needs to be confirmed as having grammatical sense, and it also needs doc update, but I'm putting it up here for some initial feedback on the format and implementation.