|
1 | 1 | """OAuth integration resources."""
|
2 | 2 |
|
3 |
| -from typing_extensions import List, Optional, overload |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import re |
| 6 | + |
| 7 | +from typing_extensions import TYPE_CHECKING, List, Optional, overload |
4 | 8 |
|
5 | 9 | from ..resources import BaseResource, Resources
|
6 | 10 | from .associations import IntegrationAssociations
|
7 | 11 |
|
| 12 | +if TYPE_CHECKING: |
| 13 | + from ..oauth import types |
| 14 | + |
8 | 15 |
|
9 | 16 | class Integration(BaseResource):
|
10 | 17 | """OAuth integration resource."""
|
@@ -118,6 +125,71 @@ def find(self) -> List[Integration]:
|
118 | 125 | for result in response.json()
|
119 | 126 | ]
|
120 | 127 |
|
| 128 | + # TODO turn this on before merging |
| 129 | + # @requires("2025.07.0") |
| 130 | + def find_by( |
| 131 | + self, |
| 132 | + integration_type: Optional[types.OAuthIntegrationType] = None, |
| 133 | + auth_type: Optional[types.OAuthIntegrationAuthType] = None, |
| 134 | + name: Optional[str] = None, |
| 135 | + description: Optional[str] = None, |
| 136 | + guid: Optional[str] = None, |
| 137 | + config: Optional[dict] = None, |
| 138 | + ) -> Integration | None: |
| 139 | + """Find an OAuth integration by various criteria. |
| 140 | +
|
| 141 | + Parameters |
| 142 | + ---------- |
| 143 | + integration_type : Optional[types.OAuthIntegrationType] |
| 144 | + The type of the integration (e.g., "aws", "azure"). |
| 145 | + auth_type : Optional[types.OAuthIntegrationAuthType] |
| 146 | + The authentication type of the integration (e.g., "Viewer", "Service Account"). |
| 147 | + name : Optional[str] |
| 148 | + A regex pattern to match the integration name. |
| 149 | + description : Optional[str] |
| 150 | + A regex pattern to match the integration description. |
| 151 | + guid : Optional[str] |
| 152 | + The unique identifier of the integration. |
| 153 | + config : Optional[dict] |
| 154 | + A dictionary of configuration key-value pairs to match against the integration's config. This will |
| 155 | + vary based on the integration type. |
| 156 | +
|
| 157 | + Returns |
| 158 | + ------- |
| 159 | + Integration | None |
| 160 | + The first matching integration, or None if no match is found. |
| 161 | + """ |
| 162 | + for integration in self.find(): |
| 163 | + match = True |
| 164 | + |
| 165 | + if integration_type is not None and integration.get("template") != integration_type: |
| 166 | + match = False |
| 167 | + |
| 168 | + if auth_type is not None and integration.get("auth_type") != auth_type: |
| 169 | + match = False |
| 170 | + |
| 171 | + if name is not None: |
| 172 | + integration_name = integration.get("name", "") |
| 173 | + if not re.search(name, integration_name): |
| 174 | + match = False |
| 175 | + |
| 176 | + if description is not None: |
| 177 | + integration_description = integration.get("description", "") |
| 178 | + if not re.search(description, integration_description): |
| 179 | + match = False |
| 180 | + |
| 181 | + if guid is not None and integration.get("guid") != guid: |
| 182 | + match = False |
| 183 | + |
| 184 | + if config is not None: |
| 185 | + integration_config = integration.get("config", {}) |
| 186 | + if not all(integration_config.get(k) == v for k, v in config.items()): |
| 187 | + match = False |
| 188 | + |
| 189 | + if match: |
| 190 | + return integration |
| 191 | + return None |
| 192 | + |
121 | 193 | def get(self, guid: str) -> Integration:
|
122 | 194 | """Get an OAuth integration.
|
123 | 195 |
|
|
0 commit comments