|
| 1 | +""" |
| 2 | +Copyright (c) 2025, Oracle and/or its affiliates. |
| 3 | +Licensed under the Universal Permissive License v1.0 as shown at |
| 4 | +https://oss.oracle.com/licenses/upl. |
| 5 | +""" |
| 6 | + |
| 7 | +from datetime import datetime |
| 8 | +from typing import Any, Dict, Literal, Optional |
| 9 | + |
| 10 | +import oci |
| 11 | +from pydantic import BaseModel, Field |
| 12 | + |
| 13 | + |
| 14 | +def _oci_to_dict(obj): |
| 15 | + """Best-effort conversion of OCI SDK model objects to plain dicts.""" |
| 16 | + if obj is None: |
| 17 | + return None |
| 18 | + try: |
| 19 | + from oci.util import to_dict as oci_to_dict |
| 20 | + |
| 21 | + return oci_to_dict(obj) |
| 22 | + except Exception: |
| 23 | + pass |
| 24 | + if isinstance(obj, dict): |
| 25 | + return obj |
| 26 | + if hasattr(obj, "__dict__"): |
| 27 | + return {k: v for k, v in obj.__dict__.items() if not k.startswith("_")} |
| 28 | + return None |
| 29 | + |
| 30 | + |
| 31 | +# region Compartment |
| 32 | + |
| 33 | + |
| 34 | +class Compartment(BaseModel): |
| 35 | + """ |
| 36 | + Pydantic model mirroring the fields of oci.identity.models.Compartment. |
| 37 | + There are no nested OCI model types in this class. |
| 38 | + """ |
| 39 | + |
| 40 | + id: Optional[str] = Field(None, description="The OCID of the compartment.") |
| 41 | + compartment_id: Optional[str] = Field( |
| 42 | + None, |
| 43 | + description="The OCID of the parent compartment " |
| 44 | + "(remember that the tenancy is simply the root compartment).", |
| 45 | + ) |
| 46 | + name: Optional[str] = Field( |
| 47 | + None, |
| 48 | + description="The name you assign to the compartment during creation. " |
| 49 | + "The name must be unique across all compartments in the parent. " |
| 50 | + "Avoid entering confidential information.", |
| 51 | + ) |
| 52 | + description: Optional[str] = Field( |
| 53 | + None, |
| 54 | + description="The description you assign to the compartment. " |
| 55 | + "Does not have to be unique, and it's changeable.", |
| 56 | + ) |
| 57 | + time_created: Optional[datetime] = Field( |
| 58 | + None, |
| 59 | + description="Date and time the compartment was created, in the format " |
| 60 | + "defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`", |
| 61 | + ) |
| 62 | + lifecycle_state: Optional[ |
| 63 | + Literal["CREATING", "ACTIVE", "INACTIVE", "DELETING", "DELETED", "FAILED"] |
| 64 | + ] = Field(None, description="The compartment's current state.") |
| 65 | + inactive_status: Optional[int] = Field( |
| 66 | + None, description="The detailed status of INACTIVE lifecycleState." |
| 67 | + ) |
| 68 | + freeform_tags: Optional[Dict[str, str]] = Field( |
| 69 | + None, |
| 70 | + description='Free-form tags for this resource. Each tag is a simple key-value pair with "' |
| 71 | + '"no predefined name, type, or namespace. For more information, see "' |
| 72 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 73 | + '"Example: `{"Department": "Finance"}`', |
| 74 | + ) |
| 75 | + defined_tags: Optional[Dict[str, Dict[str, Any]]] = Field( |
| 76 | + None, |
| 77 | + description='Defined tags for this resource. Each key is predefined and scoped to a namespace. "' |
| 78 | + '"For more information, see "' |
| 79 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 80 | + '"Example: `{"Operations": {"CostCenter": "42"}}`', |
| 81 | + ) |
| 82 | + |
| 83 | + |
| 84 | +def map_compartment(compartment_data: oci.identity.models.Compartment) -> Compartment: |
| 85 | + """ |
| 86 | + Convert an oci.identity.models.Compartment to oracle.oci_identity_mcp_server.models.Compartment. |
| 87 | + """ |
| 88 | + return Compartment( |
| 89 | + id=getattr(compartment_data, "id", None), |
| 90 | + compartment_id=getattr(compartment_data, "compartment_id", None), |
| 91 | + name=getattr(compartment_data, "name", None), |
| 92 | + description=getattr(compartment_data, "description", None), |
| 93 | + time_created=getattr(compartment_data, "time_created", None), |
| 94 | + lifecycle_state=getattr(compartment_data, "lifecycle_state", None), |
| 95 | + inactive_status=getattr(compartment_data, "inactive_status", None), |
| 96 | + freeform_tags=getattr(compartment_data, "freeform_tags", None), |
| 97 | + defined_tags=getattr(compartment_data, "defined_tags", None), |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +# end region |
| 102 | + |
| 103 | +# region Tenancy |
| 104 | + |
| 105 | + |
| 106 | +class Tenancy(BaseModel): |
| 107 | + """ |
| 108 | + Pydantic model mirroring the fields of oci.identity.models.Tenancy. |
| 109 | + There are no nested OCI model types in this class. |
| 110 | + """ |
| 111 | + |
| 112 | + id: Optional[str] = Field(None, description="The OCID of the tenancy.") |
| 113 | + name: Optional[str] = Field(None, description="The name of the tenancy.") |
| 114 | + description: Optional[str] = Field( |
| 115 | + None, description="The description of the tenancy." |
| 116 | + ) |
| 117 | + home_region_key: Optional[str] = Field( |
| 118 | + None, description="The region key for the tenancy's home region." |
| 119 | + ) |
| 120 | + freeform_tags: Optional[Dict[str, str]] = Field( |
| 121 | + None, |
| 122 | + description='Free-form tags for this resource. Each tag is a simple key-value pair with "' |
| 123 | + '"no predefined name, type, or namespace. For more information, see "' |
| 124 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 125 | + '"Example: `{"Department": "Finance"}`', |
| 126 | + ) |
| 127 | + defined_tags: Optional[Dict[str, Dict[str, Any]]] = Field( |
| 128 | + None, |
| 129 | + description='Defined tags for this resource. Each key is predefined and scoped to a namespace. "' |
| 130 | + '"For more information, see "' |
| 131 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 132 | + '"Example: `{"Operations": {"CostCenter": "42"}}`', |
| 133 | + ) |
| 134 | + |
| 135 | + |
| 136 | +def map_tenancy(tenancy_data: oci.identity.models.Tenancy) -> Tenancy: |
| 137 | + """ |
| 138 | + Convert an oci.identity.models.Tenancy to oracle.oci_identity_mcp_server.models.Tenancy. |
| 139 | + """ |
| 140 | + return Tenancy( |
| 141 | + id=getattr(tenancy_data, "id", None), |
| 142 | + name=getattr(tenancy_data, "name", None), |
| 143 | + description=getattr(tenancy_data, "description", None), |
| 144 | + home_region_key=getattr(tenancy_data, "home_region_key", None), |
| 145 | + freeform_tags=getattr(tenancy_data, "freeform_tags", None), |
| 146 | + defined_tags=getattr(tenancy_data, "defined_tags", None), |
| 147 | + ) |
| 148 | + |
| 149 | + |
| 150 | +# endregion |
| 151 | + |
| 152 | +# region AvailabilityDomain |
| 153 | + |
| 154 | + |
| 155 | +class AvailabilityDomain(BaseModel): |
| 156 | + """ |
| 157 | + Pydantic model mirroring the fields of oci.identity.models.AvailabilityDomain. |
| 158 | + There are no nested OCI model types in this class. |
| 159 | + """ |
| 160 | + |
| 161 | + id: Optional[str] = Field(None, description="The OCID of the Availability Domain.") |
| 162 | + name: Optional[str] = Field( |
| 163 | + None, description="The name of the Availability Domain." |
| 164 | + ) |
| 165 | + compartment_id: Optional[str] = Field( |
| 166 | + None, description="The OCID of the tenancy containing the Availability Domain." |
| 167 | + ) |
| 168 | + |
| 169 | + |
| 170 | +def map_availability_domain( |
| 171 | + availability_domain_data: oci.identity.models.AvailabilityDomain, |
| 172 | +) -> AvailabilityDomain: |
| 173 | + """ |
| 174 | + Convert an oci.identity.models.AvailabilityDomain to |
| 175 | + oracle.oci_identity_mcp_server.models.AvailabilityDomain. |
| 176 | + """ |
| 177 | + return AvailabilityDomain( |
| 178 | + id=getattr(availability_domain_data, "id", None), |
| 179 | + name=getattr(availability_domain_data, "name", None), |
| 180 | + compartment_id=getattr(availability_domain_data, "compartment_id", None), |
| 181 | + ) |
| 182 | + |
| 183 | + |
| 184 | +# end region |
| 185 | + |
| 186 | +# region AuthToken |
| 187 | + |
| 188 | + |
| 189 | +class AuthToken(BaseModel): |
| 190 | + """ |
| 191 | + Pydantic model mirroring the fields of oci.identity.models.AuthToken. |
| 192 | + There are no nested OCI model types in this class. |
| 193 | + """ |
| 194 | + |
| 195 | + id: Optional[str] = Field(None, description="The OCID of the auth token.") |
| 196 | + token: Optional[str] = Field(None, description="The raw auth token string.") |
| 197 | + user_id: Optional[str] = Field( |
| 198 | + None, description="The OCID of the user the password belongs to." |
| 199 | + ) |
| 200 | + description: Optional[str] = Field( |
| 201 | + None, |
| 202 | + description="The description you assign to the auth token. " |
| 203 | + "Does not have to be unique, and it's changeable.", |
| 204 | + ) |
| 205 | + time_created: Optional[datetime] = Field( |
| 206 | + None, |
| 207 | + description="Date and time the auth token was created, in the format " |
| 208 | + "defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`", |
| 209 | + ) |
| 210 | + time_expires: Optional[datetime] = Field( |
| 211 | + None, |
| 212 | + description="Date and time when this auth token will expire, in the format " |
| 213 | + "defined by RFC3339. Example: `2016-08-25T21:10:29.600Z`", |
| 214 | + ) |
| 215 | + lifecycle_state: Optional[ |
| 216 | + Literal["CREATING", "ACTIVE", "INACTIVE", "DELETING", "DELETED"] |
| 217 | + ] = Field(None, description="The auth token's current state.") |
| 218 | + inactive_status: Optional[int] = Field( |
| 219 | + None, description="The detailed status of INACTIVE lifecycleState." |
| 220 | + ) |
| 221 | + freeform_tags: Optional[Dict[str, str]] = Field( |
| 222 | + None, |
| 223 | + description='Free-form tags for this resource. Each tag is a simple key-value pair with "' |
| 224 | + '"no predefined name, type, or namespace. For more information, see "' |
| 225 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 226 | + '"Example: `{"Department": "Finance"}`', |
| 227 | + ) |
| 228 | + defined_tags: Optional[Dict[str, Dict[str, Any]]] = Field( |
| 229 | + None, |
| 230 | + description='Defined tags for this resource. Each key is predefined and scoped to a namespace. "' |
| 231 | + '"For more information, see "' |
| 232 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 233 | + '"Example: `{"Operations": {"CostCenter": "42"}}`', |
| 234 | + ) |
| 235 | + |
| 236 | + |
| 237 | +def map_auth_token(auth_token_data: oci.identity.models.AuthToken) -> AuthToken: |
| 238 | + """ |
| 239 | + Convert an oci.identity.models.AuthToken to oracle.oci_identity_mcp_server.models.AuthToken. |
| 240 | + """ |
| 241 | + return AuthToken( |
| 242 | + id=getattr(auth_token_data, "id", None), |
| 243 | + token=getattr(auth_token_data, "token", None), |
| 244 | + user_id=getattr(auth_token_data, "user_id", None), |
| 245 | + description=getattr(auth_token_data, "description", None), |
| 246 | + time_created=getattr(auth_token_data, "time_created", None), |
| 247 | + time_expires=getattr(auth_token_data, "time_expires", None), |
| 248 | + lifecycle_state=getattr(auth_token_data, "lifecycle_state", None), |
| 249 | + inactive_status=getattr(auth_token_data, "inactive_status", None), |
| 250 | + freeform_tags=getattr(auth_token_data, "freeform_tags", None), |
| 251 | + defined_tags=getattr(auth_token_data, "defined_tags", None), |
| 252 | + ) |
| 253 | + |
| 254 | + |
| 255 | +# endregion |
| 256 | + |
| 257 | +# region User |
| 258 | + |
| 259 | + |
| 260 | +class User(BaseModel): |
| 261 | + """ |
| 262 | + Pydantic model mirroring the fields of oci.identity.models.User. |
| 263 | + There are no nested OCI model types in this class. |
| 264 | + """ |
| 265 | + |
| 266 | + id: Optional[str] = Field(None, description="The OCID of the user.") |
| 267 | + compartment_id: Optional[str] = Field( |
| 268 | + None, description="The OCID of the tenancy containing the user." |
| 269 | + ) |
| 270 | + name: Optional[str] = Field( |
| 271 | + None, |
| 272 | + description="The name you assign to the user during creation. " |
| 273 | + "This is the user's login value. The name must be unique " |
| 274 | + "across all users in the tenancy and cannot be changed.", |
| 275 | + ) |
| 276 | + description: Optional[str] = Field( |
| 277 | + None, |
| 278 | + description="The description you assign to the user. " |
| 279 | + "Does not have to be unique, and it's changeable.", |
| 280 | + ) |
| 281 | + email: Optional[str] = Field(None, description="The email address of the user.") |
| 282 | + email_verified: Optional[bool] = Field( |
| 283 | + None, description="Whether the email address has been validated." |
| 284 | + ) |
| 285 | + db_user_name: Optional[str] = Field( |
| 286 | + None, |
| 287 | + description="DB username of the DB credential. Has to be unique across the tenancy.", |
| 288 | + ) |
| 289 | + identity_provider_id: Optional[str] = Field( |
| 290 | + None, description="The OCID of the IdentityProvider this user belongs to." |
| 291 | + ) |
| 292 | + external_identifier: Optional[str] = Field( |
| 293 | + None, description="Identifier of the user in the identity provider" |
| 294 | + ) |
| 295 | + time_created: Optional[datetime] = Field( |
| 296 | + None, |
| 297 | + description="Date and time the user was created, in the format defined by RFC3339. " |
| 298 | + "Example: `2016-08-25T21:10:29.600Z`", |
| 299 | + ) |
| 300 | + lifecycle_state: Optional[ |
| 301 | + Literal["CREATING", "ACTIVE", "INACTIVE", "DELETING", "DELETED"] |
| 302 | + ] = Field(None, description="The user's current state.") |
| 303 | + inactive_status: Optional[int] = Field( |
| 304 | + None, |
| 305 | + description="Returned only if the user's `lifecycleState` is INACTIVE. " |
| 306 | + "A 16-bit value showing the reason why the user is inactive: " |
| 307 | + "- bit 0: SUSPENDED (reserved for future use) " |
| 308 | + "- bit 1: DISABLED (reserved for future use) " |
| 309 | + "- bit 2: BLOCKED (the user has exceeded the maximum number of " |
| 310 | + "failed login attempts for the Console)", |
| 311 | + ) |
| 312 | + freeform_tags: Optional[Dict[str, str]] = Field( |
| 313 | + None, |
| 314 | + description='Free-form tags for this resource. Each tag is a simple key-value pair with "' |
| 315 | + '"no predefined name, type, or namespace. For more information, see "' |
| 316 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 317 | + '"Example: `{"Department": "Finance"}`', |
| 318 | + ) |
| 319 | + defined_tags: Optional[Dict[str, Dict[str, Any]]] = Field( |
| 320 | + None, |
| 321 | + description='Defined tags for this resource. Each key is predefined and scoped to a namespace. "' |
| 322 | + '"For more information, see "' |
| 323 | + '"[Resource Tags](https://docs.cloud.oracle.com/Content/General/Concepts/resourcetags.htm). "' |
| 324 | + '"Example: `{"Operations": {"CostCenter": "42"}}`', |
| 325 | + ) |
| 326 | + is_mfa_activated: Optional[bool] = Field( |
| 327 | + None, |
| 328 | + description="Indicates whether the user has activated multi-factor authentication.", |
| 329 | + ) |
| 330 | + |
| 331 | + |
| 332 | +def map_user(user_data: oci.identity.models.User) -> User: |
| 333 | + """ |
| 334 | + Convert an oci.identity.models.User to oracle.oci_identity_mcp_server.models.User. |
| 335 | + """ |
| 336 | + return User( |
| 337 | + id=getattr(user_data, "id", None), |
| 338 | + compartment_id=getattr(user_data, "compartment_id", None), |
| 339 | + name=getattr(user_data, "name", None), |
| 340 | + description=getattr(user_data, "description", None), |
| 341 | + email=getattr(user_data, "email", None), |
| 342 | + email_verified=getattr(user_data, "email_verified", None), |
| 343 | + db_user_name=getattr(user_data, "db_user_name", None), |
| 344 | + identity_provider_id=getattr(user_data, "identity_provider_id", None), |
| 345 | + external_identifier=getattr(user_data, "external_identifier", None), |
| 346 | + time_created=getattr(user_data, "time_created", None), |
| 347 | + lifecycle_state=getattr(user_data, "lifecycle_state", None), |
| 348 | + inactive_status=getattr(user_data, "inactive_status", None), |
| 349 | + freeform_tags=getattr(user_data, "freeform_tags", None), |
| 350 | + defined_tags=getattr(user_data, "defined_tags", None), |
| 351 | + is_mfa_activated=getattr(user_data, "is_mfa_activated", None), |
| 352 | + ) |
| 353 | + |
| 354 | + |
| 355 | +# endregion |
0 commit comments