Skip to content

Commit 1cb6a07

Browse files
committed
SFTP updates
This PR: 1. Creates `known_hosts` file and adds data team's host info to it 2. Creates `id_rsa` file
1 parent e2d2e9f commit 1cb6a07

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

.github/workflows/run-tests.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,11 +345,17 @@ jobs:
345345
git push
346346
fi
347347
348+
# Add to known hosts and create id_rsa file
349+
mkdir -p ~/.ssh && touch ~/.ssh/known_hosts
350+
ssh-keyscan ${{ secrets.SFTP_OPTEST_HOST }} >> ~/.ssh/known_hosts
351+
echo ${{ secrets.SFTP_OPTEST_PRIVATE_KEY }} > ~/.ssh/id_rsa
352+
chmod 400 ~/.ssh/id_rsa
353+
348354
python3 tools/send_to_data_team.py \
349355
--github_workflow_id ${{ github.run_id }} \
350356
--sftp_host ${{ secrets.SFTP_OPTEST_HOST }} \
351357
--sftp_user ${{ secrets.SFTP_OPTEST_USER }} \
352-
--sftp_private_key ${{ secrets.SFTP_OPTEST_PRIVATE_KEY }}
358+
--sftp_private_key_path ${{ secrets.SFTP_OPTEST_PRIVATE_KEY }}
353359
354360
tests-passed:
355361
if: ${{ always() }}

tools/send_to_data_team.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def __init__(
1717
github_workflow_id: int,
1818
sftp_host: str,
1919
sftp_user: str,
20-
sftp_private_key: str,
20+
sftp_private_key_path: str,
2121
metrics_directory_name: str = "metrics",
2222
):
2323
self.github_workflow_id = github_workflow_id
2424
self.sftp_host = sftp_host
2525
self.sftp_user = sftp_user
26-
self.sftp_private_key = sftp_private_key
26+
self.sftp_private_key_path = sftp_private_key_path
2727
self.metrics_dir = Path(metrics_directory_name)
2828

2929
def run(self):
@@ -45,13 +45,10 @@ def send_file(self, file_path: Path):
4545
Args:
4646
file_path: Path to the file to send.
4747
"""
48-
with tempfile.NamedTemporaryFile() as private_key_file:
49-
private_key_file.write(bytes(self.sftp_private_key, "utf-8"))
50-
private_key_file.flush()
51-
with pysftp.Connection(
52-
host=self.sftp_host, username=self.sftp_user, private_key=private_key_file.name
53-
) as sftp:
54-
sftp.put(str(file_path))
48+
with pysftp.Connection(
49+
host=self.sftp_host, username=self.sftp_user, private_key=self.sftp_private_key_path
50+
) as sftp:
51+
sftp.put(str(file_path))
5552

5653
@staticmethod
5754
def write_file(pydantic_objects: List[OpTest], file_path: Path):
@@ -168,15 +165,15 @@ def collect_metrics(self, files: Dict[str, List[Path]]) -> List[OpTest]:
168165
parser.add_argument("--github_workflow_id", type=int, help="Github workflow id associated with the run.")
169166
parser.add_argument("--sftp_host", type=str, help="Sftp host.")
170167
parser.add_argument("--sftp_user", type=str, help="Sftp user.")
171-
parser.add_argument("--sftp_private_key", type=str, help="Path to private key.")
168+
parser.add_argument("--sftp_private_key_path", type=str, help="Path to private key.")
172169

173170
args = parser.parse_args()
174171

175172
sender = SendToDataTeam(
176173
github_workflow_id=args.github_workflow_id,
177174
sftp_host=args.sftp_host,
178175
sftp_user=args.sftp_user,
179-
sftp_private_key=args.sftp_private_key,
176+
sftp_private_key_path=args.sftp_private_key_path,
180177
)
181178

182179
sender.run()

0 commit comments

Comments
 (0)