Example #1
0
 def save_cmd_details(self, data, params):
     if 'deployment_id' in data:
         deployment_id = data['deployment_id']
         item = Notifications(deployment_id,
                              cmd_channel_id=params['channel']['id'],
                              cmd_response_url=params['response_url'],
                              cmd_username=params['user']['name'])
         item.put_item()
Example #2
0
    def post_to_slack(self):
        notification = Notifications(self.deployment_id())
        item = notification.get_item()

        if item:
            self.post(item, msg_ts_type='slack_ts')
            if 'cmd_channel_id' in item:
                self.post(item, msg_ts_type='cmd_ts')
        else:
            self.post(msg_ts_type='slack_ts')
Example #3
0
    def test_as_dict(self):
        expected = {
            'deployment': 'ecs-svc/9223370476922431730',
            'cmd_username': '******',
            'slack_ts': 'slack_ts',
            'cmd_response_url': 'cmd_response_url',
            'cmd_channel_id': 'cmd_channel_id',
            'cmd_ts': 'cmd_ts'
        }

        n = Notifications(**expected)

        expected['TTL'] = int(time.time()) + int(2592000)

        assert n.as_dict() == expected
Example #4
0
    def update_notifications_item(self,
                                  slack_response,
                                  saved_item=None,
                                  msg_ts_type='slack_ts'):
        try:
            ts = slack_response['ts']
        except KeyError:
            log.error('Error: Cannot get slack timestamp. Slack response:')
            log.error(slack_response)
            return

        if saved_item:
            saved_item[msg_ts_type] = ts
            item = Notifications(**saved_item)
        else:
            item = Notifications(self.deployment_id(), ts)
        item.put_item()
Example #5
0
 def test_as_dict_bare(self):
     n = Notifications('ecs-svc/9223370476922431730')
     assert n.as_dict() == {
         'deployment': 'ecs-svc/9223370476922431730',
         'TTL': int(time.time()) + int(2592000),
     }
Example #6
0
 def test_read_missing_notification(self):
     n = Notifications(deployment='missing')
     assert n.get_item() == None
Example #7
0
 def save_cmd_details(self, deployment_id, params):
     item = Notifications(deployment_id,
                          cmd_channel_id=params['channel_id'],
                          cmd_response_url=params['response_url'],
                          cmd_username=params['user_name'])
     item.put_item()