Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1
40 changes: 29 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ env:
jobs:
pytest:
runs-on: ubuntu-latest
name: pytest
strategy:
fail-fast: false
matrix:
pydantic-version: ['pydantic<2.0.0', 'pydantic>=2.0.0']
name: pytest (Pydantic ${{ matrix.pydantic-version }})
services:
pdp:
image: permitio/pdp-v2:latest
Expand All @@ -34,23 +38,27 @@ jobs:
with:
python-version: '3.11.8'

- name: Creation env ${{ env.ENV_NAME }} under 'Permit.io Tests' workspace
- name: Creation env ${{ env.ENV_NAME }}-${{ github.run_id }}-${{ matrix.pydantic-version }}
id: create_env
run: |
ENV_KEY="${{ env.ENV_NAME }}-${{ github.run_id }}-${{ matrix.pydantic-version == 'pydantic<2.0.0' && 'v1' || 'v2' }}"
echo "ENV_KEY=$ENV_KEY" >> $GITHUB_ENV

response=$(curl -X POST \
https://api.permit.io/v2/projects/${{ env.PROJECT_ID }}/envs \
-H 'Authorization: Bearer ${{ secrets.PROJECT_API_KEY }}' \
-H 'Content-Type: application/json' \
-d '{
"key": "${{ env.ENV_NAME }}",
"name": "${{ env.ENV_NAME }}"
"key": "'"$ENV_KEY"'",
"name": "'"$ENV_KEY"'"
}')

# Extract the new env id
echo "ENV_ID=$(echo "$response" | jq -r '.id')" >> $GITHUB_ENV

echo "New env ID: $ENV_ID"
echo "New env ID: $ENV_ID with key: $ENV_KEY"

- name: Fetch API_KEY of ${{ env.ENV_NAME }}
- name: Fetch API_KEY of ${{ env.ENV_KEY }}
run: |
response=$(curl -X GET \
https://api.permit.io/v2/api-key/${{ env.PROJECT_ID }}/${{ env.ENV_ID }} \
Expand All @@ -61,6 +69,20 @@ jobs:

echo "New env api key: $ENV_API_KEY"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
# Pin pydantic version according to matrix
pip install "${{ matrix.pydantic-version }}"
# Explicitly install email-validator which is required for Pydantic email validation
pip install email-validator
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt --no-deps; fi

- name: Show installed packages
run: pip list

- name: Test with pytest
env:
PDP_URL: http://localhost:7766
Expand All @@ -69,13 +91,9 @@ jobs:
PROJECT_PDP_API_KEY: ${{ env.ENV_API_KEY }}
PDP_API_KEY: ${{ env.ENV_API_KEY }}
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pytest -s --cache-clear tests/

- name: Delete env ${{ env.ENV_NAME }}
- name: Delete env ${{ env.ENV_KEY }}
if: always()
run: |
curl -X DELETE \
Expand Down
10 changes: 8 additions & 2 deletions permit/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

import aiohttp
from loguru import logger
from pydantic.v1 import ValidationError
from typing_extensions import deprecated

from permit import ErrorDetails, HTTPValidationError
from permit.utils.pydantic_version import PYDANTIC_VERSION

if PYDANTIC_VERSION < (2, 0):
from pydantic.v1 import ValidationError
else:
from pydantic import ValidationError # type: ignore

from permit.api.models import ErrorDetails, HTTPValidationError

DEFAULT_SUPPORT_LINK = "https://permit-io.slack.com/ssb/redirect"

Expand Down
Loading