def _post_zip_file(config, app_slug, in_file): boundary = '----------ThIs_Is_tHe_bouNdaRY_$' body = '\r\n'.join([ '--' + boundary, 'Content-Disposition: form-data; name="archive"; filename="archive.zip"', 'Content-Type: application/zip', '', in_file.getvalue(), '--' + boundary + '--', '' ]) headers = { 'Content-Type': 'multipart/form-data; boundary=%s' % boundary, 'Accept': 'application/json', 'X-App-Slug': app_slug, 'X-Clutch-Username': config['username'], 'X-Clutch-Password': config['password'], } parsed_url = urlparse.urlparse(config['rpc_url']) if parsed_url.scheme == 'http': conn_class = httplib.HTTPConnection else: conn_class = httplib.HTTPSConnection conn = conn_class(parsed_url.netloc) conn.request('POST', parsed_url.path, body, headers) response = conn.getresponse() raw_data = response.read() conn.close() data = json.loads(raw_data) if data.get('error'): raise ValueError(data['error']) return data['result']
def poll(config, app_slug, **kwargs): headers = kwargs.get('headers', {}) headers.update({ 'Accept': 'application/json', 'X-Clutch-Username': config['username'], 'X-Clutch-Password': config['password'], 'X-Clutch-App-Slug': app_slug, }) parsed_url = urlparse.urlparse(config['tunnel_url']) if parsed_url.scheme == 'http': conn_class = httplib.HTTPConnection else: conn_class = httplib.HTTPSConnection conn = conn_class(parsed_url.netloc) conn.request('GET', '/poll/', '', headers) try: response = conn.getresponse() except (IOError, httplib.HTTPException): # Something busted on the server side, sleep 1 second and try again. time.sleep(1) return {} raw_data = response.read() conn.close() try: return json.loads(raw_data) except ValueError: # Something busted on the server side, sleep 2 seconds and try again. time.sleep(2) return {}
def _post_zip_file(config, app_slug, in_file): boundary = "----------ThIs_Is_tHe_bouNdaRY_$" body = "\r\n".join( [ "--" + boundary, 'Content-Disposition: form-data; name="archive"; filename="archive.zip"', "Content-Type: application/zip", "", in_file.getvalue(), "--" + boundary + "--", "", ] ) headers = { "Content-Type": "multipart/form-data; boundary=%s" % boundary, "Accept": "application/json", "X-App-Slug": app_slug, "X-Clutch-Username": config["username"], "X-Clutch-Password": config["password"], } parsed_url = urlparse.urlparse(config["rpc_url"]) if parsed_url.scheme == "http": conn_class = httplib.HTTPConnection else: conn_class = httplib.HTTPSConnection conn = conn_class(parsed_url.netloc) conn.request("POST", parsed_url.path, body, headers) response = conn.getresponse() raw_data = response.read() conn.close() data = json.loads(raw_data) if data.get("error"): raise ValueError(data["error"]) return data["result"]
def post(config, path, uuid): headers = {'Accept': 'application/json'} parsed_url = urlparse.urlparse(config['tunnel_url']) if parsed_url.scheme == 'http': conn_class = httplib.HTTPConnection else: conn_class = httplib.HTTPSConnection conn = conn_class(parsed_url.netloc) if isinstance(path, basestring): try: with open(path, 'r') as f: conn.request('POST', '/post/' + uuid, f, headers) except IOError: conn.request('POST', '/post/' + uuid, 'CLUTCH404DOESNOTEXIST', headers) else: conn.request('POST', '/post/' + uuid, json.dumps(path), headers) response = conn.getresponse() raw_data = response.read() conn.close() return json.loads(raw_data)