-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .client import * | ||
from .scan import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import hashlib | ||
import json | ||
import logging | ||
import uuid | ||
|
||
import namegenerator | ||
import strawberry | ||
import strawberry_django | ||
from ekke.types import Info | ||
|
||
from fakts import enums, inputs, models, scalars, types | ||
from fakts.base_models import DevelopmentClientConfig, Manifest | ||
from fakts.builders import create_client | ||
from fakts.models import Composition | ||
from fakts.scan import scan | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
||
|
||
def scan_backend(info: Info, input: inputs.ScanBackendInput) -> str: | ||
|
||
token = scan() | ||
|
||
|
||
|
||
return token | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import docker | ||
import re | ||
import socket | ||
|
||
def get_my_container(client: docker.DockerClient): | ||
|
||
container_id = socket.gethostname() | ||
|
||
try: | ||
return client.containers.get(container_id) | ||
except docker.errors.NotFound: | ||
|
||
potential_container_id = None | ||
|
||
try: | ||
with open("/proc/self/cgroup", "r") as file: | ||
for line in file: | ||
match = re.search(r'/docker/([a-f0-9]{64})$', line) | ||
if match: | ||
potential_container_id = match.group(1) | ||
break | ||
|
||
except FileNotFoundError: | ||
raise Exception("Could not find container id") | ||
|
||
if potential_container_id: | ||
return client.containers.get(potential_container_id) | ||
else: | ||
raise Exception("Could not find container id") | ||
|
||
|
||
|
||
def get_project_name(container): | ||
return container.labels.get("com.docker.compose.project") | ||
|
||
|
||
def retrieve_sibling_containers(client: docker.DockerClient, project_name: str): | ||
# Filter containers by Docker Compose project label | ||
filters = {"label": f"com.docker.compose.project={project_name}"} | ||
containers = client.containers.list(all=True, filters=filters) | ||
return containers | ||
|
||
|
||
|
||
def scan(): | ||
client = docker.from_env() | ||
container = get_my_container(client) | ||
|
||
project_name = get_project_name(container) | ||
print(project_name) | ||
print(container) | ||
|
||
|
||
sibling_containers = retrieve_sibling_containers(client, project_name) | ||
|
||
|
||
for container in sibling_containers: | ||
labels = container.labels | ||
|
||
if "fakts.service.template" in labels: | ||
print(container.attrs["NetworkSettings"]["Ports"]) | ||
|
||
|
||
|
||
|
||
print(container.name) | ||
print(labels["fakts.service"]) | ||
print(container) | ||
|
||
return "token" | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters