airbyte-agent-hubspot 0.15.20__py3-none-any.whl

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 (55) hide show
  1. airbyte_agent_hubspot/__init__.py +86 -0
  2. airbyte_agent_hubspot/_vendored/__init__.py +1 -0
  3. airbyte_agent_hubspot/_vendored/connector_sdk/__init__.py +82 -0
  4. airbyte_agent_hubspot/_vendored/connector_sdk/auth_strategies.py +1123 -0
  5. airbyte_agent_hubspot/_vendored/connector_sdk/auth_template.py +135 -0
  6. airbyte_agent_hubspot/_vendored/connector_sdk/cloud_utils/__init__.py +5 -0
  7. airbyte_agent_hubspot/_vendored/connector_sdk/cloud_utils/client.py +213 -0
  8. airbyte_agent_hubspot/_vendored/connector_sdk/connector_model_loader.py +957 -0
  9. airbyte_agent_hubspot/_vendored/connector_sdk/constants.py +78 -0
  10. airbyte_agent_hubspot/_vendored/connector_sdk/exceptions.py +23 -0
  11. airbyte_agent_hubspot/_vendored/connector_sdk/executor/__init__.py +31 -0
  12. airbyte_agent_hubspot/_vendored/connector_sdk/executor/hosted_executor.py +197 -0
  13. airbyte_agent_hubspot/_vendored/connector_sdk/executor/local_executor.py +1504 -0
  14. airbyte_agent_hubspot/_vendored/connector_sdk/executor/models.py +190 -0
  15. airbyte_agent_hubspot/_vendored/connector_sdk/extensions.py +655 -0
  16. airbyte_agent_hubspot/_vendored/connector_sdk/http/__init__.py +37 -0
  17. airbyte_agent_hubspot/_vendored/connector_sdk/http/adapters/__init__.py +9 -0
  18. airbyte_agent_hubspot/_vendored/connector_sdk/http/adapters/httpx_adapter.py +251 -0
  19. airbyte_agent_hubspot/_vendored/connector_sdk/http/config.py +98 -0
  20. airbyte_agent_hubspot/_vendored/connector_sdk/http/exceptions.py +119 -0
  21. airbyte_agent_hubspot/_vendored/connector_sdk/http/protocols.py +114 -0
  22. airbyte_agent_hubspot/_vendored/connector_sdk/http/response.py +102 -0
  23. airbyte_agent_hubspot/_vendored/connector_sdk/http_client.py +679 -0
  24. airbyte_agent_hubspot/_vendored/connector_sdk/logging/__init__.py +11 -0
  25. airbyte_agent_hubspot/_vendored/connector_sdk/logging/logger.py +264 -0
  26. airbyte_agent_hubspot/_vendored/connector_sdk/logging/types.py +92 -0
  27. airbyte_agent_hubspot/_vendored/connector_sdk/observability/__init__.py +11 -0
  28. airbyte_agent_hubspot/_vendored/connector_sdk/observability/models.py +19 -0
  29. airbyte_agent_hubspot/_vendored/connector_sdk/observability/redactor.py +81 -0
  30. airbyte_agent_hubspot/_vendored/connector_sdk/observability/session.py +94 -0
  31. airbyte_agent_hubspot/_vendored/connector_sdk/performance/__init__.py +6 -0
  32. airbyte_agent_hubspot/_vendored/connector_sdk/performance/instrumentation.py +57 -0
  33. airbyte_agent_hubspot/_vendored/connector_sdk/performance/metrics.py +93 -0
  34. airbyte_agent_hubspot/_vendored/connector_sdk/schema/__init__.py +75 -0
  35. airbyte_agent_hubspot/_vendored/connector_sdk/schema/base.py +161 -0
  36. airbyte_agent_hubspot/_vendored/connector_sdk/schema/components.py +238 -0
  37. airbyte_agent_hubspot/_vendored/connector_sdk/schema/connector.py +131 -0
  38. airbyte_agent_hubspot/_vendored/connector_sdk/schema/extensions.py +109 -0
  39. airbyte_agent_hubspot/_vendored/connector_sdk/schema/operations.py +146 -0
  40. airbyte_agent_hubspot/_vendored/connector_sdk/schema/security.py +213 -0
  41. airbyte_agent_hubspot/_vendored/connector_sdk/secrets.py +182 -0
  42. airbyte_agent_hubspot/_vendored/connector_sdk/telemetry/__init__.py +10 -0
  43. airbyte_agent_hubspot/_vendored/connector_sdk/telemetry/config.py +32 -0
  44. airbyte_agent_hubspot/_vendored/connector_sdk/telemetry/events.py +58 -0
  45. airbyte_agent_hubspot/_vendored/connector_sdk/telemetry/tracker.py +151 -0
  46. airbyte_agent_hubspot/_vendored/connector_sdk/types.py +241 -0
  47. airbyte_agent_hubspot/_vendored/connector_sdk/utils.py +60 -0
  48. airbyte_agent_hubspot/_vendored/connector_sdk/validation.py +822 -0
  49. airbyte_agent_hubspot/connector.py +1104 -0
  50. airbyte_agent_hubspot/connector_model.py +2660 -0
  51. airbyte_agent_hubspot/models.py +438 -0
  52. airbyte_agent_hubspot/types.py +217 -0
  53. airbyte_agent_hubspot-0.15.20.dist-info/METADATA +105 -0
  54. airbyte_agent_hubspot-0.15.20.dist-info/RECORD +55 -0
  55. airbyte_agent_hubspot-0.15.20.dist-info/WHEEL +4 -0
