Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/env/delete_env/with_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")

async def main():
app = await client.app("your_app_id")
keys = [] # The keys you want to delete
result = await app.delete_envs(keys) # Deletes the specified environment variables
print("Remaining env variables: ", result)

asyncio.run(main())
13 changes: 13 additions & 0 deletions examples/env/delete_env/with_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
keys = [] # The keys you want to delete
result = await client.delete_app_envs("app_id", keys) # Deletes the specified environment variables
print("Remaining env variables: ", result)

asyncio.run(main())
13 changes: 13 additions & 0 deletions examples/env/get_env/with_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
app = await client.app("your_app_id")
envs = await app.get_envs()
print("App envs: ", envs)

asyncio.run(main())
12 changes: 12 additions & 0 deletions examples/env/get_env/with_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
envs = await client.get_app_envs("app_id")
print("App envs: ", envs)

asyncio.run(main())
14 changes: 14 additions & 0 deletions examples/env/overwrite_env/with_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
app = await client.app("your_app_id")
envs = {"KEY": "VALUE"} # The new environment variables
result = await app.overwrite_env(envs) # Overwrites all environment variables and sets only the new ones
print("Overwrite envs result: ", result)

asyncio.run(main())
13 changes: 13 additions & 0 deletions examples/env/overwrite_env/with_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
envs = {"ONLY_THIS": "present"} # The new environment variables
result = await client.overwrite_app_envs("app_id", envs) # Overwrites all environment variables and sets only the new ones
print("Overwrite envs result:", result)

asyncio.run(main())
14 changes: 14 additions & 0 deletions examples/env/set_env/with_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
envs = {"KEY": "VALUE"} # The environment variables you want to set
app = await client.app("your_app_id")
result = await app.set_envs(envs) # Sets or updates the specified environment variables
print("Set envs result:", result)

asyncio.run(main())
13 changes: 13 additions & 0 deletions examples/env/set_env/with_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import asyncio

from squarecloud import Client

client = Client(api_key="your_api_key")


async def main():
envs = {"KEY": "VALUE"} # The environment variables you want to set
result = await client.set_app_envs("app_id", envs) # Sets or updates the specified environment variables
print("Set envs result:", result)

asyncio.run(main())
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

async def example() -> None:
app = await client.app('application_id')
backup = await app.backup()
print(backup.url) # https://squarecloud.app/dashboard/backup/f.zip

snapshot = await app.snapshot()
print(snapshot.url) # https://squarecloud.app/dashboard/backup/f.zip

asyncio.run(example())
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


async def example() -> None:
backup = await client.backup('application_id')
print(backup.url) # https://squarecloud.app/dashboard/backup/f.zip
snapshot = await client.snapshot('application_id')
print(snapshot.url) # https://squarecloud.app/dashboard/backup/f.zip


