Пример #1
0
 def make_request(self, url, method="get", data=None, headers=None):
     """
     Performs HTTP request to bitbucket
     """
     auth = OAuth1(
         self.bitbucket_consumer_key,
         self.bitbucket_consumer_secret,
         self.access_token,
         self.token_secret,
     )
     try:
         resp = getattr(requests, method)(url,
                                          data=data,
                                          auth=auth,
                                          timeout=10)
     except Exception as e:
         raise IntegrationException(
             _("Error communicating with Bitbucket: %s") % (e, ))
     if resp.status_code == 401:
         raise IntegrationException(
             _("You are not authorized to access this repo"))
     elif resp.status_code == 404:
         raise IntegrationException(_("User or repo name are incorrect"))
     elif resp.status_code not in [200, 201]:
         raise IntegrationException(
             _("Bitbucket response_code: %s") % resp.status_code)
     try:
         return resp.json()
     except Exception as e:
         raise IntegrationException(
             _("Error decoding response from Bitbucket: %s") % (e, ))
Пример #2
0
 def make_request(self, data=None):
     headers = {"User-Agent": "appenlight-slack", "Content-Type": "application/json"}
     try:
         resp = getattr(requests, "post")(
             self.api_url, data=json.dumps(data), headers=headers, timeout=3
         )
     except Exception as e:
         raise IntegrationException(_("Error communicating with Slack: %s") % (e,))
     if resp.status_code != requests.codes.ok:
         msg = "Error communicating with Slack - status code: %s"
         raise IntegrationException(msg % resp.status_code)
     return resp
Пример #3
0
 def create_client(cls, request, user_name=None, repo_name=None):
     """
     Creates REST client that can authenticate to specific repo
     uses auth tokens for current request user
     """
     config = request.registry.settings
     token = None
     secret = None
     for identity in request.user.external_identities:
         if identity.provider_name == "bitbucket":
             token = identity.access_token
             secret = identity.token_secret
             break
     if not token:
         raise IntegrationException(
             "No valid auth token present for this service")
     client = BitbucketClient(
         token,
         secret,
         user_name,
         repo_name,
         config["authomatic.pr.bitbucket.key"],
         config["authomatic.pr.bitbucket.secret"],
     )
     return client
Пример #4
0
 def speak_to_room(self, room, message, sound='RIMSHOT'):
     try:
         room = self.campfire.room(room)
         room.join()
         room.speak(message, type_='TextMessage')
     except (HTTPError, CamplightException, ConnectionError) as e:
         raise IntegrationException(str(e))
Пример #5
0
 def make_request(self, data=None):
     headers = {
         'User-Agent': 'appenlight-slack',
         'Content-Type': 'application/json'
     }
     try:
         resp = getattr(requests, 'post')(self.api_url,
                                          data=json.dumps(data),
                                          headers=headers,
                                          timeout=3)
     except Exception as e:
         raise IntegrationException(
             _('Error communicating with Slack: %s') % (e, ))
     if resp.status_code != requests.codes.ok:
         msg = 'Error communicating with Slack - status code: %s'
         raise IntegrationException(msg % resp.status_code)
     return resp
Пример #6
0
 def make_request(self, url, method='get', data=None):
     headers = {
         'Content-Type': 'application/json',
         'User-Agent': 'appenlight-flowdock',
     }
     try:
         if data:
             data = json.dumps(data)
         resp = getattr(requests, method)(url,
                                          data=data,
                                          headers=headers,
                                          timeout=10)
     except Exception as e:
         raise IntegrationException(
             _('Error communicating with Flowdock: %s') % (e, ))
     if resp.status_code > 299:
         raise IntegrationException(resp.text)
     return resp
Пример #7
0
 def make_request(self, url, method='get', data=None):
     headers = {
         'Content-Type': 'application/json',
         'User-Agent': 'appenlight-webhooks',
     }
     try:
         if data:
             data = json.dumps(data)
         resp = getattr(requests, method)(url,
                                          data=data,
                                          headers=headers,
                                          timeout=3)
     except Exception as e:
         raise IntegrationException(
             _('Error communicating with Webhooks: {}').format(e))
     if resp.status_code > 299:
         raise IntegrationException(
             'Error communicating with Webhooks - status code: {}'.format(
                 resp.status_code))
     return resp
Пример #8
0
 def make_request(self, url, method="get", data=None):
     headers = {
         "Content-Type": "application/json",
         "User-Agent": "appenlight-webhooks",
     }
     try:
         if data:
             data = json.dumps(data)
         resp = getattr(requests, method)(url,
                                          data=data,
                                          headers=headers,
                                          timeout=3)
     except Exception as e:
         raise IntegrationException(
             _("Error communicating with Webhooks: {}").format(e))
     if resp.status_code > 299:
         raise IntegrationException(
             "Error communicating with Webhooks - status code: {}".format(
                 resp.status_code))
     return resp
Пример #9
0
 def __init__(self, user_name, password, host_name, project, request=None):
     self.user_name = user_name
     self.password = password
     self.host_name = host_name
     self.project = project
     self.request = request
     try:
         self.client = jira.client.JIRA(options={'server': host_name},
                                        basic_auth=(user_name, password))
     except jira.JIRAError as e:
         raise IntegrationException(
             'Communication problem: HTTP_STATUS:%s, URL:%s ' %
             (e.status_code, e.url))
Пример #10
0
 def get_rooms(self):
     try:
         return self.campfire.rooms()
     except (HTTPError, CamplightException) as e:
         raise IntegrationException(str(e))