Skip to content

Commit 28d56b5

Browse files
authored
feat(workspace): impleöment base operations for workspaces (#32)
Co-authored-by: Datata1 <>
1 parent d13fd9c commit 28d56b5

File tree

18 files changed

+350
-296
lines changed

18 files changed

+350
-296
lines changed

examples/workspaces/create_workspace.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import asyncio
2-
import pprint
2+
import logging
33
from codesphere import CodesphereSDK, WorkspaceCreate
44

5+
logging.basicConfig(level=logging.INFO)
6+
57

68
async def main():
7-
"""Creates a new workspace in a specific team."""
8-
team_id = 12345
9+
team_id = int(999999)
910

1011
async with CodesphereSDK() as sdk:
1112
print(f"--- Creating a new workspace in team {team_id} ---")
12-
1313
workspace_data = WorkspaceCreate(
1414
name="my-new-sdk-workspace-3",
1515
planId=8,
16-
teamId=int(team_id),
16+
teamId=team_id,
1717
isPrivateRepo=True,
1818
replicas=1,
1919
)
2020

2121
created_workspace = await sdk.workspaces.create(data=workspace_data)
22-
23-
print("\n--- Details of successfully created workspace ---")
24-
pprint.pprint(created_workspace.model_dump_json())
22+
print(created_workspace.model_dump_json())
2523

2624

2725
if __name__ == "__main__":

examples/workspaces/delete_workspace.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import asyncio
2+
import logging
23
from codesphere import CodesphereSDK
34

5+
logging.basicConfig(level=logging.INFO)
6+
47

58
async def main():
69
"""Deletes a specific workspace."""
710

8-
workspace_id_to_delete = 12345
11+
workspace_id_to_delete = int(9999999)
912

1013
async with CodesphereSDK() as sdk:
11-
print(f"--- Fetching workspace with ID: {workspace_id_to_delete} ---")
1214
workspace_to_delete = await sdk.workspaces.get(
1315
workspace_id=workspace_id_to_delete
1416
)
1517

1618
print(f"\n--- Deleting workspace: '{workspace_to_delete.name}' ---")
17-
18-
# This is a destructive action!
1919
await workspace_to_delete.delete()
20-
2120
print(f"Workspace '{workspace_to_delete.name}' has been successfully deleted.")
2221

2322

examples/workspaces/env-vars/delete_envvars.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import asyncio
2-
import pprint
2+
import logging
33
from codesphere import CodesphereSDK
44

5+
logging.basicConfig(level=logging.INFO)
6+
57

68
async def main():
7-
"""Fetches a team and lists all workspaces within it."""
89
async with CodesphereSDK() as sdk:
910
teams = await sdk.teams.list()
1011
workspaces = await sdk.workspaces.list_by_team(team_id=teams[0].id)
1112

1213
workspace = workspaces[0]
14+
vars_to_delete = await workspace.env_vars.get()
15+
for env in vars_to_delete:
16+
print(env.model_dump_json(indent=2))
1317

14-
envs = await workspace.get_env_vars()
15-
print("Current Environment Variables:")
16-
pprint.pprint(envs[0].name)
17-
18-
await workspace.delete_env_vars(
19-
[envs[0].name]
20-
) # you can pass a list of strings to delete multiple env vars
18+
await workspace.env_vars.delete(vars_to_delete)
2119

22-
print("Environment Variables after deletion:")
23-
updated_envs = await workspace.get_env_vars()
24-
pprint.pprint(updated_envs)
20+
print("\n--- Verifying deletion ---")
21+
current_vars = await workspace.env_vars.get()
22+
for env in current_vars:
23+
print(env.model_dump_json(indent=2))
2524

2625

2726
if __name__ == "__main__":

examples/workspaces/env-vars/list_envvars.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import asyncio
2-
import pprint
2+
import logging
33
from codesphere import CodesphereSDK
44

5+
logging.basicConfig(level=logging.INFO)
6+
57

68
async def main():
79
"""Fetches a team and lists all workspaces within it."""
810
async with CodesphereSDK() as sdk:
911
teams = await sdk.teams.list()
1012
workspaces = await sdk.workspaces.list_by_team(team_id=teams[0].id)
11-
1213
workspace = workspaces[0]
1314

14-
envs = await workspace.get_env_vars()
15+
envs = await workspace.env_vars.get()
1516
print("Current Environment Variables:")
16-
pprint.pprint(envs)
17+
for env in envs:
18+
print(env.model_dump_json(indent=2))
1719

1820

1921
if __name__ == "__main__":

examples/workspaces/env-vars/set_envvars.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
import asyncio
2-
import pprint
3-
from codesphere import CodesphereSDK
2+
import logging
3+
from codesphere import CodesphereSDK, EnvVar
4+
5+
logging.basicConfig(level=logging.INFO)
46

57

68
async def main():
7-
"""Fetches a team and lists all workspaces within it."""
89
async with CodesphereSDK() as sdk:
910
teams = await sdk.teams.list()
1011
workspaces = await sdk.workspaces.list_by_team(team_id=teams[0].id)
11-
1212
workspace = workspaces[0]
1313

14-
envs = await workspace.get_env_vars()
15-
print("Current Environment Variables:")
16-
pprint.pprint(envs)
14+
new_vars = [
15+
EnvVar(name="MY_NEW_VAR", value="hello_world"),
16+
EnvVar(name="ANOTHER_VAR", value="123456"),
17+
]
1718

18-
envs[0].value = "new_value" # Modify an environment variable
19-
await workspace.set_env_vars(envs) # Update the environment variables
19+
await workspace.env_vars.set(new_vars)
2020

21-
print("Updated Environment Variables:")
22-
updated_envs = await workspace.get_env_vars()
23-
pprint.pprint(updated_envs)
21+
print("\n--- Verifying new list ---")
22+
current_vars = await workspace.env_vars.get()
23+
for env in current_vars:
24+
print(env.model_dump_json(indent=2))
2425

2526

2627
if __name__ == "__main__":
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import asyncio
2+
import logging
3+
from codesphere import CodesphereSDK
4+
5+
# --- Logging-Konfiguration ---
6+
logging.basicConfig(level=logging.INFO)
7+
# (Optionale Logger stummschalten)
8+
logging.getLogger("codesphere.http_client").setLevel(logging.WARNING)
9+
logging.getLogger("httpx").setLevel(logging.WARNING)
10+
11+
log = logging.getLogger(__name__)
12+
13+
14+
async def main():
15+
async with CodesphereSDK() as sdk:
16+
teams = await sdk.teams.list()
17+
workspaces = await sdk.workspaces.list_by_team(team_id=teams[0].id)
18+
workspace = workspaces[0]
19+
state = await workspace.get_status()
20+
print(state.model_dump_json(indent=2))
21+
22+
command_str = "echo Hello from $USER_NAME!"
23+
command_env = {"USER_NAME": "SDK-User"}
24+
25+
command_output = await workspace.execute_command(
26+
command=command_str, env=command_env
27+
)
28+
print(command_output.model_dump_json(indent=2))
29+
30+
31+
if __name__ == "__main__":
32+
asyncio.run(main())

examples/workspaces/get_status.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import asyncio
2+
import logging
3+
from codesphere import CodesphereSDK
4+
5+
logging.basicConfig(level=logging.INFO)
6+
7+
8+
async def main():
9+
async with CodesphereSDK() as sdk:
10+
all_teams = await sdk.teams.list()
11+
first_team = all_teams[0]
12+
workspaces = await sdk.workspaces.list_by_team(team_id=first_team.id)
13+
first_workspace = workspaces[0]
14+
state = await first_workspace.get_status()
15+
print(state.model_dump_json(indent=2))
16+
17+
18+
if __name__ == "__main__":
19+
asyncio.run(main())

examples/workspaces/get_workspace.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import asyncio
2+
import logging
23
from codesphere import CodesphereSDK
34

5+
logging.basicConfig(level=logging.INFO)
6+
47

58
async def main():
6-
"""Fetches a workspace within a Team."""
79
async with CodesphereSDK() as sdk:
8-
pass
10+
all_teams = await sdk.teams.list()
11+
if not all_teams:
12+
print("No teams found. Cannot get a workspace.")
13+
return
14+
15+
first_team = all_teams[0]
16+
17+
workspaces = await sdk.workspaces.list_by_team(team_id=first_team.id)
18+
if not workspaces:
19+
print(f"No workspaces found in team '{first_team.name}'.")
20+
return
21+
22+
first_workspace = workspaces[0]
23+
workspace_id_to_fetch = first_workspace.id
24+
workspace = await sdk.workspaces.get(workspace_id=workspace_id_to_fetch)
25+
print(workspace.model_dump_json(indent=2))
926

1027

1128
if __name__ == "__main__":
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import asyncio
2+
import logging
3+
from codesphere import CodesphereSDK
4+
5+
# --- Logging-Konfiguration ---
6+
logging.basicConfig(level=logging.INFO)
7+
8+
9+
async def main():
10+
async with CodesphereSDK() as sdk:
11+
all_teams = await sdk.teams.list()
12+
first_team = all_teams[0]
13+
team_id_to_fetch = first_team.id
14+
workspaces = await sdk.workspaces.list_by_team(team_id=team_id_to_fetch)
15+
print(f"\n--- Workspaces in Team: {first_team.name} ---")
16+
for ws in workspaces:
17+
print(ws.model_dump_json(indent=2))
18+
print("-" * 20)
19+
20+
21+
if __name__ == "__main__":
22+
asyncio.run(main())

examples/workspaces/list_workspaces.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)