|
|
@ -32,6 +32,7 @@ def get_os_for_image(image: str) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
def parse_packages(provider: str, input: str) -> list[dict]:
|
|
|
|
def parse_packages(provider: str, input: str) -> list[dict]:
|
|
|
|
output = list()
|
|
|
|
output = list()
|
|
|
|
|
|
|
|
object_distroless = dict()
|
|
|
|
for line in input.split('\n'):
|
|
|
|
for line in input.split('\n'):
|
|
|
|
if len(line) > 0:
|
|
|
|
if len(line) > 0:
|
|
|
|
object = dict()
|
|
|
|
object = dict()
|
|
|
@ -49,6 +50,16 @@ def parse_packages(provider: str, input: str) -> list[dict]:
|
|
|
|
version = "-".join(second_pass[1:])
|
|
|
|
version = "-".join(second_pass[1:])
|
|
|
|
case "debian":
|
|
|
|
case "debian":
|
|
|
|
package, version = line.split('\t')
|
|
|
|
package, version = line.split('\t')
|
|
|
|
|
|
|
|
case "distroless":
|
|
|
|
|
|
|
|
key, value = line.split(':')
|
|
|
|
|
|
|
|
if key.strip() == "Package":
|
|
|
|
|
|
|
|
del object_distroless
|
|
|
|
|
|
|
|
object_distroless = dict()
|
|
|
|
|
|
|
|
object_distroless["provider"] = "debian"
|
|
|
|
|
|
|
|
object_distroless["package"] = value.strip()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
object_distroless["version"] = value.strip()
|
|
|
|
|
|
|
|
output.append(object_distroless)
|
|
|
|
case "fedora":
|
|
|
|
case "fedora":
|
|
|
|
first_pass = line.split(' ')[0]
|
|
|
|
first_pass = line.split(' ')[0]
|
|
|
|
second_pass = first_pass.split('-')
|
|
|
|
second_pass = first_pass.split('-')
|
|
|
@ -58,7 +69,7 @@ def parse_packages(provider: str, input: str) -> list[dict]:
|
|
|
|
package, version = line.split('==')
|
|
|
|
package, version = line.split('==')
|
|
|
|
case "ubuntu":
|
|
|
|
case "ubuntu":
|
|
|
|
package, version = line.split('\t')
|
|
|
|
package, version = line.split('\t')
|
|
|
|
|
|
|
|
if provider != "distroless":
|
|
|
|
object["package"] = package
|
|
|
|
object["package"] = package
|
|
|
|
object["version"] = version
|
|
|
|
object["version"] = version
|
|
|
|
output.append(object)
|
|
|
|
output.append(object)
|
|
|
@ -70,8 +81,8 @@ def get_inspect_data(image: str) -> list[dict]:
|
|
|
|
|
|
|
|
|
|
|
|
def get_packages(image: str) -> list[dict]:
|
|
|
|
def get_packages(image: str) -> list[dict]:
|
|
|
|
os = get_os_for_image(image)
|
|
|
|
os = get_os_for_image(image)
|
|
|
|
# Default is debian ubuntu
|
|
|
|
command = list()
|
|
|
|
command = []
|
|
|
|
result = list()
|
|
|
|
match os:
|
|
|
|
match os:
|
|
|
|
case "alpine":
|
|
|
|
case "alpine":
|
|
|
|
command = ["apk", "list", "-q"]
|
|
|
|
command = ["apk", "list", "-q"]
|
|
|
@ -79,6 +90,12 @@ def get_packages(image: str) -> list[dict]:
|
|
|
|
command = ["rpm", "-qa"]
|
|
|
|
command = ["rpm", "-qa"]
|
|
|
|
case "debian":
|
|
|
|
case "debian":
|
|
|
|
command = ["dpkg-query", "-W"]
|
|
|
|
command = ["dpkg-query", "-W"]
|
|
|
|
|
|
|
|
case "distroless":
|
|
|
|
|
|
|
|
command = ["sh", "-c", "cat /var/lib/dpkg/status.d/* | egrep 'Package|Version'"]
|
|
|
|
|
|
|
|
bboxcommand = ["sh", "-c", "busybox | grep 'BusyBox v' | awk '{print $1,$2}'"]
|
|
|
|
|
|
|
|
oneline,_ = run_command_in_image(image, bboxcommand)
|
|
|
|
|
|
|
|
first_pass = oneline.decode().split()
|
|
|
|
|
|
|
|
result = [ {"provider": os, "package": first_pass[0], "version": first_pass[1]}]
|
|
|
|
case "fedora":
|
|
|
|
case "fedora":
|
|
|
|
command = ["rpm", "-qa"]
|
|
|
|
command = ["rpm", "-qa"]
|
|
|
|
case "ubuntu":
|
|
|
|
case "ubuntu":
|
|
|
@ -89,7 +106,7 @@ def get_packages(image: str) -> list[dict]:
|
|
|
|
(output, _) = run_command_in_image(image, command)
|
|
|
|
(output, _) = run_command_in_image(image, command)
|
|
|
|
(pip_output, _) = run_command_in_image(image, ["python3", "-m", "pip", "list", "--format", "freeze"])
|
|
|
|
(pip_output, _) = run_command_in_image(image, ["python3", "-m", "pip", "list", "--format", "freeze"])
|
|
|
|
os_result = parse_packages(os, output.decode())
|
|
|
|
os_result = parse_packages(os, output.decode())
|
|
|
|
result = os_result
|
|
|
|
result = result + os_result
|
|
|
|
if not pip_output:
|
|
|
|
if not pip_output:
|
|
|
|
pip_result = parse_packages("pip", pip_output.decode())
|
|
|
|
pip_result = parse_packages("pip", pip_output.decode())
|
|
|
|
result += pip_result
|
|
|
|
result += pip_result
|
|
|
|