Skip to content

Commit 9aba767

Browse files
Pythin TFE - Cleaned variable sets, reserved tag ssh key, registry a… (#49)
Cleaned variable sets, reserved tag ssh key, registry and workspaces
1 parent d5c4aa9 commit 9aba767

File tree

7 files changed

+71
-25
lines changed

7 files changed

+71
-25
lines changed

examples/variable_sets.py

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

1616
import os
1717

18-
from pytfe.types import (
18+
from pytfe import TFEClient, TFEConfig
19+
from pytfe.models import (
1920
CategoryType,
2021
Parent,
2122
Project,
@@ -24,17 +25,17 @@
2425
VariableSetCreateOptions,
2526
VariableSetIncludeOpt,
2627
VariableSetListOptions,
28+
VariableSetReadOptions,
2729
VariableSetRemoveFromProjectsOptions,
2830
VariableSetRemoveFromWorkspacesOptions,
2931
VariableSetUpdateOptions,
3032
VariableSetVariableCreateOptions,
3133
VariableSetVariableListOptions,
3234
VariableSetVariableUpdateOptions,
3335
Workspace,
36+
WorkspaceListOptions,
3437
)
3538

36-
from pytfe import TFEClient, TFEConfig
37-
3839

3940
def variable_set_example():
4041
"""Demonstrate Variable Set operations."""
@@ -193,8 +194,6 @@ def variable_set_example():
193194
print("7. Workspace operations example...")
194195
try:
195196
# List some workspaces first
196-
from pytfe.types import WorkspaceListOptions
197-
198197
workspace_options = WorkspaceListOptions(page_size=5)
199198
workspaces = list(
200199
client.workspaces.list(org_name, options=workspace_options)
@@ -272,8 +271,6 @@ 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
276-
277274
read_options = VariableSetReadOptions(
278275
include=[VariableSetIncludeOpt.VARS, VariableSetIncludeOpt.WORKSPACES]
279276
)

src/pytfe/models/__init__.py

Lines changed: 50 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 (
@@ -271,12 +277,33 @@
271277

272278
# Variables
273279
from .variable import (
280+
CategoryType,
274281
Variable,
275282
VariableCreateOptions,
276283
VariableListOptions,
277284
VariableUpdateOptions,
278285
)
279286

287+
# ── Variable Sets ──────────────────────────────────────────────────────────────
288+
from .variable_set import (
289+
Parent,
290+
VariableSet,
291+
VariableSetApplyToProjectsOptions,
292+
VariableSetApplyToWorkspacesOptions,
293+
VariableSetCreateOptions,
294+
VariableSetIncludeOpt,
295+
VariableSetListOptions,
296+
VariableSetReadOptions,
297+
VariableSetRemoveFromProjectsOptions,
298+
VariableSetRemoveFromWorkspacesOptions,
299+
VariableSetUpdateOptions,
300+
VariableSetUpdateWorkspacesOptions,
301+
VariableSetVariable,
302+
VariableSetVariableCreateOptions,
303+
VariableSetVariableListOptions,
304+
VariableSetVariableUpdateOptions,
305+
)
306+
280307
# Workspaces
281308
from .workspace import (
282309
LockedByChoice,
@@ -423,6 +450,10 @@
423450
"OrganizationCreateOptions",
424451
"OrganizationUpdateOptions",
425452
"Project",
453+
"ProjectAddTagBindingsOptions",
454+
"ProjectCreateOptions",
455+
"ProjectListOptions",
456+
"ProjectUpdateOptions",
426457
"DataRetentionPolicy",
427458
"DataRetentionPolicyChoice",
428459
"DataRetentionPolicyDeleteOlder",
@@ -434,6 +465,7 @@
434465
"Tag",
435466
"TagBinding",
436467
"TagList",
468+
"CategoryType",
437469
"Variable",
438470
"VariableCreateOptions",
439471
"VariableListOptions",
@@ -556,6 +588,23 @@
556588
"PolicySetUpdateOptions",
557589
"PolicyKind",
558590
"EnforcementLevel",
591+
# Variable Sets
592+
"Parent",
593+
"VariableSet",
594+
"VariableSetApplyToProjectsOptions",
595+
"VariableSetApplyToWorkspacesOptions",
596+
"VariableSetCreateOptions",
597+
"VariableSetIncludeOpt",
598+
"VariableSetListOptions",
599+
"VariableSetReadOptions",
600+
"VariableSetRemoveFromProjectsOptions",
601+
"VariableSetRemoveFromWorkspacesOptions",
602+
"VariableSetUpdateOptions",
603+
"VariableSetUpdateWorkspacesOptions",
604+
"VariableSetVariable",
605+
"VariableSetVariableCreateOptions",
606+
"VariableSetVariableListOptions",
607+
"VariableSetVariableUpdateOptions",
559608
]
560609

561610
# Rebuild models with forward references after all models are loaded

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)