Created
January 15, 2020 16:47
-
-
Save mrchristine/2b25f2e9c5e77b11c5ede14b1f7bd249 to your computer and use it in GitHub Desktop.
Bypass IAM Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
token = 'MYTOKEN' | |
url = 'https://EXAMPLE.cloud.databricks.com' | |
ip = 'arn:aws:iam::123456789:instance-profile/databricks_special_role' | |
class DatabricksRestClient: | |
"""A class to define wrappers for the REST API""" | |
def __init__(self, token="ABCDEFG1234", url="https://myenv.cloud.databricks.com"): | |
self.__token = {'Authorization': 'Bearer {0}'.format(token)} | |
self.__url = url | |
def get(self, endpoint, json_params = {}, printJson = False): | |
if json_params: | |
results = requests.get(self.__url + '/api/2.0' + endpoint, headers=self.__token, params=json_params).json() | |
else: | |
results = requests.get(self.__url + '/api/2.0' + endpoint, headers=self.__token).json() | |
return results | |
def post(self, endpoint, json_params = {}, printJson = True): | |
if json_params: | |
raw_results = requests.post(self.__url + '/api/2.0' + endpoint, headers=self.__token, json=json_params) | |
results = raw_results.json() | |
else: | |
print("Must have a payload in json_args param.") | |
return {} | |
if results: | |
results['http_status_code'] = raw_results.status_code | |
return results | |
else: | |
return {'http_status_code': raw_results.status_code} | |
client = DatabricksRestClient(token, url) | |
r = client.post('/instance-profiles/add', { "instance_profile_arn": ip, 'skip_validation' : True}) | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment