
    VhR                         d dl mZmZmZ eZdZdZdZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d d	lmZ  G d
 de      Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona~  
  module: podman_image
  author:
      - Sam Doran (@samdoran)
  short_description: Pull images for use by podman
  notes: []
  description:
      - Build, pull, or push images using Podman.
  options:
    arch:
      description:
        - CPU architecture for the container image
      type: str
    name:
      description:
        - Name of the image to pull, push, or delete. It may contain a tag using the format C(image:tag).
      required: True
      type: str
    executable:
      description:
        - Path to C(podman) executable if it is not in the C($PATH) on the machine running C(podman).
      default: 'podman'
      type: str
    ca_cert_dir:
      description:
        - Path to directory containing TLS certificates and keys to use.
      type: 'path'
    tag:
      description:
        - Tag of the image to pull, push, or delete.
      default: "latest"
      type: str
    pull:
      description: Whether or not to pull the image.
      default: True
      type: bool
    pull_extra_args:
      description:
        - Extra arguments to pass to the pull command.
      type: str
    push:
      description: Whether or not to push an image.
      default: False
      type: bool
    path:
      description: Path to the build context directory.
      type: str
    force:
      description:
        - Whether or not to force push or pull an image.
        - When building, force the build even if the image already exists.
      type: bool
      default: False
    state:
      description:
        - Whether an image should be present, absent, or built.
      default: "present"
      type: str
      choices:
        - present
        - absent
        - build
        - quadlet
    validate_certs:
      description:
        - Require HTTPS and validate certificates when pulling or pushing.
          Also used during build if a pull or push is necessary.
      type: bool
      aliases:
        - tlsverify
        - tls_verify
    password:
      description:
        - Password to use when authenticating to remote registries.
      type: str
    username:
      description:
        - username to use when authenticating to remote registries.
      type: str
    auth_file:
      description:
        - Path to file containing authorization credentials to the remote registry.
      aliases:
        - authfile
      type: path
    build:
      description: Arguments that control image build.
      type: dict
      default: {}
      aliases:
        - build_args
        - buildargs
      suboptions:
        container_file:
          description:
            - Content of the Containerfile to use for building the image.
              Mutually exclusive with the C(file) option which is path to the existing Containerfile.
          type: str
        file:
          description:
            - Path to the Containerfile if it is not in the build context directory.
              Mutually exclusive with the C(container_file) option.
          type: path
        volume:
          description:
            - Specify multiple volume / mount options to mount one or more mounts to a container.
          type: list
          elements: str
        annotation:
          description:
            - Dictionary of key=value pairs to add to the image. Only works with OCI images.
              Ignored for Docker containers.
          type: dict
        force_rm:
          description:
            - Always remove intermediate containers after a build, even if the build is unsuccessful.
          type: bool
          default: False
        format:
          description:
            - Format of the built image.
          type: str
          choices:
            - docker
            - oci
          default: "oci"
        cache:
          description:
            - Whether or not to use cached layers when building an image
          type: bool
          default: True
        rm:
          description: Remove intermediate containers after a successful build
          type: bool
          default: True
        extra_args:
          description:
            - Extra args to pass to build, if executed. Does not idempotently check for new build args.
          type: str
        target:
          description:
            - Specify the target build stage to build.
          type: str
    push_args:
      description: Arguments that control pushing images.
      type: dict
      default: {}
      suboptions:
        compress:
          description:
            - Compress tarball image layers when pushing to a directory using the 'dir' transport.
          type: bool
        format:
          description:
            - Manifest type to use when pushing an image using the 'dir' transport (default is manifest type of source)
          type: str
          choices:
            - oci
            - v2s1
            - v2s2
        remove_signatures:
          description: Discard any pre-existing signatures in the image
          type: bool
        sign_by:
          description:
            - Path to a key file to use to sign the image.
          type: str
        dest:
          description: Path or URL where image will be pushed.
          type: str
          aliases:
            - destination
        transport:
          description:
            - Transport to use when pushing in image. If no transport is set, will attempt to push to a remote registry
          type: str
          choices:
            - dir
            - docker
            - docker-archive
            - docker-daemon
            - oci-archive
            - ostree
        extra_args:
          description:
            - Extra args to pass to push, if executed. Does not idempotently check for new push args.
          type: str
    quadlet_dir:
      description:
        - Path to the directory to write quadlet file in.
          By default, it will be set as C(/etc/containers/systemd/) for root user,
          C(~/.config/containers/systemd/) for non-root users.
      type: path
      required: false
    quadlet_filename:
      description:
        - Name of quadlet file to write. By default it takes image name without prefixes and tags.
      type: str
    quadlet_file_mode:
      description:
        - The permissions of the quadlet file.
        - The O(quadlet_file_mode) can be specied as octal numbers or as a symbolic mode (for example, V(u+rwx) or V(u=rw,g=r,o=r)).
          For octal numbers format, you must either add a leading zero so that Ansible's YAML parser knows it is an
          octal number (like V(0644) or V(01777)) or quote it (like V('644') or V('1777')) so Ansible receives a string
          and can do its own conversion from string into number. Giving Ansible a number without following one of these
          rules will end up with a decimal number which will have unexpected results.
        - If O(quadlet_file_mode) is not specified and the quadlet file B(does not) exist, the default V('0640') mask will be used
          when setting the mode for the newly created file.
        - If O(quadlet_file_mode) is not specified and the quadlet file B(does) exist, the mode of the existing file will be used.
        - Specifying O(quadlet_file_mode) is the best way to ensure files are created with the correct permissions.
      type: raw
      required: false
    quadlet_options:
      description:
        - Options for the quadlet file. Provide missing in usual network args
          options as a list of lines to add.
      type: list
      elements: str
      required: false
a  
- name: Pull an image
  containers.podman.podman_image:
    name: quay.io/bitnami/wildfly

- name: Remove an image
  containers.podman.podman_image:
    name: quay.io/bitnami/wildfly
    state: absent

- name: Remove an image with image id
  containers.podman.podman_image:
    name: 0e901e68141f
    state: absent

- name: Pull a specific version of an image
  containers.podman.podman_image:
    name: redis
    tag: 4

- name: Build a basic OCI image
  containers.podman.podman_image:
    name: nginx
    path: /path/to/build/dir

- name: Build a basic OCI image with advanced parameters
  containers.podman.podman_image:
    name: nginx
    path: /path/to/build/dir
    build:
      cache: no
      force_rm: true
      format: oci
      annotation:
        app: nginx
        function: proxy
        info: Load balancer for my cool app
      extra_args: "--build-arg KEY=value"

- name: Build a Docker formatted image
  containers.podman.podman_image:
    name: nginx
    path: /path/to/build/dir
    build:
      format: docker

- name: Build and push an image using existing credentials
  containers.podman.podman_image:
    name: nginx
    path: /path/to/build/dir
    push: true
    push_args:
      dest: quay.io/acme

- name: Build and push an image using an auth file
  containers.podman.podman_image:
    name: nginx
    push: true
    auth_file: /etc/containers/auth.json
    push_args:
      dest: quay.io/acme

- name: Build and push an image using username and password
  containers.podman.podman_image:
    name: nginx
    push: true
    username: bugs
    password: "{{ vault_registry_password }}"
    push_args:
      dest: quay.io/acme

- name: Build and push an image to multiple registries
  containers.podman.podman_image:
    name: "{{ item }}"
    path: /path/to/build/dir
    push: true
    auth_file: /etc/containers/auth.json
  loop:
    - quay.io/acme/nginx
    - docker.io/acme/nginx

- name: Build and push an image to multiple registries with separate parameters
  containers.podman.podman_image:
    name: "{{ item.name }}"
    tag: "{{ item.tag }}"
    path: /path/to/build/dir
    push: true
    auth_file: /etc/containers/auth.json
    push_args:
      dest: "{{ item.dest }}"
  loop:
    - name: nginx
      tag: 4
      dest: docker.io/acme

    - name: nginx
      tag: 3
      dest: docker.io/acme

- name: Pull an image for a specific CPU architecture
  containers.podman.podman_image:
    name: nginx
    arch: amd64

- name: Build a container from file inline
  containers.podman.podman_image:
    name: mycustom_image
    state: build
    build:
      container_file: |-
        FROM alpine:latest
        CMD echo "Hello, World!"

- name: Create a quadlet file for an image
  containers.podman.podman_image:
    name: docker.io/library/alpine:latest
    state: quadlet
    quadlet_dir: /etc/containers/systemd
    quadlet_filename: alpine-latest
    quadlet_file_mode: '0640'
    quadlet_options:
      - Variant=arm/v7
      - |
        [Install]
        WantedBy=default.target
aT  
  image:
    description:
      - Image inspection results for the image that was pulled, pushed, or built.
    returned: success
    type: dict
    sample: [
                {
                    "Id": "6d1ef012b5674ad8a127ecfa9b5e6f5178d171b90ee462846974177fd9bdd39f",
                    "Digest": "sha256:8421d9a84432575381bfabd248f1eb56f3aa21d9d7cd2511583c68c9b7511d10",
                    "RepoTags": [
                        "docker.io/library/alpine:3.7"
                    ],
                    "RepoDigests": [
                        "docker.io/library/alpine@sha256:8421...",
                        "docker.io/library/alpine@sha256:9225..."
                    ],
                    "Parent": "",
                    "Comment": "",
                    "Created": "2019-03-07T22:19:53.447205048Z",
                    "Config": {
                        "Env": [
                                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                        ],
                        "Cmd": [
                                "/bin/sh"
                        ],
                        "ArgsEscaped": true
                    },
                    "Version": "18.06.1-ce",
                    "Author": "",
                    "Architecture": "amd64",
                    "Os": "linux",
                    "Size": 4467084,
                    "VirtualSize": 4467084,
                    "GraphDriver": {
                        "Name": "overlay",
                        "Data": {
                                "UpperDir": "/home/user/.local/share/containers/storage/overlay/3fc6.../diff",
                                "WorkDir": "/home/user/.local/share/containers/storage/overlay/3fc6.../work"
                        }
                    },
                    "RootFS": {
                        "Type": "layers",
                        "Layers": [
                                "sha256:3fc6..."
                        ]
                    },
                    "Labels": null,
                    "Annotations": {},
                    "ManifestType": "application/vnd.docker.distribution.manifest.v2+json",
                    "User": "",
                    "History": [
                        {
                                "created": "2019-03-07T22:19:53.313789681Z",
                                "created_by": "/bin/sh -c #(nop) ADD file:aa17928... in / "
                        },
                        {
                                "created": "2019-03-07T22:19:53.447205048Z",
                                "created_by": "/bin/sh -c #(nop)  CMD [\"/bin/sh\"]",
                                "empty_layer": true
                        }
                    ],
                    "NamesHistory": [
                        "docker.io/library/alpine:3.7"
                    ]
                }
            ]

N)	to_native)AnsibleModule)run_podman_command)create_quadlet_statec                        e Zd Z fdZddZddZd Zd Zd Zd Z	d Z
d	 Zd
 ZddZddZddZddZddZd Zd ZddZddZ xZS )PodmanImageManagerc                    t         t        |           || _        || _        | j                  j
                  j                  d      | _        | j                  j                  |j
                  j                  d      d      | _	        | j                  j
                  j                  d      | _
        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d	      | _        | j                  j
                  j                  d
      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        | j                  j
                  j                  d      | _        t3        | j                        \  }}|r|| _        || _
        d| j                  vrdnd}dj5                  | j                  || j                        | _        | j                   dv r| j9                          | j                   dv r| j;                          | j                   dk(  r| j=                          y y )Nname
executableT)requiredtagpullpull_extra_argspushpathforcestatevalidate_certs	auth_fileusernamepasswordca_cert_dirbuild	push_argsarchsha256:@z{name}{d}{tag})r   dr   )presentr   )absentquadlet)superr   __init__moduleresultsparamsgetr   get_bin_pathr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   parse_repository_tagformat
image_namer#   r$   make_quadlet)selfr(   r)   reporepo_tag	delimiter	__class__s         r/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/containers/podman/plugins/modules/podman_image.pyr'   zPodmanImageManager.__init__  s    $02KK&&**62	++226==3D3D\3R]a2b;;%%))%0KK&&**62	#{{11556GHKK&&**62	KK&&**62	[[''++G4
[[''++G4
"kk00445EF++//<**..z:**..z:;;--11-@[[''++G4
++//<KK&&**62	-dii8hDIDH#4883C	*11tyyISWS[S[1\::--LLN::#KKM::" #    c           	      8   dj                  | j                  g|D cg c]  }t        |       c}z         }| j                  j	                  d|z         | j
                  d   j                  |       t        | j                  | j                  |||      S c c}w )N zPODMAN-IMAGE-DEBUG: %spodman_actions)r(   r   argsexpected_rcignore_errors)joinr   r   r(   logr)   appendr   )r1   r;   r<   r=   icmds         r6   _runzPodmanImageManager._run  s    hh(0451)A,56 70367%&--c2!;;#') 	) 6s   B
c                     g }|j                         D ]C  }|r|j                  |      s|s||v s|j                  ||      }|j                  |d          E |s|j                         }|d   S )N   )
splitlines
startswithrsplitr@   )	r1   linesrH   containssplit_onmaxsplit	layer_idsline	splitlines	            r6   _get_id_from_outputz&PodmanImageManager._get_id_from_output  sv    	$$& 	/Ddooj9X(VZJZ KK(;	  1.	/ ((*I}r7   c                     d}dD cg c],  }t         j                  j                  | j                  |      . c}D ]&  }t         j                  j                  |      s#|} |S  |S c c}w )zz
        Find a Containerfile/Dockerfile path inside a podman build context.
        Return 'None' if none exist.
        N)Containerfile
Dockerfile)osr   r>   exists)r1   containerfile_pathfnamefilenames       r6    _find_containerfile_from_contextz3PodmanImageManager._find_containerfile_from_context  sd     "EdeEdii7e 	Hww~~h'%-"!!		 "!	 fs   1A&c                    | j                   r| j                   j                  d      nd}| j                   r| j                   j                  d      nd}d}|r|}n| j                  r|s| j                         }|sJt	        j
                  |t        j                        r&t        |      5 }|j                         }ddd       |S |S # 1 sw Y   |S xY w)a  
        Get the path to the Containerfile for an invocation
        of the module, and return its contents.

        See if either `file` or `container_file` in build args are populated,
        fetch their contents if so. If not, return the contents of the Containerfile
        or Dockerfile from inside the build context, if present.

        If we don't find a Containerfile/Dockerfile in any of the above
        locations, return 'None'.
        fileNcontainer_file)	r   r+   r   rZ   rU   accessR_OKopenread)r1   build_file_argcontainerfile_contentscontainer_filenamefs        r6   _get_containerfile_contentsz.PodmanImageManager._get_containerfile_contents  s     48::/4EIZZ0@!AUY!!/YY~!%!F!F!H%"))4F*P() 2Q)*&2 &%%%2 &%s   )CCc                     |syt         j                  dk  r1t        j                  |j	                               j                         S t        j                  |j	                         d      j                         S )zx
        When given the contents of a Containerfile/Dockerfile,
        return a sha256 hash of these contents.
        N)   	   F)usedforsecurity)sysversion_infohashlibr   encode	hexdigest)r1   rc   s     r6   _hash_containerfile_contentsz/PodmanImageManager._hash_containerfile_contents(  si    
 & f$>>&--/ik >>&--/ % ikr7   c                    d}| j                   xr | j                         }|xs< | j                  j                  d      duxs | j                  j                  d      du}|r| j	                  | j                               }|S )z
        If we can find a Containerfile in any of the module args
        or inside the build context, hash its contents.

        If we don't have this, return an empty string.
        Nr\   r]   )r   rZ   r   r+   rp   rf   )r1   args_containerfile_hashcontext_has_containerfileshould_hash_args_containerfiles       r6   _get_args_containerfile_hashz/PodmanImageManager._get_args_containerfile_hash;  s     #'$(II$Y$2W2W2Y! & 9JJNN6"$.9JJNN+,D8 	' *&*&G&G002'# '&r7   c                    | j                         }d}| j                         }|rI|d   j                  d|d   j                  d            }|d   j                  d      xs i }d|v r|d   }nd }|xr	 |xr ||k7  }|r| j                  s|rf| j                  dk(  s| j
                  rl| j                  r| j                  j                  d      nd }| j                  r| j                  j                  d	      nd }|r|r| j                  j                  d
       | j
                  s'|r%t        j
                  j                  |      | _        n,| j
                  s |s|s| j                  j                  d       | j                  d   j                  dj                  | j                  | j
                  xs d             | j                  j                  s| j!                  |      \  | j                  d<   | j                  d<   | j                  d   }nm| j                  d   j                  dj                  | j                               | j                  j                  s| j#                         x}| j                  d<   |s| j                         }| j                  j                  s:|d   j                  d|d   j                  d            }	||	k7  | j                  d<   nd| j                  d<   | j$                  r:| j'                         \  | j                  d<   }
| j                  dxx   d|
z   z  cc<   |r,| j                  j                  d      s|| j                  d<   y y y )N r   DigestdigestLabelszcontainerfile.hashr   r\   r]   z:Cannot specify both build file and container file content!msgz@Path to build context or file is required when building an imageactionsz$Built image {image_name} from {path}zdefault context)r/   r   imagestdoutzPulled image {image_name}r/   changedT
)
find_imageru   r+   r   r   r   r   r(   	fail_jsonrU   dirnamer)   r@   r.   r/   
check_modebuild_image
pull_imager   
push_image)r1   r~   !existing_image_containerfile_hashrr   digest_beforelabelsboth_hashes_exist_and_differ
build_filecontainer_file_txtdigest_afteroutputs              r6   r#   zPodmanImageManager.presentS  s   !,.)"&"C"C"E!!HLL58<<3IJM1X\\(+1rF#v-4:;O4P1 M(? )eDe )e(?Cd(d 	% 

&BzzW$		7;zzTZZ^^F3t
IMTZZ^^4D%EY]""4KK)).j)kyyZ "
 ;DI:>PKK)).p)qY'../U/\/\#TYY5SBS 0] 0U V{{--DHDTDTUlDmADLL)4<<+A LL1E Y'../J/Q/Q]a]l]l/Q/mn{{--48OO4EEEDLL1);;))$Qx||HeAhll86LM*7<*GY'*.Y'99,0OO,=)DLL!6LL"dVm3"))'2$)DLL! 35r7   c                 P   | j                         }| j                         }|r| j                  d   j                  dj	                  | j
                               d| j                  d<   d| j                  d   d<   | j                  j                  s| j                          y y |r| j                  d   j                  d	j	                  | j                  
             d| j                  d<   d| j                  d   d<   | j                  j                  s| j                          y y y )Nr}   zRemoved image {name})r   Tr   Deletedr~   r   zRemoved image with id {id})id)r   find_image_idr)   r@   r.   r   r(   r   remove_imager/   remove_image_id)r1   r~   image_ids      r6   r$   zPodmanImageManager.absent  s    !%%'LL#**+A+H+Hdii+H+XY&*DLL#-6DLL!'*;;))!!# *LL#**,33t3GI&*DLL#-6DLL!'*;;))$$& * r7   c                     t        | j                  d      }| j                  j                  |        | j                  j                  di | j                   y )Nr~    )r	   r(   r)   update	exit_json)r1   results_updates     r6   r0   zPodmanImageManager.make_quadlet  s?    -dkk7CN+--r7   c                 &   || j                   }| j                  dd|gd      \  }}}|dk(  r| j                  |      }ny dd|ddg}| j                  |d      \  }}}	 t        j                  |      }t        |      dk(  ry | j                  |      }| j                  || j                        s| j                  s|xs |S y # t        j
                  j                  $ r/ | j                  j                  d	j                  |
             Y w xY w)Nr~   rV   Tr=   r   ls--formatjsonz7Failed to parse JSON output from podman image ls: {out}outr{   )r/   rC   inspect_imager   loadsdecoderJSONDecodeErrorr(   r   r.   len_is_target_archr   )r1   r/   rcr   errinspect_jsonr;   imagess           r6   r   zPodmanImageManager.find_image  s   Jyy'8Z!@PTyUC7--j9Lz:v>))D)=FC	tZZ'F v;!))*5dii8		)\) ||++ 	tKK!!&_&f&fkq&f&r!s	ts    C A	DDc                      |xr |d   d   |k(  S )Nr   Architecturer   )r1   r   r   s      r6   r   z"PodmanImageManager._is_target_arch  s    ?Q74??r7   c                 0   |!t        j                  dd| j                        }g d}| j                  |d      \  }}}t        j                  |      D cg c]  }t        j                  dd|       }}|D ]  }|j                  |      s|c S  y c c}w )N:.*$rw   )r~   r   z--quietz
--no-truncTr   z^sha256:)resubr/   rC   strrG   rH   )r1   r   r;   r   
candidatesr   cs          r6   r   z PodmanImageManager.find_image_id  s    vvfb$//:H7"iiDiAJ"~~j9; ffZQ/ ;
 ; 	 A||H%	  ;s   Bc                 @   || j                   }d|ddg}| j                  |      \  }}}	 t        j                  |      }t        |      dkD  r|S y # t        j                  j
                  $ r/ | j                  j                  dj                  |             Y \w xY w)Ninspectr   r   z6Failed to parse JSON output from podman inspect: {out}r   r{   r   )
r/   rC   r   r   r   r   r(   r   r.   r   )r1   r/   r;   r   
image_datar   s         r6   r   z PodmanImageManager.inspect_image  s    J:z6:"iioJ	wJ/J z?Q ||++ 	wKK!!&^&e&ejt&e&u!v	ws   A A	BBc                    || j                   }d|dg}| j                  r|j                  d| j                  g       | j                  r|j                  d| j                  g       | j                  rF| j
                  r:dj                  | j                  | j
                        }|j                  d|g       | j                  /| j                  r|j                  d       n|j                  d	       | j                  r|j                  d
| j                  g       | j                  r.|j                  t        j                  | j                               | j                  |d      \  }}}|dk7  rp| j                  s8| j                  j!                  dj                  | j                  |             n,| j                  j!                  dj                  |             | j#                  |j%                               S )Nr   z-q--arch
--authfile{user}:{password}userr   --creds--tls-verify--tls-verify=false
--cert-dirTr   r   zHFailed to find image {image_name} locally, image pull set to {pull_bool})	pull_boolr/   r{   z!Failed to pull image {image_name}r   )r/   r   extendr   r   r   r.   r   r@   r   r   shlexsplitrC   r   r(   r   r   strip)r1   r/   r;   cred_stringr   r   r   s          r6   r   zPodmanImageManager.pull_image  s   J
D)99KK499-.>>KKt~~67==T]]-44$--RVR_R_4`KKKK01*""N+01KKt'7'789KKD$8$89:yyTy:C799%%bii"&))
 j D & E %%;BBjBY & [!!#))+..r7   c                 	   dg}|j                  d| j                  g       | j                  /| j                  r|j                  d       n|j                  d       | j                  j                  d      }|r<|j                         D ])  \  }}|j                  ddj                  ||      g       + | j                  r|j                  d	| j                  g       | j                  j                  d
      r|j                  d       | j                  j                  d      }|r|j                  d|g       | j                  r|j                  d| j                  g       | j                  j                  d      s|j                  d       | j                  j                  d      r|j                  d       | j                  j                  d      }|r|j                  d|g       | j                  j                  d      }|r| j                  r@t        j                  j                  | j                  dt        j                         z        }	nGt        j                  j                  t        j                         dt        j                         z        }	t!        |	d      5 }
|
j#                  |       d d d        |j                  d|	g       |r|j                  dd| g       | j                  j                  d      }|r|D ]  }|s|j                  d|g        | j$                  r|j                  d| j$                  g       | j&                  rF| j(                  r:dj                  | j&                  | j(                        }|j                  d|g       | j                  j                  d       }|r$|j                  t+        j,                  |             | j                  j                  d!      }|r|j                  d"|g       | j                  r|j                  | j                         | j/                  |d#$      \  }}}|d%k7  r8| j0                  j3                  d&j                  | j                  ||'      (       |rt        j4                  	       | j7                  |d)*      }| j9                  |      ||z   fS # 1 sw Y   xY w)+Nr   z-tr   r   
annotationz--annotationz{k}={v})kvr   force_rmz
--force-rmr.   r   r   cachez
--no-cachermz--rmr\   z--filer]   z%Containerfile.generated_by_ansible_%swz--labelzcontainerfile.hash=volumez--volumer   r   r   r   
extra_argstargetz--targetTr   r   z*Failed to build image {image}: {out} {err})r~   r   r   r{   z-->)rH   )r   r/   r   r@   r   r+   itemsr.   r   r   r   rU   r>   timetempfile
gettempdirr`   writer   r   r   r   r   rC   r(   r   removerQ   r   )r1   containerfile_hashr;   r   r   r   image_formatcontainerfiler   container_file_pathre   r   r   r   r   r   r   r   last_ids                      r6   r   zPodmanImageManager.build_image  s   yT4??+,*""N+01ZZ^^L1
"((* J1^Y-=-=Q-=-GHIJ KKt'7'789::>>*%KK%zz~~h/KK\2399KK499-.zz~~g&KK%::>>$KK

