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
4 changes: 2 additions & 2 deletions ANNOUNCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Blosc2 and HDF5 data repositories.

This is a major release that includes a big refactoring for getting rid of
the PubSub code (which, to be frank, was not bringing too much benefit).
We have added a new `cat2agent` to watch a directory and sync changes to a
We have added a new `cat2-agent` to watch a directory and sync changes to a
Caterva2 server.

Finally, fixed a few bugs and added some new features, such as the
`cat2agent` command line client, which allows you to watch a directory and
`cat2-agent` command line client, which allows you to watch a directory and
sync changes to a Caterva2 server. This is particularly useful for
automatically uploading new datasets to a Caterva2 server, or for keeping
a local copy of a remote Caterva2 server.
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ client.get("@public/examples/tomo-guess-test.b2nd")
```
- Via the [command line client](https://ironarray.io/caterva2-doc/tutorials/cli.html)
```sh
cat2cli info @public/kevlar/entry/data/data.b2nd
cat2-client info @public/kevlar/entry/data/data.b2nd
```
- Via the [REST API](https://ironarray.io/caterva2-doc/tutorials/RESTAPI.html) using a REST client like [Postman](https://www.postman.com/) or [curl](https://curl.se/) (see [here](https://cat2.cloud/demo/docs)).

Expand Down Expand Up @@ -72,7 +72,7 @@ accesses the relevant datasets stored either locally or remotely. The server ser
```
In general, if you intend to run Caterva2 services, client programs, or the test suite, you need to enable the proper extra features by appending `[feature1,feature2...]` to the last argument of `pip` commands above. The following extras are supported:

- `subscriber` for running the Caterva2 server service
- `server` for running the Caterva2 server service
- `clients` to use Caterva2 client programs (command-line or terminal)
- `blosc2-plugins` to enable extra Blosc2 features like Btune or JPEG 2000 support
- `plugins` to enable web GUI features like the tomography display
Expand Down Expand Up @@ -114,7 +114,7 @@ dir1/ ds-1d-b.b2nd ds-1d.b2nd ds-hello

Now:

- create a virtual environment and install Caterva2 with the `[subscriber,clients]` extras (see above).
- create a virtual environment and install Caterva2 with the `[server,clients]` extras (see above).
- copy the configuration file `caterva2.sample.toml` to `caterva2.toml`.

Servers (and clients, to a limited extent) may get their configuration from a `caterva2.toml` file at the current directory (or an alternative file given with the `--conf` option).
Expand All @@ -123,17 +123,17 @@ See also [configuration.md](configuration.md) in Caterva2 tutorials.
Then run the server:

```sh
CATERVA2_SECRET=c2sikrit cat2sub & # server
CATERVA2_SECRET=c2sikrit cat2-server & # server
```
The `CATERVA2_SECRET` environment variable is obligatory and is explained below in the following section.

### User authentication
The Caterva2 server includes some support for authenticating users. To enable it, run the server with the environment variable `CATERVA2_SECRET` set to some non-empty, secure string that will be used for various user management operations. Note that new accounts may be registered, but their addresses are not verified. Password recovery does not work either.

To create a user, you can use the `cat2adduser` command line client. For example:
To create a user, you can use the `cat2-admin adduser` command. For example:

```sh
cat2adduser user@example.com foobar11
cat2-admin adduser user@example.com foobar11
```

