Skip to content

Commit

Permalink
use tofu output to populate local env vars, then use it to populate r…
Browse files Browse the repository at this point in the history
…emote env vars
  • Loading branch information
GondekNP committed Jan 4, 2024
1 parent 50d389c commit a7de6c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .deployment/tofu/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "sftp_server_endpoint" {
description = "The endpoint of the SFTP server"
value = module.sftp.sftp_server_endpoint
}

output "sftp_admin_username" {
description = "The username of the SFTP admin user"
value = module.sftp.sftp_admin_username
}
8 changes: 8 additions & 0 deletions .devcontainer/scripts/export_tofu_env_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

cd /workspace/.deployment/tofu
tofu refresh
export sftp_admin_username="$(tofu output sftp_admin_username)"
export sftp_server_endpoint="$(tofu output sftp_server_endpoint)"
echo "# TOFU ENV VARS" >> ~/.bashrc
echo "SFTP_ADMIN_USERNAME=$sftp_admin_username" >> ~/.bashrc
echo "SFTP_SERVER_ENDPOINT=$sftp_server_endpoint" >> ~/.bashrc
12 changes: 7 additions & 5 deletions src/util/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ def __init__(self, hostname, username, private_key, port=22):
self.username = username
self.port = port

# TODO: This doesn't seem best practice - AWS is adding a leading \ to newlines \n
# private_key_file = io.StringIO(private_key.replace("\\n", "\n"))
private_key_file = io.StringIO(private_key)
self.private_key = paramiko.RSAKey.from_private_key(private_key_file)

self.available_cogs = None

print(f"Initialized SFTPClient for {self.hostname} as {self.username}")
self.connect()
self.available_cogs = self.get_available_cogs()
self.disconnect()

def connect(self):
"""Connects to the sftp server and returns the sftp connection object"""
Expand Down Expand Up @@ -126,3 +123,8 @@ def get_available_cogs(self):
available_cogs[top_level_folder] = s3_file_path

return available_cogs

def update_available_cogs(self):
self.connect()
self.available_cogs = self.get_available_cogs()
self.disconnect()

0 comments on commit a7de6c2

Please sign in to comment.