Ejemplo n.º 1
0
def update_console(console_path, server_path, context_path):
    print('Updating the main.*.bundle.js file')
    ret_val = True
    basepath_regex = r'"app.config".*?basePath:"(.*?)"'
    result = Common_utilities.update_file(mainjs_file, basepath_regex, server_path)

    if not result:
        ret_val = False
        logging.error('main.*.bundle.js failed to update !')
        print('main.*.bundle.js failed to update !')

    ####   Update the index.html file   ####
    print('Updating the index.html file')
    contextpath_regex = r'<base href="/(.*?)/"'
    result = Common_utilities.update_file(index_html_file, contextpath_regex, context_path)

    if not result:
        ret_val = False
        logging.error('index.html failed to update !')
        print('index.html failed to update !')

    ####   Update the .htaccess file   ####
    print('Updating the .htaccess file')
    basepath_regex = r'RewriteBase /(.*?)/'
    result1 = Common_utilities.update_file(htaccess_file, basepath_regex, context_path)
    redirectionrule_regex = r'RewriteRule . /(.*?)/'
    result2 = Common_utilities.update_file(htaccess_file, redirectionrule_regex, context_path)

    if not result1 or not result2:
        ret_val = False
        logging.error('.htaccess failed to update !')
        print('.htaccess failed to update !')
    
    return ret_val
Ejemplo n.º 2
0
def get_locale_properties():
    logging.info('----Inside function gete_locale_properties()----')
    logging.info('Reading locales properties')
    locale_properties_list = []
    ####   Add all locale properties    ####
    locale_properties_list.append(
        Common_utilities.read_property('email.properties.signup.locale'))
    locale_properties_list.append(
        Common_utilities.read_property(
            'email.properties.resetpassword.locale'))
    locale_properties_list.append(
        Common_utilities.read_property('email.properties.license.locale'))
    return locale_properties_list
Ejemplo n.º 3
0
def process_mongodb_properties():
    logging.info('----Inside function process_mongodb_properties()----')
    logging.info('Reading mongodb server properties')
    Common_utilities.add_property('spring.data.mongodb.repositories.enabled', 'true\n')
    mongodb_uri = Common_utilities.read_property('spring.data.mongodb.uri', False)

    ####   Mongo DB properties if mongo uri not provided   ####
    if mongodb_uri == '':
    ####   Mongo DB properties for authenticated server   ####
        mongodb_uri = construct_mongo_uri()
    else:
        mongo_server = Common_utilities.read_property('spring.data.mongodb.host', False)
        mongo_port = Common_utilities.read_property('spring.data.mongodb.port', False)
        mongo_database = Common_utilities.read_property('spring.data.mongodb.database', False)
        mongodb_username = Common_utilities.read_property('spring.data.mongodb.username', False)
        mongodb_password = Common_utilities.read_property('spring.data.mongodb.password', False)

        if mongo_server != '' or mongo_port != '' or mongo_database != '' or mongodb_username != '' or mongodb_password != '':
            Common_utilities.exit('Either mongo uri or other mongo properties should be provided')
    return mongodb_uri
Ejemplo n.º 4
0
def process_smtp_properties():
    logging.info('----Inside function process_smtp_properties()----')
    logging.info('Reading SMTP server properties')
    Common_utilities.add_property('spring.mail.properties.mail.smtp.starttls.enable', 'true\n')
    smtp_host = Common_utilities.read_property('spring.mail.host')
    smtp_port = Common_utilities.read_property('spring.mail.port')
    smtp_isAuthenticated = Common_utilities.read_property('installer.smtp.authenticated')
    smtp_isAuthenticated = Common_utilities.str_to_bool(smtp_isAuthenticated)

    smtp_obj = Classes.Smtp_server(smtp_host, smtp_port, smtp_isAuthenticated)

    ####   Read username and password if smtp is authenticated   ####
    if smtp_isAuthenticated:
        logging.info('Reading SMTP server username and password')
        smtp_username = Common_utilities.read_property('spring.mail.username')
        smtp_password = Common_utilities.read_property('spring.mail.password')
        Common_utilities.add_property('spring.mail.properties.mail.smtp.auth', 'true\n')
        smtp_obj.username = smtp_username
        smtp_obj.password = smtp_password

    return smtp_obj
