Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci: lint and tests #1

Merged
merged 5 commits into from
May 30, 2024
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
81 changes: 0 additions & 81 deletions .github/workflows/ci.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Lint

on:
push:
branches: ["main"]
pull_request:

jobs:
lint-python:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- run: pip install tox
- run: tox -e check_codestyle

lint-markdown:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Lint markdown files
uses: avto-dev/markdown-lint@v1.5.0
with:
args: "**/*.md"
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Tests

on:
push:
branches: ["main"]
pull_request:

jobs:
tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.9
- run: pip install tox
- run: tox -e py
1 change: 1 addition & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-length: false
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# eimis-prosante-connect-module
A synapse module used by EIMIS to filter and map users registered through Prosanté Connect
# EIMIS Pro Santé Connect module

![Matrix](https://img.shields.io/badge/matrix-000000?logo=Matrix&logoColor=white)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/eimis-ans/eimis-prosante-connect-module/lint.yml?label=lint&logo=github)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/eimis-ans/eimis-prosante-connect-module/test.yml?label=test&logo=github)
![License](https://img.shields.io/badge/license-Apache%202-blue.svg)

A synapse module used by EIMIS to filter and map users registered through Pro Santé Connect

## OIDC configuration

Todo: how to configure keycloak to have the same token than PSC?

## Synapse configuration

```yaml
- idp_id: psc
idp_name: "Pro Santé Connect"
idp_icon: "{{ mxc_psc.stdout }}"
discover: false
issuer: "{{ prosante_connect.issuer }}"
authorization_endpoint: "{{ prosante_connect.authorization_endpoint }}"
token_endpoint: "{{ prosante_connect.token_endpoint }}"
userinfo_endpoint: "{{ prosante_connect.userinfo_endpoint }}"
jwks_uri: "{{ prosante_connect.jwks_uri }}"
client_id: "{{ prosante_connect.client_id }}"
client_secret: "{{ prosante_connect.client_secret }}"
user_profile_method: userinfo_endpoint
scopes: ["openid", "scope_all"]
user_mapping_provider:
module: synapse.psc_mapping_provider.ProsanteConnectMappingProvider
config:
localpart_template: "{{ user.preferred_username }}"
display_name_template: "{{ user.given_name }} {{ user.family_name }}"
email_template: "{{ user.email }}"
backchannel_logout_enabled: true # Optional
```

## User info

<https://industriels.esante.gouv.fr/produits-et-services/pro-sante-connect/userinfo>

## Dev

### lint

```bash
tox -e check_codestyle
```

### test

```bash
tox -e py
```
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.9"
services:
db:
image: postgres:15-alpine
Expand Down Expand Up @@ -49,7 +48,7 @@ services:
start_period: 30s

synapse:
image: matrixdotorg/synapse:v1.98.0
image: matrixdotorg/synapse:v1.104.0
ports:
- "8008:8008"
volumes:
Expand Down
14 changes: 5 additions & 9 deletions psc_mapping_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import logging
from typing import (
Dict,
Optional, Any, List,
)
from typing import Any, Dict, List, Optional

import attr
from authlib.oidc.core import UserInfo
from jinja2 import Template, Environment
from jinja2 import Environment, Template
from synapse.config import ConfigError
from synapse.handlers.oidc import OidcMappingProvider, Token, UserAttributeDict
from synapse.types import map_username_to_mxid_localpart
Expand Down Expand Up @@ -40,14 +37,13 @@ class ProsanteConnectMappingConfig:


class ProsanteConnectMappingProvider(OidcMappingProvider[ProsanteConnectMappingConfig]):

def __init__(self, parsed_config: ProsanteConnectMappingConfig):
self._config = parsed_config

@staticmethod
def parse_config(config: dict) -> ProsanteConnectMappingConfig:
def parse_template_config_with_claim(
option_name: str, default_claim: str
option_name: str, default_claim: str
) -> Template:
template_name = f"{option_name}_template"
template = config.get(template_name)
Expand Down Expand Up @@ -108,10 +104,10 @@ def get_remote_user_id(self, userinfo: UserInfo) -> str:
return self._config.subject_template.render(user=userinfo).strip()

async def map_user_attributes(
self, userinfo: UserInfo, token: Token, failures: int
self, userinfo: UserInfo, token: Token, failures: int
) -> UserAttributeDict:
localpart = None
logger.info("Mapping user attributes with userinfo %s", userinfo)
logger.info("PSC Mapping user attributes with userinfo %s", userinfo)

if self._config.localpart_template:
localpart = self._config.localpart_template.render(user=userinfo).strip()
Expand Down
25 changes: 0 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
[project]
name = "eimis-prosante-connect-module"
description = "A synapse module used by EIMIS to filter and map users registered through Prosanté Connect"
authors = [
{ name = "Eimis team", email = "eimis@beta.gouv.fr" },
]
readme = "README.md"
version = "0.0.1"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"requests",
'importlib-metadata; python_version<"3.10"',
"authlib >=0.15.1",
"unpaddedbase64 >=2.1.0",
"jinja2 >=3.0",
"pymacaroons >=0.13.0",
"twisted >=18.9.0"
]

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project.optional-dependencies]
ALONE = ["matrix-synapse>=1.98.0"]
40 changes: 40 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[metadata]
name = psc_mapping_provider
description = "A synapse module used by EIMIS to filter and map users registered through Prosanté Connect"
long_description = file: README.md
long_description_content_type = text/markdown
version = 0.1.0

classifiers =
License :: OSI Approved :: Apache Software License

[options]
python_requires = >= 3.9
install_requires =
attrs


[options.extras_require]
dev =
# for tests
matrix-synapse
tox
twisted
aiounittest
# for type checking
mypy == 0.910
# for linting
black == 22.3.0
flake8 == 4.0.1
isort == 5.9.3


[flake8]
# see https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# for error codes. The ones we ignore are:
# W503: line break before binary operator
# W504: line break after binary operator
# E203: whitespace before ':' (which is contrary to pep8?)
# E501: Line too long (black enforces this for us)
# (this is a subset of those ignored in Synapse)
ignore=W503,W504,E203,E501
3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

Loading