def _get_secret(self, name):
        """
        Gets a Kubernetes secret.

        :param name: The name of the secret.
        :type name: str
        """
        response = self._store.get(self._secrets_endpoint + '/' + name)

        if response.status_code != requests.codes.OK:
            raise KeyError('No secrets for {0}'.format(name))

        secrets = {}
        rj = response.json()

        # The we have a data key use it directly
        if 'data' in rj.keys():
            rj = rj['data']
        # If we have an items key pull the data from the first item
        # FIXME: Verify it's the right data :-)
        elif 'items' in rj.keys():
            rj = rj['items'][0]['data']

        for k, v in rj.items():
            secrets[k.replace('-', '_')] = base64.decodebytes(v)

        return secrets
    def _get_secret(self, name):
        """
        Gets a Kubernetes secret.

        :param name: The name of the secret.
        :type name: str
        """
        response = self._store.get(self._secrets_endpoint + '/' + name)

        if response.status_code != requests.codes.OK:
            raise KeyError('No secrets for {0}'.format(name))

        secrets = {}
        rj = response.json()

        # The we have a data key use it directly
        if 'data' in rj.keys():
            rj = rj['data']
        # If we have an items key pull the data from the first item
        # FIXME: Verify it's the right data :-)
        elif 'items' in rj.keys():
            rj = rj['items'][0]['data']

        for k, v in rj.items():
            secrets[k.replace('-', '_')] = base64.decodebytes(v)

        return secrets
Exemple #3
0
    def _decode_basic_auth(self, req):
        """
        Decodes basic auth from the header.

        :param req: Request instance that will be passed through.
        :type req: falcon.Request
        :returns: tuple -- (username, passphrase) or (None, None) if empty.
        """
        if req.auth is not None:
            if req.auth.lower().startswith('basic '):
                try:
                    return tuple(base64.decodebytes(
                        req.auth[6:].encode('utf-8')).decode().split(':'))
                except base64.binascii.Error:
                    self.logger.info(
                        'Bad base64 data sent. Setting to no user/pass.')
        # Default meaning no user or password
        return (None, None)
    def _decode_basic_auth(self, req):
        """
        Decodes basic auth from the header.

        :param req: Request instance that will be passed through.
        :type req: falcon.Request
        :returns: tuple -- (username, passphrase) or (None, None) if empty.
        :rtype: tuple
        """
        if req.auth is not None:
            if req.auth.lower().startswith("basic "):
                try:
                    decoded = tuple(base64.decodebytes(req.auth[6:].encode("utf-8")).decode().split(":"))
                    self.logger.debug("Credentials given: {0}".format(decoded))
                    return decoded
                except base64.binascii.Error:
                    self.logger.info("Bad base64 data sent. Setting to no user/pass.")
        # Default meaning no user or password
        return (None, None)
Exemple #5
0
    def _decode_basic_auth(self, req):
        """
        Decodes basic auth from the header.

        :param req: Request instance that will be passed through.
        :type req: falcon.Request
        :returns: tuple -- (username, passphrase) or (None, None) if empty.
        """
        if req.auth is not None:
            if req.auth.lower().startswith('basic '):
                try:
                    return tuple(
                        base64.decodebytes(
                            req.auth[6:].encode('utf-8')).decode().split(':'))
                except base64.binascii.Error:
                    self.logger.info(
                        'Bad base64 data sent. Setting to no user/pass.')
        # Default meaning no user or password
        return (None, None)