Skip to content

Commit

Permalink
Merge 5208dc4 into a7c46d6
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdonnnj committed Dec 8, 2021
2 parents a7c46d6 + 5208dc4 commit 96cd98d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/guacscanner/ConnectionParameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ConnectionParameters:
"rdp_username",
"vnc_password",
"vnc_username",
"windows_sftp_base",
)

"""The private SSH key to use when transferring data via VNC."""
Expand All @@ -32,3 +33,6 @@ class ConnectionParameters:

"""The user name to use when Guacamole establishes a VNC connection."""
vnc_username: str

"""The base path to use for configuring SFTP connections to Windows instances."""
windows_sftp_base: str
2 changes: 1 addition & 1 deletion src/guacscanner/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "1.0.2"
__version__ = "1.1.0"
70 changes: 55 additions & 15 deletions src/guacscanner/guacscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>0 An error occurred.
Usage:
guacscanner [--log-level=LEVEL] [--oneshot] [--sleep=SECONDS] [--postgres-password=PASSWORD|--postgres-password-file=FILENAME] [--postgres-username=USERNAME|--postgres-username-file=FILENAME] [--private-ssh-key=KEY|--private-ssh-key-file=FILENAME] [--rdp-password=PASSWORD|--rdp-password-file=FILENAME] [--rdp-username=USERNAME|--rdp-username-file=FILENAME] [--region=REGION] [--vnc-password=PASSWORD|--vnc-password-file=FILENAME] [--vnc-username=USERNAME|--vnc-username-file=FILENAME] [--vpc-id=VPC_ID]
guacscanner [--log-level=LEVEL] [--oneshot] [--sleep=SECONDS] [--postgres-password=PASSWORD|--postgres-password-file=FILENAME] [--postgres-username=USERNAME|--postgres-username-file=FILENAME] [--private-ssh-key=KEY|--private-ssh-key-file=FILENAME] [--rdp-password=PASSWORD|--rdp-password-file=FILENAME] [--rdp-username=USERNAME|--rdp-username-file=FILENAME] [--region=REGION] [--vnc-password=PASSWORD|--vnc-password-file=FILENAME] [--vnc-username=USERNAME|--vnc-username-file=FILENAME] [--vpc-id=VPC_ID] [--windows-sftp-base=SFTPBASE|--windows-sftp-base-file=FILENAME]
guacscanner (-h | --help)
Options:
Expand Down Expand Up @@ -37,6 +37,8 @@
or destroyed in the specified VPC ID. If not
specified then the ID of the VPC in which the host
resides will be used.
--windows-sftp-base=SFTPBASE If specified then the specified value will be used as the base path for configuring Windows SFTP connections. Otherwise, the path will be read from a local file.
--windows-sftp-base-file=FILENAME The file from which the base path for Windows SFTP connections will be read. [default: /run/secrets/windows-sftp-base]
"""


Expand Down Expand Up @@ -360,12 +362,15 @@ def add_instance_connection(
connection_name = get_connection_name(instance)
is_windows = False
connection_protocol = "vnc"
# Note that the Windows VNC server software in use must support a connection
# to display 1 for this port to work.
connection_port = 5901
if instance.platform and instance.platform.lower() == "windows":
logging.debug("Instance %s is Windows and therefore uses RDP.", instance.id)
logging.debug(
"Instance %s is Windows and therefore uses different parameters for VNC.",
instance.id,
)
is_windows = True
connection_protocol = "rdp"
connection_port = 3389

with db_connection.cursor() as cursor:
cursor.execute(
Expand Down Expand Up @@ -440,15 +445,49 @@ def add_instance_connection(
),
)
if is_windows:
# mypy gives a warning on this line because we are
# re-assigning the variable with a tuple of a different
# length, but we know this is safe to do here.
guac_conn_params = ( # type: ignore
guac_conn_params = (
(
connection_id,
"cursor",
"local",
),
(
connection_id,
"sftp-directory",
f"{connection_parameters.windows_sftp_base}/Documents",
),
(
connection_id,
"sftp-username",
connection_parameters.rdp_username,
),
(
connection_id,
"sftp-private-key",
connection_parameters.private_ssh_key,
),
(
connection_id,
"sftp-server-alive-interval",
60,
),
# This must be the root of the filesystem to give access to any
# network drives through Guacamole's file sharing functionality.
(
connection_id,
"ignore-cert",
"sftp-root-directory",
"/",
),
(
connection_id,
"enable-sftp",
True,
),
(
connection_id,
"color-depth",
24,
),
(
connection_id,
"hostname",
Expand All @@ -457,18 +496,13 @@ def add_instance_connection(
(
connection_id,
"password",
connection_parameters.rdp_password,
connection_parameters.vnc_password,
),
(
connection_id,
"port",
connection_port,
),
(
connection_id,
"username",
connection_parameters.rdp_username,
),
)

logging.debug(
Expand Down Expand Up @@ -693,6 +727,11 @@ def main() -> None:
with open(validated_args["--private-ssh-key-file"], "r") as file:
private_ssh_key = file.read()

windows_sftp_base = validated_args["--windows-sftp-base"]
if windows_sftp_base is None:
with open(validated_args["--windows-sftp-base-file"], "r") as file:
windows_sftp_base = file.read()

db_connection_string = f"user={postgres_username} password={postgres_password} host={postgres_hostname} port={postgres_port} dbname={postgres_db_name}"

vpc_id = validated_args["--vpc-id"]
Expand Down Expand Up @@ -784,6 +823,7 @@ def main() -> None:
rdp_username=rdp_username,
vnc_password=vnc_password,
vnc_username=vnc_username,
windows_sftp_base=windows_sftp_base,
),
guacuser_id,
)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_guacscanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_log_levels(level):
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={DUMMY_VPC_ID}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(logging.root, "handlers", []):
Expand Down Expand Up @@ -157,6 +158,7 @@ def test_addition_of_guacuser():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down Expand Up @@ -206,6 +208,7 @@ def test_guacuser_already_exists():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down Expand Up @@ -279,6 +282,7 @@ def test_new_linux_instance():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down Expand Up @@ -349,6 +353,7 @@ def test_terminated_instance():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down Expand Up @@ -414,6 +419,7 @@ def test_stopped_instance():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down Expand Up @@ -487,6 +493,7 @@ def test_new_windows_instance():
"--vnc-password=dummy_vnc_password",
"--vnc-username=dummy_vnc_username",
f"--vpc-id={vpc_id}",
"--windows-sftp-base=/C:/Users/dummy_user",
],
):
with patch.object(
Expand Down

0 comments on commit 96cd98d

Please sign in to comment.