Debian Codegraph @

lib/Sys/Virt/Secret.pm

raw
1 # -*- perl -*-
2 #
3 # Copyright (C) 2006 Red Hat
4 # Copyright (C) 2006-2007 Daniel P. Berrange
5 #
6 # This program is free software; You can redistribute it and/or modify
7 # it under either:
8 #
9 # a) the GNU General Public License as published by the Free
10 # Software Foundation; either version 2, or (at your option) any
11 # later version,
12 #
13 # or
14 #
15 # b) the "Artistic License"
16 #
17 # The file "LICENSE" distributed along with this file provides full
18 # details of the terms and conditions of the two licenses.
19
20 =pod
21
22 =head1 NAME
23
24 Sys::Virt::Secret - Represent & manage a libvirt secret
25
26 =head1 DESCRIPTION
27
28 The C<Sys::Virt::Secret> module represents a secret managed
29 by the virtual machine monitor.
30
31 =head1 METHODS
32
33 =over 4
34
35 =cut
36
37 package Sys::Virt::Secret;
38
39 use strict;
40 use warnings;
41
42
43 sub _new {
44 my $proto = shift;
45 my $class = ref($proto) || $proto;
46 my %params = @_;
47
48 my $con = exists $params{connection} ? $params{connection} : die "connection parameter is required";
49 my $self;
50 if (exists $params{usageID} ||
51 exists $params{usageType}) {
52 die "usageID parameter must be provided with usageType" unless exists $params{usageID};
53 die "usageType parameter must be provided with usageID" unless exists $params{usageType};
54 $self = Sys::Virt::Secret::_lookup_by_usage($con, $params{usageType}, $params{usageID});
55 } elsif (exists $params{uuid}) {
56 if (length($params{uuid}) == 16) {
57 $self = Sys::Virt::Secret::_lookup_by_uuid($con, $params{uuid});
58 } elsif (length($params{uuid}) == 32 ||
59 length($params{uuid}) == 36) {
60 $self = Sys::Virt::Secret::_lookup_by_uuid_string($con, $params{uuid});
61 } else {
62 die "UUID must be either 16 unsigned bytes, or 32/36 hex characters long";
63 }
64 } elsif (exists $params{xml}) {
65 $self = Sys::Virt::Secret::_define_xml($con, $params{xml}, $params{flags});
66 } else {
67 die "usageID, xml or uuid parameters are required";
68 }
69
70 bless $self, $class;
71
72 return $self;
73 }
74
75
76 =item my $uuid = $sec->get_uuid()
77
78 Returns a 16 byte long string containing the raw globally unique identifier
79 (UUID) for the secret.
80
81 =item my $uuid = $sec->get_uuid_string()
82
83 Returns a printable string representation of the raw UUID, in the format
84 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'.
85
86 =item my $type = $sec->get_usage_type()
87
88 Returns the usage type of this secret. The usage type determines the
89 format of the unique identifier for this secret.
90
91 =item my $id = $sec->get_usage_id()
92
93 Returns the identifier of the object with which the secret is to
94 be used. For secrets with a usage type of volume, the identifier
95 is the fully qualified path.
96
97 =item my $xml = $sec->get_xml_description()
98
99 Returns an XML document containing a complete description of
100 the secret's configuration
101
102 =item $sec->undefine()
103
104 Remove the configuration associated with a secret previously defined
105 with the C<define_secret> method in L<Sys::Virt>.
106
107 =item $bytes = $sec->get_value()
108
109 Returns the raw bytes for the value of this secret, or undef if
110 there is no value stored with the secret.
111
112 =item $sec->set_value($bytes)
113
114 Sets the value for the secret to be C<$bytes>.
115
116 =back
117
118 =head1 CONSTANTS
119
120 This section documents constants that are used with various
121 APIs described above
122
123 =head2 SECRET USAGE TYPE
124
125 The following constants refer to the different usage types
126
127 =over 4
128
129 =item Sys::Virt::Secret::USAGE_TYPE_NONE
130
131 The constant for secrets which are not assigned for use with a
132 particular object
133
134 =item Sys::Virt::Secret::USAGE_TYPE_VOLUME
135
136 The constant for secrets which are to be used for storage
137 volume encryption. The usage ID for secrets will refer to
138 the fully qualified volume path.
139
140 =item Sys::Virt::Secret::USAGE_TYPE_CEPH
141
142 The constant for secrets which are to be used for authenticating
143 to CEPH storage volumes. The usage ID for secrets will refer to
144 the server name.
145
146 =item Sys::Virt::Secret::USAGE_TYPE_ISCSI
147
148 The constant for secrets which are to be used for authenticating
149 to iSCSI storage volumes. The usage ID for secrets will refer to
150 the server name.
151
152 =item Sys::Virt::Secret::USAGE_TYPE_TLS
153
154 The constant for secrets which are to be used for authenticating
155 for the TLS environment. The usage ID for the secret can be any
156 name. The UUID for the secret will be used by the hypervisor to
157 fetch the secret value.
158
159 =item Sys::Virt::Secret::USAGE_TYPE_VTPM
160
161 The constant for secrets which are to be used for encrypting
162 virtual TPM state. The usage ID for the secret will refer to
163 the TPM path. The UUID for the secret will be used by the
164 hypervisor to fetch the secret value.
165
166 =back
167
168 =head2 LIST FILTERING
169
170 The following constants are used to filter object lists
171
172 =over 4
173
174 =item Sys::Virt::Secret::LIST_EPHEMERAL
175
176 Include any secrets marked as ephemeral
177
178 =item Sys::Virt::Secret::LIST_NO_EPHEMERAL
179
180 Include any secrets not marked as ephemeral
181
182 =item Sys::Virt::Secret::LIST_PRIVATE
183
184 Include any secrets marked as private
185
186 =item Sys::Virt::Secret::LIST_NO_PRIVATE
187
188 Include any secrets not marked as private
189
190 =back
191
192 =head2 SECRET DEFINE
193
194 The following constants can be used to control the behaviour
195 of secret define operations
196
197 =over 4
198
199 =item Sys::Virt::Secret::DEFINE_VALIDATE
200
201 Validate the XML document against the XML schema
202
203 =back
204
205 =head2 EVENT ID CONSTANTS
206
207 =over 4
208
209 =item Sys::Virt::Secret::EVENT_ID_LIFECYCLE
210
211 Secret lifecycle events
212
213 =item Sys::Virt::Secret::EVENT_ID_VALUE_CHANGED
214
215 Secret value change events
216
217 =back
218
219 =head2 LIFECYCLE CHANGE EVENTS
220
221 The following constants allow secret lifecycle change events to be
222 interpreted. The events contain both a state change, and a
223 reason though the reason is currently unused.
224
225 =over 4
226
227 =item Sys::Virt::Secret::EVENT_DEFINED
228
229 Indicates that a persistent configuration has been defined for
230 the secret.
231
232 =item Sys::Virt::Secret::EVENT_UNDEFINED
233
234 The persistent configuration has gone away
235
236 =back
237
238 =cut
239
240
241 1;
242
243 =head1 AUTHORS
244
245 Daniel P. Berrange <[email protected]>
246
247 =head1 COPYRIGHT
248
249 Copyright (C) 2006-2009 Red Hat
250 Copyright (C) 2006-2007 Daniel P. Berrange
251
252 =head1 LICENSE
253
254 This program is free software; you can redistribute it and/or modify
255 it under the terms of either the GNU General Public License as published
256 by the Free Software Foundation (either version 2 of the License, or at
257 your option any later version), or, the Artistic License, as specified
258 in the Perl README file.
259
260 =head1 SEE ALSO
261
262 L<Sys::Virt>, L<Sys::Virt::Error>, C<http://libvirt.org>
263
264 =cut