CloudStack create API signature


/ Published in: Bash
Save to your folder(s)

CloudStack create API signature


Copy this code and paste it in your HTML
  1. ##
  2. # api.sh
  3. #
  4. # Public API port
  5. address="https://"
  6. # API key
  7. api_key="<apikey>"
  8. # Secret key
  9. secret_key="<secretkey>"
  10.  
  11. # API entry point
  12. api_path="/client/api"
  13.  
  14. # DATE
  15. date=$(date '+%Y%m%d-%H%M')
  16.  
  17. # OUTPUT file
  18. output="${HOME}/reports/capacity_${date}.csv"
  19. echo '"Zone","Resource","Used","Available","Percent","Allocated Used","Available(Oversub)","Percent"' > ${output}
  20.  
  21. # Management Server
  22. dbserver="<server>"
  23.  
  24. ###
  25. ### create signature
  26. ###
  27. generate_string(){
  28.  
  29. local strings=$(echo -n $@ | tr " " "&")
  30. local pre_encoded_request=$(python -c "import urllib; print urllib.quote('''${strings}''','''=& ''').replace('''+''','''%20''')")
  31. local sorted_request=$(echo -n ${pre_encoded_request[@]} | tr "&" "\n" | \
  32. sort -fd -t'=' | tr "\n" "&" | sed -e 's/\&$//' )
  33. encoded_query=$(python -c "import urllib; print urllib.quote('''${sorted_request}''','''=&:+-^''').replace('''''','''''').lower()")
  34.  
  35. }
  36.  
  37. generate_signature(){
  38.  
  39. signature=$(echo -n $@ | \
  40. openssl sha1 -binary -hmac ${secret_key} | \
  41. openssl base64 )
  42. signature=$(python -c "import urllib; print urllib.quote('''${signature}''').replace('''/''','''%2F''')")
  43.  
  44. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.