Handle Config¶
Config dataclass ¶
additional_setting: typ.Dict[str, str] = {} instance-attribute ¶
JijZept API Config.
Attributes:
| Name | Type | Description |
|---|---|---|
query_url | str | Endpoint for Query API. |
post_url | str | Endpoint for Post Instance API. |
proxy | str | Proxy URL. Defaults to None. |
token | str | Secret token to connect API. |
additional_setting | dict[str, str] | Parameters for thirdparty samplers. |
Note
How to write config.toml¶
Write url and token under [default], and ThirdpartySampler's parameters under [default.thirdparty-setting]. The following is a config.toml example with ThirdpartySampler's parameters.
[default]
url = "https://api.jijzept.com/"
token = "715df11165044899867df0f7bb8a60e9"
[default.thirdparty-setting]
da4_token = "da4df11165044899867df0f7bb8a60e9"
da4_url = "https://jijcloud.da4.net/"
__init__(*, url=None, token=None, proxy=None, config=None, config_env='default') ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url | str | dict[str, str] | None | Endpoint for connecting to JijZept API. If you want to set | None |
token | str | None | token to connect JijZept API. Defaults to None. | None |
proxy | str | None | proxy server. Defaults to None. | None |
config | PATH_TYPE | None | config file path. Defaults to None. | None |
config_env | str | config environment name. Defaults to "default". | 'default' |
Raises:
| Type | Description |
|---|---|
ConfigError | parse error. |
TypeError | url schema or config path is invaild. |
ValidationError | url schema or config path is invaild. |
UrlInfo dataclass ¶
Class that holds the query_url and post_url of an API endpoint.
config_file_path(file_path=None) ¶
Get config file path.
Configuration files are explored in the following order When found, the path to the file is returned, or None if not found. If the user specifies a file path in file_path arguments, it is returned in preference to all of the following.
The search goes for the jijzept and jijzept_config.toml files in the following directories.
- Current directory: pathlib.Path().cwd()
- $XDG_CONFIG_HOME
- ~/.config
The search order of this function is the priority order of config files in JijZept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | Union[Path, str, None] | file path. Defaults to None. | None |
Returns:
| Type | Description |
|---|---|
Optional[Path] | pathlib.Path | None: config file path |
create_config(*, token, host_url, config_path=CONFIG_PATH) ¶
Create new config file with the given token and host_url values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token | str | The token to set in the config file. | required |
host_url | HttpUrl | The host URL to set in the config file. | required |
config_path | FilePath | The path to the directory where the config file should be created. Defaults to CONFIG_PATH. | CONFIG_PATH |
Raises:
| Type | Description |
|---|---|
FileExistsError | If the config file already exists. |
Returns:
| Type | Description |
|---|---|
FilePath | pydantic.FilePath: The path to the newly created config file. |
load_config(*, file_path, config='default') ¶
Load config file (TOML file).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | Path | path to config file. | required |
config | str | loading enviroment name. Defaults to 'default'. | 'default' |
Raises:
| Type | Description |
|---|---|
TypeError | if 'config' enviroment is not defined in config file. |
Returns:
| Name | Type | Description |
|---|---|---|
dict | dict | ex. {'token': 'xxxx', 'url': 'xxxx'} |