Ejemplo n.º 5
0
def validate_console(console_path):
    global mainjs_file
    global index_html_file
    global htaccess_file

    ####   Search for the main.*.js file   ####
    mainjs_regex = re.compile(r'main\.(.*)\.bundle\.js$')
    mainjs_found = False
    for file in os.listdir(console_path):
        if mainjs_regex.match(str(file)):
            mainjs = file
            logging.debug('Found {}'.format(mainjs))
            mainjs_found = True

    ####   Check if main.js file found   ####
    if not mainjs_found:
        Common_utilities.exit('main.*.bundle.js file required for console configuration not found!')

    mainjs_file = os.path.join(console_path, mainjs)

    ####   Check if index.html exists   ####
    index_html_file = os.path.join(console_path, 'index.html')
    if not os.path.exists(index_html_file):
        Common_utilities.exit('index.html file required for console configuration not found!')

    ####   Check if .htaccess exists   ####
    htaccess_file = os.path.join(console_path, '.htaccess')
    if not os.path.exists(htaccess_file):
        Common_utilities.exit('.htaccess file required for console configuration not found!')
Ejemplo n.º 6
0
def apache_deploy(distfolder):
    logging.info('----Inside function apache_deploy()----')
    deployment_path = os.path.abspath(
        Common_utilities.read_property('installer.apache.path'))
    if not os.path.exists(deployment_path):
        Common_utilities.exit('Invalid apache path!')
    try:
        apache_context = Common_utilities.read_property(
            'installer.apache.context')
        apache_context_path = os.path.join(deployment_path, apache_context)
        logging.debug(
            'Deploying folder to Apache folder: {}'.format(deployment_path))

        Directory_utilities.copy_folder_contents(distfolder,
                                                 apache_context_path)

        print('Folder deployed to apache successfully!')
        logging.info('Deployment successful !\n')
    except Exception as err:
        Common_utilities.exit('Error with apache deployment: {}'.format(err))
Ejemplo n.º 7
0
def construct_mongo_uri():
    logging.info('----Inside function construct_mongo_uri()----')
    ####   Read mongo properties from dictionary   ####
    logging.info('Reading Mongo DB properties')
    mongo_server = Common_utilities.read_property('spring.data.mongodb.host')
    mongo_port = Common_utilities.read_property('spring.data.mongodb.port')
    mongo_database = Common_utilities.read_property('spring.data.mongodb.database')
    mongodb_authenticated = Common_utilities.read_property('installer.mongodb.authenticated')

    ####   change string to boolean    ####
    mongodb_authenticated = Common_utilities.str_to_bool(mongodb_authenticated)

    ####   Read username and password if mongo db is authenticated   ####
    if mongodb_authenticated:
        logging.info('Reading Mongo DB username and password')
        mongo_username = Common_utilities.read_property('spring.data.mongodb.username')
        mongo_password = Common_utilities.read_property('spring.data.mongodb.password')
        uri = 'mongodb://{}:{}@{}:{}/{}'.format(mongo_username, mongo_password, mongo_server, mongo_port, \
                                                mongo_database)

    else:
        uri = 'mongodb://{}:{}'.format(mongo_server, mongo_port)
    logging.debug('Connection string for mongo = {}'.format(uri))
    return uri
