|
1 | 1 | """OAuth association resources.""" |
2 | 2 |
|
3 | | -from typing_extensions import List |
| 3 | +from __future__ import annotations |
4 | 4 |
|
5 | | -from ..context import Context |
6 | | -from ..resources import BaseResource, Resources |
| 5 | +from functools import partial |
| 6 | + |
| 7 | +from typing_extensions import TYPE_CHECKING, List, Optional |
| 8 | + |
| 9 | +from ..context import requires |
| 10 | +from ..resources import BaseResource, Resources, _matches_exact, _matches_pattern |
| 11 | + |
| 12 | +if TYPE_CHECKING: |
| 13 | + from ..context import Context |
| 14 | + from ..oauth import types |
7 | 15 |
|
8 | 16 |
|
9 | 17 | class Association(BaseResource): |
@@ -59,16 +67,71 @@ def find(self) -> List[Association]: |
59 | 67 | for result in response.json() |
60 | 68 | ] |
61 | 69 |
|
| 70 | + @requires("2025.07.0-dev") |
| 71 | + def find_by( |
| 72 | + self, |
| 73 | + integration_type: Optional[types.OAuthIntegrationType | str] = None, |
| 74 | + auth_type: Optional[types.OAuthIntegrationAuthType | str] = None, |
| 75 | + name: Optional[str] = None, |
| 76 | + description: Optional[str] = None, |
| 77 | + guid: Optional[str] = None, |
| 78 | + ) -> Association | None: |
| 79 | + """Find an OAuth integration associated with content by various criteria. |
| 80 | +
|
| 81 | + Parameters |
| 82 | + ---------- |
| 83 | + integration_type : Optional[types.OAuthIntegrationType | str] |
| 84 | + The type of the integration (e.g., "aws", "azure"). |
| 85 | + auth_type : Optional[types.OAuthIntegrationAuthType | str] |
| 86 | + The authentication type of the integration (e.g., "Viewer", "Service Account"). |
| 87 | + name : Optional[str] |
| 88 | + A regex pattern to match the integration name. For exact matches, use `^` and `$`. For example, |
| 89 | + `^My Integration$` will match only "My Integration". |
| 90 | + description : Optional[str] |
| 91 | + A regex pattern to match the integration description. For exact matches, use `^` and `$`. For example, |
| 92 | + `^My Integration Description$` will match only "My Integration Description". |
| 93 | + guid : Optional[str] |
| 94 | + The unique identifier of the integration. |
| 95 | +
|
| 96 | + Returns |
| 97 | + ------- |
| 98 | + Association | None |
| 99 | + The first matching association, or None if no match is found. |
| 100 | + """ |
| 101 | + filters = [] |
| 102 | + if integration_type is not None: |
| 103 | + filters.append( |
| 104 | + partial(_matches_exact, key="oauth_integration_template", value=integration_type) |
| 105 | + ) |
| 106 | + if auth_type is not None: |
| 107 | + filters.append( |
| 108 | + partial(_matches_exact, key="oauth_integration_auth_type", value=auth_type) |
| 109 | + ) |
| 110 | + if name is not None: |
| 111 | + filters.append(partial(_matches_pattern, key="oauth_integration_name", pattern=name)) |
| 112 | + if description is not None: |
| 113 | + filters.append( |
| 114 | + partial(_matches_pattern, key="oauth_integration_description", pattern=description) |
| 115 | + ) |
| 116 | + if guid is not None: |
| 117 | + filters.append(partial(_matches_exact, key="oauth_integration_guid", value=guid)) |
| 118 | + |
| 119 | + for association in self.find(): |
| 120 | + if all(f(association) for f in filters): |
| 121 | + return association |
| 122 | + |
| 123 | + return None |
| 124 | + |
62 | 125 | def delete(self) -> None: |
63 | 126 | """Delete integration associations.""" |
64 | 127 | data = [] |
65 | 128 |
|
66 | 129 | path = f"v1/content/{self.content_guid}/oauth/integrations/associations" |
67 | 130 | self._ctx.client.put(path, json=data) |
68 | 131 |
|
69 | | - def update(self, integration_guid: str) -> None: |
| 132 | + def update(self, integration_guids: list[str]) -> None: |
70 | 133 | """Set integration associations.""" |
71 | | - data = [{"oauth_integration_guid": integration_guid}] |
| 134 | + data = [{"oauth_integration_guid": guid} for guid in integration_guids] |
72 | 135 |
|
73 | 136 | path = f"v1/content/{self.content_guid}/oauth/integrations/associations" |
74 | 137 | self._ctx.client.put(path, json=data) |
0 commit comments