How to use the keen.utilities.requires_key function in keen

To help you get started, we’ve selected a few keen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keenlabs / KeenClient-Python / keen / api.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def revoke_access_key(self, access_key_id):
        """
        Revokes an access key. "Bad dog! No biscuit!"

        :param access_key_id: the 'key' value of the access key to revoke
        """
        url = "{0}/{1}/projects/{2}/keys/{3}/revoke".format(self.base_url, self.api_version,
                                                            self.project_id, access_key_id)
        headers = utilities.headers(self.master_key)
        response = self.fulfill(HTTPMethods.POST, url, headers=headers, timeout=self.get_timeout)

        self._error_handling(response)
        return response.json()
github keenlabs / KeenClient-Python / keen / saved_queries.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def delete(self, query_name):
        """
        Deletes a saved query from a project with a query name.
        Master key must be set.
        """

        url = "{0}/{1}".format(self.saved_query_url, query_name)
        response = self._get_json(HTTPMethods.DELETE, url, self._get_master_key())

        return True
github keenlabs / KeenClient-Python / keen / api.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def update_access_key_full(self, access_key_id, name, is_active, permitted, options):
        """
        Replaces the 'name', 'is_active', 'permitted', and 'options' values of a given key.
        A master key must be set first.

        :param access_key_id: the 'key' value of the access key for which the values will be replaced
        :param name: the new name desired for this access key
        :param is_active: whether the key should become enabled (True) or revoked (False)
        :param permitted: the new list of permissions desired for this access key
        :param options: the new dictionary of options for this access key
        """
        url = "{0}/{1}/projects/{2}/keys/{3}".format(self.base_url, self.api_version,
                                                     self.project_id, access_key_id)
        headers = utilities.headers(self.master_key)
        payload_dict = {
            "name": name,
github keenlabs / KeenClient-Python / keen / cached_datasets.py View on Github external
    @requires_key(KeenKeys.READ)
    def get(self, dataset_name):
        """ Fetch a single Cached Dataset for a Project. Read key must be set.

        :param dataset_name: Name of Cached Dataset (not `display_name`)
        """
        url = "{0}/{1}".format(self._cached_datasets_url, dataset_name)
        return self._get_json(HTTPMethods.GET, url, self._get_read_key())
github keenlabs / KeenClient-Python / keen / saved_queries.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def update_full(self, query_name, saved_query_full_definition):
        """
        Updates the saved query via a PUT request to Keen IO Saved Query
        endpoint. The entire query definition must be provided--anything
        excluded will be considered an explicit removal of that property.

        Master key must be set.
        """

        return self.create(query_name, saved_query_full_definition)
github keenlabs / KeenClient-Python / keen / cached_datasets.py View on Github external
    @requires_key(KeenKeys.READ)
    def all(self):
        """ Fetch all Cached Datasets for a Project. Read key must be set.
        """
        return self._get_json(HTTPMethods.GET,
                              self._cached_datasets_url,
                              self._get_master_key())
github keenlabs / KeenClient-Python / keen / saved_queries.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def create(self, query_name, saved_query):
        """
        Creates the saved query via a PUT request to Keen IO Saved Query endpoint.
        Master key must be set.
        """
        url = "{0}/{1}".format(self.saved_query_url, query_name)
        payload = saved_query

        # To support clients that may have already called dumps() to work around how this used to
        # work, make sure it's not a str. Hopefully it's some sort of mapping. When we actually
        # try to send the request, client code will get an InvalidJSONError if payload isn't
        # a json-formatted string.
        if not isinstance(payload, str):
            payload = json.dumps(saved_query)

        response = self._get_json(HTTPMethods.PUT, url, self._get_master_key(), data=payload)
github keenlabs / KeenClient-Python / keen / api.py View on Github external
    @requires_key(KeenKeys.WRITE)
    def post_event(self, event):
        """
        Posts a single event to the Keen IO API. The write key must be set first.

        :param event: an Event to upload
        """

        url = "{0}/{1}/projects/{2}/events/{3}".format(self.base_url, self.api_version,
                                                       self.project_id,
                                                       event.event_collection)
        headers = utilities.headers(self.write_key)
        payload = event.to_json()
        response = self.fulfill(HTTPMethods.POST, url, data=payload, headers=headers, timeout=self.post_timeout)
        self._error_handling(response)
github keenlabs / KeenClient-Python / keen / api.py View on Github external
    @requires_key(KeenKeys.MASTER)
    def create_access_key(self, name, is_active=True, permitted=[], options={}):
        """
        Creates a new access key. A master key must be set first.

        :param name: the name of the access key to create
        :param is_active: Boolean value dictating whether this key is currently active (default True)
        :param permitted: list of strings describing which operation types this key will permit
                          Legal values include "writes", "queries", "saved_queries", "cached_queries",
                          "datasets", and "schema".
        :param options: dictionary containing more details about the key's permitted and restricted
                        functionality
        """

        url = "{0}/{1}/projects/{2}/keys".format(self.base_url, self.api_version, self.project_id)
        headers = utilities.headers(self.master_key)