Ejemplo n.º 8
0
def jboss_deploy(warfile):
    logging.info('----Inside function jboss_deploy()----')
    deployment_mode = Common_utilities.read_property('installer.jboss.mode')
    logging.debug('deployment mode is: {}'.format(deployment_mode))
    print('Deployment mode is: {}'.format(deployment_mode))

    ####   Copy to jboss deployment in case of single-server mode   ####
    if deployment_mode == 'standalone':
        print('Deploying WAR to JBOSS...')
        deployment_path = os.path.abspath(
            Common_utilities.read_property('installer.jboss.path'))

        if not os.path.exists(deployment_path):
            Common_utilities.exit('Invalid jboss path!')

        logging.debug('JBOSS deployment path: {}'.format(deployment_path))
        logging.debug('Copying WAR to JBOSS deployment folder {}'.format(
            deployment_path))
        new_warfile = os.path.join(deployment_path, os.path.basename(warfile))

        ####   Remove the duplicate war   ####
        logging.debug('')
        result = duplicate_war(new_warfile)

        if not result:
            Common_utilities.exit('JBOSS deployment failed.')

        ####   Copy war to jboss   ####
        try:
            shutil.copy(warfile, deployment_path)
        except Exception as err:
            Common_utilities.exit(
                'JBOSS deployment failed with error: {}'.format(err))

        ####   Check if deployed successfully   ####
        war_deployed = new_warfile + '.deployed'
        war_undeployed = new_warfile + '.deployed'
        war_failed = new_warfile + '.failed'

        ####    Set timeout for deployment as 2 minutes    ####
        timeout = time.time() + 60 * 2

        while not (os.path.exists(war_deployed)
                   or os.path.exists(war_undeployed)
                   or os.path.exists(war_failed)) and time.time() < timeout:
            sleep(2)
            print('!.!.!.!.!.!.!.!.!.!.!.!.!.!.!.!')

        if os.path.exists(war_deployed):
            logging.info('WAR deployed successfully !\n')
            print('War deployed successfully!\n')
            return True
        else:
            logging.error('JBOSS deployment failed.')
            print('War deployment failed! Check JBOSS logs')
            return False
    elif deployment_mode == 'cluster':
        out_dir = os.path.join(os.getcwd(), 'out')
        print(
            'Updated WAR file is placed at output folder: {}. Please refer to section 5.2 in \"Installation Guide.pdf\" for detailed deployment steps.\n'
            .format(out_dir))
    else:
        Common_utilities.exit(
            'Invalid jboss mode. Value can be either \'cluster\' or \'standalone\''
        )
Ejemplo n.º 9
0
def process_sysmgr_properties():
    logging.info('----Inside function process_sysmgr_properties()----')
    sysmgr_username = Common_utilities.read_property('sysmgr.context.username')
    sysmgr_password = Common_utilities.read_property('sysmgr.context.password')
Ejemplo n.º 10
0
def process_licensing_properties():
    logging.info('----Inside function process_licensing_properties()----')
    licensing_mail_to = Common_utilities.read_property('email.properties.license.mailTo')
    licensing_mail_from = Common_utilities.read_property('email.properties.license.mailFrom')
    licensing_mail_locale = Common_utilities.read_property('email.properties.license.locale')
Ejemplo n.º 11
0
def process_reset_password_properties():
    logging.info('----Inside function process_reset_password_properties()----')
    reset_password_mail_from = Common_utilities.read_property('email.properties.resetpassword.mailFrom')
    reset_password_mail_locale = Common_utilities.read_property('email.properties.resetpassword.locale')
Ejemplo n.º 12
0
def process_signup_properties():
    logging.info('----Inside function process_signup_properties()----')
    signup_registration_mail_from = Common_utilities.read_property('email.properties.signup.registrationMailFrom')
    signup_activation_mail_from = Common_utilities.read_property('email.properties.signup.activationMailFrom')
    signup_mail_locale = Common_utilities.read_property('email.properties.signup.locale')
