Closed jmaupetit closed 5 months ago
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
"$@"
Purpose
We need to support the official IRVE statique data schema [1] to create and fetch statique entries.
Proposal
References