Skip to content

freyamade/openapi-fs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAPIFS: OpenAPI Rest API via FUSE

Mount a valid OpenAPI supporting REST API as a directory, and support CRUDL commands via file-system commands. Supports setting Bearer tokens for authentication into the API as well.

Directory structure is generated via parsing URL path specifications, and maps 1-to-1 to endpoints available on the API for consistency. To handle nested URL structures under individual objects (i.e. /heroes/1/villains), all individual objects will be a directory and the data for the object will be contained in the data.json file.

Prerequisites

  • Python 3.11+ and Poetry
  • System Dependencies: You must have FUSE and its development headers installed (e.g., libfuse-dev and fuse on Ubuntu/Debian).
  • OpenAPI Documentation File: If needed, a simple FastAPI system is provided and can be used for investigation.

Setup

  1. Install Dependencies

    poetry install

    If you want to use the Test API, include its dependencies using the following;

    poetry install --with test_api
  2. Test API (if required):

    poetry run python -m test_api

Usage

You must provide a Swagger file URL when starting the server. This file will be read to determine the URL of the server and how to supply any authentication (if necessary).

poetry run python -m fs [OPTIONS] API_URL MOUNTPOINT

As an example, to mount the test api to a local mount directory;

mkdir test_api_fs
poetry run python -m fs http://localhost:8000/openapi.json test_api_fs

If you need to set Authorization headers, you can use the -H flag;

poetry run python -m fs http://localhost:8000/openapi.json -H Authorization "Basic aGVyb19tYW5hZ2VyOmFiYzEyMw==" test_api_fs

NOTE You need to provide this header to access test_api_fs/heroes/*/villains/ or else it will be empty.

Unmounting

To remove the mounted directory, simply run

umount test_api_fs

or whatever other directory you have mounted.

CRUDL Mapping;

Using the Test API schema as our examples;

List Heroes

ls test_api_fs/heroes

Create New Hero

echo '{"age":52,"secret_name":"Brian","id":3,"name":"Test Hero 3"}' > test_api_fs/heroes/new.json

Any edits to the new.json file will result in a POST request being sent.

Read Hero Details

cat test_api_fs/heroes/1/data.json

Update Hero Details

sed s/oldvalue/newvalue/ test_api_fs/heroes/1/data.json > test_api_fs/heroes/1/data.json

Temporary files cannot be created under the filesystem due to its nature so sed -i doesn't work as intended.

Delete Hero

rm test_api_fs/heroes/2/data.json

Assumptions Made

  • For sake of ease, API objects are assumed to have either an id or pk property, used as a parameter to the URLs.
  • If you have an API that does not reflect this and have ideas on how to expand this library to enable it, please send a PR!

About

An experiment with FUSE, attempting to map CRUDL methods to Filesystem commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages