This commit is contained in:
Félix Baylac-Jacqué 2021-10-17 18:16:29 +02:00
commit cfae863043
No known key found for this signature in database
GPG key ID: EFD315F31848DBA4
8 changed files with 190 additions and 0 deletions

20
README.md Normal file
View file

@ -0,0 +1,20 @@
# Axione FTTH - Test d'Éligibilité
## Configuration
Ce programme se configure à l'aide du fichier ini se trouvant à `/etc/axione-elig-test.ini`. Vous pouvez utiliser `./elig-test.ini.sample` de ce dépôt git comme point de départ.
## Jouer les Tests
TODO
## Debugger l'Application Localement
Travailler depuis la VM whitelistée par Axione est peu pratique. C'est pourquoi nous avons ajouté un mode debug permettant de simuler les réponses d'Axione.
Pour l'activer, il vous faudra mettre la variable d'environnement `DEBUG` a `true`. Vous pouvez également utiliser un fichier de configuration ne se trouvant pas a `/etc/axione-elig-test.ini` à l'aide de la variable d'environnement `CONFIG`.
Par example:
```bash
$ DEBUG=true CONFIG=./elig-test.ini python elig-test.py
```

0
axione_api/__init__.py Normal file
View file

67
axione_api/api.py Normal file
View file

@ -0,0 +1,67 @@
import base64
import http.client
import sys
from datetime import (datetime, timezone)
def ptoRequest(ptoRef):
ts = datetime.now(timezone.utc).isoformat()
return f'''
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ent="http://structureadresseftth.axione.fr/model/entreprise" xmlns:com="http://structureadresseftth.axione.fr/model/commun">
<soapenv:Header/>
<soapenv:Body>
<ent:obtentionStructureAdresseDemandeSoap>
<ent:entete versionWS="3.0" horodatageRequete="{ts}">
<com:operateurCommercial nom="AQUILENET" identifiant=""/>
</ent:entete>
<ent:referenceAdresse referenceHexacle="" identifiantImmeuble="" referencePTO="{ptoRef}" referenceBAN="">
</ent:referenceAdresse>
</ent:obtentionStructureAdresseDemandeSoap>
</soapenv:Body>
</soapenv:Envelope>
'''
def query_axione_pto(cfg, ptoRef):
body = ptoRequest(ptoRef)
# Note: the password should be the base64 of username:password.
# Don't ask why.
passwd = base64.b64encode(f"{cfg.username}:{cfg.password}".encode("utf8")).decode("utf8")
headers = {
'User-Agent': 'aquilenet-elig-test/0.1',
'Accept': '*/*',
'Accept-Encoding': 'identity',
'Connection': 'Keep-Alive',
'Authorization': passwd
}
resp = None
if not cfg.debug:
try:
conn = http.client.HTTPSConnection("ws-eligftth-val.axione.fr", 443, source_address=(cfg.source_addr,0), timeout=120)
conn.request("POST", "/v3/fai", body, headers=headers)
response = conn.getresponse()
respData = response.read()
except Exception as e:
print("Error while querying Axione: ", file=sys.stderr)
print(str(e), file=sys.stderr)
print("Query Body: ")
print(body)
print("Query Headers: ")
print(str(headers))
sys.exit(1)
finally:
conn.close()
else:
print("===================")
print("Injecting dummy response for request: ")
print("HEADERS: ")
print(headers)
print("BODY: ")
print(body)
print("===================")
with open("./fixtures/dummy-data-1.xml","r") as f:
dummyData = f.read()
return dummyData
return resp
def parse_response(resp_str):
return

17
axione_api/config.py Normal file
View file

@ -0,0 +1,17 @@
import configparser
class Config:
def __init__(self, username, password, source_addr):
self.username = username
self.password = password
self.source_addr = source_addr
self.debug = False
def parse_config(cfgPath):
cfg = configparser.ConfigParser()
with open(cfgPath,"r") as f:
cfg.read_file(f)
username = cfg.get("API","username")
passwd = cfg.get("API","password")
source_addr = cfg.get("API","source_addr")
return Config(username, passwd, source_addr)

6
elig-test.ini.sample Normal file
View file