v.KK=12!ZZ^^,<=yy&(ggll499>ehlhqhqhs>s&t#&(ggll'')+RUYU^U^U`+`'b#)3/ ,1*+,KK#678KK&9:L9M$NOP) 1KKQ01 >>KKt~~67==T]]-44$--RVR_R_4`KKKK01ZZ^^L1
KKJ/0)KKV,-99KK		"yyTy:C7KK!!&R&Y&Yoo3C 'Z '9! : II)***35*A!!'*C#I55M, ,s   'SSc                 L   dg}| j                   /| j                   r|j                  d       n|j                  d       | j                  r|j                  d| j                  g       | j                  rF| j
                  r:dj                  | j                  | j
                        }|j                  d|g       | j                  r|j                  d| j                  g       | j                  j                  d	      r|j                  d
       | j                  j                  d      }|r|j                  d|g       | j                  j                  d      r|j                  d       | j                  j                  d      }|r|j                  d|g       | j                  j                  d      }|r$|j                  t        j                  |             |j                  | j                         | j                  j                  d      }| j                  j                  d      }|| j                  }|r<|dk(  rd}n|dk(  rd}nd}|dk(  rd|vrd}|j                  || j                  |      }	nW|}	d|vrQd|vrMt        |j                  d      j                  d            dk(  r!|j                  d      dz   | j                  z   }	d|	vr$d|	vr d|	vr| j                   j#                  d !       |j                  |	       | j                   j%                  d"j                  | j                  |	#             | j&                  d$   j                  d%j)                  |             d&| j&                  d'<   d(\  }
}| j                   j*                  sp| j-                  |d&)      \  }}
}|d*k7  rT| j                   j#                  d+j                  | j                  ,      |
|| j&                  d$   | j&                  d-   .       | j/                  | j                        |
|z   fS )/Nr   r   r   r   r   r   r   r   compressz
--compressr.   r   remove_signaturesz--remove-signaturessign_byz	--sign-byr   dest	transportdockerz{transport}://{dest}ostreez{transport}:{name}@{dest}z{transport}:{dest}docker-daemonr    z{transport}:{dest}:latest)r   r   r   r!   /   zNDestination must be a full URL or path to a directory with image name and tag.r{   z?PODMAN-IMAGE-DEBUG: Pushing image {image_name} to {dest_string})r/   dest_stringr}   r9   Tr   )rw   rw   r   r   z!Failed to push image {image_name}r   r:   )r|   r   stderrr}   r:   )r   r@   r   r   r   r   r.   r   r   r+   r   r   r/   r   r   rstripr(   r   r?   r)   r>   r   rC   r   )r1   r;   r   push_formatsign_by_keypush_extra_argsr   r   dest_format_stringr   r   r   r   s                r6   r   zPodmanImageManager.push_imageP  s   x*""N+01KKt'7'789==T]]-44$--RVR_R_4`KKKK01>>KKt~~67>>j)KK%nn((2KK[12>>12KK-.nn((3KKk23..,,\:KKO45DOO$ ~~!!&)NN&&{3	<??DH$%;"h&%@"%9"/CtO)D&,33idii^b3cKK$3d?s4;;s;K;Q;QRU;V7W[\7\"kk#.4tFk!c&<XcAcKK!!&v!wK Y``K a A 	BY&&sxx~6"&YS{{%%99T9>LBSQw%%*M*T*T# +U +0s LL3#'<<0@#A	 & C !!$//2C#I==r7   c                     || j                   }d|g}| j                  r|j                  d       | j                  |d      \  }}}|dk7  r-| j                  j                  dj                  ||             |S )	Nrmi--forceTr   r   z*Failed to remove image {image_name}. {err})r/   r   r{   )r/   r   r@   rC   r(   r   r.   )r1   r/   r;   r   r   r   s         r6   r   zPodmanImageManager.remove_image  s    Jz"::KK	"yyTy:C7KK!!&R&Y&Y%3 'Z '0! 1
r7   c                     |!t        j                  dd| j                        }d|g}| j                  r|j	                  d       | j                  |d      \  }}}|dk7  r-| j                  j                  dj                  ||	      
       |S )Nr   rw   r   r   Tr   r   z0Failed to remove image with id {image_id}. {err})r   r   r{   )	r   r   r/   r   r@   rC   r(   r   r.   )r1   r   r;   r   r   r   s         r6   r   z"PodmanImageManager.remove_image_id  s    vvfb$//:Hx ::KK	"yyTy:C7KK!!&X&_&_!s '` ',! -
