| 
									
										
										
										
											2023-02-02 17:10:35 +01:00
										 |  |  | #  Copyright 2021 Collate | 
					
						
							|  |  |  | #  Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | #  you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | #  You may obtain a copy of the License at | 
					
						
							|  |  |  | #  http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | #  Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | #  distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | #  See the License for the specific language governing permissions and | 
					
						
							|  |  |  | #  limitations under the License. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | This script generates the Python models from the JSON Schemas definition. Additionally, it replaces the `SecretStr` | 
					
						
							|  |  |  | pydantic class used for the password fields with the `CustomSecretStr` pydantic class which retrieves the secrets | 
					
						
							|  |  |  | from a configured secrets' manager. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-11 09:59:15 +01:00
										 |  |  | import datamodel_code_generator.model.pydantic | 
					
						
							|  |  |  | from datamodel_code_generator.imports import Import | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-02 12:49:45 -08:00
										 |  |  | UNICODE_REGEX_REPLACEMENT_FILE_PATHS = [ | 
					
						
							| 
									
										
										
										
											2023-02-10 19:55:50 +05:30
										 |  |  |     "ingestion/src/metadata/generated/schema/entity/classification/tag.py", | 
					
						
							| 
									
										
										
										
											2023-02-02 12:49:45 -08:00
										 |  |  |     "ingestion/src/metadata/generated/schema/entity/events/webhook.py", | 
					
						
							|  |  |  |     "ingestion/src/metadata/generated/schema/entity/teams/user.py", | 
					
						
							|  |  |  |     "ingestion/src/metadata/generated/schema/entity/type.py", | 
					
						
							|  |  |  |     "ingestion/src/metadata/generated/schema/type/basic.py", | 
					
						
							|  |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-11 09:59:15 +01:00
										 |  |  | datamodel_code_generator.model.pydantic.types.IMPORT_SECRET_STR = Import.from_full_path( | 
					
						
							|  |  |  |     "metadata.ingestion.models.custom_pydantic.CustomSecretStr" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from datamodel_code_generator.__main__ import main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | args = "--input openmetadata-spec/src/main/resources/json/schema --input-file-type jsonschema --output ingestion/src/metadata/generated/schema --set-default-enum-member".split( | 
					
						
							|  |  |  |     " " | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | main(args) | 
					
						
							| 
									
										
										
										
											2023-02-02 12:49:45 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | for file_path in UNICODE_REGEX_REPLACEMENT_FILE_PATHS: | 
					
						
							|  |  |  |     with open(file_path, "r", encoding="UTF-8") as file_: | 
					
						
							|  |  |  |         content = file_.read() | 
					
						
							|  |  |  |         content = content.replace("(?U)", "(?u)") | 
					
						
							|  |  |  |     with open(file_path, "w", encoding="UTF-8") as file_: | 
					
						
							|  |  |  |         file_.write(content) |