Skip to content

Instantly share code, notes, and snippets.

@tai271828
Last active September 21, 2018 15:38
Show Gist options
  • Select an option

  • Save tai271828/07244f0ff6e7721201d207f32818563c to your computer and use it in GitHub Desktop.

Select an option

Save tai271828/07244f0ff6e7721201d207f32818563c to your computer and use it in GitHub Desktop.
Access MaaS metadata API by querying credential first
#!/usr/bin/env python3
#
# cat /proc/cmdline
#
# to know the content of the option cloud-config-url to get preseed by curl
# and then fill in the following variables
#
# Finally, use the output in the following command:
# curl -H '<output>' <endpoint>
#
# You shall get the metadata if it is available.
#
import oauthlib.oauth1 as oauth1
import time
# Fill in me
consumer_key = ''
token_key = ''
token_secret = ''
endpoint = ''
client = oauth1.Client(consumer_key, client_secret='',
resource_owner_key=token_key, resource_owner_secret=token_secret,
signature_method=oauth1.SIGNATURE_PLAINTEXT,
timestamp=str(int(time.time())))
for k, v in client.sign(endpoint)[1].items():
print("%s: %s" % (k, v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment