refactor(docker): use builtin parse_rfc3339 function

dev
Jef Roosens 2022-05-09 14:58:20 +02:00
parent ea4c4fce16
commit 5a5f7f8346
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 4 additions and 9 deletions

View File

@ -67,13 +67,6 @@ pub mut:
end_time time.Time [skip] end_time time.Time [skip]
} }
fn docker_timestamp_to_time(s string) ?time.Time {
parts := s.split('.')
clipped := parts[0] + '.' + parts[1][..3]
return time.parse_rfc3339(clipped)
}
// inspect_container returns the result of inspecting a container with a given // inspect_container returns the result of inspecting a container with a given
// ID. // ID.
pub fn inspect_container(id string) ?ContainerInspect { pub fn inspect_container(id string) ?ContainerInspect {
@ -85,10 +78,10 @@ pub fn inspect_container(id string) ?ContainerInspect {
mut data := json.decode(ContainerInspect, res.text) ? mut data := json.decode(ContainerInspect, res.text) ?
data.state.start_time = docker_timestamp_to_time(data.state.start_time_str) ? data.state.start_time = time.parse_rfc3339(data.state.start_time_str) ?
if data.state.status == 'exited' { if data.state.status == 'exited' {
data.state.end_time = docker_timestamp_to_time(data.state.end_time_str) ? data.state.end_time = time.parse_rfc3339(data.state.end_time_str) ?
} }
return data return data
@ -101,6 +94,8 @@ pub fn remove_container(id string) ?bool {
return res.status_code == 204 return res.status_code == 204
} }
// get_container_logs retrieves the logs for a Docker container, both stdout &
// stderr.
pub fn get_container_logs(id string) ?string { pub fn get_container_logs(id string) ?string {
res := request('GET', urllib.parse('/v1.41/containers/$id/logs?stdout=true&stderr=true') ?) ? res := request('GET', urllib.parse('/v1.41/containers/$id/logs?stdout=true&stderr=true') ?) ?
mut res_bytes := res.text.bytes() mut res_bytes := res.text.bytes()