Skip to content

Commit

Permalink
Seperate allowed images and allowed containers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hdwhdw committed Dec 12, 2024
1 parent 15beef8 commit 68cf038
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions host_modules/docker_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,43 @@
MOD_NAME = "docker_service"

# The set of allowed containers that can be managed by this service.
# First element is the image name, second element is the container name.
ALLOWED_CONTAINERS = [
("docker-syncd-brcm", "syncd"),
("docker-acms", "acms"),
("docker-sonic-gnmi", "gnmi"),
("docker-sonic-telemetry", "telemetry"),
("docker-snmp", "snmp"),
("docker-platform-monitor", "pmon"),
("docker-lldp", "lldp"),
("docker-dhcp-relay", "dhcp_relay"),
("docker-router-advertiser", "radv"),
("docker-teamd", "teamd"),
("docker-fpm-frr", "bgp"),
("docker-orchagent", "swss"),
("docker-sonic-restapi", "restapi"),
("docker-eventd", "eventd"),
("docker-database", "database"),
]
ALLOWED_CONTAINERS = {
"syncd",
"acms",
"gnmi",
"telemetry",
"snmp",
"pmon",
"lldp",
"dhcp_relay",
"radv",
"teamd",
"bgp",
"swss",
"restapi",
"eventd",
"database",
}

# The set of allowed images that can be managed by this service.
ALLOWED_IMAGES = {
"docker-syncd-brcm",
"docker-syncd-cisco"
"docker-acms",
"docker-sonic-gnmi",
"docker-sonic-telemetry",
"docker-snmp",
"docker-platform-monitor",
"docker-lldp",
"docker-dhcp-relay",
"docker-router-advertiser",
"docker-teamd",
"docker-fpm-frr",
"docker-orchagent",
"docker-sonic-restapi",
"docker-eventd",
"docker-database",
}


def is_allowed_container(container):
Expand All @@ -38,10 +57,7 @@ def is_allowed_container(container):
Returns:
bool: True if the container is allowed, False otherwise.
"""
for _, allowed_container in ALLOWED_CONTAINERS:
if container == allowed_container:
return True
return False
return container in ALLOWED_CONTAINERS


def is_allowed_image(image):
Expand All @@ -55,10 +71,7 @@ def is_allowed_image(image):
bool: True if the image is allowed, False otherwise.
"""
image_name = image.split(":")[0] # Remove tag if present
for allowed_image, _ in ALLOWED_CONTAINERS:
if image_name == allowed_image:
return True
return False
return image_name in ALLOWED_IMAGES


class DockerService(host_service.HostModule):
Expand Down

0 comments on commit 68cf038

Please sign in to comment.