mongo-replication 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. mongo_replication-0.1.1/.env.example +145 -0
  2. mongo_replication-0.1.1/.github/workflows/ci.yaml +53 -0
  3. mongo_replication-0.1.1/.github/workflows/release.yaml +61 -0
  4. mongo_replication-0.1.1/.gitignore +58 -0
  5. mongo_replication-0.1.1/.pre-commit-config.yaml +44 -0
  6. mongo_replication-0.1.1/CHANGELOG.md +636 -0
  7. mongo_replication-0.1.1/LICENSE +21 -0
  8. mongo_replication-0.1.1/PKG-INFO +606 -0
  9. mongo_replication-0.1.1/PUBLISHING.md +183 -0
  10. mongo_replication-0.1.1/README.md +567 -0
  11. mongo_replication-0.1.1/docs/banner.png +0 -0
  12. mongo_replication-0.1.1/docs/configuration.md +939 -0
  13. mongo_replication-0.1.1/docs/presidio.md +747 -0
  14. mongo_replication-0.1.1/docs/technical-design.md +1262 -0
  15. mongo_replication-0.1.1/docs/test-coverage.md +195 -0
  16. mongo_replication-0.1.1/pyproject.toml +149 -0
  17. mongo_replication-0.1.1/src/mongo_replication/README.md +611 -0
  18. mongo_replication-0.1.1/src/mongo_replication/__init__.py +15 -0
  19. mongo_replication-0.1.1/src/mongo_replication/cli/__init__.py +0 -0
  20. mongo_replication-0.1.1/src/mongo_replication/cli/commands/__init__.py +8 -0
  21. mongo_replication-0.1.1/src/mongo_replication/cli/commands/init.py +819 -0
  22. mongo_replication-0.1.1/src/mongo_replication/cli/commands/run.py +931 -0
  23. mongo_replication-0.1.1/src/mongo_replication/cli/commands/scan.py +705 -0
  24. mongo_replication-0.1.1/src/mongo_replication/cli/interactive/__init__.py +0 -0
  25. mongo_replication-0.1.1/src/mongo_replication/cli/interactive/selectors.py +113 -0
  26. mongo_replication-0.1.1/src/mongo_replication/cli/main.py +79 -0
  27. mongo_replication-0.1.1/src/mongo_replication/cli/reporters/__init__.py +0 -0
  28. mongo_replication-0.1.1/src/mongo_replication/cli/reporters/progress.py +61 -0
  29. mongo_replication-0.1.1/src/mongo_replication/cli/reporters/scan_report.py +158 -0
  30. mongo_replication-0.1.1/src/mongo_replication/cli/reporters/templates/scan_report.md.j2 +106 -0
  31. mongo_replication-0.1.1/src/mongo_replication/cli/utils/__init__.py +0 -0
  32. mongo_replication-0.1.1/src/mongo_replication/cli/utils/cascade_tree.py +180 -0
  33. mongo_replication-0.1.1/src/mongo_replication/cli/utils/output.py +80 -0
  34. mongo_replication-0.1.1/src/mongo_replication/cli/utils/signal_handler.py +111 -0
  35. mongo_replication-0.1.1/src/mongo_replication/config/__init__.py +21 -0
  36. mongo_replication-0.1.1/src/mongo_replication/config/config_template.yaml.j2 +260 -0
  37. mongo_replication-0.1.1/src/mongo_replication/config/defaults.yaml +202 -0
  38. mongo_replication-0.1.1/src/mongo_replication/config/manager.py +337 -0
  39. mongo_replication-0.1.1/src/mongo_replication/config/models.py +440 -0
  40. mongo_replication-0.1.1/src/mongo_replication/config/presidio.yaml +625 -0
  41. mongo_replication-0.1.1/src/mongo_replication/config/presidio_config.py +146 -0
  42. mongo_replication-0.1.1/src/mongo_replication/engine/__init__.py +23 -0
  43. mongo_replication-0.1.1/src/mongo_replication/engine/cascade_filter.py +361 -0
  44. mongo_replication-0.1.1/src/mongo_replication/engine/connection.py +212 -0
  45. mongo_replication-0.1.1/src/mongo_replication/engine/discovery.py +181 -0
  46. mongo_replication-0.1.1/src/mongo_replication/engine/field_exclusion.py +150 -0
  47. mongo_replication-0.1.1/src/mongo_replication/engine/indexes.py +281 -0
  48. mongo_replication-0.1.1/src/mongo_replication/engine/jobs.py +257 -0
  49. mongo_replication-0.1.1/src/mongo_replication/engine/orchestrator.py +431 -0
  50. mongo_replication-0.1.1/src/mongo_replication/engine/pii/__init__.py +25 -0
  51. mongo_replication-0.1.1/src/mongo_replication/engine/pii/custom_operators.py +481 -0
  52. mongo_replication-0.1.1/src/mongo_replication/engine/pii/pii_analyzer.py +388 -0
  53. mongo_replication-0.1.1/src/mongo_replication/engine/pii/pii_handler.py +89 -0
  54. mongo_replication-0.1.1/src/mongo_replication/engine/pii/pii_redaction.py +200 -0
  55. mongo_replication-0.1.1/src/mongo_replication/engine/pii/presidio_analyzer.py +443 -0
  56. mongo_replication-0.1.1/src/mongo_replication/engine/pii/presidio_anonymizer.py +349 -0
  57. mongo_replication-0.1.1/src/mongo_replication/engine/pii/sampler.py +295 -0
  58. mongo_replication-0.1.1/src/mongo_replication/engine/relationships.py +425 -0
  59. mongo_replication-0.1.1/src/mongo_replication/engine/replicator.py +837 -0
  60. mongo_replication-0.1.1/src/mongo_replication/engine/state.py +526 -0
  61. mongo_replication-0.1.1/src/mongo_replication/engine/transformations.py +234 -0
  62. mongo_replication-0.1.1/src/mongo_replication/engine/validation.py +140 -0
  63. mongo_replication-0.1.1/tests/__init__.py +0 -0
  64. mongo_replication-0.1.1/tests/conftest.py +58 -0
  65. mongo_replication-0.1.1/tests/unit/__init__.py +0 -0
  66. mongo_replication-0.1.1/tests/unit/cli/test_init.py +58 -0
  67. mongo_replication-0.1.1/tests/unit/cli/test_scan.py +218 -0
  68. mongo_replication-0.1.1/tests/unit/test_cascade_replication.py +590 -0
  69. mongo_replication-0.1.1/tests/unit/test_config_models.py +320 -0
  70. mongo_replication-0.1.1/tests/unit/test_config_transformations.py +139 -0
  71. mongo_replication-0.1.1/tests/unit/test_error_summarization.py +131 -0
  72. mongo_replication-0.1.1/tests/unit/test_field_exclusion.py +323 -0
  73. mongo_replication-0.1.1/tests/unit/test_indexes.py +430 -0
  74. mongo_replication-0.1.1/tests/unit/test_jobs.py +232 -0
  75. mongo_replication-0.1.1/tests/unit/test_match_filter.py +270 -0
  76. mongo_replication-0.1.1/tests/unit/test_presidio_analyzer.py +308 -0
  77. mongo_replication-0.1.1/tests/unit/test_presidio_anonymizer.py +463 -0
  78. mongo_replication-0.1.1/tests/unit/test_presidio_config.py +411 -0
  79. mongo_replication-0.1.1/tests/unit/test_schema_relationship_analyzer.py +336 -0
  80. mongo_replication-0.1.1/tests/unit/test_transformations.py +355 -0
  81. mongo_replication-0.1.1/uv.lock +2788 -0
@@ -0,0 +1,145 @@
1
+ # MongoDB Replication Tool - Environment Variables
2
+ # =================================================
3
+ # This file contains example environment variable configurations
4
+ # for the job-based replication architecture.
5
+
6
+ # ------------------------------------------------------------
7
+ # Example 1: Single Production Job
8
+ # ------------------------------------------------------------
9
+ # Use case: Replicate from production to analytics database
10
+
11
+ MONGOREP_PROD_ENABLED=true
12
+ MONGOREP_PROD_SOURCE_URI=mongodb://localhost:27017/prod_db
13
+ MONGOREP_PROD_DESTINATION_URI=mongodb://localhost:27017/analytics_db
14
+ MONGOREP_PROD_CONFIG_PATH=config/prod_config.yaml
15
+
16
+ # Usage:
17
+ # rep scan prod
18
+ # rep run prod
19
+
20
+
21
+ # ------------------------------------------------------------
22
+ # Example 2: Multiple Jobs (Different Destinations)
23
+ # ------------------------------------------------------------
24
+ # Use case: Replicate same source to multiple destinations
25
+
26
+ # Job 1: Production to Analytics
27
+ MONGOREP_PROD_TO_ANALYTICS_ENABLED=true
28
+ MONGOREP_PROD_TO_ANALYTICS_SOURCE_URI=mongodb://prod-host:27017/prod_db
29
+ MONGOREP_PROD_TO_ANALYTICS_DESTINATION_URI=mongodb://analytics-host:27017/analytics_db
30
+ MONGOREP_PROD_TO_ANALYTICS_CONFIG_PATH=config/prod_to_analytics.yaml
31
+
32
+ # Job 2: Production to Backup
33
+ MONGOREP_PROD_TO_BACKUP_ENABLED=true
34
+ MONGOREP_PROD_TO_BACKUP_SOURCE_URI=mongodb://prod-host:27017/prod_db
35
+ MONGOREP_PROD_TO_BACKUP_DESTINATION_URI=mongodb://backup-host:27017/backup_db
36
+ MONGOREP_PROD_TO_BACKUP_CONFIG_PATH=config/prod_to_backup.yaml
37
+
38
+ # Usage:
39
+ # rep scan prod_to_analytics
40
+ # rep run prod_to_analytics
41
+ # rep scan prod_to_backup
42
+ # rep run prod_to_backup
43
+
44
+
45
+ # ------------------------------------------------------------
46
+ # Example 3: Staging to Development
47
+ # ------------------------------------------------------------
48
+ # Use case: Replicate staging data to development environment
49
+
50
+ MONGOREP_STAGING_TO_DEV_ENABLED=true
51
+ MONGOREP_STAGING_TO_DEV_SOURCE_URI=mongodb://staging-host:27017/staging_db
52
+ MONGOREP_STAGING_TO_DEV_DESTINATION_URI=mongodb://localhost:27017/dev_db
53
+ MONGOREP_STAGING_TO_DEV_CONFIG_PATH=config/staging_to_dev.yaml
54
+
55
+
56
+ # ------------------------------------------------------------
57
+ # Example 4: Using MongoDB Atlas
58
+ # ------------------------------------------------------------
59
+ # Use case: Replicate from Atlas cluster to local database
60
+
61
+ MONGOREP_ATLAS_TO_LOCAL_ENABLED=true
62
+ MONGOREP_ATLAS_TO_LOCAL_SOURCE_URI=mongodb+srv://username:password@cluster0.example.mongodb.net/mydb?retryWrites=true&w=majority
63
+ MONGOREP_ATLAS_TO_LOCAL_DESTINATION_URI=mongodb://localhost:27017/local_db
64
+ MONGOREP_ATLAS_TO_LOCAL_CONFIG_PATH=config/atlas_to_local.yaml
65
+
66
+
67
+ # ------------------------------------------------------------
68
+ # Example 5: With Authentication
69
+ # ------------------------------------------------------------
70
+ # Use case: Connect to databases requiring authentication
71
+
72
+ MONGOREP_SECURE_JOB_ENABLED=true
73
+ MONGOREP_SECURE_JOB_SOURCE_URI=mongodb://admin:SecurePass123@prod-host:27017/prod_db?authSource=admin
74
+ MONGOREP_SECURE_JOB_DESTINATION_URI=mongodb://admin:SecurePass456@analytics-host:27017/analytics_db?authSource=admin
75
+ MONGOREP_SECURE_JOB_CONFIG_PATH=config/secure_job.yaml
76
+
77
+
78
+ # ------------------------------------------------------------
79
+ # Environment Variable Pattern Reference
80
+ # ------------------------------------------------------------
81
+ #
82
+ # For each job, set these 4 environment variables:
83
+ #
84
+ # MONGOREP_<JOB_ID>_ENABLED=true|false
85
+ # - Enable or disable this replication job
86
+ # - Example: MONGOREP_PROD_ENABLED=true
87
+ #
88
+ # MONGOREP_<JOB_ID>_SOURCE_URI=<mongodb-uri>
89
+ # - MongoDB connection URI for the source database
90
+ # - Example: MONGOREP_PROD_SOURCE_URI=mongodb://localhost:27017/source_db
91
+ #
92
+ # MONGOREP_<JOB_ID>_DESTINATION_URI=<mongodb-uri>
93
+ # - MongoDB connection URI for the destination database
94
+ # - Example: MONGOREP_PROD_DESTINATION_URI=mongodb://localhost:27017/dest_db
95
+ #
96
+ # MONGOREP_<JOB_ID>_CONFIG_PATH=<path-to-yaml>
97
+ # - Path to the YAML configuration file
98
+ # - Required for 'rep run' command
99
+ # - Generated by 'rep scan' if not provided
100
+ # - Example: MONGOREP_PROD_CONFIG_PATH=config/prod_config.yaml
101
+ #
102
+ # ------------------------------------------------------------
103
+ # Job ID Naming Rules
104
+ # ------------------------------------------------------------
105
+ #
106
+ # - Use uppercase letters, numbers, and underscores
107
+ # - Should be descriptive and unique
108
+ # - Examples: PROD, STAGING, PROD_TO_ANALYTICS, DAILY_BACKUP
109
+ # - Internally normalized to lowercase (PROD → prod)
110
+ #
111
+ # ------------------------------------------------------------
112
+ # MongoDB URI Format
113
+ # ------------------------------------------------------------
114
+ #
115
+ # Standard format:
116
+ # mongodb://[username:password@]host[:port]/database[?options]
117
+ #
118
+ # Atlas format:
119
+ # mongodb+srv://username:password@cluster.mongodb.net/database[?options]
120
+ #
121
+ # Common options:
122
+ # - authSource=admin (authentication database)
123
+ # - retryWrites=true (retry failed writes)
124
+ # - w=majority (write concern)
125
+ # - ssl=true (enable SSL/TLS)
126
+ #
127
+ # Examples:
128
+ # - Local: mongodb://localhost:27017/mydb
129
+ # - Auth: mongodb://user:pass@host:27017/mydb?authSource=admin
130
+ # - Atlas: mongodb+srv://user:pass@cluster.mongodb.net/mydb
131
+ #
132
+ # ------------------------------------------------------------
133
+ # Security Best Practices
134
+ # ------------------------------------------------------------
135
+ #
136
+ # 1. Never commit .env files with real credentials to git
137
+ # 2. Use .env.example for documentation
138
+ # 3. Add .env to .gitignore
139
+ # 4. Use environment-specific files (.env.dev, .env.prod)
140
+ # 5. Rotate credentials regularly
141
+ # 6. Use read-only credentials for source databases
142
+ # 7. Use restricted credentials for destination databases
143
+ # 8. Consider using secret management tools for production
144
+ #
145
+ # ------------------------------------------------------------
@@ -0,0 +1,53 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ jobs:
12
+ ci:
13
+ name: Run CI
14
+ runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
18
+
19
+ steps:
20
+ - name: Checkout code
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Set up uv
24
+ uses: astral-sh/setup-uv@v4
25
+ with:
26
+ enable-cache: true
27
+ cache-dependency-glob: "uv.lock"
28
+
29
+ - name: Set up Python ${{ matrix.python-version }}
30
+ uses: actions/setup-python@v5
31
+ with:
32
+ python-version: ${{ matrix.python-version }}
33
+
34
+ - name: Install dependencies
35
+ run: uv sync --all-extras --dev
36
+
37
+ - name: Run lint
38
+ run: uv run task lint
39
+
40
+ - name: Run build
41
+ run: uv run task build
42
+
43
+ - name: Run tests
44
+ run: uv run task test
45
+
46
+ - name: Upload coverage reports
47
+ if: matrix.python-version == '3.10'
48
+ uses: codecov/codecov-action@v4
49
+ with:
50
+ file: ./coverage.xml
51
+ flags: unittests
52
+ name: codecov-umbrella
53
+ fail_ci_if_error: false
@@ -0,0 +1,61 @@
1
+ name: Release
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: ["CI"]
6
+ branches:
7
+ - main
8
+ types:
9
+ - completed
10
+
11
+ jobs:
12
+ release:
13
+ name: Release to PyPI
14
+ runs-on: ubuntu-latest
15
+ if: ${{ github.event.workflow_run.conclusion == 'success' }}
16
+ concurrency: release
17
+ permissions:
18
+ id-token: write
19
+ contents: write
20
+
21
+ steps:
22
+ - name: Checkout code
23
+ uses: actions/checkout@v4
24
+ with:
25
+ fetch-depth: 0
26
+ token: ${{ secrets.GITHUB_TOKEN }}
27
+
28
+ - name: Set up uv
29
+ uses: astral-sh/setup-uv@v4
30
+ with:
31
+ enable-cache: true
32
+ cache-dependency-glob: "uv.lock"
33
+
34
+ - name: Set up Python
35
+ uses: actions/setup-python@v5
36
+ with:
37
+ python-version: "3.10"
38
+
39
+ - name: Install dependencies
40
+ run: |
41
+ uv sync --all-extras --dev
42
+ uv pip install python-semantic-release
43
+
44
+ - name: Python Semantic Release
45
+ id: release
46
+ uses: python-semantic-release/python-semantic-release@v9.12.0
47
+ with:
48
+ github_token: ${{ secrets.GITHUB_TOKEN }}
49
+
50
+ - name: Publish to PyPI
51
+ if: steps.release.outputs.released == 'true'
52
+ uses: pypa/gh-action-pypi-publish@release/v1
53
+ with:
54
+ password: ${{ secrets.PYPI_API_TOKEN }}
55
+
56
+ - name: Publish GitHub Release
57
+ if: steps.release.outputs.released == 'true'
58
+ uses: python-semantic-release/publish-action@v9.12.0
59
+ with:
60
+ github_token: ${{ secrets.RELEASE_TOKEN }}
61
+ tag: ${{ steps.release.outputs.tag }}
@@ -0,0 +1,58 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual environments
24
+ venv/
25
+ env/
26
+ ENV/
27
+ .venv
28
+
29
+ # IDE
30
+ .vscode/
31
+ .idea/
32
+ *.swp
33
+ *.swo
34
+ *~
35
+ .DS_Store
36
+
37
+ # Testing
38
+ .pytest_cache/
39
+ .coverage
40
+ htmlcov/
41
+ .tox/
42
+
43
+ # Environment variables
44
+ .env
45
+ .env.local
46
+
47
+ # Configuration (may contain sensitive data)
48
+ config/*.yaml
49
+ !config/example_*.yaml
50
+
51
+ # Logs
52
+ *.log
53
+
54
+ # Distribution / packaging
55
+ *.whl
56
+
57
+ # uv
58
+ .python-version
@@ -0,0 +1,44 @@
1
+ default_language_version:
2
+ python: python3.10
3
+
4
+ default_stages: [ pre-commit, pre-push ]
5
+
6
+ repos:
7
+ # Common Hooks
8
+ - repo: https://github.com/pre-commit/pre-commit-hooks
9
+ rev: v6.0.0
10
+ hooks:
11
+ - id: check-merge-conflict
12
+ - id: trailing-whitespace
13
+ - id: end-of-file-fixer
14
+ - id: check-added-large-files
15
+ args: [ '--maxkb=25000' ]
16
+ - id: check-case-conflict
17
+ - id: check-docstring-first
18
+ - id: check-ast
19
+ - id: check-yaml
20
+ - id: check-json
21
+
22
+ # Lock uv
23
+ - repo: https://github.com/astral-sh/uv-pre-commit
24
+ # uv version.
25
+ rev: 0.11.3
26
+ hooks:
27
+ - id: uv-lock
28
+
29
+ # Linter (ruff)
30
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
31
+ rev: v0.15.9
32
+ hooks:
33
+ - id: ruff-check
34
+ args: [ --fix ]
35
+ name: Lint python code
36
+ language_version: python3.10
37
+
38
+ # Formatter (ruff)
39
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
40
+ rev: v0.15.9
41
+ hooks:
42
+ - id: ruff-format
43
+ name: Format python code
44
+ language_version: python3.10