Ejemplo n.º 13
0
def verify_aemDB(properties):
    logging.info('----Inside function verify_aemDB()----')

    ####   Read database properties   ####
    logging.info('Reading AEM DB properties')
    sql_hostname = Common_utilities.read_property(
        'installer.datasource.hostname')
    sql_port = Common_utilities.read_property('installer.datasource.port')
    sql_database = Common_utilities.read_property(
        'installer.datasource.database')
    aemdb_authenticated = Common_utilities.read_property(
        'installer.datasource.authenticated')

    # change string to boolean
    aemdb_authenticated = Common_utilities.str_to_bool(aemdb_authenticated)

    ####   Read database username and password   ####
    if aemdb_authenticated:
        logging.info('Reading AEM database username and password')
        sql_username = Common_utilities.read_property(
            'spring.datasource.username')
        sql_password = Common_utilities.read_property(
            'spring.datasource.password')

    ####   Check whether the database is mysql or mssql
    database = Common_utilities.read_property('database-id')
    logging.info('Database id is {}'.format(database))

    ####   Construct jdbc connection string
    if database == 'mysql':
        jdbc_str = 'jdbc:mysql://{}:{}/{}\n'.format(sql_hostname, sql_port,
                                                    sql_database)
        jdbc_driver = 'com.mysql.cj.jdbc.Driver\n'
    elif database == 'mssqlserver':
        jdbc_str = 'jdbc:sqlserver://{}:{};database={}\n'.format(
            sql_hostname, sql_port, sql_database)
        jdbc_driver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver\n'
    else:
        ####   Invalid value of database-id
        logging.error(
            'Invalid value of database-id. Value can be either mysql or mssqlserver !'
        )
        print(
            'Invalid value of database-id. Value can be either mysql or mssqlserver !'
        )
        return False

    logging.debug('JDBC connection string is: {}'.format(jdbc_str))

    ####   Set additional aem db properties   ####
    Common_utilities.add_property('spring.datasource.url', jdbc_str)
    Common_utilities.add_property('spring.datasource.driver-class-name',
                                  jdbc_driver)
    Common_utilities.add_property(
        'mybatis.configuration.database-id',
        Common_utilities.read_property('database-id'))

    ####   Test mssql connection   ####
    driver = '{ODBC Driver 13 for SQL Server}'
    if database == 'mssqlserver':
        print('Verifying mssql connection...')
        try:
            if aemdb_authenticated:
                connStr = 'DRIVER=' + driver + ';SERVER=' + sql_hostname + ',' + sql_port + ';DATABASE=' + sql_database + ';UID=' + sql_username + ';PWD=' + sql_password
                logging.info('mssql connection string: {}'.format(connStr))
            else:
                connStr = 'DRIVER=' + driver + ';SERVER=' + sql_hostname + ',' + sql_port + ';DATABASE=' + sql_database
                logging.info('mssql connection string: {}'.format(connStr))

            conn = pyodbc.connect(connStr)
            logging.info('mssql connected')
            print("mssql connected")

            ####   Error handling   ####
        except Exception as err:
            logging.error("mssql connection failed with error: {}".format(err))
            print("mssql connection failed with error: {}".format(err))
            return False

        ####   Close connection   ####
        else:
            logging.debug('Closing mssql connection')
            conn.close()
            return True

    ####   Test mysql connection   ####
    elif database == 'mysql':
        print('Verifying mysql connection...')
        try:
            if aemdb_authenticated:
                conn = connection.MySQLConnection(host=sql_hostname,
                                                  user=sql_username,
                                                  passwd=sql_password,
                                                  database=sql_database,
                                                  port=sql_port)
            else:
                conn = connection.MySQLConnection(host=sql_hostname,
                                                  database=sql_database,
                                                  port=sql_port)

            logging.debug('Connection string for mysql = {}'.format(conn))
            logging.info('mysql connected')
            print('mysql connected')

        ####   Error handling   ####
        except mysql.connector.Error as err:
            if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
                logging.error(
                    'mysql connection failed with error: Invalid user name or password !'
                )
                print(
                    'mysql connection failed with error: Invalid user name or password !'
                )
            elif err.errno == errorcode.ER_BAD_DB_ERROR:
                logging.error(
                    'mysql connection failed with error: Database does not exist !'
                )
                print(
                    'mysql connection failed with error: Database does not exist !'
                )
            else:
                logging.error(
                    'mysql connection failed with error: {}'.format(err))
                print(err)
            return False

        ####   Close connection   ####
        else:
            logging.debug('Closing myssql connection')
            conn.close()
            return True

    return True