From 5594ad02caf3e79af5896db85c0090656bbb812d Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Mon, 6 Nov 2023 18:27:51 +0000 Subject: [PATCH 1/6] build(deps): update dependencies and add pipeline --- .github/workflows/codeql-analysis.yml | 71 ++++++++++++++++++++++++++ .github/workflows/release-please.yml | 37 ++++++++++++++ .github/workflows/test.yml | 36 +++++++++++++ ScribeMi/__init__.py | 2 +- requirements.txt | Bin 198 -> 196 bytes tests/test_ScribeMi.py | 33 +++++++----- 6 files changed, 164 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..a19b8b2 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: 'CodeQL' + +on: + push: + branches: ['master'] + pull_request: + # The branches below must be a subset of the branches above + branches: ['master'] + schedule: + - cron: '15 3 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ['python'] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..e6a2f64 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,37 @@ +on: + push: + branches: + - master + +permissions: + contents: write + pull-requests: write + +name: release-please + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/release-please-action@v3 + id: release + with: + release-type: python + package-name: 'ScribeMi' + include-v-in-tag: false + token: ${{ secrets.PATFORRELEASE }} + - uses: actions/checkout@v4 + if: ${{ steps.release.outputs.release_created }} + - uses: actions/setup-python@v4 + if: ${{ steps.release.outputs.release_created }} + with: + python-version: '3.10' + cache: 'pip' + - run: pip install -r requirements.txt + if: ${{ steps.release.outputs.release_created }} + - run: python3 -m build + if: ${{ steps.release.outputs.release_created }} + - uses: pypa/gh-action-pypi-publish@release/v1 + if: ${{ steps.release.outputs.release_created }} + with: + password: ${{ secrets.PYPI_PASSWORD }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b3b9aef --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Clone + uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + cache: 'pip' + - name: Install deps + run: pip install -r requirements.txt + - name: Run tests + run: python -m coverage run -m unittest + env: + CLIENT_ID: ${{ secrets.CLIENT_ID }} + USER: ${{ secrets.USER }} + PASSWORD: ${{ secrets.PASSWORD }} + USER_POOL_ID: ${{ secrets.USER_POOL_ID }} + FEDERATED_POOL_ID: ${{ secrets.FEDERATED_POOL_ID }} + - name: Publish code coverage + uses: paambaati/codeclimate-action@v5.0.0 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: coverage xml diff --git a/ScribeMi/__init__.py b/ScribeMi/__init__.py index 00e75dd..cf194cf 100644 --- a/ScribeMi/__init__.py +++ b/ScribeMi/__init__.py @@ -1 +1 @@ -from .ScribeMi import MI \ No newline at end of file +from .ScribeMi import MI, UnauthenticatedException diff --git a/requirements.txt b/requirements.txt index 1f2cbbbb761a80a6ab92b99f010092b6ae2291ca..2de280123d80eb46a3e20f6a514e2618dcdbab00 100644 GIT binary patch delta 35 ncmX@cc!Y6+7^^vh9)s~jX?12p2EB>yj+`LA5fGbAoM;LFj$;RT delta 37 ncmX@Yc#Ls^7^@kB9)rn5X?0cuAj4>)t0Si=kYNbI6Z=g8nRo}F diff --git a/tests/test_ScribeMi.py b/tests/test_ScribeMi.py index 387d543..4f1d332 100644 --- a/tests/test_ScribeMi.py +++ b/tests/test_ScribeMi.py @@ -1,5 +1,4 @@ -from ScribeMi import MI -from ScribeMi.ScribeMi import UnauthenticatedException +from ScribeMi import MI, UnauthenticatedException import unittest import os from dotenv import load_dotenv @@ -13,18 +12,19 @@ """ env = { - 'API_URL': os.environ['API_URL'], - 'IDENTITY_POOL_ID': os.environ['IDENTITY_POOL_ID'], - 'USER_POOL_ID': os.environ['USER_POOL_ID'], - 'CLIENT_ID': os.environ['CLIENT_ID'], - 'REGION': os.environ['REGION'], + "API_URL": os.environ["API_URL"], + "IDENTITY_POOL_ID": os.environ["IDENTITY_POOL_ID"], + "USER_POOL_ID": os.environ["USER_POOL_ID"], + "CLIENT_ID": os.environ["CLIENT_ID"], + "REGION": os.environ["REGION"], } username_and_password = { - 'username': os.environ['USERNAME'], - 'password': os.environ['PASSWORD'], + "username": os.environ["USERNAME"], + "password": os.environ["PASSWORD"], } + class TestScribeMiAuth(unittest.TestCase): def test_fetch_credentials_with_username_and_password(self): client = MI(env) @@ -33,7 +33,7 @@ def test_fetch_credentials_with_username_and_password(self): def test_fetch_credentials_with_refresh_token(self): client = MI(env) client.authenticate(username_and_password) - client.authenticate({ 'refresh_token': client.tokens['refresh_token'] }) + client.authenticate({"refresh_token": client.tokens["refresh_token"]}) def test_reauthenticate(self): client = MI(env) @@ -53,24 +53,29 @@ def test_throws_if_not_authenticated(self): except UnauthenticatedException: assert True + class TestScribeMiErrorHandling(unittest.TestCase): def test_throws_on_error_response(self): client = MI(env) client.authenticate(username_and_password) try: - client.get_task('invalidJobid') + client.get_task("invalidJobid") assert False except: assert True + class TestScribeMiEndpoints(unittest.TestCase): def test_endpoints(self): client = MI(env) client.authenticate(username_and_password) - jobid = client.submit_task('tests/companies_house_document.pdf', { - 'filetype': 'pdf', - }) + jobid = client.submit_task( + "tests/companies_house_document.pdf", + { + "filetype": "pdf", + }, + ) client.list_tasks() From 5298468c916e6bccb8503fe90ae775184359d95a Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Mon, 6 Nov 2023 18:33:30 +0000 Subject: [PATCH 2/6] build(deps): fix pipeline --- .github/workflows/test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3b9aef..2bd537d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,11 +23,13 @@ jobs: - name: Run tests run: python -m coverage run -m unittest env: - CLIENT_ID: ${{ secrets.CLIENT_ID }} - USER: ${{ secrets.USER }} + USERNAME: ${{ secrets.USERNAME }} PASSWORD: ${{ secrets.PASSWORD }} + API_URL: ${{ secrets.API_URL }} + IDENTITY_POOL_ID: ${{ secrets.IDENTITY_POOL_ID }} USER_POOL_ID: ${{ secrets.USER_POOL_ID }} - FEDERATED_POOL_ID: ${{ secrets.FEDERATED_POOL_ID }} + CLIENT_ID: ${{ secrets.CLIENT_ID }} + REGION: ${{ secrets.REGION }} - name: Publish code coverage uses: paambaati/codeclimate-action@v5.0.0 env: From a632e852f372b9439524bddaf8fa3fdb06f0c013 Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Wed, 29 Nov 2023 15:47:56 +0000 Subject: [PATCH 3/6] fix: update branch --- scribemi/__init__.py | 1 + tests/test_scribemi.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 scribemi/__init__.py diff --git a/scribemi/__init__.py b/scribemi/__init__.py new file mode 100644 index 0000000..2a8d7b4 --- /dev/null +++ b/scribemi/__init__.py @@ -0,0 +1 @@ +from .ScribeMi import MI diff --git a/tests/test_scribemi.py b/tests/test_scribemi.py index aa83b11..e3b8c7e 100644 --- a/tests/test_scribemi.py +++ b/tests/test_scribemi.py @@ -33,7 +33,15 @@ def test_fetch_credentials_with_username_and_password(self): def test_fetch_credentials_with_refresh_token(self): client = MI(env) client.authenticate(username_and_password) - client.authenticate({"refresh_token": client.tokens["refresh_token"]}) + tokens = client.tokens + if tokens != None: + refresh_token = tokens.get("refresh_token") + if refresh_token != None: + client.authenticate({"refresh_token": refresh_token}) + else: + assert False + else: + assert False def test_reauthenticate(self): client = MI(env) @@ -72,13 +80,14 @@ def test_endpoints(self): jobid = client.submit_task( "tests/companies_house_document.pdf", - { - "filetype": "pdf", - }, + {"filetype": "pdf"}, ) client.list_tasks() + if jobid == None: + assert False + task = client.get_task(jobid) try: From b3bb1f362787340c328a0facba3f9c9bc67da46e Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Wed, 29 Nov 2023 15:51:35 +0000 Subject: [PATCH 4/6] fix: more after merge --- .github/workflows/release-please.yml | 1 + .github/workflows/test.yml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index d85ae98..845397a 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -20,6 +20,7 @@ jobs: package-name: 'scribemi' include-v-in-tag: false token: ${{ secrets.PATFORRELEASE }} + release-as: 1.3.0 - uses: actions/checkout@v4 if: ${{ steps.release.outputs.release_created }} - uses: actions/setup-python@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65c10ed..71e0208 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,12 +24,12 @@ jobs: - name: Run tests run: python -m coverage run -m pytest env: + CLIENT_ID: ${{ secrets.CLIENT_ID }} USERNAME: ${{ secrets.USERNAME }} PASSWORD: ${{ secrets.PASSWORD }} - API_URL: ${{ secrets.API_URL }} - IDENTITY_POOL_ID: ${{ secrets.IDENTITY_POOL_ID }} USER_POOL_ID: ${{ secrets.USER_POOL_ID }} - CLIENT_ID: ${{ secrets.CLIENT_ID }} + IDENTITY_POOL_ID: ${{ secrets.IDENTITY_POOL_ID }} + API_URL: ${{ secrets.API_URL }} REGION: ${{ secrets.REGION }} - name: Publish code coverage uses: paambaati/codeclimate-action@v5.0.0 From 3d57cde5477f973cf0518cdd7c7d89e7d920186e Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Wed, 29 Nov 2023 16:00:47 +0000 Subject: [PATCH 5/6] fix: delete codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 71 --------------------------- 1 file changed, 71 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index a19b8b2..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,71 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: 'CodeQL' - -on: - push: - branches: ['master'] - pull_request: - # The branches below must be a subset of the branches above - branches: ['master'] - schedule: - - cron: '15 3 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: ['python'] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 From 92c29842c330de3c890364f0ae667ef159564d27 Mon Sep 17 00:00:00 2001 From: ailinvenerus Date: Wed, 29 Nov 2023 16:34:24 +0000 Subject: [PATCH 6/6] fix: update dependencies --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index abd0ea5..da90694 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,12 @@ aws-requests-auth==0.4.3 -boto3==1.29.3 -botocore==1.32.3 +boto3==1.29.7 +botocore>=1.32.0,<=1.33.2 certifi==2023.11.17 charset-normalizer==3.3.2 colorama==0.4.6 coverage==7.3.2 docutils==0.20.1 -idna==3.4 +idna==3.6 importlib-metadata==6.8.0 iniconfig==2.0.0 jaraco.classes==3.3.0 @@ -19,7 +19,7 @@ nh3==0.2.14 packaging==23.2 pkginfo==1.9.6 pluggy==1.3.0 -Pygments==2.17.1 +Pygments==2.17.2 pytest==7.4.3 pytest-cov==4.1.0 python-dateutil==2.8.2 @@ -30,7 +30,7 @@ requests==2.31.0 requests-toolbelt==1.0.0 rfc3986==2.0.0 rich==13.7.0 -s3transfer==0.7.0 +s3transfer==0.8.0 scribeauth==1.1.1 six==1.16.0 twine==4.0.2