#!/usr/bin/env python
# -*- coding: utf-8 -*-

# -------------------------------------------------------------------
# Copyright (c) 2010-2019 Denis Machard
# This file is part of the extensive automation project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA
# -------------------------------------------------------------------

import sys
sys.path.insert(0, '../../../' )

from ea.libs import Settings
from common_bdd import querySQL

# initialize settings module to read the settings.ini file
Settings.initialize(path="./")

# prefix_table = Settings.get( 'Database', 'table-prefix')
aes_pwd = Settings.get( 'Database', 'test-environment-password')

print("Encrypt test environment value in 'test-environment'")
rows = querySQL( query = """SELECT * FROM `test-environment`;""")

for line in rows:
    id, _, value, _ = line
    sql = "UPDATE `test-environment` SET value=AES_ENCRYPT('%s', '%s') WHERE id=%s;" % (
                value,
                aes_pwd,
                id
            )
    querySQL( query = sql )

Settings.finalize()

sys.exit(0)