From 9cb4aa2fc282832415be31b7439c9d9b1ff78b3b Mon Sep 17 00:00:00 2001 From: Alex Wolf Date: Sat, 6 Jan 2024 15:19:13 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Pull=20testuser=20API=20keys=20f?= =?UTF-8?q?rom=20AWS=20secrets=20(#32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 12 +++++++----- laminci/nox.py | 30 +++++++++++++++++++++++------- pyproject.toml | 2 ++ tests/test_login.py | 5 +++++ 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 tests/test_login.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78f52a5..536ed1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,8 +29,7 @@ jobs: ssh-key: ${{ secrets.READ_LNDOCS }} path: lndocs ref: main - - name: Setup Python - uses: actions/setup-python@v3 + - uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - name: Cache pre-commit @@ -39,8 +38,11 @@ jobs: path: | ~/.cache/pre-commit key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} - - run: | - python -m pip install --upgrade pip - pip install nox + - run: pip install nox + - uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 - run: nox -s lint - run: nox -s build diff --git a/laminci/nox.py b/laminci/nox.py index f055606..e1d299d 100644 --- a/laminci/nox.py +++ b/laminci/nox.py @@ -1,3 +1,4 @@ +import json import os from pathlib import Path from typing import Dict, Optional @@ -9,20 +10,35 @@ from ._env import get_package_name -def login_testuser1(session: Session, env: Optional[Dict[str, str]] = None): +def _login_lamin_user(user_email: str, env: Optional[Dict[str, str]] = None): + import boto3 import lamindb_setup as ln_setup if env is not None: os.environ.update(env) - ln_setup.login("testuser1@lamin.ai", key="cEvcwMJFX4OwbsYVaMt2Os6GxxGgDUlBGILs2RyS") + session = boto3.session.Session() + client = session.client( + service_name="secretsmanager", + region_name="us-east-1", + ) + arn = ( + "arn:aws:secretsmanager:us-east-1:586130067823:secret:laminlabs-internal-sZj1MU" + ) + secrets = json.loads(client.get_secret_value(SecretId=arn)["SecretString"]) + if user_email == "testuser1@lamin.ai": + ln_setup.login(user_email, key=secrets["LAMIN_TESTUSER1_API_KEY"]) + elif user_email == "testuser2@lamin.ai": + ln_setup.login(user_email, key=secrets["LAMIN_TESTUSER2_API_KEY"]) + else: + raise NotImplementedError -def login_testuser2(session: Session, env: Optional[Dict[str, str]] = None): - import lamindb_setup as ln_setup +def login_testuser1(session: Session, env: Optional[Dict[str, str]] = None): + _login_lamin_user("testuser1@lamin.ai", env=env) - if env is not None: - os.environ.update(env) - ln_setup.login("testuser2@lamin.ai", key="goeoNJKE61ygbz1vhaCVynGERaRrlviPBVQsjkhz") + +def login_testuser2(session: Session, env: Optional[Dict[str, str]] = None): + _login_lamin_user("testuser2@lamin.ai", env=env) def run_pre_commit(session: Session): diff --git a/pyproject.toml b/pyproject.toml index 6213489..51ffdd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,8 @@ dev = [ "pre-commit", "pytest>=6.0", "pytest-cov", + "boto3", + "lamindb_setup", ] [project.scripts] diff --git a/tests/test_login.py b/tests/test_login.py new file mode 100644 index 0000000..306eb34 --- /dev/null +++ b/tests/test_login.py @@ -0,0 +1,5 @@ +from laminci.nox import _login_lamin_user + + +def test_login_testuser1(): + _login_lamin_user("testuser1@lamin.ai")