예제 #1
0
def data():
    """
    Fixture to return an instance of encryptedData

    The unencrypted string is TEST_STRING
    """

    instance = EncryptedData(TEST_STRING)

    return instance
예제 #2
0
def _retrieveAllConfigDB():
    """
    get the server config from database with one call

    remark: for support for continous entries dedicated dicts for
            description and type are used for interim processing

    :return: config dict
    """

    config = {}
    delay = False

    conf_dict = {}
    type_dict = {}
    desc_dict = {}
    cont_dict = {}

    db_config = Session.query(Config).all()

    # put all information in the dicts for later processing

    for conf in db_config:
        log.debug("[retrieveAllConfigDB] key %r:%r" % (conf.Key, conf.Value))

        conf_dict[conf.Key] = conf.Value
        type_dict[conf.Key] = conf.Type
        desc_dict[conf.Key] = conf.Description

        # a continuous entry is indicated by the type 'C' and the description
        # search for the entry which starts with '0:' as it will provide the
        # number of continuous entries

        if conf.Type == 'C' and conf.Description[:len('0:')] == '0:':
            _start, num = conf.Description.split(':')
            cont_dict[conf.Key] = int(num)

    # ---------------------------------------------------------------------- --

    # cleanup the config from continuous entries

    for key, number in cont_dict.items():

        value = conf_dict[key]

        for i in range(number + 1):

            search_key = u"%s__[%d:%d]" % (key, i, number)

            if search_key in conf_dict:
                value = value + conf_dict[search_key]
                del conf_dict[search_key]

        conf_dict[key] = value

        search_key = u"%s__[%d:%d]" % (key, number, number)
        # allow the reading of none existing entries
        type_dict[key] = type_dict.get(search_key)
        desc_dict[key] = desc_dict.get(search_key)

    # ---------------------------------------------------------------------- --

    # normal processing as before continous here

    for key, value in conf_dict.items():

        if key.startswith("linotp.") is False:
            key = u"linotp." + key

        if isinstance(key, str):
            key = u'' + key

        nVal = expand_here(value)
        config[key] = nVal

    # ---------------------------------------------------------------------- --

    # special treatment of encrypted_data / password:
    # instead of decrypting the data during the loading of the config, the
    # encrypted data is provided EncryptedData object, which allows to only
    # decrypt the data when needed.
    # This allows to drop the delayed loading handling
    #

    for key, value in config.items():

        myTyp = type_dict.get(key)

        if myTyp and myTyp in ['password', 'encrypted_data']:
            config[key] = EncryptedData(value)

    return config, False