Skip to content

Commit 2933197

Browse files
Pythin TFE - Cleaned variable sets, reserved tag ssh key, registry and workspaces
1 parent d5c4aa9 commit 2933197

7 files changed

Lines changed: 35 additions & 26 deletions

File tree

examples/variable_sets.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515

1616
import os
1717

18-
from pytfe.types import (
19-
CategoryType,
18+
from pytfe import TFEClient, TFEConfig
19+
from pytfe.models.project import Project
20+
from pytfe.models.variable import CategoryType
21+
from pytfe.models.variable_set import (
2022
Parent,
21-
Project,
2223
VariableSetApplyToProjectsOptions,
2324
VariableSetApplyToWorkspacesOptions,
2425
VariableSetCreateOptions,
@@ -30,10 +31,8 @@
3031
VariableSetVariableCreateOptions,
3132
VariableSetVariableListOptions,
3233
VariableSetVariableUpdateOptions,
33-
Workspace,
3434
)
35-
36-
from pytfe import TFEClient, TFEConfig
35+
from pytfe.models.workspace import Workspace
3736

3837

3938
def variable_set_example():
@@ -193,7 +192,7 @@ def variable_set_example():
193192
print("7. Workspace operations example...")
194193
try:
195194
# List some workspaces first
196-
from pytfe.types import WorkspaceListOptions
195+
from pytfe.models.workspace import WorkspaceListOptions
197196

198197
workspace_options = WorkspaceListOptions(page_size=5)
199198
workspaces = list(
@@ -272,7 +271,7 @@ def variable_set_example():
272271

273272
# 9. Read the variable set with includes
274273
print("9. Reading variable set with includes...")
275-
from pytfe.types import VariableSetReadOptions
274+
from pytfe.models.variable_set import VariableSetReadOptions
276275

277276
read_options = VariableSetReadOptions(
278277
include=[VariableSetIncludeOpt.VARS, VariableSetIncludeOpt.WORKSPACES]

src/pytfe/models/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,13 @@
137137
EnforcementLevel,
138138
PolicyKind,
139139
)
140-
from .project import Project
140+
from .project import (
141+
Project,
142+
ProjectAddTagBindingsOptions,
143+
ProjectCreateOptions,
144+
ProjectListOptions,
145+
ProjectUpdateOptions,
146+
)
141147

142148
# ── Query Runs ────────────────────────────────────────────────────────────────
143149
from .query_run import (
@@ -423,6 +429,10 @@
423429
"OrganizationCreateOptions",
424430
"OrganizationUpdateOptions",
425431
"Project",
432+
"ProjectAddTagBindingsOptions",
433+
"ProjectCreateOptions",
434+
"ProjectListOptions",
435+
"ProjectUpdateOptions",
426436
"DataRetentionPolicy",
427437
"DataRetentionPolicyChoice",
428438
"DataRetentionPolicyDeleteOlder",

src/pytfe/resources/registry_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def create_with_vcs_connection(
147147
}
148148
}
149149

150-
# Determine the URL based on options - exactly like Go implementation
150+
# Determine the URL based on options
151151
if options.vcs_repo.oauth_token_id and not options.vcs_repo.branch:
152152
path = "/api/v2/registry-modules"
153153
else:
@@ -157,7 +157,7 @@ def create_with_vcs_connection(
157157
)
158158
path = f"/api/v2/organizations/{options.vcs_repo.organization_name}/registry-modules/vcs"
159159

160-
# Validate agent execution mode like Go implementation
160+
# Validate agent execution mode for API requirements
161161
if (
162162
options.test_config
163163
and options.test_config.agent_execution_mode == AgentExecutionMode.REMOTE

src/pytfe/resources/workspaces.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def _build_workspace_payload(
576576

577577
def delete(self, workspace: str, *, organization: str) -> None:
578578
"""Delete workspace by organization and workspace name."""
579-
# Validate parameters (similar to Go implementation)
579+
# Validate parameters for proper API usage
580580
if not valid_string_id(organization):
581581
raise InvalidOrgError()
582582
if not valid_string_id(workspace):
@@ -588,15 +588,15 @@ def delete(self, workspace: str, *, organization: str) -> None:
588588

589589
def delete_by_id(self, workspace_id: str) -> None:
590590
"""Delete workspace by workspace ID."""
591-
# Validate parameters (similar to Go implementation)
591+
# Validate parameters for proper API usage
592592
if not valid_string_id(workspace_id):
593593
raise InvalidWorkspaceIDError()
594594

595595
self.t.request("DELETE", f"/api/v2/workspaces/{workspace_id}")
596596

597597
def safe_delete(self, workspace: str, *, organization: str) -> None:
598598
"""Safely delete workspace by organization and name."""
599-
# Validate parameters (similar to Go implementation)
599+
# Validate parameters for proper API usage
600600
if not valid_string_id(organization):
601601
raise InvalidOrgError()
602602
if not valid_string_id(workspace):
@@ -609,7 +609,7 @@ def safe_delete(self, workspace: str, *, organization: str) -> None:
609609

610610
def safe_delete_by_id(self, workspace_id: str) -> None:
611611
"""Safely delete workspace by workspace ID."""
612-
# Validate parameters (similar to Go implementation)
612+
# Validate parameters for proper API usage
613613
if not valid_string_id(workspace_id):
614614
raise InvalidWorkspaceIDError()
615615

src/pytfe/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def has_tags_regex_defined(vcs_repo: VCSRepo | None) -> bool:
133133

134134
def validate_workspace_create_options(options: WorkspaceCreateOptions) -> None:
135135
"""
136-
Validate workspace create options similar to Go implementation.
136+
Validate workspace create options for proper API usage.
137137
Raises specific validation errors if validation fails.
138138
"""
139139
# Check required name
@@ -179,7 +179,7 @@ def validate_workspace_create_options(options: WorkspaceCreateOptions) -> None:
179179

180180
def validate_workspace_update_options(options: WorkspaceUpdateOptions) -> None:
181181
"""
182-
Validate workspace update options similar to Go implementation.
182+
Validate workspace update options for proper API usage.
183183
Raises specific validation errors if validation fails.
184184
"""
185185
# Check name format if provided
@@ -216,7 +216,7 @@ def validate_workspace_update_options(options: WorkspaceUpdateOptions) -> None:
216216

217217
def validate_oauth_client_create_options(options: OAuthClientCreateOptions) -> None:
218218
"""
219-
Validate OAuth client create options similar to Go implementation.
219+
Validate OAuth client create options for proper API usage.
220220
Raises specific validation errors if validation fails.
221221
"""
222222
from .errors import (

tests/units/test_reserved_tag_key.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
import pytest
66

7-
from src.pytfe._http import HTTPTransport
8-
from src.pytfe.errors import (
7+
from pytfe._http import HTTPTransport
8+
from pytfe.errors import (
99
InvalidOrgError,
1010
ValidationError,
1111
)
12-
from src.pytfe.models.reserved_tag_key import (
12+
from pytfe.models.reserved_tag_key import (
1313
ReservedTagKeyCreateOptions,
1414
ReservedTagKeyListOptions,
1515
ReservedTagKeyUpdateOptions,
1616
)
17-
from src.pytfe.resources.reserved_tag_key import ReservedTagKey
17+
from pytfe.resources.reserved_tag_key import ReservedTagKey
1818

1919

2020
class TestReservedTagKeyParsing:

tests/units/test_ssh_keys.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
import pytest
66

7-
from src.pytfe._http import HTTPTransport
8-
from src.pytfe.errors import (
7+
from pytfe._http import HTTPTransport
8+
from pytfe.errors import (
99
InvalidOrgError,
1010
InvalidSSHKeyIDError,
1111
)
12-
from src.pytfe.models.ssh_key import (
12+
from pytfe.models.ssh_key import (
1313
SSHKeyCreateOptions,
1414
SSHKeyUpdateOptions,
1515
)
16-
from src.pytfe.resources.ssh_keys import SSHKeys
16+
from pytfe.resources.ssh_keys import SSHKeys
1717

1818

1919
class TestSSHKeyParsing:

0 commit comments

Comments
 (0)