1 (* Simple demo program showing how to list out secrets.
2 Usage: list_secrets [URI]
3 (C) Copyright 2018 Pino Toscano, Red Hat Inc.
9 module C = Libvirt.Connect
10 module S = Libvirt.Secret
12 let string_of_secret_usage_type = function
14 | S.Volume -> "volume"
22 if Array.length Sys.argv >= 2 then
26 let conn = C.connect_auth_readonly ?name (C.get_auth_default ()) in
28 (* List all the secrets. *)
29 let secrets = C.list_secrets conn (C.num_of_secrets conn) in
30 let secrets = Array.to_list secrets in
31 let secrets = List.map (S.lookup_by_uuid_string conn) secrets in
34 let uuid = S.get_uuid_string secret in
35 let usageType = string_of_secret_usage_type (S.get_usage_type secret) in
36 let usageId = S.get_usage_id secret in
37 printf "%*s %-7s %s\n%!"
38 (Libvirt.uuid_string_length) uuid usageType usageId
41 Libvirt.Virterror err ->
42 eprintf "error: %s\n" (Libvirt.Virterror.to_string err)
45 (* Run the garbage collector which is a good way to check for
46 * memory corruption errors and reference counting issues in libvirt.