|
1 |
| -import json |
2 | 1 | import logging
|
3 | 2 | import os
|
4 | 3 | import re
|
5 |
| -import tempfile |
6 | 4 | from datetime import timedelta
|
7 | 5 | from typing import Any, Dict, List, Optional, Union
|
8 | 6 |
|
|
17 | 15 | PlatformInstanceConfigMixin,
|
18 | 16 | )
|
19 | 17 | from datahub.configuration.validate_field_removal import pydantic_removed_field
|
20 |
| -from datahub.configuration.validate_multiline_string import pydantic_multiline_string |
21 | 18 | from datahub.ingestion.glossary.classification_mixin import (
|
22 | 19 | ClassificationSourceConfigMixin,
|
23 | 20 | )
|
| 21 | +from datahub.ingestion.source.common.gcp_credentials_config import GCPCredential |
24 | 22 | from datahub.ingestion.source.data_lake_common.path_spec import PathSpec
|
25 | 23 | from datahub.ingestion.source.sql.sql_config import SQLCommonConfig, SQLFilterConfig
|
26 | 24 | from datahub.ingestion.source.state.stateful_ingestion_base import (
|
@@ -107,50 +105,8 @@ class BigQueryUsageConfig(BaseUsageConfig):
|
107 | 105 | )
|
108 | 106 |
|
109 | 107 |
|
110 |
| -class BigQueryCredential(ConfigModel): |
111 |
| - project_id: str = Field(description="Project id to set the credentials") |
112 |
| - private_key_id: str = Field(description="Private key id") |
113 |
| - private_key: str = Field( |
114 |
| - description="Private key in a form of '-----BEGIN PRIVATE KEY-----\\nprivate-key\\n-----END PRIVATE KEY-----\\n'" |
115 |
| - ) |
116 |
| - client_email: str = Field(description="Client email") |
117 |
| - client_id: str = Field(description="Client Id") |
118 |
| - auth_uri: str = Field( |
119 |
| - default="https://accounts.google.com/o/oauth2/auth", |
120 |
| - description="Authentication uri", |
121 |
| - ) |
122 |
| - token_uri: str = Field( |
123 |
| - default="https://oauth2.googleapis.com/token", description="Token uri" |
124 |
| - ) |
125 |
| - auth_provider_x509_cert_url: str = Field( |
126 |
| - default="https://www.googleapis.com/oauth2/v1/certs", |
127 |
| - description="Auth provider x509 certificate url", |
128 |
| - ) |
129 |
| - type: str = Field(default="service_account", description="Authentication type") |
130 |
| - client_x509_cert_url: Optional[str] = Field( |
131 |
| - default=None, |
132 |
| - description="If not set it will be default to https://www.googleapis.com/robot/v1/metadata/x509/client_email", |
133 |
| - ) |
134 |
| - |
135 |
| - _fix_private_key_newlines = pydantic_multiline_string("private_key") |
136 |
| - |
137 |
| - @root_validator(skip_on_failure=True) |
138 |
| - def validate_config(cls, values: Dict[str, Any]) -> Dict[str, Any]: |
139 |
| - if values.get("client_x509_cert_url") is None: |
140 |
| - values["client_x509_cert_url"] = ( |
141 |
| - f"https://www.googleapis.com/robot/v1/metadata/x509/{values['client_email']}" |
142 |
| - ) |
143 |
| - return values |
144 |
| - |
145 |
| - def create_credential_temp_file(self) -> str: |
146 |
| - with tempfile.NamedTemporaryFile(delete=False) as fp: |
147 |
| - cred_json = json.dumps(self.dict(), indent=4, separators=(",", ": ")) |
148 |
| - fp.write(cred_json.encode()) |
149 |
| - return fp.name |
150 |
| - |
151 |
| - |
152 | 108 | class BigQueryConnectionConfig(ConfigModel):
|
153 |
| - credential: Optional[BigQueryCredential] = Field( |
| 109 | + credential: Optional[GCPCredential] = Field( |
154 | 110 | default=None, description="BigQuery credential informations"
|
155 | 111 | )
|
156 | 112 |
|
|
0 commit comments