asyncio.run(example())
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'squarecloud-api'
version = '3.7.5'
version = '3.8.0'
description = 'SquareCloud API wrapper'
authors = ['Robert Nogueira <robertlucasnogueira@gmail.com>']
repository = 'https://github.com/squarecloudofc/wrapper-api-py'
Expand Down
8 changes: 4 additions & 4 deletions squarecloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from .client import Client
from .data import (
AppData,
Backup,
BackupInfo,
Snapshot,
SnapshotInfo,
DeployData,
DNSRecord,
DomainAnalytics,
Expand All @@ -29,8 +29,8 @@
'Endpoint',
'Response',
'AppData',
'Backup',
'BackupInfo',
'Snapshot',
'SnapshotInfo',
'DeployData',
'DNSRecord',
'DomainAnalytics',
Expand Down
128 changes: 116 additions & 12 deletions squarecloud/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from io import BytesIO
from typing import TYPE_CHECKING, Any, Callable, Coroutine, TypeVar

from typing_extensions import deprecated

from squarecloud import errors

from ._internal.decorators import validate
from .data import (
AppData,
Backup,
BackupInfo,
Snapshot,
SnapshotInfo,
DeployData,
DNSRecord,
DomainAnalytics,
Expand Down Expand Up @@ -53,7 +55,7 @@ def __init__(self) -> None:
"""
self._status: StatusData | None = None
self._logs: LogsData | None = None
self._backup: Backup | None = None
self._backup: Snapshot | None = None
self._app_data: AppData | None = None

@property
Expand All @@ -79,7 +81,8 @@ def logs(self) -> LogsData:
return self._logs

@property
def backup(self) -> Backup:
@deprecated("this property will be removed in future versions, use the 'snapshot' property instead")
def backup(self) -> Snapshot:
"""
The backup method is a property that returns the cached Backup of
the application.
Expand Down Expand Up @@ -130,7 +133,7 @@ def update(self, *args) -> None:
self._status = arg
elif isinstance(arg, LogsData):
self._logs = arg
elif isinstance(arg, Backup):
elif isinstance(arg, Snapshot):
self._backup = arg
elif isinstance(arg, AppData):
self._app_data = arg
Expand All @@ -140,7 +143,7 @@ def update(self, *args) -> None:
for i in [
StatusData,
LogsData,
Backup,
Snapshot,
AppData,
]
]
Expand Down Expand Up @@ -458,17 +461,31 @@ async def status(self, *_args, **_kwargs) -> StatusData:
return status

@_update_cache
@_notify_listener(Endpoint.backup())
async def backup(self, *_args, **_kwargs) -> Backup:
@_notify_listener(Endpoint.snapshot())
@deprecated("this method will be removed in future versions, use the 'snapshot' method instead")
async def backup(self, *_args, **_kwargs) -> Snapshot:
"""
The backup function is used to create a backup of the application.

:param self: Refer to the class instance
:return: A Backup object
:rtype: Backup
"""
backup: Backup = await self.client.backup(self.id)
backup: Snapshot = await self.client.snapshot(self.id)
return backup

@_update_cache
@_notify_listener(Endpoint.snapshot())
async def snapshot(self, *_args, **_kwargs) -> Snapshot:
"""
The Snapshot function is used to create a snapshot of the application.

:param self: Refer to the class instance
:return: A Snapshot object
:rtype: Snapshot
"""
snapshot: Snapshot = await self.client.snapshot(self.id)
return snapshot

async def start(self) -> Response:
"""
Expand Down Expand Up @@ -638,28 +655,115 @@ async def github_integration(self, access_token: str) -> str:
return webhook

async def domain_analytics(self) -> DomainAnalytics:
"""
Retrieve analytics data for the application's domain.

:param self: Refer to the instance of the class.
:returns: An instance of :class:`DomainAnalytics` containing analytics data for the domain.
:rtype: DomainAnalytics
:raises Exception: If the analytics data could not be retrieved.
"""
analytics: DomainAnalytics = await self.client.domain_analytics(
self.id, avoid_listener=True
)
return analytics # TODO:
return analytics

async def set_custom_domain(self, custom_domain: str) -> Response:
"""
Sets a custom domain for the application.

:param custom_domain: The custom domain to be assigned to the application.
:type custom_domain: str
:return: The response from the domain assignment operation.
:rtype: Response
"""
response: Response = await self.client.set_custom_domain(
self.id, custom_domain, avoid_listener=True
)
return response

async def all_backups(self) -> Response:
backups: list[BackupInfo] = await self.client.all_app_backups(self.id)
@deprecated("this method will be removed in future versions, use the 'all_snapshots' method instead")
async def all_backups(self) -> list[SnapshotInfo]:
backups: list[SnapshotInfo] = await self.client.all_app_snapshots(self.id)
return backups

async def all_snapshots(self) -> list[SnapshotInfo]:
"""
Retrieve all snapshots of the application.

:return: A list of SnapshotInfo objects representing all snapshots of the application.
:rtype: list[SnapshotInfo]
"""
snapshots: list[SnapshotInfo] = await self.client.all_app_snapshots(self.id)
return snapshots

@validate
async def move_file(self, origin: str, dest: str) -> Response:
"""
Moves a file from the origin path to the destination path within the application.

:param origin: The source path of the file to be moved.
:type origin: str
:param dest: The destination path where the file should be moved.
:type dest: str
:return: A Response object containing the result of the file move operation.
:rtype: Response
"""

return await self.client.move_app_file(self.id, origin, dest)

async def current_integration(self) -> Response:
return await self.client.current_app_integration(self.id)

@_notify_listener(Endpoint.dns_records())
async def dns_records(self) -> list[DNSRecord]:
"""
Retrieve the DNS records associated with the application.

:returns: A list of DNSRecord objects representing the DNS records.
:rtype: list[DNSRecord]
"""

return await self.client.dns_records(self.id)

async def get_envs(self) -> dict[str, str]:
"""
Get environment variables of the application.

:return: A dictionary of the environment variables that were set.
:rtype: dict[str, str]
"""
return await self.client.get_app_envs(self.id)

async def set_envs(self, envs: dict[str, str]) -> dict[str,str]:
"""
Set environment variables or edits for the application.

:param envs: A dictionary containing environment variable names and their corresponding values.
:type envs: dict[str, str]
:return: A dictionary of the environment variables that were set.
:rtype: dict[str, str]
"""
return await self.client.set_app_envs(self.id, envs)

async def delete_envs(self, keys: list[str]) -> dict[str,str]:
"""
Deletes environment variables from the application.

:param keys: A list of environment variable keys to be deleted.
:type keys: list[str]
:returns: A dictionary containing the remaining variables.
:rtype: dict[str, str]
"""
return await self.client.delete_app_envs(self.id, keys)

async def overwrite_env(self, envs: dict[str, str]) -> dict[str,str]:
"""
Overwrites the environment variables for the application.

:param envs: A dictionary containing the environment variables to set, where keys are variable names and values are their corresponding values.
:type envs: dict[str, str]
:return: A dictionary of the environment variables.
:rtype: dict[str, str]
"""
return await self.client.overwrite_app_envs(self.id, envs)
Loading