Skip to content

Instantly share code, notes, and snippets.

@garywill
Created January 29, 2024 14:03
Show Gist options
  • Save garywill/ffd7141979300d2b50f061e2bc64f598 to your computer and use it in GitHub Desktop.
Save garywill/ffd7141979300d2b50f061e2bc64f598 to your computer and use it in GitHub Desktop.
Use bash and python to edit AMO addon description
#!/bin/sh -e
# modified from https://github.com/mikhirev/mozjwt
# External dependencies: openssl. python3
ADDON='' ## write your addon here
# obtain this values at https://addons.mozilla.org/en-US/developers/addon/api/key/
# secrets
ISS=user:xxxxx:xxx
SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
################################################
./gen-json.py || exit 1
base64url() {
openssl base64 | tr -d '=\n' | tr /+ _-
}
timezone_offset=0 # hour
cs_time_offset=-30 # second
echo "timezone_offset = $timezone_offset"
echo "cs_time_offset = $cs_time_offset"
JTI=`openssl rand 32 2>/dev/null | base64url`
IAT=`date +%s`
IAT=$(( $IAT - 60*60*($timezone_offset) + ($cs_time_offset) ))
EXP=$(( $IAT+ 5*60 ))
echo "IAT = $IAT"
echo "EXP = $EXP"
JOSE=`echo -n '{"alg":"HS256","typ":"JWT"}' | base64url`
CLAIMS=`echo -n "{\"iss\":\"$ISS\",\"jti\":\"$JTI\",\"iat\":$IAT,\"exp\":$EXP}" | base64url`
DGST=`echo -n "$JOSE.$CLAIMS" | openssl dgst -sha256 -hmac $SECRET -binary | base64url`
JWT="$JOSE.$CLAIMS.$DGST"
# echo "$JWT"
echo ""
# curl -H "Authorization: JWT $JWT" https://addons.mozilla.org/api/v5/accounts/profile/
echo ""
echo ""
curl -H "Authorization: JWT $JWT" \
-H "Content-Type: application/json" \
https://addons.mozilla.org/api/v5/addons/addon/$ADDON/ \
-X PATCH \
-v \
--data-binary @jsonobj.json
echo ""
#!/usr/bin/python3
import json
obj = {
'summary': {},
'description': {},
}
obj['summary']['en-US'] = open('summary_en-US.txt').read()
obj['summary']['zh-CN'] = open('summary_zh-CN.txt').read()
obj['summary']['zh-TW'] = open('summary_zh-TW.txt').read()
obj['description']['en-US'] = open('desc_en-US.html').read()
obj['description']['zh-CN'] = open('desc_zh-CN.html').read()
obj['description']['zh-TW'] = open('desc_zh-TW.html').read()
with open('jsonobj.json', 'w') as f:
f.write(json.dumps(obj, ensure_ascii=False, indent=2))
f.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment