Coverage for src/lightmlrestapi/cli/make_encrypt_pwd.py: 76%
21 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-06 07:16 +0200
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-06 07:16 +0200
1"""
2@file
3@brief Creates and runs an Falcon application.
4"""
5import os
6import sys
7import pandas
10def encrypt_pwd(input="", output="", algo="sha224", fLOG=print): # pylint: disable=W0622
11 """
12 Encrypts passwords to setup a REST API
13 with *lightmlrestapi*.
15 :param input: file containing two columns <login>,<clear password>
16 (comma separated values), no header, encoding is *utf-8*
17 :param output: file containing two columns <login>,<encrypted password>,
18 csv, encoding is *utf-8*
19 :param algo: algorithm used to hash the passwords
20 :param fLOG: logging function
22 .. cmdref::
23 :title: Encrypts password
24 :cmd: -m lightmlrestapi encrypt_pwd --help
25 :lid: cmd_encrypt_pwd_cmd
27 Encrypts passwords for a REST API created by *lightmlrestapi*.
28 """
29 try:
30 from ..args.encrypt_helper import encrypt_passwords
31 except (ImportError, ValueError):
32 folder = os.path.normpath(os.path.join(
33 os.path.abspath(os.path.dirname(__file__)), "..", ".."))
34 sys.path.append(folder)
35 from lightmlrestapi.args.encrypt_helper import encrypt_passwords
37 if not os.path.exists(input):
38 raise FileNotFoundError("File '{0}' not found".format(input))
40 if fLOG:
41 fLOG("[encrypt_pwd] encrypt '{0}'".format(input))
42 df = pandas.read_csv(input, sep=',', encoding='utf-8', header=None)
43 df2 = encrypt_passwords(df, algo=algo)
44 if fLOG:
45 fLOG("[encrypt_pwd] to '{0}'".format(output))
46 df2.to_csv(output, sep=',', encoding='utf-8', header=False, index=False)
47 if fLOG:
48 fLOG("[encrypt_pwd] done.")