Skip to main content

Use the internal API of a RUDI Producer node

Project description

Code style: black

Caution: this librairy is still a work in progress.

RUDI Node tools: rudi-node-write library

This library offers tools to take advantage of the internal API of a RUDI Producer node ( also referred as RUDI node).

Installation

$ pip install rudi_node_write

Authentication

To use the RUDI node internal API /api/admin/..., you'll need an authentication JWT in every header request.

This library provides a RudiNodeJwtFactory connector that calls a JWT server running locally or on the RUDI node to create/renew the JWT.

rudi_node_credentials = {
    "url": "<rudi node url>",
    "usr": "<my user name>",  # either use 'usr' & 'pwd', or the base64url encoded usr:pwd pair in 'b64auth'
    "pwd": "<my password>",
    "b64auth": "<base64url encoded usr:pwd pair>"  # optional / alternative way of declaring the usr:pwd pair
}

from rudi_node_write.connectors.io_rudi_jwt_factory import RudiNodeJwtFactory

node_jwt_factory = RudiNodeJwtFactory(rudi_node_credentials["url"], rudi_node_credentials)

Usage: RudiNodeApiConnector

One can create, read, update or delete metadata with a RudiNodeApiConnector object using the [RUDI API](. /doc/rudi-api/RUDI producer internal API - 1.3.0.yml).

from rudi_node_write.connectors.io_rudi_jwt_factory import RudiNodeJwtFactory
from rudi_node_write.connectors.io_rudi_api_write import RudiNodeApiConnector

rudi_node_url = 'https://bacasable.fenix.rudi-univ-rennes1.fr'
node_jwt_factory = RudiNodeJwtFactory(rudi_node_url, {"usr": "<my user name>", "pwd": "<my password>"})

rudi_api = RudiNodeApiConnector(server_url=rudi_node_url, jwt_factory=node_jwt_factory)
print("metadata count:", rudi_api.metadata_count)
print("metadata alt count:", len(rudi_api.metadata_list))
print("metadata producers declared on the node:", rudi_api.producer_names)
print("searching a metadata with a file name:", rudi_api.find_metadata_with_media_name('toucan.jpg'))

Usage: RudiNodeMediaConnector

The upload of file is done with a RudiNodeMediaConnector that let you connect to a RUDI node Media server. This also needs an authentication in the request header, that is created with the RudiMediaHeadersFactoryBasicAuth object.

from rudi_node_write.connectors.io_rudi_media_write import RudiMediaHeadersFactoryBasicAuth, RudiNodeMediaConnector

rudi_node_url = 'https://bacasable.fenix.rudi-univ-rennes1.fr'
media_headers_factory = RudiMediaHeadersFactoryBasicAuth(usr="<my user name>", pwd="<my password>")
rudi_media = RudiNodeMediaConnector(server_url=rudi_node_url, headers_factory=media_headers_factory)

print("listing the media stored on the RUDI node: ", rudi_media.media_list)

Testing

The tests can be analyzed for further information about how to call the "RUDI API" and the "RUDI Media" servers.

$ pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rudi-node-write-0.1.1.tar.gz (49.3 kB view hashes)

Uploaded Source

Built Distribution

rudi_node_write-0.1.1-py3-none-any.whl (58.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page