Skip to content

Commit

Permalink
Merge pull request #1 from IGNF/update_annexe
Browse files Browse the repository at this point in the history
Ajout de la mise à jour des annexes sur la Géoplateforme
  • Loading branch information
CorentinPeutin authored May 2, 2024
2 parents 49643bb + e2023fa commit 643ae5e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
requests
pyotp
argparse
34 changes: 34 additions & 0 deletions update_annexes/totp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pyotp
import argparse

args = None
def parse() -> None:

global args

parser = argparse.ArgumentParser(
prog="totp.py",
description="Tool to obtain the totp value",
epilog="",
)

parser.add_argument(
"--totp_key",
action="store",
dest="totp_key",
help="Value of totp's key",
required=True,
)

args = parser.parse_args()

def main() -> None:

parse()

totp = pyotp.TOTP(args.totp_key)

print(totp.now())

if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions update_annexes/update_annexe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
token=null
compteur=0
while [ "$token" == "null" ] && [[ $compteur != 10 ]]
do
sleep 5
compteur=$((compteur+1))
totp=`python3 update_annexes/totp.py --totp_key $3`

user=`curl --request POST \
--url https://sso.geopf.fr/realms/geoplateforme/protocol/openid-connect/token \
--header "content-type: application/x-www-form-urlencoded" \
-d 'client_id=gpf-warehouse&username='$1'&password='$2'&client_secret=BK2G7Vvkn7UDc8cV7edbCnHdYminWVw2&grant_type=password&totp='$totp`

token=`echo $user | jq '.access_token' | cut -d'"' -f2`
done

for dossier in `ls dist`
do
echo $dossier
for fichier in `ls dist/$dossier`
do
echo $fichier
resultat=`curl --request GET \
--url "https://data.geopf.fr/api/datastores/2d4dd9f5-ce16-4e7f-81d5-7e392209b7ff/annexes?limit=1&path=/$dossier/$fichier" \
--header "Authorization: Bearer $token"`

id_annexe=`echo $resultat | jq '.[0]._id' | cut -d'"' -f2`

curl --request PUT \
--url https://data.geopf.fr/api/datastores/2d4dd9f5-ce16-4e7f-81d5-7e392209b7ff/annexes/$id_annexe \
--header "Authorization: Bearer $token" \
--header 'Content-Type: multipart/form-data' \
--form file=@dist/$dossier/$fichier
done
done

0 comments on commit 643ae5e

Please sign in to comment.