Skip to content

Commit

Permalink
Powergate v1.2.1 + design updates (#52)
Browse files Browse the repository at this point in the history
* new client api

Signed-off-by: Aaron Sutula <hi@asutula.com>

* update to latest proto file

Signed-off-by: Aaron Sutula <hi@asutula.com>

* update integration tests and examples

Signed-off-by: Aaron Sutula <hi@asutula.com>

* import iterable

Signed-off-by: Aaron Sutula <hi@asutula.com>

* fix some imports

Signed-off-by: Aaron Sutula <hi@asutula.com>

* update to powergate 1.1.2, use published grpc bindings

Signed-off-by: Aaron Sutula <hi@asutula.com>

* feat: powergate v1 update

* fix: examples

* fix: linting + formating

* chore: readme update

Co-authored-by: Aaron Sutula <hi@asutula.com>
Co-authored-by: Antreas Pogiatzis <antreas@deplatformer.io>
  • Loading branch information
3 people committed Nov 15, 2020
1 parent 429967f commit db0e39a
Show file tree
Hide file tree
Showing 82 changed files with 1,410 additions and 14,611 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@ dmypy.json
.pytype/

# Cython debug symbols
cython_debug/
cython_debug/

.vscode
8 changes: 3 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pytest = "*"
docker = "*"
gitpython = "*"
pytest-docker = "*"
grpcio-tools = "*"
secretstorage = {markers = "sys_platform == 'linux'"}
keyring = "==19.1.0"
flake8 = "*"
isort = "*"
pylint = "*"
mypy = "*"
pygate-grpc = {editable = true,path = "."}

[requires]
python_version = "3.7"
Expand All @@ -31,10 +31,8 @@ publish = "twine upload dist/*"
format = "bash -c \"python -m isort setup.py pygate_grpc tests && python -m black $(git ls-files '*.py')\""
lint = "bash -c \"python -m flake8\""
integration-test = "python -m pytest tests/integration/"
test-ffs = "python -m pytest tests/integration/test_ffs.py"

[packages]
grpcio = "*"
protobuf = "*"
six = "*"
grpc-powergate-client = "==1.1.2"
mypy-extensions = "*"
deprecated = "*"
570 changes: 289 additions & 281 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![CodeFactor](https://www.codefactor.io/repository/github/pygate/pygate-grpc/badge)](https://www.codefactor.io/repository/github/pygate/pygate-grpc)
[![PyPI version](https://badge.fury.io/py/pygate-grpc.svg)](https://badge.fury.io/py/pygate-grpc)
![Tests](https://github.com/pygate/pygate-gRPC/workflows/Tests/badge.svg)
[![Downloads](https://pepy.tech/badge/pygate-grpc)](https://pepy.tech/project/pygate-grpc)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

A Python interface to [Textile](https://textile.io/)'s [Powergate](https://docs.textile.io/powergate/) [Filecoin](https://filecoin.io/) API
Expand All @@ -28,7 +29,7 @@ from pygate_grpc.client import PowerGateClient

client = PowerGateClient("127.0.0.1:5002", False)

healthcheck = client.health.check()
build_info = client.build_info()
```

Simple as that!
Expand Down
26 changes: 0 additions & 26 deletions cidconfig.json

This file was deleted.

62 changes: 62 additions & 0 deletions examples/apply_pull_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
from pathlib import Path
from pygate_grpc.client import PowerGateClient


if __name__ == "__main__":

hostName = "127.0.0.1:5002"

# Create client
c = PowerGateClient(hostName, False)

# Create user
user = c.admin.users.create()
print("User created:")
print(user)

# Stage file
print("Staging testfile.txt to IPFS storage")
path = Path(os.path.abspath(__file__))
staged_file = c.data.stage_file(path.parent / "testfile.txt", user.token)
print("Applying storage config...")

# Apply the default storage config to the given file
c.config.apply(staged_file.cid, override=False, token=user.token)

# Override push with another config
addresses = c.wallet.addresses(user.token)
wallet = addresses[0].address
new_config = {
"hot": {"enabled": True, "allowUnfreeze": True, "ipfs": {"addTimeout": 30}},
"cold": {
"enabled": True,
"filecoin": {
"replicationFactor": 1,
"dealMinDuration": 518400,
"excludedMiners": ["t01101"],
"trustedMiners": ["t01000", "t02000"],
"countryCodes": ["ca", "nl"],
"renew": {"enabled": True, "threshold": 3},
"address": wallet,
"maxPrice": 50,
},
},
"repairable": True,
}

c.config.apply(staged_file.cid, override=True, config=new_config, token=user.token)

# Check that CID is stored
check = c.data.cid_info([staged_file.cid], user.token)
print("Checking CID storage...")
print(check)

# Get the data back
print("Retrieving file " + staged_file.cid)
file_bytes = c.data.get(staged_file.cid, user.token)

# Write to a file on disk
print("Saving as 'testfile_copy.txt'")
with open(path.parent / "testfile_copy.txt", "wb") as f:
f.write(file_bytes)
25 changes: 25 additions & 0 deletions examples/cidconfig_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"hot": {
"enabled": true,
"ipfs": {
"addTimeout": "30"
}
},
"cold": {
"enabled": true,
"filecoin": {
"replicationFactor": "1",
"dealMinDuration": "518400",
"excludedMiners": ["t01101"],
"countryCodes": ["ca", "nl"],
"renew": {
"enabled": true,
"threshold": "3"
},
"address": "f3ugglyobkqbsi7m7vgcnvpk7mswinrv5s6wm2abrmeq6m5zw2i2xwknjxg566konp4esxfnxjaefaa3uy3waa",
"maxPrice": "5"
}
},
"repairable": true

}
36 changes: 36 additions & 0 deletions examples/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pygate_grpc.client import PowerGateClient

import os
import json
from pathlib import Path


client = PowerGateClient("127.0.0.1:5002", False)

print("Creating a new user:")
user = client.admin.users.create()
tk = user.token
print("Token: " + tk)
print("Using the new user token to request the default config:")
default_config = client.config.default(tk)

wallets = client.wallet.addresses(token=tk)
print("Addresses: {0}".format(default_config))

print("Loading new default config...")
path = Path(os.path.abspath(__file__))
with open(path.parent / "cidconfig_example.json", "r") as f:
config = json.load(f)
config["cold"]["filecoin"]["address"] = wallets[0].address

client.config.set_default(config, tk)

default_config = client.config.default(tk)
print("Updated default config:")
print(default_config)

test_bytes = b"These are some test bytes"
staged_file = client.data.stage_bytes(test_bytes, user.token)
print("StagedFile: ", staged_file)

stage = client.config.apply(staged_file.cid, token=user.token, config=config)
45 changes: 45 additions & 0 deletions examples/deals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import time

from pygate_grpc.client import PowerGateClient

if __name__ == "__main__":

hostName = "127.0.0.1:5002"

# Create client
client = PowerGateClient(hostName)

# Create user
user = client.admin.users.create()
print("User created:")
print(user)

print("Applying storage config...")
stage_res = client.data.stage_bytes(
b"These are the contents of a test file", token=user.token
)
apply_res = client.config.apply(stage_res.cid, token=user.token)

# Check that cid is in the process of being stored by Powegate
check = client.data.cid_info([stage_res.cid], user.token)
print("Checking cid storage...")
print(check)

# Wait some time so that we can get some deals
time.sleep(60)

# Check information about the storage deal
storage_deals = client.deals.storage_deal_records(
include_pending=True, include_final=True, token=user.token
)
print("Storage deals: ")
for record in storage_deals:
print(record)

# Check information about the retrieval deals
retrieval_deals = client.deals.retrieval_deal_records(
include_pending=True, include_final=True, token=user.token
)
print("Retrieval deals: ")
for record in retrieval_deals:
print(record)
21 changes: 0 additions & 21 deletions examples/ffs_config.py

This file was deleted.

49 changes: 0 additions & 49 deletions examples/ffs_deals.py

This file was deleted.

54 changes: 0 additions & 54 deletions examples/ffs_push_pull_file.py

This file was deleted.

0 comments on commit db0e39a

Please sign in to comment.