-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'gh/main' into master_bb
- Loading branch information
Showing
7 changed files
with
159 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
name: pre-commit | ||
on: [push, pull_request] | ||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
# | ||
# Please keep the list sorted. | ||
# | ||
Julien Riou <[email protected]> | ||
Nicolas Payart <[email protected]> | ||
Stéphane Lesimple <[email protected]> | ||
Wifried Roset <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/sh | ||
exec sftp -S $(dirname $0)/sftpwrapper.py "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import getpass | ||
import os | ||
import sys | ||
|
||
from lib import find_executable, get_hostvars, manage_conf_file | ||
|
||
|
||
def main(): | ||
argv = list(sys.argv[1:]) | ||
|
||
bastion_user = None | ||
bastion_host = None | ||
bastion_port = None | ||
remote_user = None | ||
remote_port = 22 | ||
default_configuration_file = "/etc/ovh/bastion/config.yml" | ||
|
||
iteration = enumerate(argv) | ||
for i, e in iteration: | ||
if e == "-o" and argv[i + 1].startswith("User="): | ||
remote_user = argv[i + 1].split("=")[-1] | ||
next(iteration) | ||
elif e == "-o" and argv[i + 1].startswith("Port="): | ||
remote_port = argv[i + 1].split("=")[-1] | ||
next(iteration) | ||
|
||
sftpcmd = argv.pop() | ||
host = argv.pop() | ||
|
||
# Playbook environment variables are not pushed to the sftp wrapper | ||
# Skipping this source of configuration | ||
|
||
# Read from configuration file | ||
bastion_host, bastion_port, bastion_user = manage_conf_file( | ||
os.getenv("BASTION_CONF_FILE", default_configuration_file), | ||
bastion_host, | ||
bastion_port, | ||
bastion_user, | ||
) | ||
|
||
# Read from inventory and environment variables | ||
if not bastion_host or not bastion_port or not bastion_user: | ||
inventory = get_hostvars(host) | ||
bastion_port = inventory.get("bastion_port", os.getenv("BASTION_PORT", 22)) | ||
bastion_user = inventory.get( | ||
"bastion_user", os.getenv("BASTION_USER", getpass.getuser()) | ||
) | ||
bastion_host = inventory.get("bastion_host", os.getenv("BASTION_HOST")) | ||
|
||
args = [ | ||
"ssh", | ||
"{}@{}".format(bastion_user, bastion_host), | ||
"-p", | ||
bastion_port, | ||
"-o", | ||
"StrictHostKeyChecking=no", | ||
"-T", | ||
"--", | ||
"--user", | ||
remote_user, | ||
"--port", | ||
remote_port, | ||
"--host", | ||
host, | ||
"--osh", | ||
"sftp", | ||
] | ||
|
||
os.execv( | ||
find_executable("ssh"), | ||
[str(e).strip() for e in args], | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |