Skip to content

Commit

Permalink
Embed Targetd Config (DIS-2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecinestpasunepipe committed Oct 24, 2023
1 parent 84da0fc commit 6d497ab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
34 changes: 19 additions & 15 deletions acquire/acquire.py
Original file line number Diff line number Diff line change
Expand Up @@ -2166,21 +2166,6 @@ def main() -> None:
except ValueError as err:
parser.exit(err)

if args.targetd:
from targetd.tools.targetd import start_client

# Configure your targetd agent here
config = {
"function": "agent",
"topics": ["/host/a", "/host/*"],
"link": "pipe-server://tmp/b",
"address": "10.0.2.3",
"port": 1884,
"cacert": Path("targetd.crt"),
}
start_client(args, presets=config)
parser.exit("Done")

if args.log_to_dir:
# When args.upload files are specified, only these files are uploaded
# and no other action is done. Thus a log file specifically named
Expand All @@ -2207,6 +2192,25 @@ def main() -> None:
log.exception(err)
parser.exit(1)

if args.targetd:
from targetd.tools.targetd import start_client

Check warning on line 2196 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L2195-L2196

Added lines #L2195 - L2196 were not covered by tests

# set @auto hostname to real hostname
if args.targetd_hostname == "@auto":
args.targetd_hostname = f"/host/{Target.open('local').hostname}"

Check warning on line 2200 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L2199-L2200

Added lines #L2199 - L2200 were not covered by tests

config = {

Check warning on line 2202 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L2202

Added line #L2202 was not covered by tests
"function": args.targetd_func,
"topics": [args.targetd_hostname, args.targetd_groupname, args.targetd_globalname],
"link": args.targetd_link,
"address": args.targetd_ip,
"port": args.targetd_port,
"cacert_str": args.targetd_cacert,
"cacert": None,
}
start_client(args, presets=config)
return

Check warning on line 2212 in acquire/acquire.py

View check run for this annotation

Codecov / codecov/patch

acquire/acquire.py#L2211-L2212

Added lines #L2211 - L2212 were not covered by tests

if args.upload:
try:
upload_files(args.upload, args.upload_plugin, args.no_proxy)
Expand Down
20 changes: 17 additions & 3 deletions acquire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
from acquire.outputs import OUTPUTS
from acquire.uploaders.plugin_registry import UploaderRegistry

# Acquire Configuration for CAgent and TargetD
CAGENT_TARGETD_ATTRS = {
"cagent_key",
"cagent_certificate",
"targetd_func",
"targetd_cacert",
"targetd_ip",
"targetd_port",
"targetd_hostname",
"targetd_groupname",
"targetd_globalname",
"targetd_link",
}


class StrEnum(str, Enum):
"""Sortable and serializible string-based enum"""
Expand Down Expand Up @@ -288,9 +302,9 @@ def check_and_set_acquire_args(
raise ValueError("No public key available (embedded or argument)")
setattr(args, "public_key", public_key)

# set cagent related configuration
setattr(args, "cagent_key", args.config.get("cagent_key"))
setattr(args, "cagent_certificate", args.config.get("cagent_certificate"))
# set cagent/targetd related configuration
for attr in CAGENT_TARGETD_ATTRS:
setattr(args, attr, args.config.get(attr))

if not args.children and args.skip_parent:
raise ValueError("--skip-parent can only be set with --children")
Expand Down

0 comments on commit 6d497ab

Please sign in to comment.