Ejemplo n.º 1
0
    def test_from_username_and_password_password_none(self):
        """
        Assert that from_username_and_password() returns a none if password is None.
        """

        instance = WpCredentials.from_username_and_password(
            username='******', password=None)

        self.assertIsNone(instance)
Ejemplo n.º 2
0
    def test_from_aws_secrets_manager(self):
        """
        Assert that from_aws_secrets_manager() returns a class instance.
        """

        instance = WpCredentials.from_aws_secrets_manager(
            secret_id='my-secret-id', region='my-region')

        self.assertTrue(isinstance(instance, WpCredentials))
    def test_database_properties_credential_username_none(self):
        """
        Assert that from_aws_secrets_manager() returns a class instance.
        """

        instance = WpConnection(db_host=None, db_name='wp_default', credentials=WpCredentials.from_username_and_password(None, 'password'))

        self.assertIsInstance(instance, WpConnection)
        self.assertIsNone(instance.db_host)
        self.assertIsNone(instance.credentials)
Ejemplo n.º 4
0
    def test_from_username_and_password(self):
        """
        Assert that from_username_and_password() returns a class instance.
        """

        instance = WpCredentials.from_username_and_password(
            username='******', password='******')

        self.assertTrue(isinstance(instance, WpCredentials))
        self.assertEqual(instance.username, 'username',
                         'User name shoulld be "username"')
        self.assertEqual(instance.password, 'password',
                         'Password shoulld be "password"')
    def test_database_connection(self):

        dbSettings = self._load_settings()
        self.assertTrue(dbSettings is not None,
                        "test_settings.json must exist...")

        instance = WpDatabase(wp_connection=WpConnection(
            db_host=dbSettings["dbHost"],
            db_name=dbSettings["dbName"],
            credentials=WpCredentials.from_username_and_password(
                dbSettings["dbUser"], dbSettings["dbPassword"])))

        self.assertTrue(instance.test_config(), "Database connection failed")
    def test_get_database_version(self):

        dbSettings = self._load_settings()
        self.assertTrue(dbSettings is not None,
                        "test_settings.json must exist...")

        instance = WpDatabase(wp_connection=WpConnection(
            db_host=dbSettings["dbHost"],
            db_name=dbSettings["dbName"],
            credentials=WpCredentials.from_username_and_password(
                dbSettings["dbUser"], dbSettings["dbPassword"])))

        wpVer = instance.get_database_version()
        self.assertTrue(wpVer is not None and wpVer.wp_version is not None,
                        "Wordpress Version returned '{}'".format(wpVer))
    def test_database_properties(self):
        """
        Assert that from_aws_secrets_manager() returns a class instance.
        """

        instance = WpDatabase(wp_connection=WpConnection(
            db_host='127.0.0.1:3306',
            db_name='wp_default',
            credentials=WpCredentials.from_username_and_password(
                'root', 'password')))

        self.assertTrue(isinstance(instance, WpDatabase))
        self.assertTrue(isinstance(instance.connection, WpConnection))
        self.assertTrue(instance.connection.db_host == '127.0.0.1',
                        'Actual is: {0}'.format(instance.connection.db_host))
        self.assertTrue(instance.connection.db_port == '3306',
                        'Actual is: {0}'.format(instance.connection.db_port))
        self.assertTrue(instance.connection.db_name == 'wp_default',
                        'Actual is: {0}'.format(instance.connection.db_name))
        self.assertTrue(
            isinstance(instance.connection.credentials, WpCredentials))
        self.assertTrue(instance.connection.credentials.username is 'root')
        self.assertTrue(instance.connection.credentials.password is 'password')
    def test_database_properties(self):
        """
        Assert that from_aws_secrets_manager() returns a class instance.
        """

        instance = WpConnection(db_host='127.0.0.1', db_name='wp_default', credentials=WpCredentials.from_username_and_password('root', 'password'))

        self.assertIsInstance(instance, WpConnection)
        self.assertEqual(instance.db_host, '127.0.0.1')
        self.assertIsInstance(instance.credentials, WpCredentials)
        self.assertEqual(instance.credentials.username, 'root')
        self.assertEqual(instance.credentials.password, 'password')
Ejemplo n.º 9
0
def run_from_cli():
    """ Perform an update instigated from a CLI. """

    arg_parser = argparse.ArgumentParser()

    arg_parser.add_argument(
        '--version',
        action='version',
        version='%(prog)s {version}'.format(version=__version__))

    arg_parser.add_argument(
        '--admin-credentials-aws-secret-id',
        help='Amazon Web Services (AWS) Secrets Manager secret ID holding '
        'the admin credentials.',
        required=False)

    arg_parser.add_argument(
        '--admin-credentials-aws-region',
        help='Amazon Web Services (AWS) region in which the secret resides.',
        required=False)

    arg_parser.add_argument('--admin-username',
                            help='database admin user username',
                            required=False)

    arg_parser.add_argument('--admin-password',
                            help='database admin user password',
                            required=False)

    arg_parser.add_argument('--wp-config',
                            help='Path and filename of wp-config.php',
                            required=True)

    arg_parser.add_argument('--log-level', default='INFO', help='log level')

    args = arg_parser.parse_args()

    logging.basicConfig(level=str(args.log_level).upper())

    username = args.admin_username
    password = args.admin_password

    if (not username) != (not password):
        arg_parser.error(
            'You must specify both --admin-username and --admin-password or '
            'neither.')
        exit(1)

    secret_id = args.admin_credentials_aws_secret_id
    region = args.admin_credentials_aws_region

    if username and secret_id:
        arg_parser.error('You cannot specify both --admin-username and '
                         '--admin-credentials-aws-secret-id.')
        exit(2)

    if (not username) and (not secret_id):
        arg_parser.error('You must specify either --admin-username or '
                         '--admin-credentials-aws-secret-id.')
        exit(3)

    if username:
        credentials = WpCredentials.from_username_and_password(
            username=username, password=password)
    else:
        credentials = WpCredentials.from_aws_secrets_manager(
            secret_id=secret_id, region=region)

    wpdatabase2.ensure(wp_config_filename=args.wp_config,
                       credentials=credentials,
                       force=False)