Пример #1
0
    def _do_request(self, uri, method, payload, err_msg):
        resp, content = rest.splunkd_request(uri, self.session_key, method,
                                             data=payload, retry=3)
        if resp is None and content is None:
            return None

        if resp.status in (200, 201):
            return xdp.parse_conf_xml_dom(content)
        else:
            _LOGGER.error("%s, reason=%s", err_msg, resp.reason)
        return None
Пример #2
0
    def _get_credentials(self, realm, user, app, owner, prop):
        """
        @return: clear or encrypted password for specified realm, user
        """

        endpoint = self._get_endpoint(realm, user, app, owner)
        response, content = rest.splunkd_request(
            endpoint, self._session_key, method="GET")
        if response and response.status in (200, 201) and content:
            password = xdp.parse_conf_xml_dom(content)[0]
            return password[prop]
        return None
Пример #3
0
    def _get_credentials(self, realm, user, app, owner, prop):
        """
        @return: clear or encrypted password for specified realm, user
        """

        endpoint = self._get_endpoint(realm, user, app, owner)
        response, content = rest.splunkd_request(endpoint,
                                                 self._session_key,
                                                 method="GET")
        if response and response.status in (200, 201) and content:
            password = xdp.parse_conf_xml_dom(content)[0]
            return password[prop]
        return None
Пример #4
0
    def _do_request(self, uri, method, payload, err_msg):
        resp, content = rest.splunkd_request(uri,
                                             self.session_key,
                                             method,
                                             data=payload,
                                             retry=3)
        if resp is None and content is None:
            return None

        if resp.status in (200, 201):
            return xdp.parse_conf_xml_dom(content)
        else:
            _LOGGER.error("%s, reason=%s", err_msg, resp.reason)
        return None
Пример #5
0
    def get_all_passwords(self):
        """
        @return: a list of dict when successful, None when failed.
        the dict at least contains
        {
            "realm": xxx,
            "username": yyy,
            "clear_password": zzz,
        }
        """

        endpoint = "{}/services/storage/passwords?count=0&offset=0".format(
            self._splunkd_uri)
        response, content = rest.splunkd_request(
            endpoint, self._session_key, method="GET")
        if response and response.status in (200, 201) and content:
            return xdp.parse_conf_xml_dom(content)
Пример #6
0
    def get_all_passwords(self):
        """
        @return: a list of dict when successful, None when failed.
        the dict at least contains
        {
            "realm": xxx,
            "username": yyy,
            "clear_password": zzz,
        }
        """

        endpoint = "{}/services/storage/passwords?count=0&offset=0".format(
            self._splunkd_uri)
        response, content = rest.splunkd_request(endpoint,
                                                 self._session_key,
                                                 method="GET")
        if response and response.status in (200, 201) and content:
            return xdp.parse_conf_xml_dom(content)
Пример #7
0
    def get_conf(self, user, appname, file_name, stanza=None):
        """
        @return: a list of dict stanza objects if successful.
                 Otherwise return None
        """

        if stanza:
            uri = "".join((self.splunkd_uri, "/servicesNS/", user, "/",
                           appname, "/configs/conf-", file_name, "/", stanza))
        else:
            uri = "".join((self.splunkd_uri, "/servicesNS/", user, "/",
                           appname, "/configs/conf-", file_name,
                           "?count=0&offset=0"))
        msg = "Failed to get conf={0}, stanza={1}".format(file_name, stanza)
        content = self._do_request(uri, "GET", None, msg)
        if content is not None:
            return xdp.parse_conf_xml_dom(content)
        return None
Пример #8
0
    def get_conf(self, user, appname, file_name, stanza=None):
        """
        @return: a list of dict stanza objects if successful.
                 Otherwise return None
        """

        if stanza:
            uri = "".join((self.splunkd_uri, "/servicesNS/", user, "/",
                           appname, "/configs/conf-", file_name, "/", stanza))
        else:
            uri = "".join((self.splunkd_uri, "/servicesNS/", user, "/",
                           appname, "/configs/conf-", file_name,
                           "?count=0&offset=0"))
        msg = "Failed to get conf={0}, stanza={1}".format(file_name, stanza)
        content = self._do_request(uri, "GET", None, msg)
        if content is not None:
            return xdp.parse_conf_xml_dom(content)
        return None
Пример #9
0
    def get_data_input(self, user, appname, input_type, stanza_name=None):
        """
        @user: ACL user
        @appname: target app directory
        @input_type: if it is a script input, the input_type "script",
                     for modinput, say snow, the intput_type "snow"
        @stanza_name: name of the stanza to be deleted
        @return: a list of dict objects, each is a stanza if success otherwise
                 None
        """

        if stanza_name:
            uri = "{}/servicesNS/{}/{}/data/inputs/{}/{}".format(
                self.splunkd_uri, user, appname, input_type, stanza_name)
        else:
            uri = "{}/servicesNS/{}/{}/data/inputs/{}?count=0&offset=0".format(
                self.splunkd_uri, user, appname, input_type)

        msg = "Failed to get data input stanza for {}, {}, {}".format(
            appname, input_type, stanza_name)
        content = self._do_request(uri, "GET", None, msg)
        if content is not None:
            return xdp.parse_conf_xml_dom(content)
        return None
Пример #10
0
    def get_data_input(self, user, appname, input_type, stanza_name=None):
        """
        @user: ACL user
        @appname: target app directory
        @input_type: if it is a script input, the input_type "script",
                     for modinput, say snow, the intput_type "snow"
        @stanza_name: name of the stanza to be deleted
        @return: a list of dict objects, each is a stanza if success otherwise
                 None
        """

        if stanza_name:
            uri = "{}/servicesNS/{}/{}/data/inputs/{}/{}".format(
                self.splunkd_uri, user, appname, input_type, stanza_name)
        else:
            uri = "{}/servicesNS/{}/{}/data/inputs/{}?count=0&offset=0".format(
                self.splunkd_uri, user, appname, input_type)

        msg = "Failed to get data input stanza for {}, {}, {}".format(
            appname, input_type, stanza_name)
        content = self._do_request(uri, "GET", None, msg)
        if content is not None:
            return xdp.parse_conf_xml_dom(content)
        return None