@@ -187,34 +187,10 @@ pub(crate) const COMPONENT_SEPARATOR: char = ',';
187187type Result < T > = anyhow:: Result < T > ;
188188
189189/// A backend/transport for OCI/Docker images.
190- #[ derive( Copy , Clone , Hash , Debug , PartialEq , Eq ) ]
191- pub enum Transport {
192- /// A remote Docker/OCI registry (`registry:` or `docker://`)
193- Registry ,
194- /// A local OCI directory (`oci:`)
195- OciDir ,
196- /// A local OCI archive tarball (`oci-archive:`)
197- OciArchive ,
198- /// A local Docker archive tarball (`docker-archive:`)
199- DockerArchive ,
200- /// Local container storage (`containers-storage:`)
201- ContainerStorage ,
202- /// Local directory (`dir:`)
203- Dir ,
204- /// Local Docker daemon (`docker-daemon:`)
205- DockerDaemon ,
206- }
190+ pub type Transport = containers_image_proxy:: transport:: Transport ;
207191
208192/// Combination of a remote image reference and transport.
209- ///
210- /// For example,
211- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
212- pub struct ImageReference {
213- /// The storage and transport for the image
214- pub transport : Transport ,
215- /// The image name (e.g. `quay.io/somerepo/someimage:latest`)
216- pub name : String ,
217- }
193+ pub type ImageReference = containers_image_proxy:: ImageReference ;
218194
219195/// Policy for signature verification.
220196#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -240,77 +216,6 @@ pub struct OstreeImageReference {
240216 pub imgref : ImageReference ,
241217}
242218
243- impl TryFrom < & str > for Transport {
244- type Error = anyhow:: Error ;
245-
246- fn try_from ( value : & str ) -> Result < Self > {
247- Ok ( match value {
248- Self :: REGISTRY_STR | "docker" => Self :: Registry ,
249- Self :: OCI_STR => Self :: OciDir ,
250- Self :: OCI_ARCHIVE_STR => Self :: OciArchive ,
251- Self :: DOCKER_ARCHIVE_STR => Self :: DockerArchive ,
252- Self :: CONTAINERS_STORAGE_STR => Self :: ContainerStorage ,
253- Self :: LOCAL_DIRECTORY_STR => Self :: Dir ,
254- Self :: DOCKER_DAEMON_STR => Self :: DockerDaemon ,
255- o => return Err ( anyhow ! ( "Unknown transport '{}'" , o) ) ,
256- } )
257- }
258- }
259-
260- impl Transport {
261- const OCI_STR : & ' static str = "oci" ;
262- const OCI_ARCHIVE_STR : & ' static str = "oci-archive" ;
263- const DOCKER_ARCHIVE_STR : & ' static str = "docker-archive" ;
264- const CONTAINERS_STORAGE_STR : & ' static str = "containers-storage" ;
265- const LOCAL_DIRECTORY_STR : & ' static str = "dir" ;
266- const REGISTRY_STR : & ' static str = "registry" ;
267- const DOCKER_DAEMON_STR : & ' static str = "docker-daemon" ;
268-
269- /// Retrieve an identifier that can then be re-parsed from [`Transport::try_from::<&str>`].
270- pub fn serializable_name ( & self ) -> & ' static str {
271- match self {
272- Transport :: Registry => Self :: REGISTRY_STR ,
273- Transport :: OciDir => Self :: OCI_STR ,
274- Transport :: OciArchive => Self :: OCI_ARCHIVE_STR ,
275- Transport :: DockerArchive => Self :: DOCKER_ARCHIVE_STR ,
276- Transport :: ContainerStorage => Self :: CONTAINERS_STORAGE_STR ,
277- Transport :: Dir => Self :: LOCAL_DIRECTORY_STR ,
278- Transport :: DockerDaemon => Self :: DOCKER_DAEMON_STR ,
279- }
280- }
281- }
282-
283- impl TryFrom < & str > for ImageReference {
284- type Error = anyhow:: Error ;
285-
286- fn try_from ( value : & str ) -> Result < Self > {
287- let ( transport_name, mut name) = value
288- . split_once ( ':' )
289- . ok_or_else ( || anyhow ! ( "Missing ':' in {}" , value) ) ?;
290- let transport: Transport = transport_name. try_into ( ) ?;
291- if name. is_empty ( ) {
292- return Err ( anyhow ! ( "Invalid empty name in {}" , value) ) ;
293- }
294- if transport_name == "docker" {
295- name = name
296- . strip_prefix ( "//" )
297- . ok_or_else ( || anyhow ! ( "Missing // in docker:// in {}" , value) ) ?;
298- }
299- Ok ( Self {
300- transport,
301- name : name. to_string ( ) ,
302- } )
303- }
304- }
305-
306- impl FromStr for ImageReference {
307- type Err = anyhow:: Error ;
308-
309- fn from_str ( s : & str ) -> Result < Self > {
310- Self :: try_from ( s)
311- }
312- }
313-
314219impl TryFrom < & str > for SignatureSource {
315220 type Error = anyhow:: Error ;
316221
@@ -388,28 +293,6 @@ impl FromStr for OstreeImageReference {
388293 }
389294}
390295
391- impl std:: fmt:: Display for Transport {
392- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
393- let s = match self {
394- // TODO once skopeo supports this, canonicalize as registry:
395- Self :: Registry => "docker://" ,
396- Self :: OciArchive => "oci-archive:" ,
397- Self :: DockerArchive => "docker-archive:" ,
398- Self :: OciDir => "oci:" ,
399- Self :: ContainerStorage => "containers-storage:" ,
400- Self :: Dir => "dir:" ,
401- Self :: DockerDaemon => "docker-daemon:" ,
402- } ;
403- f. write_str ( s)
404- }
405- }
406-
407- impl std:: fmt:: Display for ImageReference {
408- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
409- write ! ( f, "{}{}" , self . transport, self . name)
410- }
411- }
412-
413296impl std:: fmt:: Display for SignatureSource {
414297 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
415298 match self {
@@ -642,7 +525,7 @@ mod tests {
642525 Transport :: DockerArchive ,
643526 Transport :: OciDir ,
644527 ] {
645- assert_eq ! ( Transport :: try_from( v. serializable_name ( ) ) . unwrap( ) , v) ;
528+ assert_eq ! ( Transport :: try_from( v. to_string ( ) . as_ref ( ) ) . unwrap( ) , v) ;
646529 }
647530 }
648531
0 commit comments