示例#1
0
    def post_webhook(self, webhook):
        signature, date = cryptotool.sign(webhook['payload'], webhook['security_key'], version=2)
        headers = {
            'Date': date,
            'X-Signature': signature,
            'X-Scalr-Webhook-Id': webhook['history_id'],
            'Content-type': 'application/json',
        }

        if webhook['url'] == 'SCALR_MAIL_SERVICE':
            url = 'https://my.scalr.com/webhook_mail.php'
        else:
            url = webhook['url']

        try:
            r = requests.post(url, data=webhook['payload'], headers=headers, timeout=3)
        except requests.exceptions.RequestException:
            msg = '{0}, url: {1}'.format(sys.exc_info()[0].__name__, url)
            raise DBQueueEvent.PostError(msg)

        if r.status_code <= 205:
            msg = "Request OK. url: {0}, webhook history_id: {1}, status: {2}"
            msg = msg.format(url, webhook['history_id'], r.status_code)
            LOG.debug(msg)
        else:
            webhook['error_msg'] = r.text.encode('ascii', 'replace')
            msg = "Request failed. url: {0}, webhook history_id: {1}, status: {2}, text: {3}"
            msg = msg.format(url, webhook['history_id'], r.status_code, r.text)
            LOG.warning(msg)
        return r.status_code
示例#2
0
    def post_webhook(self, webhook, headers=None):
        if headers is None:
            signature, date = cryptotool.sign(webhook['payload'],
                                              webhook['security_key'],
                                              version=2)
            headers = {
                'Date': date,
                'X-Signature': signature,
                'X-Scalr-Webhook-Id': webhook['history_id'],
                'Content-type': 'application/json',
            }

        if webhook['url'] == 'SCALR_MAIL_SERVICE':
            url = self.config['_scalr_mail_service_url']
        else:
            url = webhook['url']

        webhook['dtlasthandleattempt'] = str(
            datetime.datetime.utcnow().replace(microsecond=0))

        resp = self.https_session.post(
            url,
            data=webhook['payload'],
            headers=headers,
            timeout=webhook['timeout'],
            allow_redirects=False,
            verify=not self.args['--disable-ssl-verification'])

        if resp.status_code > 205:
            webhook['error_msg'] = resp.text.encode('ascii', 'replace')

        return resp
示例#3
0
    def post_webhook(self, webhook, headers=None):
        if headers is None:
            signature, date = cryptotool.sign(
                webhook['payload'], webhook['security_key'], version=2)
            headers = {
                'Date': date,
                'X-Signature': signature,
                'X-Scalr-Webhook-Id': webhook['history_id'],
                'Content-type': 'application/json',
            }

        if webhook['url'] == 'SCALR_MAIL_SERVICE':
            url = self.config['_scalr_mail_service_url']
        else:
            url = webhook['url']

        webhook['dtlasthandleattempt'] = str(datetime.datetime.utcnow().replace(microsecond=0))

        resp = self.https_session.post(
            url, data=webhook['payload'], headers=headers, timeout=webhook['timeout'],
            allow_redirects=False, verify=not self.args['--disable-ssl-verification'])

        if resp.status_code > 205:
            webhook['error_msg'] = resp.text.encode('ascii', 'replace')

        return resp
示例#4
0
 def _encrypt(self, server_id, key, data, headers=None):
     assert server_id
     assert key
     assert data
     crypto_algo = dict(name="des_ede3_cbc", key_size=24, iv_size=8)
     data = cryptotool.encrypt(crypto_algo, data, cryptotool.decrypt_key(key))
     headers = headers or dict()
     headers['X-Signature'], headers['Date'] = cryptotool.sign(data, key)
     headers['X-Server-Id'] = server_id
     return data, headers
示例#5
0
 def _encrypt(self, server_id, crypto_key, data, headers=None):
     assert server_id, 'server_id'
     assert crypto_key, 'scalarizr.key'
     assert data, 'data to encrypt'
     crypto_algo = dict(name="des_ede3_cbc", key_size=24, iv_size=8)
     data = cryptotool.encrypt_scalarizr(crypto_algo, data, cryptotool.decrypt_key(crypto_key))
     headers = headers or dict()
     headers['X-Signature'], headers['Date'] = cryptotool.sign(data, crypto_key)
     headers['X-Server-Id'] = server_id
     return data, headers
示例#6
0
 def _encrypt(self, server_id, key, data, headers=None):
     assert server_id
     assert key
     assert data
     crypto_algo = dict(name="des_ede3_cbc", key_size=24, iv_size=8)
     data = cryptotool.encrypt(crypto_algo, data,
                               cryptotool.decrypt_key(key))
     headers = headers or dict()
     headers['X-Signature'], headers['Date'] = cryptotool.sign(data, key)
     headers['X-Server-Id'] = server_id
     return data, headers
示例#7
0
 def _encrypt(self, server_id, crypto_key, data, headers=None):
     assert server_id, 'server_id'
     assert crypto_key, 'scalarizr.key'
     assert data, 'data to encrypt'
     crypto_algo = dict(name="des_ede3_cbc", key_size=24, iv_size=8)
     data = cryptotool.encrypt_scalarizr(crypto_algo, data, cryptotool.decrypt_key(crypto_key))
     headers = headers or dict()
     headers['X-Signature'], headers['Date'] = cryptotool.sign(data, crypto_key)
     headers['X-Server-Id'] = server_id
     msg = "Server: {0}, key: {1} ... {2}".format(server_id, crypto_key[0:5], crypto_key[-5:])
     LOG.debug(msg)
     return data, headers
示例#8
0
 def _encrypt(self, server_id, crypto_key, data, headers=None):
     assert server_id, 'server_id'
     assert crypto_key, 'scalarizr.key'
     assert data, 'data to encrypt'
     crypto_algo = dict(name="des_ede3_cbc", key_size=24, iv_size=8)
     data = cryptotool.encrypt_scalarizr(crypto_algo, data,
                                         cryptotool.decrypt_key(crypto_key))
     headers = headers or dict()
     headers['X-Signature'], headers['Date'] = cryptotool.sign(
         data, crypto_key)
     headers['X-Server-Id'] = server_id
     msg = "Server: {0}, key: {1} ... {2}".format(server_id,
                                                  crypto_key[0:5],
                                                  crypto_key[-5:])
     LOG.debug(msg)
     return data, headers
示例#9
0
 def sign_data(self, data, utc_struct_time=None):
     return cryptotool.sign(data, self.crypto_key, utc_struct_time, self.DATE_FORMAT)
示例#10
0
文件: rpc.py 项目: AnyBucket/scalr
 def sign_data(self, data, timestamp=None):
     return cryptotool.sign(data, self.crypto_key, timestamp, self.DATE_FORMAT)
示例#11
0
文件: rpc.py 项目: alisheikh/scalr
 def sign_data(self, data, utc_struct_time=None):
     return cryptotool.sign(data, self.crypto_key, utc_struct_time, self.DATE_FORMAT)
示例#12
0
 def sign_data(self, data, timestamp=None):
     return cryptotool.sign(data, self.crypto_key, timestamp,
                            self.DATE_FORMAT)