r7   )r   F)NNr9   rE   )N)NN)__name__
__module____qualname__r'   rC   rQ   rZ   rf   rp   ru   r#   r$   r0   r   r   r   r   r   r   r   r   r   __classcell__)r5   s   @r6   r   r     sj    ' R
)"&8&'04*l'$.
,@%/NS6jP>dr7   r   c                     | j                  dd      }t        |      dk(  rt        |      S | j                  dd      }t        |      dk(  rd|d   vrt        |      S | d fS )Nr!   rE   r   r    r   )rI   r   tuple)	repo_namepartss     r6   r-   r-     se    S!$E
5zQU|S!$E
5zQ3eAh.U|d?r7   c                     t        t        d<i dt        dd      dt        d      dt        dd	      d
t        dd	      dt        d      dt        dd	      dt        d      dt        dd	      dt        ddg d      dt        dddg      dt        dd	      dt        ddg      dt        d      dt        dd      d t        d      d!t        dd      d"t        d      d#t        d$d      d%t        d&dd'      d(t        d)d*d+gi t        t        d)      t        dd	      t        d      t        d      t        dd,d-gd,.      t        dd	      t        dd	      t        d&d/      t        d      t        d      0
      1      d2t        d)i t        t        d      t        dg d34      t        d      t        d      t        dd5g      t        d      t        dg d64      7      8      dddgfddgddgf9      } t        dg g i d:;      }t        | |        | j                  d<i | y )=Nr   r   T)typer   r   )r   r   latest)r   defaultr   boolr   r   Fr   r   r   r#   )r$   r#   r   r%   )r   r  choicesr   	tlsverify
tls_verify)r   aliasesr   podmanr   authfiler   r   )r   no_logr   quadlet_dirquadlet_filenamequadlet_file_moderawquadlet_optionslist)r   elementsr   r   dict
build_args	buildargsocir   )r   r  r  )r   r  )
r   r   r\   r]   r.   r   r   r   r   r   )r   r  r  optionsr   )r  v2s1v2s2)r   r  destination)dirzdocker-archiver   zoci-archiver   r   )r   r.   r   r   r   r   r   )r   r  r  )argument_specsupports_check_moderequired_togethermutually_exclusiverw   )r   r}   r:   r~   r   r   )r   r  r   r   )r(   r)   s     r6   mainr    s    @
540@
5!@
 %2@
 640	@

 !e,@
 651@
 5!@
 FE2@
 E9>gh@
  Vk<5PQ@
 9@
 =@
 u%@
 uT2@
 &)@
  &59!@
" "u-#@
$ #>%@
& !fuuM'@
( %{3#0!vu=6*#'U#3"!& 1 %
 FD96Ve<#/U+	)@
R !v.U4KL&*&7 e,5=/C#/""!
S@
B !$
 *%*%
MJFX G vw'Fwr7   __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr   rU   r   r   r   r   rm   rk   ansible.module_utils._textr   ansible.module_utils.basicr   Hansible_collections.containers.podman.plugins.module_utils.podman.commonr   Iansible_collections.containers.podman.plugins.module_utils.podman.quadletr	   objectr   r-   r  r   r   r7   r6   <module>r+     s   
 A @[z}~E
N  	 	     
 0 4 g j DV r zF r7   