-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into hoh-time-datetime
- Loading branch information
Showing
23 changed files
with
766 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
# Aleph.im Message Specification | ||
|
||
This library aims to provide an easy way to create, update and validate | ||
This library aims to provide an easy way to create, update and manipulate | ||
messages from Aleph.im. | ||
|
||
It mainly consists in [pydantic](https://pydantic-docs.helpmanual.io/) | ||
models that provide field type validation and IDE autocompletion for messages. | ||
|
||
## Status | ||
This library provides: | ||
* schema validation when parsing messages. | ||
* cryptographic hash validation that the `item_hash` matches the content of the message. | ||
* type validation using type checkers such as [mypy](https://www.mypy-lang.org/) in development environments. | ||
* autocompletion support in development editors. | ||
|
||
Currently, only basic type validation is included. Advanced data and signature | ||
validation is not included. | ||
The `item_hash` is commonly used as unique message identifier on Aleph.im. | ||
|
||
In the future, this library would be useful within other projects such as | ||
the client library [aleph-client](https://github.com/aleph-im/aleph-client). | ||
Cryptographic signatures are out of scope of this library and part of the `aleph-sdk-python` | ||
project, due to their extended scope and dependency on cryptographic libraries. | ||
|
||
This library is used in both client and node software of Aleph.im. | ||
|
||
## Usage | ||
|
||
```shell | ||
pip install aleph-message | ||
``` | ||
|
||
```python | ||
import requests | ||
from aleph_message import Message | ||
from aleph_message import parse_message | ||
from pydantic import ValidationError | ||
|
||
message_dict = requests.get(ALEPH_API_SERVER + "/api/v0/messages.json?hashes=...").json() | ||
ALEPH_API_SERVER = "https://official.aleph.cloud" | ||
MESSAGE_ITEM_HASH = "9b21eb870d01bf64d23e1d4475e342c8f958fcd544adc37db07d8281da070b00" | ||
|
||
message_dict = requests.get(ALEPH_API_SERVER + "/api/v0/messages.json?hashes=" + MESSAGE_ITEM_HASH).json() | ||
|
||
try: | ||
message = Message(**message_dict) | ||
message = parse_message(message_dict["messages"][0]) | ||
print(message.sender) | ||
except ValidationError as e: | ||
print(e.json()) | ||
print(e.json(indent=4)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from .models import Message, MessagesResponse | ||
from .models import MessagesResponse, parse_message | ||
|
||
__all__ = ["parse_message", "MessagesResponse"] | ||
__version__ = "0.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .abstract import BaseExecutableContent | ||
from .instance import InstanceContent | ||
from .program import ProgramContent | ||
|
||
__all__ = ["BaseExecutableContent", "InstanceContent", "ProgramContent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC | ||
from typing import Any, Dict, List, Optional | ||
|
||
from pydantic import Field | ||
|
||
from .environment import ( | ||
FunctionEnvironment, | ||
HostRequirements, | ||
MachineResources, | ||
) | ||
from .volume import MachineVolume | ||
from ..abstract import BaseContent, HashableModel | ||
|
||
|
||
class BaseExecutableContent(HashableModel, BaseContent, ABC): | ||
"""Abstract content for execution messages (Instances, Programs).""" | ||
|
||
allow_amend: bool = Field(description="Allow amends to update this function") | ||
metadata: Optional[Dict[str, Any]] = Field(description="Metadata of the VM") | ||
authorized_keys: Optional[List[str]] = Field( | ||
description="SSH public keys authorized to connect to the VM", | ||
) | ||
variables: Optional[Dict[str, str]] = Field( | ||
default=None, description="Environment variables available in the VM" | ||
) | ||
environment: FunctionEnvironment = Field( | ||
description="Properties of the execution environment" | ||
) | ||
resources: MachineResources = Field(description="System resources required") | ||
requirements: Optional[HostRequirements] = Field( | ||
default=None, description="System properties required" | ||
) | ||
volumes: List[MachineVolume] = Field( | ||
default=[], description="Volumes to mount on the filesystem" | ||
) | ||
replaces: Optional[str] = Field( | ||
default=None, | ||
description="Previous version to replace. Must be signed by the same address", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
|
||
|
||
class Encoding(str, Enum): | ||
"""Code and data can be provided in plain format, as zip or as squashfs partition.""" | ||
|
||
plain = "plain" | ||
zip = "zip" | ||
squashfs = "squashfs" | ||
|
||
|
||
class MachineType(str, Enum): | ||
"""Two types of execution environments supported: | ||
Instance (Virtual Private Server) and Function (Program oriented).""" | ||
|
||
vm_instance = "vm-instance" | ||
vm_function = "vm-function" |
Oops, something went wrong.