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

Add IRVE static schema and API endpoints #19

Merged
merged 3 commits into from
Apr 10, 2024
Merged

Conversation

jmaupetit
Copy link
Member

@jmaupetit jmaupetit commented Apr 9, 2024

Purpose

We need to support the official IRVE statique data schema [1] to create and fetch statique entries.

Proposal

  • add Statique model & factory
  • add base auth/statique routers
  • add statique create / bulk endpoints
  • add statique test dataset
  • refine API endpoints response model
  • test API endpoints

References

  1. https://schema.data.gouv.fr/etalab/schema-irve-statique/2.3.1/documentation.html

@jmaupetit jmaupetit self-assigned this Apr 9, 2024
@jmaupetit
Copy link
Member Author

Here is an example client implementation used to test the official dataset:

#!/usr/bin/env bash

set -eo pipefail

# Command wrappers
declare CSVGREP="csvgrep"
declare CSVJSON="csvjson"
declare HTTP="http"
declare JQ="jq"

# Authentication
declare OIDC_TOKEN_URL="http://localhost:8080/realms/qualicharge/protocol/openid-connect/token"
declare OIDC_CLIENT_ID="api"
declare OIDC_CLIENT_SECRET="super-secret"
declare OIDC_USERNAME="johndoe"
declare OIDC_PASSWORD="pass"

# QualiCharge
declare QUALICHARGE_API_BASE_URL="http://localhost:8010/api/v1"
declare QUALICHARGE_STATIQUE_CSV="data/irve-statique.csv"

# Get OIDC access token
function get_token() {

  "${HTTP}" --form POST \
    "${OIDC_TOKEN_URL}" \
    client_id="${OIDC_CLIENT_ID}" \
    client_secret="${OIDC_CLIENT_SECRET}" \
    username="${OIDC_USERNAME}" \
    password="${OIDC_PASSWORD}" \
    grant_type="password" | \
      "${JQ}" -r .access_token
}

# Test /whoami endpoint
function whoami() {

  local token
  local endpoint="/auth/whoami"

  token="$(get_token)"

  "${HTTP}" \
    "${QUALICHARGE_API_BASE_URL}${endpoint}" \
    Authorization:" Bearer ${token}"
}

# Create statique entries
function statique_bulk() {

  local -i n=${1:-100}
  local token
  local endpoint="/statique/bulk"
  local pattern="Bouygues Energies et Services"
  # local pattern="TotalEnergies"
  local column="nom_operateur"

  # We should add the header row
  n=$((n+1))

  token="$(get_token)"

  ${CSVGREP} -m "${pattern}" -c ${column} ${QUALICHARGE_STATIQUE_CSV} | \
  head -n ${n} | \
    ${CSVJSON} -I | \
    "${HTTP}" \
      "${QUALICHARGE_API_BASE_URL}${endpoint}" \
      Authorization:" Bearer ${token}"
}

# Execute sub-command
"$@"

The IRVE statique dataset is useful to test endpoints implementation
with real data using a generic client.
Implement temporary endpoints using fake data. Items are not stored yet.
@jmaupetit jmaupetit force-pushed the add-irve-static-schema branch from e507179 to 77edf95 Compare April 10, 2024 16:10
@jmaupetit jmaupetit marked this pull request as ready for review April 10, 2024 16:11
@jmaupetit jmaupetit merged commit 831c3ec into main Apr 10, 2024
8 checks passed
@jmaupetit jmaupetit deleted the add-irve-static-schema branch April 10, 2024 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant