jamesremuscat / pyze

Unofficial Python client and API for Renault ZE
MIT License
111 stars 30 forks source link

PyZe CLI: Add helper to generate all useful HTTP headers #32

Open boekabart opened 4 years ago

boekabart commented 4 years ago

In order to fiddle around in fiddler, postman etc, it's useful to be able to quickly generate the correct headers. I'm using the following python script for it:

#!/usr/bin/python3
from pyze.api import Gigya, Kamereon, Vehicle
import os
kamApiKey = os.environ['KAMEREON_API_KEY']

g = Gigya()
jwt = g.get_jwt_token()
k = Kamereon(gigya=g)  # Gigya argument is optional - if not supplied it will create one
tok = k.get_token()
print('Content-Type: application/vnd.api+json\n' \
        + 'apikey: ' + kamApiKey + '\n' \
        + 'x-gigya-id_token: ' + jwt + '\n' \
        + 'x-kamereon-authorization: Bearer ' + tok)

I suppose it'd be useful to add this as a feature in pyze cli.

I have python set up in WSL (linux under windows), and use the following bash script to get 1) the correct API keys from the 'cloud' 1) the headers copied straight into the clipboard:

#!/bin/bash
export KAMEREON_API_KEY=`wget -q -O - https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_en_GB.json | jq .servers.wiredProd.apikey -r`
export GIGYA_API_KEY=`wget -q -O - https://renault-wrd-prod-1-euw1-myrapp-one.s3-eu-west-1.amazonaws.com/configuration/android/config_en_GB.json | jq .servers.gigyaProd.apikey -r`
./genZoeToken.py | clip.exe
echo Zoe API headers copied to clipboard