@ -0,0 +1,6 @@
[API]
username = ws.aquilenet
password = xxx
# Whitelisted IP address from axione
# to send the requests from.
source_addr = xxx.xxx.xxx.xxx

23
elig-test.py Normal file
View file

@ -0,0 +1,23 @@
import os
import xml.etree.ElementTree as ET
from axione_api.api import query_axione_pto
from axione_api.config import parse_config
if __name__ == '__main__':
cfg_path = os.environ.get("CONFIG", "/etc/axione-elig-test.ini")
print(f'Reading the "{cfg_path}" config file')
cfg = parse_config(cfg_path)
cfg.debug = True if "DEBUG" in os.environ else False
if cfg.debug:
print("===================")
print("DEBUG_MODE")
print("No requests will be performed")
print("We'll inject some dummy data instead")
print("===================")
print("")
resp = query_axione_pto(cfg, "SPTH-BIEM2-0197")
if resp != None:
respTree = ET.fromstring(resp)

52
fixtures/dummy-data-1.xml Normal file
View file

@ -0,0 +1,52 @@
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:obtentionStructureAdresseReponseSoap xmlns:ns2="http://structureadresseftth.axione.fr/model/commun" xmlns:ns3="http://structureadresseftth.axione.fr/model/entreprise">
<ns3:entete horodatageReponse="2021-10-17T12:22:23.421+02:00" horodatageRequete="2021-10-17T10:22:22.339431Z" identifiantReponse="1634466143421" versionWS="3.0">
<ns2:operateurCommercial identifiant="" nom="AQUILENET"/>
</ns3:entete>
<ns3:codeRetour>
<ns2:codeRetour>0
</ns2:codeRetour>
</ns3:codeRetour>
<ns3:codeOI>SPTH
</ns3:codeOI>
<ns3:etatImmeuble>true
</ns3:etatImmeuble>
<ns3:structureDetaillee>
<ns2:adresse referenceHexacle="6444522ETP">
<ns2:referenceRivoli codeInsee="64445" codeRivoli="2832" numeroVoie="64"/>
</ns2:adresse>
<ns2:batiment conditionsSyndic="true" etatBatiment="RACCORDABLE" identifiantImmeuble="IMM64-497143" referenceBatiment="RESIDENCE NORMAND PRINCE - BAT-C4">
<ns2:referenceGeographique coordonneeImmeubleX="-0.34664856587184095" coordonneeImmeubleY="43.3043072700435" typeProjection="WGS84"/>
<ns2:escalier reference="NA">
<ns2:etage nombreLignesActives="2" nombreLignesExistantes="3" nombreLocauxFTTH="3" refPriseCommandeObligatoire="false" reference="RDC">
<ns2:listePbo>
<ns2:pbo referencePBO="BA64_BIEM2 D 17-18" typePbo="IMMEUBLE GAINE TECHNIQUE"/>
</ns2:listePbo>
<ns2:listeLignesFTTH>
<ns2:ligneFTTH>
<ns2:prise etiquetteAPoser="Non" referencePBO="BA64_BIEM2 D 17-18">
<ns2:referencePTO>SPTH-BIEM2-0197
</ns2:referencePTO>
<ns2:referencePrisePromoteur/>
<ns2:statutLigneFTTH actif="false" commercialisable="true" existant="true" raccordable="true" rompu="false"/>
</ns2:prise>
</ns2:ligneFTTH>
<ns2:ligneFTTH>
<ns2:local localisationLocalOC="" localisationLocalOI=""/>
</ns2:ligneFTTH>
</ns2:listeLignesFTTH>
<ns2:pm referencePM="ADR-64445-BIEM-02" referencePMT="PMT-64-BIEM2">
<ns2:typeEmplacementPM>PME
</ns2:typeEmplacementPM>
<ns2:responsableBrassage>OC
</ns2:responsableBrassage>
</ns2:pm>
</ns2:etage>
</ns2:escalier>
</ns2:batiment>
</ns3:structureDetaillee>
</ns3:obtentionStructureAdresseReponseSoap>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

5
shell.nix Normal file
View file

@ -0,0 +1,5 @@
{ pkgs ? import <nixpkgs> {}}:
pkgs.mkShell({
nativeBuildInputs = [pkgs.poetry];
})