@@ -0,0 +1,109 @@
1
+ """
2
+ Extension models for future features.
3
+
4
+ These models are defined but NOT yet added to the main schema models.
5
+ They serve as:
6
+ 1. Type hints for future use
7
+ 2. Documentation of planned extensions
8
+ 3. Ready-to-use structures when features are implemented
9
+
10
+ NOTE: These are not currently active in the schema. They will be added
11
+ to Operation, Schema, or other models when their respective features
12
+ are implemented.
13
+ """
14
+
15
+ from typing import Literal, Optional
16
+
17
+ from pydantic import BaseModel, ConfigDict
18
+
19
+
20
+ class PaginationConfig(BaseModel):
21
+ """
22
+ Configuration for pagination support.
23
+
24
+ NOT YET USED - Defined for future implementation.
25
+
26
+ When active, will be added to Operation model as:
27
+ x_pagination: Optional[PaginationConfig] = Field(None, alias="x-pagination")
28
+ """
29
+
30
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
31
+
32
+ style: Literal["cursor", "offset", "page", "link"]
33
+ limit_param: str = "limit"
34
+
35
+ # Cursor-based pagination
36
+ cursor_param: Optional[str] = None
37
+ cursor_source: Optional[Literal["body", "headers"]] = "body"
38
+ cursor_path: Optional[str] = None
39
+
40
+ # Offset-based pagination
41
+ offset_param: Optional[str] = None
42
+
43
+ # Page-based pagination
44
+ page_param: Optional[str] = None
45
+
46
+ # Response parsing
47
+ data_path: str = "data"
48
+ has_more_path: Optional[str] = None
49
+
50
+ # Limits
51
+ max_page_size: Optional[int] = None
52
+ default_page_size: int = 100
53
+
54
+
55
+ class RateLimitConfig(BaseModel):
56
+ """
57
+ Configuration for rate limiting.
58
+
59
+ NOT YET USED - Defined for future implementation.
60
+
61
+ When active, might be added to Server or root OpenAPIConnector as:
62
+ x_rate_limit: Optional[RateLimitConfig] = Field(None, alias="x-rate-limit")
63
+ """
64
+
65
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
66
+
67
+ max_requests: int
68
+ time_window_seconds: int
69
+ retry_after_header: Optional[str] = "Retry-After"
70
+ respect_retry_after: bool = True
71
+
72
+
73
+ class RetryConfig(BaseModel):
74
+ """
75
+ Configuration for retry strategy with exponential backoff.
76
+
77
+ Used to configure automatic retries for transient errors (429, 5xx, timeouts, network errors).
78
+ Can be specified at the connector level via x-airbyte-retry-config in the OpenAPI spec's info section.
79
+
80
+ By default, retries are enabled with max_attempts=3. To disable retries, set max_attempts=1
81
+ in your connector's x-airbyte-retry-config.
82
+
83
+ Example YAML usage:
84
+ info:
85
+ title: My API
86
+ x-airbyte-retry-config:
87
+ max_attempts: 5
88
+ initial_delay_seconds: 2.0
89
+ retry_after_header: "X-RateLimit-Reset"
90
+ retry_after_format: "unix_timestamp"
91
+ """
92
+
93
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
94
+
95
+ # Core retry settings (max_attempts=3 enables retries by default)
96
+ max_attempts: int = 3
97
+ initial_delay_seconds: float = 1.0
98
+ max_delay_seconds: float = 60.0
99
+ exponential_base: float = 2.0
100
+ jitter: bool = True
101
+
102
+ # Which errors to retry
103
+ retry_on_status_codes: list[int] = [429, 500, 502, 503, 504]
104
+ retry_on_timeout: bool = True
105
+ retry_on_network_error: bool = True
106
+
107
+ # Header-based delay extraction
108
+ retry_after_header: str = "Retry-After"
109
+ retry_after_format: Literal["seconds", "milliseconds", "unix_timestamp"] = "seconds"
@@ -0,0 +1,146 @@
1
+ """
2
+ Operation and PathItem models for OpenAPI 3.1.
3
+
4
+ References:
5
+ - https://spec.openapis.org/oas/v3.1.0#operation-object
6
+ - https://spec.openapis.org/oas/v3.1.0#path-item-object
7
+ """
8
+
9
+ from typing import Any, Dict, List, Optional
10
+
11
+ from pydantic import BaseModel, ConfigDict, Field, model_validator
12
+
13
+ from ..extensions import ActionTypeLiteral
14
+ from .components import Parameter, PathOverrideConfig, RequestBody, Response
15
+ from .security import SecurityRequirement
16
+
17
+
18
+ class Operation(BaseModel):
19
+ """
20
+ Single API operation (GET, POST, PUT, PATCH, DELETE, etc.).
21
+
22
+ OpenAPI Reference: https://spec.openapis.org/oas/v3.1.0#operation-object
23
+
24
+ Extensions:
25
+ - x-airbyte-entity: Entity name (Airbyte extension)
26
+ - x-airbyte-action: Semantic action (Airbyte extension)
27
+ - x-airbyte-path-override: Path override (Airbyte extension)
28
+ - x-airbyte-record-extractor: JSONPath to extract records from response (Airbyte extension)
29
+
30
+ Future extensions (not yet active):
31
+ - x-airbyte-pagination: Pagination configuration for list operations
32
+ """
33
+
34
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
35
+
36
+ # Standard OpenAPI fields
37
+ tags: Optional[List[str]] = None
38
+ summary: Optional[str] = None
39
+ description: Optional[str] = None
40
+ external_docs: Optional[Dict[str, Any]] = Field(None, alias="externalDocs")
41
+ operation_id: Optional[str] = Field(None, alias="operationId")
42
+ parameters: Optional[List[Parameter]] = None
43
+ request_body: Optional[RequestBody] = Field(None, alias="requestBody")
44
+ responses: Dict[str, Response] = Field(default_factory=dict)
45
+ callbacks: Optional[Dict[str, Any]] = None
46
+ deprecated: Optional[bool] = None
47
+ security: Optional[List[SecurityRequirement]] = None
48
+ servers: Optional[List[Any]] = None # Can override root servers
49
+
50
+ # Airbyte extensions
51
+ x_airbyte_entity: str = Field(..., alias="x-airbyte-entity")
52
+ x_airbyte_action: ActionTypeLiteral = Field(..., alias="x-airbyte-action")
53
+ x_airbyte_path_override: Optional[PathOverrideConfig] = Field(
54
+ None,
55
+ alias="x-airbyte-path-override",
56
+ description=("Override path for HTTP requests when OpenAPI path " "differs from actual endpoint"),
57
+ )
58
+ x_airbyte_record_extractor: Optional[str] = Field(
59
+ None,
60
+ alias="x-airbyte-record-extractor",
61
+ description=(
62
+ "JSONPath expression to extract records from API response envelopes. "
63
+ "When specified, executor extracts data at this path instead of returning "
64
+ "full response. Returns array for list/search actions, single record for "
65
+ "get/create/update/delete actions."
66
+ ),
67
+ )
68
+ x_airbyte_meta_extractor: Optional[Dict[str, str]] = Field(
69
+ None,
70
+ alias="x-airbyte-meta-extractor",
71
+ description=(
72
+ "Dictionary mapping field names to JSONPath expressions for extracting "
73
+ "metadata (pagination info, request IDs, etc.) from API response envelopes. "
74
+ "Each key becomes a field in ExecutionResult.meta with the value extracted "
75
+ "using the corresponding JSONPath expression. "
76
+ "Example: {'pagination': '$.pagination', 'request_id': '$.requestId'}"
77
+ ),
78
+ )
79
+ x_airbyte_file_url: Optional[str] = Field(None, alias="x-airbyte-file-url")
80
+ x_airbyte_untested: Optional[bool] = Field(
81
+ None,
82
+ alias="x-airbyte-untested",
83
+ description=(
84
+ "Mark operation as untested to skip cassette validation in readiness checks. "
85
+ "Use this for operations that cannot be recorded (e.g., webhooks, real-time streams). "
86
+ "Validation will generate a warning instead of an error when cassettes are missing."
87
+ ),
88
+ )
89
+
90
+ # Future extensions (commented out, defined for future use)
91
+ # from .extensions import PaginationConfig
92
+ # x_pagination: Optional[PaginationConfig] = Field(None, alias="x-airbyte-pagination")
93
+
94
+ @model_validator(mode="after")
95
+ def validate_download_action_requirements(self) -> "Operation":
96
+ """
97
+ Validate download operation requirements.
98
+
99
+ Rules:
100
+ - If x-airbyte-action is "download":
101
+ - x-airbyte-file-url must be non-empty if provided
102
+ - If x-airbyte-action is not "download":
103
+ - x-airbyte-file-url must not be present
104
+ """
105
+ action = self.x_airbyte_action
106
+ file_url = self.x_airbyte_file_url
107
+
108
+ if action == "download":
109
+ # If file_url is provided, it must be non-empty
110
+ if file_url is not None and not file_url.strip():
111
+ raise ValueError("x-airbyte-file-url must be non-empty when provided for download operations")
112
+ else:
113
+ # Non-download actions cannot have file_url
114
+ if file_url is not None:
115
+ raise ValueError(f"x-airbyte-file-url can only be used with x-airbyte-action: download, but action is '{action}'")
116
+
117
+ return self
118
+
119
+
120
+ class PathItem(BaseModel):
121
+ """
122
+ Path item containing operations for different HTTP methods.
123
+
124
+ OpenAPI Reference: https://spec.openapis.org/oas/v3.1.0#path-item-object
125
+ """
126
+
127
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
128
+
129
+ # Common fields for all operations
130
+ summary: Optional[str] = None
131
+ description: Optional[str] = None
132
+ servers: Optional[List[Any]] = None
133
+ parameters: Optional[List[Parameter]] = None
134
+
135
+ # HTTP methods (all optional)
136
+ get: Optional[Operation] = None
137
+ put: Optional[Operation] = None
138
+ post: Optional[Operation] = None
139
+ delete: Optional[Operation] = None
140
+ options: Optional[Operation] = None
141
+ head: Optional[Operation] = None
142
+ patch: Optional[Operation] = None
143
+ trace: Optional[Operation] = None
144
+
145
+ # Reference support
146
+ ref: Optional[str] = Field(None, alias="$ref")
@@ -0,0 +1,213 @@
1
+ """
2
+ Security scheme models for OpenAPI 3.1.
3
+
4
+ References:
5
+ - https://spec.openapis.org/oas/v3.1.0#security-scheme-object
6
+ - https://spec.openapis.org/oas/v3.1.0#oauth-flows-object
7
+ """
8
+
9
+ from typing import Any, Dict, List, Literal, Optional
10
+
11
+ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
12
+
13
+
14
+ class OAuth2Flow(BaseModel):
15
+ """
16
+ OAuth 2.0 flow configuration.
17
+
18
+ OpenAPI Reference: https://spec.openapis.org/oas/v3.1.0#oauth-flow-object
19
+ """
20
+
21
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
22
+
23
+ authorization_url: Optional[str] = Field(None, alias="authorizationUrl")
24
+ token_url: Optional[str] = Field(None, alias="tokenUrl")
25
+ refresh_url: Optional[str] = Field(None, alias="refreshUrl")
26
+ scopes: Dict[str, str] = Field(default_factory=dict)
27
+
28
+
29
+ class OAuth2Flows(BaseModel):
30
+ """
31
+ Collection of OAuth 2.0 flows.
32
+
33
+ OpenAPI Reference: https://spec.openapis.org/oas/v3.1.0#oauth-flows-object
34
+ """
35
+
36
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
37
+
38
+ implicit: Optional[OAuth2Flow] = None
39
+ password: Optional[OAuth2Flow] = None
40
+ client_credentials: Optional[OAuth2Flow] = Field(None, alias="clientCredentials")
41
+ authorization_code: Optional[OAuth2Flow] = Field(None, alias="authorizationCode")
42
+
43
+
44
+ class AuthConfigFieldSpec(BaseModel):
45
+ """
46
+ Specification for a user-facing authentication config field.
47
+
48
+ This defines a single input field that users provide for authentication.
49
+ """
50
+
51
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
52
+
53
+ type: Literal["string", "integer", "boolean", "number"] = "string"
54
+ title: Optional[str] = None
55
+ description: Optional[str] = None
56
+ format: Optional[str] = None # e.g., "email", "uri"
57
+ pattern: Optional[str] = None # Regex validation
58
+ airbyte_secret: bool = Field(False, alias="airbyte_secret")
59
+ default: Optional[Any] = None
60
+
61
+
62
+ class AuthConfigOption(BaseModel):
63
+ """
64
+ A single authentication configuration option.
65
+
66
+ Defines user-facing fields and how they map to auth parameters.
67
+ """
68
+
69
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
70
+
71
+ title: Optional[str] = None
72
+ description: Optional[str] = None
73
+ type: Literal["object"] = "object"
74
+ required: List[str] = Field(default_factory=list)
75
+ properties: Dict[str, AuthConfigFieldSpec] = Field(default_factory=dict)
76
+ auth_mapping: Dict[str, str] = Field(
77
+ default_factory=dict,
78
+ description="Mapping from auth parameters (e.g., 'username', 'password', 'token') to template strings using ${field} syntax",
79
+ )
80
+
81
+
82
+ class AirbyteAuthConfig(BaseModel):
83
+ """
84
+ Airbyte auth configuration extension (x-airbyte-auth-config).
85
+
86
+ Defines user-facing authentication configuration and how it maps to
87
+ the underlying OpenAPI security scheme.
88
+
89
+ Either a single auth option or multiple options via oneOf.
90
+ """
91
+
92
+ model_config = ConfigDict(populate_by_name=True, extra="forbid")
93
+
94
+ # Single option fields
95
+ title: Optional[str] = None
96
+ description: Optional[str] = None
97
+ type: Optional[Literal["object"]] = None
98
+ required: Optional[List[str]] = None
99
+ properties: Optional[Dict[str, AuthConfigFieldSpec]] = None
100
+ auth_mapping: Optional[Dict[str, str]] = None
101
+
102
+ # Multiple options (oneOf)
103
+ one_of: Optional[List[AuthConfigOption]] = Field(None, alias="oneOf")
104
+
105
+ @model_validator(mode="after")
106
+ def validate_config_structure(self) -> "AirbyteAuthConfig":
107
+ """Validate that either single option or oneOf is provided, not both."""
108
+ has_single = self.type is not None or self.properties is not None or self.auth_mapping is not None
109
+ has_one_of = self.one_of is not None and len(self.one_of) > 0
110
+
111
+ if not has_single and not has_one_of:
112
+ raise ValueError("Either single auth option (type/properties/auth_mapping) or oneOf must be provided")
113
+
114
+ if has_single and has_one_of:
115
+ raise ValueError("Cannot have both single auth option and oneOf")
116
+
117
+ if has_single:
118
+ # Validate single option has required fields
119
+ if self.type != "object":
120
+ raise ValueError("Single auth option must have type='object'")
121
+ if not self.properties:
122
+ raise ValueError("Single auth option must have properties")
123
+ if not self.auth_mapping:
124
+ raise ValueError("Single auth option must have auth_mapping")
125
+
126
+ return self
127
+
128
+
129
+ class SecurityScheme(BaseModel):
130
+ """
131
+ Security scheme definition.
132
+
133
+ OpenAPI Reference: https://spec.openapis.org/oas/v3.1.0#security-scheme-object
134
+
135
+ Supported Types:
136
+ - apiKey: API key in header/query/cookie
137
+ - http: HTTP authentication (basic, bearer, digest, etc.)
138
+ - oauth2: OAuth 2.0 flows
139
+
140
+ Extensions:
141
+ - x-airbyte-token-path: JSON path to extract token from auth response (Airbyte extension)
142
+ - x-airbyte-token-refresh: OAuth2 token refresh configuration (dict with auth_style, body_format)
143
+ - x-airbyte-auth-config: User-facing authentication configuration (Airbyte extension)
144
+
145
+ Future extensions (not yet active):
146
+ - x-grant-type: OAuth grant type for refresh tokens
147
+ - x-refresh-endpoint: Custom refresh endpoint URL
148
+ """
149
+
150
+ model_config = ConfigDict(populate_by_name=True, extra="allow")
151
+
152
+ # Standard OpenAPI fields
153
+ type: Literal["apiKey", "http", "oauth2", "openIdConnect"]
154
+ description: Optional[str] = None
155
+
156
+ # apiKey specific
157
+ name: Optional[str] = None
158
+ in_: Optional[Literal["query", "header", "cookie"]] = Field(None, alias="in")
159
+
160
+ # http specific
161
+ scheme: Optional[str] = None # e.g., "basic", "bearer", "digest"
162
+ bearer_format: Optional[str] = Field(None, alias="bearerFormat")
163
+
164
+ # oauth2 specific
165
+ flows: Optional[OAuth2Flows] = None
166
+
167
+ # openIdConnect specific
168
+ open_id_connect_url: Optional[str] = Field(None, alias="openIdConnectUrl")
169
+
170
+ # Airbyte extensions
171
+ x_token_path: Optional[str] = Field(None, alias="x-airbyte-token-path")
172
+ x_token_refresh: Optional[Dict[str, Any]] = Field(None, alias="x-airbyte-token-refresh")
173
+ x_airbyte_auth_config: Optional[AirbyteAuthConfig] = Field(None, alias="x-airbyte-auth-config")
174
+ x_airbyte_token_extract: Optional[List[str]] = Field(
175
+ None,
176
+ alias="x-airbyte-token-extract",
177
+ description="List of fields to extract from OAuth2 token responses and use as server variables",
178
+ )
179
+
180
+ @field_validator("x_airbyte_token_extract", mode="after")
181
+ @classmethod
182
+ def validate_token_extract(cls, v: Optional[List[str]]) -> Optional[List[str]]:
183
+ """Validate x-airbyte-token-extract has no duplicates."""
184
+ if v is not None:
185
+ if len(v) != len(set(v)):
186
+ duplicates = [x for x in v if v.count(x) > 1]
187
+ raise ValueError(f"x-airbyte-token-extract contains duplicate fields: {set(duplicates)}")
188
+ return v
189
+
190
+ # Future extensions (commented out, defined for future use)
191
+ # x_grant_type: Optional[Literal["refresh_token", "client_credentials"]] = Field(None, alias="x-grant-type")
192
+ # x_refresh_endpoint: Optional[str] = Field(None, alias="x-refresh-endpoint")
193
+
194
+ @model_validator(mode="after")
195
+ def validate_security_scheme(self) -> "SecurityScheme":
196
+ """Validate that required fields are present based on security type."""
197
+ if self.type == "apiKey":
198
+ if not self.name or not self.in_:
199
+ raise ValueError("apiKey type requires 'name' and 'in' fields")
200
+ elif self.type == "http":
201
+ if not self.scheme:
202
+ raise ValueError("http type requires 'scheme' field")
203
+ elif self.type == "oauth2":
204
+ if not self.flows:
205
+ raise ValueError("oauth2 type requires 'flows' field")
206
+ elif self.type == "openIdConnect":
207
+ if not self.open_id_connect_url:
208
+ raise ValueError("openIdConnect type requires 'openIdConnectUrl' field")
209
+ return self
210
+
211
+
212
+ # SecurityRequirement is a dict mapping security scheme name to list of scopes
213
+ SecurityRequirement = Dict[str, List[str]]
@@ -0,0 +1,182 @@
1
+ """Secret handling utilities for the Airbyte SDK.
2
+
3
+ This module provides utilities for handling sensitive data like API keys, tokens,
4
+ and passwords. It uses Pydantic's SecretStr to ensure secrets are obfuscated in
5
+ logs, error messages, and string representations.
6
+
7
+ Example:
8
+ >>> from .secrets import SecretStr
9
+ >>> api_key = SecretStr("my-secret-key")
10
+ >>> print(api_key) # Outputs: **********
11
+ >>> print(repr(api_key)) # Outputs: SecretStr('**********')
12
+ >>> api_key.get_secret_value() # Returns: 'my-secret-key'
13
+ """
14
+
15
+ import os
16
+ import re
17
+ from typing import Any, Dict, Optional
18
+
19
+ from pydantic import SecretStr
20
+
21
+ __all__ = [
22
+ "SecretStr",
23
+ "convert_to_secret_dict",
24
+ "get_secret_values",
25
+ "resolve_env_var_references",
26
+ ]
27
+
28
+
29
+ def convert_to_secret_dict(secrets: Dict[str, str]) -> Dict[str, SecretStr]:
30
+ """Convert a dictionary of plain string secrets to SecretStr values.
31
+
32
+ Args:
33
+ secrets: Dictionary with string keys and plain string secret values
34
+
35
+ Returns:
36
+ Dictionary with string keys and SecretStr values
37
+
38
+ Example:
39
+ >>> plain_secrets = {"api_key": "secret123", "token": "token456"}
40
+ >>> secret_dict = convert_to_secret_dict(plain_secrets)
41
+ >>> print(secret_dict["api_key"]) # Outputs: **********
42
+ """
43
+ return {key: SecretStr(value) for key, value in secrets.items()}
44
+
45
+
46
+ def get_secret_values(secrets: Dict[str, SecretStr]) -> Dict[str, str]:
47
+ """Extract plain string values from a dictionary of SecretStr values.
48
+
49
+ Args:
50
+ secrets: Dictionary with string keys and SecretStr values
51
+
52
+ Returns:
53
+ Dictionary with string keys and plain string values
54
+
55
+ Warning:
56
+ Use with caution. This exposes the actual secret values.
57
+
58
+ Example:
59
+ >>> secret_dict = {"api_key": SecretStr("secret123")}
60
+ >>> plain_dict = get_secret_values(secret_dict)
61
+ >>> print(plain_dict["api_key"]) # Outputs: secret123
62
+ """
63
+ return {key: value.get_secret_value() for key, value in secrets.items()}
64
+
65
+
66
+ class SecretResolutionError(Exception):
67
+ """Raised when environment variable resolution fails."""
68
+
69
+ pass
70
+
71
+
72
+ def resolve_env_var_references(
73
+ secret_mappings: Dict[str, Any],
74
+ strict: bool = True,
75
+ env_vars: Optional[Dict[str, str]] = None,
76
+ ) -> Dict[str, str]:
77
+ """Resolve environment variable references in secret values.
78
+
79
+ This function processes a dictionary of secret mappings and resolves any
80
+ environment variable references using the ${ENV_VAR_NAME} syntax. All
81
+ environment variable references in the values will be replaced with their
82
+ actual values from the provided environment variable map or os.environ.
83
+
84
+ Args:
85
+ secret_mappings: Dictionary mapping secret keys to values that may contain
86
+ environment variable references (e.g., {"token": "${API_KEY}"})
87
+ strict: If True, raises SecretResolutionError when a referenced environment
88
+ variable is not found. If False, leaves unresolved references as-is.
89
+ env_vars: Optional dictionary of environment variables to use for resolution.
90
+ If None, uses os.environ.
91
+
92
+ Returns:
93
+ Dictionary with the same keys but environment variable references resolved
94
+ to their actual values as plain strings
95
+
96
+ Raises:
97
+ SecretResolutionError: When strict=True and a referenced environment variable
98
+ is not found or is empty
99
+ ValueError: When an environment variable name doesn't match valid naming
100
+ conventions (must start with letter or underscore, followed by
101
+ alphanumeric characters or underscores)
102
+
103
+ Example:
104
+ >>> import os
105
+ >>> os.environ["MY_TOKEN"] = "secret_value_123"
106
+ >>> mappings = {"token": "${MY_TOKEN}", "literal": "plain_value"}
107
+ >>> resolved = resolve_env_var_references(mappings)
108
+ >>> print(resolved)
109
+ {'token': 'secret_value_123', 'literal': 'plain_value'}
110
+
111
+ >>> # Using custom env_vars dict
112
+ >>> custom_env = {"CUSTOM_TOKEN": "my_secret"}
113
+ >>> mappings = {"token": "${CUSTOM_TOKEN}"}
114
+ >>> resolved = resolve_env_var_references(mappings, env_vars=custom_env)
115
+ >>> print(resolved)
116
+ {'token': 'my_secret'}
117
+
118
+ >>> # Multiple references in one value
119
+ >>> mappings = {"combined": "${PREFIX}_${SUFFIX}"}
120
+ >>> os.environ["PREFIX"] = "api"
121
+ >>> os.environ["SUFFIX"] = "key"
122
+ >>> resolved = resolve_env_var_references(mappings)
123
+ >>> print(resolved["combined"])
124
+ 'api_key'
125
+
126
+ >>> # Missing variable with strict=True (raises error)
127
+ >>> try:
128
+ ... resolve_env_var_references({"token": "${MISSING_VAR}"})
129
+ ... except SecretResolutionError as e:
130
+ ... print(f"Error: {e}")
131
+ Error: Environment variable 'MISSING_VAR' not found or empty
132
+
133
+ >>> # Missing variable with strict=False (keeps reference)
134
+ >>> resolved = resolve_env_var_references(
135
+ ... {"token": "${MISSING_VAR}"},
136
+ ... strict=False
137
+ ... )
138
+ >>> print(resolved["token"])
139
+ ${MISSING_VAR}
140
+ """
141
+ resolved = {}
142
+
143
+ # Use provided env_vars or default to os.environ
144
+ env_source = env_vars if env_vars is not None else os.environ
145
+
146
+ # Environment variable name pattern: starts with letter or underscore,
147
+ # followed by alphanumeric or underscores
148
+ env_var_pattern = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)\}")
149
+
150
+ for key, value in secret_mappings.items():
151
+ if isinstance(value, str):
152
+
153
+ def replacer(match: re.Match) -> str:
154
+ """Replace a single ${ENV_VAR} reference with its value."""
155
+ env_var_name = match.group(1)
156
+
157
+ # Validate environment variable name format
158
+ if not re.match(r"^[A-Za-z_][A-Za-z0-9_]*$", env_var_name):
159
+ raise ValueError(
160
+ f"Invalid environment variable name: '{env_var_name}'. "
161
+ "Must start with a letter or underscore, followed by "
162
+ "alphanumeric characters or underscores."
163
+ )
164
+
165
+ env_value = env_source.get(env_var_name)
166
+
167
+ if env_value is None or env_value == "":
168
+ if strict:
169
+ raise SecretResolutionError(f"Environment variable '{env_var_name}' not found or empty")
170
+ # In non-strict mode, keep the original reference
171
+ return match.group(0)
172
+
173
+ return env_value
174
+
175
+ # Replace all ${ENV_VAR} references in the value
176
+ resolved_value = env_var_pattern.sub(replacer, value)
177
+ resolved[key] = resolved_value
178
+ else:
179
+ # Non-string values are converted to strings
180
+ resolved[key] = str(value)
181
+
182
+ return resolved
@@ -0,0 +1,10 @@
1
+ """Telemetry tracking for Airbyte SDK."""
2
+
3
+ from .config import TelemetryConfig, TelemetryMode
4
+ from .tracker import SegmentTracker
5
+
6
+ __all__ = [
7
+ "TelemetryConfig",
8
+ "TelemetryMode",
9
+ "SegmentTracker",
10
+ ]