Add SSH key file creation from environment variables with error handling
This commit is contained in:
@@ -76,7 +76,36 @@ end
|
|||||||
-- return false
|
-- return false
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
|
local function createSSHKeyFilesFromEnv()
|
||||||
|
if SSH_PRIVATE_KEY == "" or SSH_PUBLIC_KEY == "" then
|
||||||
|
log("SSH_PRIVATE_KEY or SSH_PUBLIC_KEY env var is empty, skipping SSH key file creation.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local priv_fh = io.open(SSH_IDENTITY_FILE, "w")
|
||||||
|
if not priv_fh then
|
||||||
|
log("Failed to open SSH identity file for writing: " .. SSH_IDENTITY_FILE)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
priv_fh:write(SSH_PRIVATE_KEY)
|
||||||
|
priv_fh:close()
|
||||||
|
os.execute(("chmod 600 %q"):format(SSH_IDENTITY_FILE))
|
||||||
|
log("Wrote SSH private key to " .. SSH_IDENTITY_FILE)
|
||||||
|
|
||||||
|
local pub_fh = io.open(SSH_IDENTITY_FILE .. ".pub", "w")
|
||||||
|
if not pub_fh then
|
||||||
|
log("Failed to open SSH public key file for writing: " .. SSH_IDENTITY_FILE .. ".pub")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
pub_fh:write(SSH_PUBLIC_KEY)
|
||||||
|
pub_fh:close()
|
||||||
|
os.execute(("chmod 644 %q"):format(SSH_IDENTITY_FILE .. ".pub"))
|
||||||
|
log("Wrote SSH public key to " .. SSH_IDENTITY_FILE .. ".pub")
|
||||||
|
end
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
|
createSSHKeyFilesFromEnv()
|
||||||
|
|
||||||
log(("Watching container='%s' since='%s'"):format(CONTAINER_NAME, SINCE))
|
log(("Watching container='%s' since='%s'"):format(CONTAINER_NAME, SINCE))
|
||||||
log(("Looking for pattern: %q"):format(ERROR_PATTERN))
|
log(("Looking for pattern: %q"):format(ERROR_PATTERN))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user