Last active
July 12, 2019 05:17
-
-
Save loftwah/8d614faf82dd0fa322b92ede65b3dbc1 to your computer and use it in GitHub Desktop.
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
def postdata(self, resource, source): | |
self.authorize() | |
token = self.token | |
headers = {'Authorization': 'rocketskates ' + token} | |
logger.debug(source) | |
fin = open(source, 'rb') | |
files = {'file': fin} | |
session = requests.session() | |
session.auth = ('rocketskates', 'r0cketsk8ts') | |
#curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: multipart/form-data" -F "file=@[filepath]/[filename]" --insecure https://[endpoint url]/api/v3/isos/[filename] | |
r = session.post('https://172.20.0.3:8092/api/v3/isos', files=files, verify=False) | |
if r.status_code == 201 or r.status_code == 200: | |
return r.json() | |
else: | |
logger.error('Error on Post ' + str(r.status_code)) | |
temp = r.json() | |
def authorize(self): | |
try: | |
r = requests.get( | |
self.url + '/api/v3/users/rocketskates/token?ttl=28800', | |
auth=(self.username, self.password), verify=self.verify_cert) | |
if r.status_code == 200: | |
body = r.json() | |
self.token = body['Token'] | |
elif r.status_code == 401 or r.status_code == 403: | |
logger.error('Failed Authorizing ' + str(r.status_code)) | |
raise AuthorizationError(self.username + ', ' + self.password, | |
'Failed To Authenticate with the ' | |
'Digital Rebar Server', | |
r.status_code, r.text) | |
except requests.ConnectionError as err: | |
logger.error('Error Connecting to Digital Rebar Server') | |
raise ConnectionError(self.url, | |
'Failed to Connect with the Digital Rebar ' | |
'Server', | |
400, str(err.message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def authorize(self):
try:
r = requests.get(
self.url + '/api/v3/users/rocketskates/token?ttl=28800',
auth=(self.username, self.password), verify=self.verify_cert)
if r.status_code == 200:
body = r.json()
self.token = body['Token']
elif r.status_code == 401 or r.status_code == 403:
logger.error('Failed Authorizing ' + str(r.status_code))
raise AuthorizationError(self.username + ', ' + self.password,
'Failed To Authenticate with the '
'Digital Rebar Server',
r.status_code, r.text)
except requests.ConnectionError as err:
logger.error('Error Connecting to Digital Rebar Server')
raise ConnectionError(self.url,
'Failed to Connect with the Digital Rebar '
'Server',
400, str(err.message))