Compare commits

..

No commits in common. "35abc609a7a4bcfbc1d90e2515ca6f5746327254" and "c6b723a47657995e8546bdf8683978195f21bb72" have entirely different histories.

5 changed files with 23 additions and 84 deletions

View file

@ -9,7 +9,7 @@ There has not been an official release of PyZipline on PyPi yet, meaning these i
type: warning type: warning
attrs: {class: annotate} attrs: {class: annotate}
**Please make sure to install the matching version of PyZipline for your Zipline version!** **Please make sure to install the matching version of PyZipline for your Zipline version!**
This documentation assumes you are using Zipline `3.7.9`. This documentation assumes you are using Zipline `3.7.8`.
If you are not, please see [Versioning](./versioning.md) for a list of supported versions. If you are not, please see [Versioning](./versioning.md) for a list of supported versions.
If you're on [Zipline's `trunk` version](https://github.com/diced/zipline/tree/trunk), use `*` to get the latest versions of PyZipline. (1) If you're on [Zipline's `trunk` version](https://github.com/diced/zipline/tree/trunk), use `*` to get the latest versions of PyZipline. (1)
/// ///

View file

@ -4,4 +4,4 @@ Below is a table containing versions of Zipline, alongside their respective PyZi
| PyZipline Versions | Zipline Versions | Supported | Security Fixes | | PyZipline Versions | Zipline Versions | Supported | Security Fixes |
| :----------------: | :--------------: | :----------------------: | :-----------------------: | | :----------------: | :--------------: | :----------------------: | :-----------------------: |
| `0.1.0` | `3.7.9` | :white_check_mark: | :white_check_mark: | | `0.1.0` | `3.7.8` | :white_check_mark: | :white_check_mark: |

View file

@ -1,9 +1,8 @@
"""This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API.""" """This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API."""
import logging
from datetime import datetime from datetime import datetime
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
from pydantic import BaseModel, ConfigDict, Field from pydantic import BaseModel, Field
class File(BaseModel): class File(BaseModel):
@ -147,47 +146,13 @@ class Stats(BaseModel):
class Embed(BaseModel): class Embed(BaseModel):
"""Object containing a user's embed settings
Attributes:
color (Optional[str]): String of the embed's color
title (Optional[str]): String of the embed's title
site_name (Optional[str]): String of the embed's site name
description (Optional[str]): String of the embed's description
"""
color: Optional[str] = None color: Optional[str] = None
title: Optional[str] = None title: Optional[str] = None
siteName: Optional[str] = None siteName: Optional[str] = None
description: Optional[str] = None description: Optional[str] = None
def __str__(self):
if self.title is None:
return "None"
return self.title
class User(BaseModel): class User(BaseModel):
"""Object containing user information
/// admonition | Contains Sensitive Information
type: danger
Please be mindful of how you use/store this object, as it contains sensitive information such as the user's token and TOTP information.
///
Attributes:
id (int): Integer ID of the user
uuid (str): String of the user's UUID
username (str): String of the user's username
avatar (Optional[str]): String of the user's avatar, base64 encoded
token (str): String of the user's token
administrator (bool): Boolean of whether the user is an administrator
super_admin (bool): Boolean of whether the user is a super administrator
system_theme (str): String of the user's system theme
embed (Embed): Embed object of the user's embed
totp_secret (Optional[str]): String of the user's TOTP secret
domains (List[str]): List of Strings of the user's domains
oauth (Optional[List[OAuth]]): List of [OAuth](.#pyzipline.models.OAuth) objects
ratelimit (Optional[datetime]): Datetime object of when the user's ratelimit expires
"""
id: int id: int
uuid: str uuid: str
username: str username: str
@ -205,45 +170,15 @@ class User(BaseModel):
return self.username return self.username
class Versions(BaseModel): class Versions(BaseModel):
"""Object containing the current, stable, and upstream versions of Zipline
Attributes:
stable (str): String of the stable version
upstream (str): String of the upstream version
current (str): String of the current version
"""
stable: str stable: str
upstream: str upstream: str
current: str current: str
class Version(BaseModel):
"""Model containing the current, stable, and upstream versions of Zipline
Attributes: class Version(BaseModel):
is_upstream (bool): Boolean of whether the current version is upstream (`trunk` branch)
update_to_type (str): String of the type of update available, one of 'stable' or 'upstream'
versions (Versions): Versions object containing the current, stable, and upstream versions
"""
isUpstream: bool isUpstream: bool
updateToType: str updateToType: str
versions: Versions versions: Versions
def __str__(self): def __str__(self):
return self.versions.current return self.versions.current
class ZiplineApiConfig(BaseModel):
"""Represents a configuration instance for the ZiplineApi/RestAdapter class.
Args:
hostname (str): The hostname of your Zipline instance, WITHOUT https or http.
token (str): String used for authentication when making requests.
ssl (bool): Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
enforced_signing (bool): Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
logger (logging.Logger): If your app has a logger, pass it in here.
"""
model_config = ConfigDict(arbitrary_types_allowed=True)
hostname: str
token: str = ''
ssl: bool = True
enforced_signing: bool = True
logger: logging.Logger = logging.getLogger(__name__)

View file

@ -6,32 +6,36 @@ import requests
from urllib3 import disable_warnings from urllib3 import disable_warnings
from pyzipline.exceptions import HTTPFailure, PyZiplineError from pyzipline.exceptions import HTTPFailure, PyZiplineError
from pyzipline.models import Result, ZiplineApiConfig from pyzipline.models import Result
class RestAdapter: class RestAdapter:
"""Constructor for RestAdapter """Constructor for RestAdapter
Args: Args:
config (ZiplineApiConfig): Configuration object for the ZiplineApi class hostname (str): The hostname of your Zipline instance, WITHOUT https or http.
token (str = None): String used for authentication when making requests.
ssl (bool = True): Normally set to True, but if your Zipline instance doesn't use SSL/TLS, set this to False.
enforced_signing (bool = True): Normally set to True, but if having SSL/TLS cert validation issues, can turn off with False.
logger (logging.Logger = None): If your app has a logger, pass it in here.
Raises: Raises:
ValueError: Raised when the keyword arguments passed to the class constructor conflict. ValueError: Raised when the keyword arguments passed to the class constructor conflict.
""" """
def __init__(self, config = ZiplineApiConfig): def __init__(self, hostname: str, token: str = '', ssl: bool = True, enforced_signing: bool = True, logger: logging.Logger = None):
self._url = f"http{'s' if config.ssl else ''}://{config.hostname}/api/" self._url = f"http{'s' if ssl else ''}://{hostname}/api/"
self._token = config.token self._token = token
self._ssl = config.ssl self._ssl = ssl
self._enforced_signing = config.enforced_signing self._enforced_signing = enforced_signing
self._logger = config.logger or logging.getLogger(__name__) self._logger = logger or logging.getLogger(__name__)
if config.ssl is False and config.enforced_signing is True: if ssl is False and enforced_signing is True:
raise ValueError("Cannot enforce signing without SSL") raise ValueError("Cannot enforce signing without SSL")
if not config.ssl and not config.enforced_signing: if not ssl and not enforced_signing:
disable_warnings() disable_warnings()
def _do(self, http_method: str, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments def _do(self, http_method: str, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
"""Internal method to make a request to the Zipline server. You shouldn't use this directly. """Internal method to make a request to the Zipline server. You shouldn't use this directly.
Args: Args:
@ -78,7 +82,7 @@ class RestAdapter:
return Result(success=is_success, status_code=response.status_code, message=data_out['error'], data=data_out) return Result(success=is_success, status_code=response.status_code, message=data_out['error'], data=data_out)
def delete(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments def delete(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, timeout: float = 60) -> Result:
"""Make a DELETE request to the Zipline server. You should almost never have to use this directly. """Make a DELETE request to the Zipline server. You should almost never have to use this directly.
Args: Args:
@ -105,7 +109,7 @@ class RestAdapter:
""" """
return self._do(http_method='GET', endpoint=endpoint, headers=headers, params=params, timeout=timeout) return self._do(http_method='GET', endpoint=endpoint, headers=headers, params=params, timeout=timeout)
def patch(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments def patch(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
"""Make a PATCH request to the Zipline server. You should almost never have to use this directly. """Make a PATCH request to the Zipline server. You should almost never have to use this directly.
Args: Args:
@ -120,7 +124,7 @@ class RestAdapter:
""" """
return self._do(http_method='PATCH', endpoint=endpoint, headers=headers, params=params, json=json, files=files, timeout=timeout) return self._do(http_method='PATCH', endpoint=endpoint, headers=headers, params=params, json=json, files=files, timeout=timeout)
def post(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result: # pylint: disable=too-many-arguments def post(self, endpoint: str, headers: dict = None, params: dict = None, json: dict = None, files: dict = None, timeout: float = 60) -> Result:
"""Make a POST request to the Zipline server. You should almost never have to use this directly. """Make a POST request to the Zipline server. You should almost never have to use this directly.
Args: Args:

View file

@ -42,7 +42,7 @@ class ZiplineApi:
self, self,
config: ZiplineApiConfig config: ZiplineApiConfig
): ):
self._rest_adapter = RestAdapter(config) self._rest_adapter = RestAdapter(hostname=config.hostname, token=config.token, ssl=config.ssl, enforced_signing=config.enforced_signing, logger=config.logger)
def create_invite(self, expiry: timedelta = timedelta(days=1), count: int = 1) -> Union[Invite, List[Invite]]: def create_invite(self, expiry: timedelta = timedelta(days=1), count: int = 1) -> Union[Invite, List[Invite]]:
"""Create an invite code """Create an invite code