uselagoon / lagoon-sync

Apache License 2.0
6 stars 5 forks source link

Better error logging for SSH commands #104

Closed rocketeerbkw closed 11 months ago

rocketeerbkw commented 11 months ago

This PR does two things:

  1. Supress SSH warnings
  2. Log SSH stdout on error

When trying to sync a database with the wrong password

before:

[INFO]  2023/09/28 14:42:55 Running the following for target (pr-3) ssh -tt -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 32222 amazeeio-example-pr-3@ssh.lagoon.amazeeio.cloud service=cli 'mysql -h${MARIADB_HOST:-mariadb} -u${MARIADB_USERNAME:-drupal} -pfoo -P${MARIADB_PORT:-3306} ${MARIADB_DATABASE:-drupal} < /tmp/lagoon_sync_mariadb_1695912112725148153.sql'
[FATAL] 2023/09/28 14:43:05 github.com/uselagoon/lagoon-sync/utils.LogFatalError:logs.go:76 Warning: Permanently added '[ssh.lagoon.amazeeio.cloud]:32222' (ED25519) to the list of known hosts.
Connection to ssh.lagoon.amazeeio.cloud closed.

after:

INFO]  2023/09/28 18:44:06 Running the following for target (pr-3) ssh -tt -o LogLevel=FATAL -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 32222 amazeeio-example-pr-3@ssh.lagoon.amazeeio.cloud service=cli 'mysql -h${MARIADB_HOST:-mariadb} -u${MARIADB_USERNAME:-drupal} -pfoo -P${MARIADB_PORT:-3306} ${MARIADB_DATABASE:-drupal} < /tmp/lagoon_sync_mariadb_1695926615304245222.sql'
[ERROR] 2023/09/28 18:44:15 github.com/uselagoon/lagoon-sync/utils.LogError:logs.go:76 ERROR 1045 (28000): Access denied for user 'redacted'@'redacted' (using password: YES)
command terminated with exit code 1

[FATAL] 2023/09/28 18:44:15 github.com/uselagoon/lagoon-sync/utils.LogFatalError:logs.go:90 Error: exit status 1

closes #103

bomoko commented 11 months ago

awesome! Thanks @rocketeerbkw