From 29331978e694455814833f1e21c9401bf71195f4 Mon Sep 17 00:00:00 2001 From: KshitijaChoudhari Date: Fri, 24 Oct 2025 12:05:51 +0530 Subject: [PATCH 1/2] Pythin TFE - Cleaned variable sets, reserved tag ssh key, registry and workspaces --- examples/variable_sets.py | 15 +++++++-------- src/pytfe/models/__init__.py | 12 +++++++++++- src/pytfe/resources/registry_module.py | 4 ++-- src/pytfe/resources/workspaces.py | 8 ++++---- src/pytfe/utils.py | 6 +++--- tests/units/test_reserved_tag_key.py | 8 ++++---- tests/units/test_ssh_keys.py | 8 ++++---- 7 files changed, 35 insertions(+), 26 deletions(-) diff --git a/examples/variable_sets.py b/examples/variable_sets.py index 85749f91..7c027cd3 100644 --- a/examples/variable_sets.py +++ b/examples/variable_sets.py @@ -15,10 +15,11 @@ import os -from pytfe.types import ( - CategoryType, +from pytfe import TFEClient, TFEConfig +from pytfe.models.project import Project +from pytfe.models.variable import CategoryType +from pytfe.models.variable_set import ( Parent, - Project, VariableSetApplyToProjectsOptions, VariableSetApplyToWorkspacesOptions, VariableSetCreateOptions, @@ -30,10 +31,8 @@ VariableSetVariableCreateOptions, VariableSetVariableListOptions, VariableSetVariableUpdateOptions, - Workspace, ) - -from pytfe import TFEClient, TFEConfig +from pytfe.models.workspace import Workspace def variable_set_example(): @@ -193,7 +192,7 @@ def variable_set_example(): print("7. Workspace operations example...") try: # List some workspaces first - from pytfe.types import WorkspaceListOptions + from pytfe.models.workspace import WorkspaceListOptions workspace_options = WorkspaceListOptions(page_size=5) workspaces = list( @@ -272,7 +271,7 @@ def variable_set_example(): # 9. Read the variable set with includes print("9. Reading variable set with includes...") - from pytfe.types import VariableSetReadOptions + from pytfe.models.variable_set import VariableSetReadOptions read_options = VariableSetReadOptions( include=[VariableSetIncludeOpt.VARS, VariableSetIncludeOpt.WORKSPACES] diff --git a/src/pytfe/models/__init__.py b/src/pytfe/models/__init__.py index b08b26b8..e20ce1b4 100644 --- a/src/pytfe/models/__init__.py +++ b/src/pytfe/models/__init__.py @@ -137,7 +137,13 @@ EnforcementLevel, PolicyKind, ) -from .project import Project +from .project import ( + Project, + ProjectAddTagBindingsOptions, + ProjectCreateOptions, + ProjectListOptions, + ProjectUpdateOptions, +) # ── Query Runs ──────────────────────────────────────────────────────────────── from .query_run import ( @@ -423,6 +429,10 @@ "OrganizationCreateOptions", "OrganizationUpdateOptions", "Project", + "ProjectAddTagBindingsOptions", + "ProjectCreateOptions", + "ProjectListOptions", + "ProjectUpdateOptions", "DataRetentionPolicy", "DataRetentionPolicyChoice", "DataRetentionPolicyDeleteOlder", diff --git a/src/pytfe/resources/registry_module.py b/src/pytfe/resources/registry_module.py index 8daf49e9..b65d4d8c 100644 --- a/src/pytfe/resources/registry_module.py +++ b/src/pytfe/resources/registry_module.py @@ -147,7 +147,7 @@ def create_with_vcs_connection( } } - # Determine the URL based on options - exactly like Go implementation + # Determine the URL based on options if options.vcs_repo.oauth_token_id and not options.vcs_repo.branch: path = "/api/v2/registry-modules" else: @@ -157,7 +157,7 @@ def create_with_vcs_connection( ) path = f"/api/v2/organizations/{options.vcs_repo.organization_name}/registry-modules/vcs" - # Validate agent execution mode like Go implementation + # Validate agent execution mode for API requirements if ( options.test_config and options.test_config.agent_execution_mode == AgentExecutionMode.REMOTE diff --git a/src/pytfe/resources/workspaces.py b/src/pytfe/resources/workspaces.py index 2f600b00..81b49f5f 100644 --- a/src/pytfe/resources/workspaces.py +++ b/src/pytfe/resources/workspaces.py @@ -576,7 +576,7 @@ def _build_workspace_payload( def delete(self, workspace: str, *, organization: str) -> None: """Delete workspace by organization and workspace name.""" - # Validate parameters (similar to Go implementation) + # Validate parameters for proper API usage if not valid_string_id(organization): raise InvalidOrgError() if not valid_string_id(workspace): @@ -588,7 +588,7 @@ def delete(self, workspace: str, *, organization: str) -> None: def delete_by_id(self, workspace_id: str) -> None: """Delete workspace by workspace ID.""" - # Validate parameters (similar to Go implementation) + # Validate parameters for proper API usage if not valid_string_id(workspace_id): raise InvalidWorkspaceIDError() @@ -596,7 +596,7 @@ def delete_by_id(self, workspace_id: str) -> None: def safe_delete(self, workspace: str, *, organization: str) -> None: """Safely delete workspace by organization and name.""" - # Validate parameters (similar to Go implementation) + # Validate parameters for proper API usage if not valid_string_id(organization): raise InvalidOrgError() if not valid_string_id(workspace): @@ -609,7 +609,7 @@ def safe_delete(self, workspace: str, *, organization: str) -> None: def safe_delete_by_id(self, workspace_id: str) -> None: """Safely delete workspace by workspace ID.""" - # Validate parameters (similar to Go implementation) + # Validate parameters for proper API usage if not valid_string_id(workspace_id): raise InvalidWorkspaceIDError() diff --git a/src/pytfe/utils.py b/src/pytfe/utils.py index 9adf58d3..d6e9b385 100644 --- a/src/pytfe/utils.py +++ b/src/pytfe/utils.py @@ -133,7 +133,7 @@ def has_tags_regex_defined(vcs_repo: VCSRepo | None) -> bool: def validate_workspace_create_options(options: WorkspaceCreateOptions) -> None: """ - Validate workspace create options similar to Go implementation. + Validate workspace create options for proper API usage. Raises specific validation errors if validation fails. """ # Check required name @@ -179,7 +179,7 @@ def validate_workspace_create_options(options: WorkspaceCreateOptions) -> None: def validate_workspace_update_options(options: WorkspaceUpdateOptions) -> None: """ - Validate workspace update options similar to Go implementation. + Validate workspace update options for proper API usage. Raises specific validation errors if validation fails. """ # Check name format if provided @@ -216,7 +216,7 @@ def validate_workspace_update_options(options: WorkspaceUpdateOptions) -> None: def validate_oauth_client_create_options(options: OAuthClientCreateOptions) -> None: """ - Validate OAuth client create options similar to Go implementation. + Validate OAuth client create options for proper API usage. Raises specific validation errors if validation fails. """ from .errors import ( diff --git a/tests/units/test_reserved_tag_key.py b/tests/units/test_reserved_tag_key.py index 12cbc50d..490a93a9 100644 --- a/tests/units/test_reserved_tag_key.py +++ b/tests/units/test_reserved_tag_key.py @@ -4,17 +4,17 @@ import pytest -from src.pytfe._http import HTTPTransport -from src.pytfe.errors import ( +from pytfe._http import HTTPTransport +from pytfe.errors import ( InvalidOrgError, ValidationError, ) -from src.pytfe.models.reserved_tag_key import ( +from pytfe.models.reserved_tag_key import ( ReservedTagKeyCreateOptions, ReservedTagKeyListOptions, ReservedTagKeyUpdateOptions, ) -from src.pytfe.resources.reserved_tag_key import ReservedTagKey +from pytfe.resources.reserved_tag_key import ReservedTagKey class TestReservedTagKeyParsing: diff --git a/tests/units/test_ssh_keys.py b/tests/units/test_ssh_keys.py index 057b9ac8..55008464 100644 --- a/tests/units/test_ssh_keys.py +++ b/tests/units/test_ssh_keys.py @@ -4,16 +4,16 @@ import pytest -from src.pytfe._http import HTTPTransport -from src.pytfe.errors import ( +from pytfe._http import HTTPTransport +from pytfe.errors import ( InvalidOrgError, InvalidSSHKeyIDError, ) -from src.pytfe.models.ssh_key import ( +from pytfe.models.ssh_key import ( SSHKeyCreateOptions, SSHKeyUpdateOptions, ) -from src.pytfe.resources.ssh_keys import SSHKeys +from pytfe.resources.ssh_keys import SSHKeys class TestSSHKeyParsing: From 8ef6f97ddb4d50d17a9f2367af85ea8fdd755c2d Mon Sep 17 00:00:00 2001 From: KshitijaChoudhari Date: Mon, 27 Oct 2025 10:19:59 +0530 Subject: [PATCH 2/2] Python TFE - Cleaned example-variable_sets --- examples/variable_sets.py | 14 ++++++------- src/pytfe/models/__init__.py | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/examples/variable_sets.py b/examples/variable_sets.py index 7c027cd3..4a6ca505 100644 --- a/examples/variable_sets.py +++ b/examples/variable_sets.py @@ -16,23 +16,25 @@ import os from pytfe import TFEClient, TFEConfig -from pytfe.models.project import Project -from pytfe.models.variable import CategoryType -from pytfe.models.variable_set import ( +from pytfe.models import ( + CategoryType, Parent, + Project, VariableSetApplyToProjectsOptions, VariableSetApplyToWorkspacesOptions, VariableSetCreateOptions, VariableSetIncludeOpt, VariableSetListOptions, + VariableSetReadOptions, VariableSetRemoveFromProjectsOptions, VariableSetRemoveFromWorkspacesOptions, VariableSetUpdateOptions, VariableSetVariableCreateOptions, VariableSetVariableListOptions, VariableSetVariableUpdateOptions, + Workspace, + WorkspaceListOptions, ) -from pytfe.models.workspace import Workspace def variable_set_example(): @@ -192,8 +194,6 @@ def variable_set_example(): print("7. Workspace operations example...") try: # List some workspaces first - from pytfe.models.workspace import WorkspaceListOptions - workspace_options = WorkspaceListOptions(page_size=5) workspaces = list( client.workspaces.list(org_name, options=workspace_options) @@ -271,8 +271,6 @@ def variable_set_example(): # 9. Read the variable set with includes print("9. Reading variable set with includes...") - from pytfe.models.variable_set import VariableSetReadOptions - read_options = VariableSetReadOptions( include=[VariableSetIncludeOpt.VARS, VariableSetIncludeOpt.WORKSPACES] ) diff --git a/src/pytfe/models/__init__.py b/src/pytfe/models/__init__.py index e20ce1b4..f3eb33bc 100644 --- a/src/pytfe/models/__init__.py +++ b/src/pytfe/models/__init__.py @@ -277,12 +277,33 @@ # Variables from .variable import ( + CategoryType, Variable, VariableCreateOptions, VariableListOptions, VariableUpdateOptions, ) +# ── Variable Sets ────────────────────────────────────────────────────────────── +from .variable_set import ( + Parent, + VariableSet, + VariableSetApplyToProjectsOptions, + VariableSetApplyToWorkspacesOptions, + VariableSetCreateOptions, + VariableSetIncludeOpt, + VariableSetListOptions, + VariableSetReadOptions, + VariableSetRemoveFromProjectsOptions, + VariableSetRemoveFromWorkspacesOptions, + VariableSetUpdateOptions, + VariableSetUpdateWorkspacesOptions, + VariableSetVariable, + VariableSetVariableCreateOptions, + VariableSetVariableListOptions, + VariableSetVariableUpdateOptions, +) + # Workspaces from .workspace import ( LockedByChoice, @@ -444,6 +465,7 @@ "Tag", "TagBinding", "TagList", + "CategoryType", "Variable", "VariableCreateOptions", "VariableListOptions", @@ -566,6 +588,23 @@ "PolicySetUpdateOptions", "PolicyKind", "EnforcementLevel", + # Variable Sets + "Parent", + "VariableSet", + "VariableSetApplyToProjectsOptions", + "VariableSetApplyToWorkspacesOptions", + "VariableSetCreateOptions", + "VariableSetIncludeOpt", + "VariableSetListOptions", + "VariableSetReadOptions", + "VariableSetRemoveFromProjectsOptions", + "VariableSetRemoveFromWorkspacesOptions", + "VariableSetUpdateOptions", + "VariableSetUpdateWorkspacesOptions", + "VariableSetVariable", + "VariableSetVariableCreateOptions", + "VariableSetVariableListOptions", + "VariableSetVariableUpdateOptions", ] # Rebuild models with forward references after all models are loaded