Skip to content

Commit 56b2dae

Browse files
feat: Adding env routes
1 parent 9f978c8 commit 56b2dae

File tree

12 files changed

+193
-0
lines changed

12 files changed

+193
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
async def main():
8+
app = await client.app("your_app_id")
9+
keys = [] # The keys you want to delete
10+
result = await app.delete_envs(keys) # Deletes the specified environment variables
11+
print("Remaining env variables: ", result)
12+
13+
asyncio.run(main())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
keys = [] # The keys you want to delete
10+
result = await client.delete_app_envs("app_id", keys) # Deletes the specified environment variables
11+
print("Remaining env variables: ", result)
12+
13+
asyncio.run(main())

examples/env/get_env/with_app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
app = await client.app("your_app_id")
10+
envs = await app.get_envs()
11+
print("App envs: ", envs)
12+
13+
asyncio.run(main())
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
envs = await client.get_app_envs("app_id")
10+
print("App envs: ", envs)
11+
12+
asyncio.run(main())
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
app = await client.app("your_app_id")
10+
envs = {"KEY": "VALUE"} # The new environment variables
11+
result = await app.overwrite_env(envs) # Overwrites all environment variables and sets only the new ones
12+
print("Overwrite envs result: ", result)
13+
14+
asyncio.run(main())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
envs = {"ONLY_THIS": "present"} # The new environment variables
10+
result = await client.overwrite_app_envs("app_id", envs) # Overwrites all environment variables and sets only the new ones
11+
print("Overwrite envs result:", result)
12+
13+
asyncio.run(main())

examples/env/set_env/with_app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
envs = {"KEY": "VALUE"} # The environment variables you want to set
10+
app = await client.app("your_app_id")
11+
result = await app.set_envs(envs) # Sets or updates the specified environment variables
12+
print("Set envs result:", result)
13+
14+
asyncio.run(main())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
from squarecloud import Client
4+
5+
client = Client(api_key="your_api_key")
6+
7+
8+
async def main():
9+
envs = {"KEY": "VALUE"} # The environment variables you want to set
10+
result = await client.set_app_envs("app_id", envs) # Sets or updates the specified environment variables
11+
print("Set envs result:", result)
12+
13+
asyncio.run(main())

squarecloud/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,15 @@ async def current_integration(self) -> Response:
685685
@_notify_listener(Endpoint.dns_records())
686686
async def dns_records(self) -> list[DNSRecord]:
687687
return await self.client.dns_records(self.id)
688+
689+
async def get_envs(self) -> dict[str, str]:
690+
return await self.client.get_app_envs(self.id)
691+
692+
async def set_envs(self, envs: dict[str, str]) -> dict[str,str]:
693+
return await self.client.set_app_envs(self.id, envs)
694+
695+
async def delete_envs(self, keys: list[str]) -> dict[str,str]:
696+
return await self.client.delete_app_envs(self.id, keys)
697+
698+
async def overwrite_env(self, envs: dict[str, str]) -> dict[str,str]:
699+
return await self.client.overwrite_app_envs(self.id, envs)

squarecloud/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,23 @@ async def current_app_integration(self, app_id: str) -> str | None:
751751
app_id
752752
)
753753
return response.response["webhook"]
754+
755+
async def get_app_envs(self, app_id: str) -> dict[str, str]:
756+
response: Response = await self._http.get_environment_variables(app_id)
757+
return response.response
758+
759+
async def set_app_envs(self, app_id: str, envs: dict[str, str]) -> dict[str, str]:
760+
response: Response = await self._http.set_environment_variable(app_id, envs)
761+
return response.response
762+
763+
async def delete_app_envs(self, app_id: str, keys: list[str]) -> dict[str, str]:
764+
response: Response = await self._http.delete_environment_variable(app_id, keys)
765+
return response.response
766+
767+
async def overwrite_app_envs(self, app_id: str, envs: dict[str, str]) -> dict[str, str]:
768+
response: Response = await self._http.overwrite_environment_variables(app_id, envs)
769+
return response.response
770+
771+
async def clear_app_envs(self, app_id: str) -> dict[str, str]:
772+
response: Response = await self._http.overwrite_environment_variables(app_id, {})
773+
return response.response

0 commit comments

Comments
 (0)