1
0
forked from ScoDoc/ScoDoc

fonction d'anonymisation

This commit is contained in:
Emmanuel Viennet 2021-08-17 08:49:19 +02:00
parent 737f88988d
commit 47811943c1
2 changed files with 15 additions and 1 deletions

View File

@ -35,6 +35,18 @@ BEGIN
END LOOP;
END;
$$ LANGUAGE plpgsql;
-- Fonction pour anonymisation:
-- inspirée par https://www.simononsoftware.com/random-string-in-postgresql/
CREATE FUNCTION random_text_md5( integer ) returns text
LANGUAGE SQL
AS $$
select upper( substring( (SELECT string_agg(md5(random()::TEXT), '')
FROM generate_series(
1,
CEIL($1 / 32.)::integer)
), 1, $1) );
$$;
"""
)
db.session.commit()

View File

@ -205,7 +205,9 @@ def _drop_ano_db(ano_db_name):
"""drop temp database if it exists"""
existing_databases = [
s.split("|")[0].strip()
for s in subprocess.check_output(["psql", "-l"]).split("\n")[3:]
for s in subprocess.check_output(["psql", "-l"])
.decode(scu.SCO_ENCODING)
.split("\n")[3:]
]
if ano_db_name not in existing_databases:
log("_drop_ano_db: no temp db, nothing to drop")