-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from IGNF/update_annexe
Ajout de la mise à jour des annexes sur la Géoplateforme
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
requests | ||
pyotp | ||
argparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |