Completed
Pull Request — master (#564)
by
unknown
02:26
created

DatadogBaseAction.run()   B

Complexity

Conditions 5

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
c 1
b 0
f 1
dl 0
loc 9
rs 8.5454
1
from abc import ABCMeta, abstractmethod
2
from datadog import initialize
3
from st2actions.runners.pythonrunner import Action
4
5
6
class DatadogBaseAction(Action):
0 ignored issues
show
Unused Code introduced by
This abstract class does not seem to be used anywhere.
Loading history...
7
    __metaclass__ = ABCMeta
8
9
    def __init__(self, config):
10
        super(DatadogBaseAction, self).__init__(config)
11
        self._init_dd()
12
13
    def _init_dd(self):
14
        options = {
15
            'api_key': self.config['api_key'],
16
            'app_key': self.config['app_key']
17
        }
18
        initialize(**options)
19
20
    @abstractmethod
21
    def _run(self, **kwargs):
22
        pass
23
24
    def run(self, **kwargs):
25
        # Removing empty strings, None from kwargs without excluding 0
26
        args = {k: v for k, v in kwargs.iteritems()
27
                if str(v).strip() and v is not None}
28
        out = self._run(**args)
29
        errors = out.get("errors")
30
        if errors:
31
            return (False, errors)
32
        return (True, out)
33