Completed
Pull Request — master (#408)
by Anthony
02:07
created

BaseAction._do_function()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
from st2actions.runners.pythonrunner import Action
2
import requests
3
from requests.auth import HTTPBasicAuth
4
5
6
class BaseAction(Action):
7
    def __init__(self, config):
8
        super(BaseAction, self).__init__(config)
9
        self.config = config
10
11
    def get_connection(self):
12
        """
13
        Get a connection to the Kubernetes IO API Service
14
        """
15
        user = self.config['user']
16
        password = self.config['password']
17
        base_api = self.config['kubernetes_api_url']
18
        verify = self.config.get('verify', True)
19
20
        # TODO : Instantiate API connection and return
21
        self.client = requests.get(base_api, auth=HTTPBasicAuth(user, password),
22
                                   verify=verify, stream=True)
23
        return self.client
24
25
    def _do_function(self, module, action, **kwargs):
26
        result = getattr(module, action)(**kwargs)
27
        return self.resultsets.formatter(result)