12345678module remote910import rand11import os12131415pub struct Object {16pub:17 found bool18 body []u819 tag string20}2122232425pub interface Backend {26mut:27 get(key string) !Object28 list(prefix string) ![]string29 put_if_absent(key string, body []u8) !bool30 put_if_match(key string, body []u8, tag string) !bool31 delete(key string) !32}3334pub const probe_key = 'koh-probe'3536373839pub fn check(mut backend Backend) ! {40 payload := 'koh probe'.bytes()41 42 43 key := '${probe_key}-${rand.hex(16)}'44 if !backend.put_if_absent(key, payload)! {45 return error('the remote refused to store a new object')46 }47 defer {48 49 backend.delete(key) or {}50 }51 if backend.put_if_absent(key, payload)! {52 return error('the remote overwrote an existing object — conditional writes are not working')53 }54 probe := backend.get(key)!55 if !probe.found || probe.body != payload {56 return error('the remote did not give back what was written')57 }58 59 backend.delete(key)!60}616263pub fn tls_roots(url string) !string {64 mut roots := ''65 if url.starts_with('https://') {66 for path in [os.getenv('SSL_CERT_FILE'), '/etc/ssl/cert.pem',67 '/etc/ssl/certs/ca-certificates.crt', '/etc/ssl/certs/ca-bundle.crt',68 '/etc/pki/tls/certs/ca-bundle.crt', '/etc/ssl/ca-bundle.pem'] {69 if path != '' && os.is_file(path) {70 roots = path71 break72 }73 }74 if roots == '' {75 return error('no system CA bundle found — set SSL_CERT_FILE to your trusted CA bundle')76 }77 }78 return roots79}