Client queries then require the same user credentials:
Expand All @@ -145,11 +145,11 @@ client = cat2.Client("https://cat2.cloud/demo", ('user@example.com', 'foobar11')
- The command line client can be authenticated with the `--user` and `--pass` options

### The command line client
Now that the services are running, we can use the `cat2cli` client to talk
Now that the services are running, we can use the `cat2-client` client to talk
to the server. In another shell, let's list all the available roots in the system:

```sh
cat2cli --user "user@example.com" --pass "foobar11" roots
cat2-client --user "user@example.com" --pass "foobar11" roots
```

```
Expand All @@ -160,20 +160,20 @@ cat2cli --user "user@example.com" --pass "foobar11" roots
First let's upload a file from the `root-example`folder to the `@personal` root:

```sh
cat2cli --username user@example.com --password foobar11 upload root-example/ds-1d.b2nd @personal/ds-1d.b2nd
cat2-client --username user@example.com --password foobar11 upload root-example/ds-1d.b2nd @personal/ds-1d.b2nd
```

Now, one can list the datasets in the `@personal` root and see that the uploaded file appears

```sh
cat2cli --username user@example.com --password foobar11 list @personal
cat2-client --username user@example.com --password foobar11 list @personal
>> ds-1d.b2nd
```

Let's ask the server for more info about the dataset:

```sh
cat2cli --username user@example.com --password foobar11 info @personal/ds-1d.b2nd
cat2-client --username user@example.com --password foobar11 info @personal/ds-1d.b2nd
```

```
Expand All @@ -191,7 +191,7 @@ Getting info for @personal/ds-1d.b2nd
'cparams': {'codec': 5, 'codec_meta': 0, 'clevel': 1, 'filters': [0, 0, 0, 0, 0, 1], 'filters_meta': [0, 0, 0, 0, 0, 0], 'typesize': 8, 'blocksize': 80, 'nthreads': 1, 'splitmode': 1, 'tuner': 0, 'use_dict': False, 'filters, meta': [[1, 0]]},
'cratio': 1.5929908403026682,
'nbytes': 8000,
'urlpath': '/home/lshaw/Caterva2/_caterva2/sub/personal/2fa87091-84c6-44f9-a57e-7f04290630b1/ds-1d.b2nd',
'urlpath': '/home/lshaw/Caterva2/_caterva2/state/personal/2fa87091-84c6-44f9-a57e-7f04290630b1/ds-1d.b2nd',
'vlmeta': {},
'nchunks': 10,
'mtime': None
Expand All @@ -202,10 +202,10 @@ Getting info for @personal/ds-1d.b2nd

This command returns a JSON object with the dataset's metadata, including its shape, chunks, blocks, data type, and compression parameters. The `schunk` field contains information about the underlying Blosc2 super-chunk that stores the dataset's data.

There are more commands available in the `cat2cli` client; ask for help with:
There are more commands available in the `cat2-client` client; ask for help with:

```sh
cat2cli --help
cat2-client --help
```

### Docs
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ the content of ``caterva2.sample.toml`` to ``caterva2.toml``
and run the following commands::

$ rm -r _caterva2/
$ cat2adduser superuser@example.com foobarfoo -S
$ cat2-admin adduser superuser@example.com foobarfoo -S
$ CATERVA2_SECRET="123" cat2sub

And experiment a bit with uploading, browsing and downloading files.
Expand Down
2 changes: 1 addition & 1 deletion SPECS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ There should be a configuration file (by default $CWD/caterva2.toml) where the c
[server]
http = "localhost:8000"
urlbase = "https://cat2.example.com" # e.g. served by reverse proxy
statedir = "_caterva2/sub"
statedir = "_caterva2/state"
loglevel = "warning"
```

Expand Down
8 changes: 4 additions & 4 deletions caterva2.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

# The server section must define:
#
# - statedir: the directory where the server's data will be stored (default: _caterva2/sub)
# - statedir: the directory where the server's data will be stored (default: _caterva2/state)
# - http: where the server listens to (a unix socket or a host/port) (default: localhost:8000)
# - urlbase: the base url users will use to reach the server (default: http://localhost:8000)
# - quota: if defined, it will limit the disk usage (default: 0, no limit)
# - maxusers: if defined, it will limit the number of users (default: 0, no limit)
# - login: if true, users will need to authenticate (default: true)
# - register: if true, users will be able to register (default: false)
#
[subscriber]
statedir = "_caterva2/sub"
#http = "_caterva2/sub/uvicorn.socket"
[server]
statedir = "_caterva2/state"
#http = "_caterva2/state/uvicorn.socket"
http = "localhost:8000"
urlbase = "http://localhost:8000"
quota = "10G"
Expand Down
6 changes: 3 additions & 3 deletions caterva2/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def slice_to_string(slice_):

def get_auth_cookie(urlbase, user_auth, timeout=5):
"""
Authenticate to a subscriber as a user and get an authorization cookie.
Authenticate to a server as a user and get an authorization cookie.

Authentication fields will usually be ``username`` and ``password``.

Parameters
----------
urlbase : str
The base of URLs of the subscriber to query.
The base of URLs of the server to query.
user_auth : dict
A mapping of fields and values used as data to be posted for
authenticating the user.
Expand All @@ -55,7 +55,7 @@ def get_auth_cookie(urlbase, user_auth, timeout=5):
-------
str
An authentication token that may be used as a cookie in further
requests to the subscriber.
requests to the server.

Examples
--------
Expand Down
4 changes: 2 additions & 2 deletions caterva2/clients/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ def main():
conf = utils.get_conf()
parser = utils.get_parser()
parser.add_argument(
"--subscriber",
"--server",
dest="urlbase",
type=utils.urlbase_type,
default=conf.get("subscriber.url", cat2.sub_urlbase_default),
default=conf.get("server.url", cat2.sub_urlbase_default),
)
parser.add_argument("--username", default=conf.get("client.username"))
parser.add_argument("--password", default=conf.get("client.password"))
Expand Down
4 changes: 2 additions & 2 deletions caterva2/clients/tbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def main():
conf = utils.get_conf()
parser = utils.get_parser()
parser.add_argument(
"--subscriber",
"--server",
dest="urlbase",
type=utils.urlbase_type,
default=conf.get("subscriber.url", api.sub_urlbase_default),
default=conf.get("server.url", api.sub_urlbase_default),
)
parser.add_argument("--username", default=conf.get("client.username"))
parser.add_argument("--password", default=conf.get("client.password"))
Expand Down
7 changes: 2 additions & 5 deletions caterva2/services/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io
import itertools
import json
import logging
import mimetypes
import os
import pathlib
Expand Down Expand Up @@ -53,8 +52,6 @@
# Set CATERVA2_SECRET=XXX in .env file in working directory
dotenv.load_dotenv()

# Logging
logger = logging.getLogger("sub")

# State
locks = {}
Expand Down Expand Up @@ -2579,11 +2576,11 @@ def guess_dset_ctype(path: pathlib.Path, meta) -> str | None:

def main():
# Load configuration (args)
conf = utils.get_conf("subscriber")
conf = utils.get_conf("server")
parser = utils.get_parser(
http=conf.get(".http", "localhost:8000"),
loglevel=conf.get(".loglevel", "warning"),
statedir=conf.get(".statedir", "_caterva2/sub"),
statedir=conf.get(".statedir", "_caterva2/state"),
)
args = utils.run_parser(parser)

Expand Down
2 changes: 1 addition & 1 deletion caterva2/services/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def parse_size(size):
return int(number * units[unit])


conf = utils.get_conf("subscriber")
conf = utils.get_conf("server")

urlbase = conf.get(".urlbase", "http://localhost:8000")
login = conf.get(".login", True)
Expand Down
2 changes: 1 addition & 1 deletion caterva2/tests/caterva2-login.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[subscriber]
[server]
login = true
register = true
maxusers = 5
2 changes: 1 addition & 1 deletion caterva2/tests/caterva2-nologin.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[subscriber]
[server]
login = false
register = false
maxusers = 5
4 changes: 2 additions & 2 deletions caterva2/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def pytest_configure(config):

@pytest.fixture(scope="session")
def client(services): # noqa: F811
urlbase = services.get_urlbase("subscriber")
urlbase = services.get_urlbase("server")
return cat2.Client(urlbase)


Expand All @@ -36,5 +36,5 @@ def auth_client(services, sub_user): # noqa: F811
if not sub_user:
return None

urlbase = services.get_urlbase("subscriber")
urlbase = services.get_urlbase("server")
return cat2.Client(urlbase, sub_user)
6 changes: 3 additions & 3 deletions caterva2/tests/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def http_service_check(conf, conf_sect, def_host, path):


def sub_check(conf):
return http_service_check(conf, "subscriber", get_sub_ep(), "/api/roots")
return http_service_check(conf, "server", get_sub_ep(), "/api/roots")


TestRoot = collections.namedtuple("TestRoot", ["name", "source"])
Expand All @@ -110,7 +110,7 @@ def __init__(self, state_dir, reuse_state=True, roots=None, configuration=None):
self._setup_done = False

def _start_server(self, *args, check=None):
name = "subscriber"
name = "server"
if check is not None and check():
raise RuntimeError(
f'check for service "{name}" succeeded before start'
Expand Down Expand Up @@ -222,7 +222,7 @@ def make_sub_user(services):
if not os.environ.get("CATERVA2_SECRET"):
return None

state_dir = services.state_dir / "subscriber"
state_dir = services.state_dir / "server"
return srv_utils.add_user(
"user@example.com", password="foobar11", is_superuser=True, state_dir=state_dir
)
Expand Down
6 changes: 3 additions & 3 deletions caterva2/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@pytest.fixture
def fill_public(client, examples_dir):
# Manually copy some files to the public area (TEST_STATE_DIR)
dest_dir = pathlib.Path(TEST_STATE_DIR) / "subscriber/public"
dest_dir = pathlib.Path(TEST_STATE_DIR) / "server/public"
fnames = [str(fname.relative_to(examples_dir)) for fname in examples_dir.rglob("*") if fname.is_file()]
for fname in fnames:
orig = examples_dir / fname
Expand Down Expand Up @@ -937,8 +937,8 @@ def test_adduser_maxexceeded(auth_client, configuration):
pytest.skip("authentication support needed")

# TODO: make this to work; currently this returns None
# maxusers = configuration.get("subscriber.maxusers")
# For now, keep in sync with subscriber.maxusers in caterva2/tests/caterva2-login.toml
# maxusers = configuration.get("server.maxusers")
# For now, keep in sync with server.maxusers in caterva2/tests/caterva2-login.toml
maxusers = 5
# Add maxusers users; we already have one user, so the next loop should fail
# when reaching the creation of last user
Expand Down
2 changes: 1 addition & 1 deletion caterva2/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@pytest.fixture
def sub_urlbase(services):
return services.get_urlbase("subscriber")
return services.get_urlbase("server")


def cli(cargs, binary=False, sub_user=None) -> str or dict:
Expand Down
9 changes: 5 additions & 4 deletions caterva2/tools/adduser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
###############################################################################

"""
Add a user to the subscriber database.
Add a user to the server database.

Contrarily to `cat2cli adduser`, this script does not require a running Caterva2 subscriber.
Contrarily to `cat2-client adduser`, this script does not require a running Caterva2 server.
Note: This script is deprecated. Use `cat2-admin adduser` instead.
"""

from caterva2 import utils
Expand All @@ -19,9 +20,9 @@

def main():
# Load configuration (args)
conf = utils.get_conf("subscriber")
conf = utils.get_conf("server")
parser = utils.get_parser(
statedir=conf.get(".statedir", "_caterva2/sub"),
statedir=conf.get(".statedir", "_caterva2/state"),
)
parser.add_argument("username")
parser.add_argument("password", nargs="?")
Expand Down
Loading