File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -65,17 +65,30 @@ if grep -q "\-\-remediate" <<< "$@"; then
65
65
die
66
66
fi
67
67
68
+ IMAGE_NAME=$( podman image exists " $1 " \
69
+ && podman image inspect --format " {{.Id}} {{.RepoTags}}" " $1 " )
70
+ CONTAINER_NAME=$( podman container exists " $1 " \
71
+ && podman container inspect --format " {{.Id}} {{.Name}}" " $1 " )
72
+
73
+ if [ -n " $IMAGE_NAME " ] && [ -n " $CONTAINER_NAME " ]; then
74
+ echo " Ambiguous target, container image and container with the same name detected: '$1 '." >&2
75
+ echo " Please rather use an unique ID to specify the target of the scan." >&2
76
+ die
77
+ fi
78
+
68
79
# Check if the target of scan is image or container.
69
80
CLEANUP=0
70
- if podman images | grep -q $1 ; then
81
+ if [ -n " $IMAGE_NAME " ] ; then
71
82
ID=$( podman create $1 ) || die
72
- IMG_NAME=$( podman images --format " {{.ID}} ({{.Repository}}:{{.Tag}})" | grep -m1 $1 )
73
- TARGET=" podman-image://$IMG_NAME "
83
+ TARGET=" podman-image://$IMAGE_NAME "
74
84
CLEANUP=1
75
- else
85
+ elif [ -n " $CONTAINER_NAME " ] ; then
76
86
# If the target was not found in images we suppose it is a container.
77
87
ID=$1
78
- TARGET=" podman-container://$1 "
88
+ TARGET=" podman-container://$CONTAINER_NAME "
89
+ else
90
+ echo " Target of the scan not found: '$1 '." >&2
91
+ die
79
92
fi
80
93
81
94
# podman init creates required files such as: /run/.containerenv - we don't care about output and exit code
You can’t perform that action at this time.
0 commit comments