softlayer-python
softlayer-python copied to clipboard
BearerAuthentication Should throw an error if the user has the XMLRPC endpoint enabled
IAMClient might also want to throw an exception for that too.
I'd rather not set the URL specifically incase someone is using a non-standard api endpoint or something
Also, add docs on how to use IAMClient
rough example
import requests
import SoftLayer
hdrs = { 'Accept' : 'application/json',
'Content-Type' : 'application/x-www-form-urlencoded' }
params = { 'grant_type' : 'urn:ibm:params:oauth:grant-type:apikey',
'apikey' : '32characterLongAPIKEYhere' }
resp = requests.post('https://iam.cloud.ibm.com/identity/token', data = params, headers = hdrs)
assert resp.status_code in (200, 202)
json = resp.json()
auth = SoftLayer.auth.BearerAuthentication('', json['access_token'])
client = SoftLayer.API.IAMClient(auth = auth)
debugger = SoftLayer.DebugTransport(client.transport)
client.transport = debugger
try:
result = client['SoftLayer_Account'].getObject()
print(result['id'])
print("======== RESULT ========")
except Exception as e:
print(e)
for call in client.transport.get_last_calls():
print(client.transport.print_reproduceable(call))
"""
$> python test.py
Calling: SoftLayer_Account::getObject(id=None, mask='', filter='None', args=(), limit=None, offset=None))
307608
======== RESULT ========
curl -u $SL_USER:$SL_APIKEY -X GET -H "Accept: */*" -H "Accept-Encoding: gzip, deflate, compress"
-H "Authorization: Bearer aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTHIS IS THE WHERE THE TOKEN WOULD BE....aaaaaaaaaaaaaaaaaaaa"
'https://api.softlayer.com/rest/v3.1/SoftLayer_Account/getObject.json'
""""