map structure result
Showcase automatically convert a api call result, which is a json response, to a internal object, so that you can retrieve sub nodes and fields to map to your result
Demo
source
Main task yaml file
tasks:
- name: task
desc: |
test reg with a registered name
in this case the registered reslt name is: test2_httpbinget_result
task:
- func: shell
name: httpbinget
desc: it will use the given name as var name to register the result
do:
- 'curl -s -X GET "https://httpbin.org/get" -H "accept: application/json"'
reg: httpbin_get_result
- func: cmd
dvars:
- name: api_response
value: '{{.httpbin_get_result.Output}}'
flags:
- toObj
- v
- name: api_response_headers
desc: test if I can get immediately access of converted object
value: '{{.api_response_object.headers}}'
flags:
- v
- name: api_response_headers_host
value: '{{.api_response_object.headers.Host}}'
flags:
- v
do:
- name: print
cmd: '{{.httpbin_get_result.Code}}'
- name: print
cmd: '{{.httpbin_get_result.Output}}'
- name: print
cmd: '{{.api_response}}'
- name: inspect
cmd:
- exec_vars
- debug_vars
- name: print
cmd: '{{.api_response_object.headers.Host}}'
- name: printObj
cmd: api_response_headers
- name: print
desc: |
you can not use this header directly, if you intend to use a sub node, then you should use query and register a sub node
cmd: '{{.api_response_headers}}'
- name: print
cmd: '{{.api_response_headers_host}}'
Main log file
loading [Config]: ./tests/functests/upconfig.yml
Main config:
Version -> 1.0.0
RefDir -> ./tests/functests
WorkDir -> cwd
AbsWorkDir -> /up_project/up
TaskFile -> c0141
Verbose -> vvv
ModuleName -> self
ShellType -> /bin/sh
MaxCallLayers -> 8
Timeout -> 3600000
MaxModuelCallLayers -> 256
EntryTask -> task
ModRepoUsernameRef ->
ModRepoPasswordRef ->
work dir: /up_project/up
-exec task: task
loading [Task]: ./tests/functests/c0141
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: test reg with a registered name
in this case the registered reslt name is: test2_httpbinget_result
]
-Step1: [httpbinget: it will use the given name as var name to register the result ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
cmd( 1):
curl -s -X GET "https://httpbin.org/get" -H "accept: application/json"
-
{
"args": {},
"headers": {
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
}
-
.. ok
. ok
-Step2:
dvar> api_response:
"{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}"
-
{
"args": {},
"headers": {
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
}
dvar[object]> api_response_object:
{
"headers": {
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56",
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get",
"args": {
}
}
dvar> api_response_headers:
"map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]"
-
map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]
dvar> api_response_headers_host:
"httpbin.org"
-
httpbin.org
self: final context exec vars:
(*core.Cache)({
"api_response": "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
"api_response_object": {
"url": "https://httpbin.org/get",
"args": {
},
"headers": {
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56",
"Accept": "application/json",
"Host": "httpbin.org"
},
"origin": "118.208.99.38"
},
"api_response_headers": "map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]",
"api_response_headers_host": "httpbin.org",
"httpbin_get_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"last_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0
})
~SubStep1: [print: ]
0
~SubStep2: [print: ]
{
"args": {},
"headers": {
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
}
~SubStep3: [print: ]
{
"args": {},
"headers": {
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
}
~SubStep4: [inspect: ]
1: inspect[exec_vars]
(*core.Cache)({
"api_response_headers_host": "httpbin.org",
"httpbin_get_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"last_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"api_response": "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
"api_response_object": {
"args": {
},
"headers": {
"Accept": "application/json",
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
},
"api_response_headers": "map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]"
})
2: inspect[debug_vars]
-debug vars-
"UpRunTimeVars"
(*core.Cache)({
"up_runtime_task_layer_number": 0
})
"RuntimeVarsAndDvarsMerged"
(*core.Cache)({
"last_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"httpbin_get_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
})
})
"ExecbaseVars"
(*core.Cache)({
"last_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"httpbin_get_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
})
})
"TaskVars"
(*core.Cache)({
})
"ExecContextVars"
(*core.Cache)({
"api_response_headers": "map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]",
"api_response_headers_host": "httpbin.org",
"httpbin_get_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"last_result": (*utils.ExecResult)({
Cmd: "curl -s -X GET \"https://httpbin.org/get\" -H \"accept: application/json\"",
Code: 0,
Output: "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
ErrMsg: ""
}),
"up_runtime_task_layer_number": 0,
"api_response": "{\n \"args\": {}, \n \"headers\": {\n \"Accept\": \"application/json\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"curl/7.70.0\", \n \"X-Amzn-Trace-Id\": \"Root=1-5f7c662a-71e177ac294dbe8d6c31fc56\"\n }, \n \"origin\": \"118.208.99.38\", \n \"url\": \"https://httpbin.org/get\"\n}",
"api_response_object": {
"args": {
},
"headers": {
"Host": "httpbin.org",
"User-Agent": "curl/7.70.0",
"X-Amzn-Trace-Id": "Root=1-5f7c662a-71e177ac294dbe8d6c31fc56",
"Accept": "application/json"
},
"origin": "118.208.99.38",
"url": "https://httpbin.org/get"
}
})
--
~SubStep5: [print: ]
httpbin.org
~SubStep6: [printObj: ]
object:
api_response_headers: "map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]"
~SubStep7: [print: you can not use this header directly, if you intend to use a sub node, then you should use query and register a sub node
]
map[Accept:application/json Host:httpbin.org User-Agent:curl/7.70.0 X-Amzn-Trace-Id:Root=1-5f7c662a-71e177ac294dbe8d6c31fc56]
~SubStep8: [print: ]
httpbin.org
Logs with different verbose level
Raw logs with different verbose level