Skip to content

libms 0.5.0

Install from the command line:
Learn more about npm packages
$ npm install @into-cps-association/libms@0.5.0
Install via package.json:
"@into-cps-association/libms": "0.5.0"

About this version

Overview

The lib microservice is a simplified file manager providing graphQL API. It has two features:

  • provide a listing of directory contents.
  • transfer a file to user.

⬇️ Install

Default NPM Registry

The default registry for npm packages is npmjs. Install the package with the following commands

sudo npm install -g @into-cps-association/libms

The package on npmjs is published less frequently than the one on Github NPM Registry. But the package on npmjs is more stable version of libms and should be used for production purposes.

Github NPM Registry

The package is also available in Github packages registry.

Set the registry and install the package with the following commands

sudo npm config set @into-cps-association:registry https://npm.pkg.github.com
sudo npm install -g @into-cps-association/libms

The npm install command asks for username and password. The username is your Github username and the password is your Github personal access token. In order for the npm to download the package, your personal access token needs to have read:packages scope.

⚙️ Configure

The microservices requires config specified in INI format. The template configuration file is:

PORT='4001'
MODE='local' or 'gitlab'
LOCAL_PATH ='/Users/<Username>/DTaaS/files'
LOG_LEVEL='debug'
APOLLO_PATH='/lib' or ''
GRAPHQL_PLAYGROUND='false' or 'true'

#Only needed if git mode
GIT_USER1_REPO_URL='<git repo url>'
GIT_USER1_API_TOKEN='<TOKEN>'
...
GIT_USERX_REPO_URL='<git repo url>'
GIT_USERX_API_TOKEN='<TOKEN>'

The LOCAL_PATH variable is the absolute filepath to the location of the local directory which will be served to users by the Library microservice.

Replace the default values the appropriate values for your setup. Please save this config in a file.

🚀 Use

Display help.

$libms -h
Usage: libms [options]

The lib microservice is a file server. It supports file transfer
over GraphQL and HTTP protocols.

Options:
  -c, --config <file>  provide the config file (default .env)
  -H, --http <file>    enable the HTTP server with the specified config
  -h, --help           display help for libms

Both the options are not mandatory.

Configuration file

The config is saved .env file by convention. If -c is not specified The libms looks for .env file in the working directory from which it is run. If you want to run libms without explicitly specifying the configuration file, run

libms

To run libms with a custom config file,

libms -c FILE-PATH
libms --config FILE-PATH

If the environment file is named something other than .env, for example as config/.env.default, you can run

libms -c "config/.env.default"

You can press Ctl+C to halt the application.

Protocol Support

The libms supports GraphQL protocol by default. It is possible to enable the HTTP protocol by setting the -H option.

To run libms with a custom config for HTTP protocol, use

libms -H FILE-PATH
libms --http FILE-PATH
Please see this sample HTTP config file
{
  "name": "DTaaS Fileserver",
  "auth": false,
  "editor": "edward",
  "packer": "zip",
  "diff": true,
  "zip": true,
  "buffer": true,
  "dirStorage": true,
  "online": false,
  "open": false,
  "oneFilePanel": true,
  "keysPanel": false,
  "prefix": "/lib/files",
  "confirmCopy": true,
  "confirmMove": true,
  "showConfig": false,
  "showFileName": true,
  "contact": false,
  "configDialog": false,
  "console": false,
  "terminal": false,
  "vim": false,
  "columns": "name-size-date-owner-mode",
  "export": false,
  "import": false,
  "dropbox": false,
  "dropboxToken": "",
  "log": true
}

Application Programming Interface (API)

The lib microservice application provides services at two end points:

HTTP protocol

Endpoint: localhost:PORT/lib/files

This option needs to be enabled with -H http.json flag. The regular file upload and download options become available.

GraphQL protocol

Endpoint: localhost:PORT/lib

GraphQL API details The lib microservice takes two distinct GraphQL queries.

Directory Listing

This query receives directory path and provides list of files in that directory. A sample query and response are given here.

query {
  listDirectory(path: "user1") {
    repository {
      tree {
        blobs {
          edges {
            node {
              name
              type
            }
          }
        }
        trees {
          edges {
            node {
              name
              type
            }
          }
        }
      }
    }
  }
}
{
  "data": {
    "listDirectory": {
      "repository": {
        "tree": {
          "blobs": {
            "edges": []
          },
          "trees": {
            "edges": [
              {
                "node": {
                  "name": "common",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "data",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "digital twins",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "functions",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "models",
                  "type": "tree"
                }
              },
              {
                "node": {
                  "name": "tools",
                  "type": "tree"
                }
              }
            ]
          }
        }
      }
    }
  }
}

Fetch a File

This query receives directory path and send the file contents to user in response.

To check this query, create a file files/user2/data/welcome.txt with content of hello world.

A sample query and response are given here.

query {
  readFile(path: "user2/data/sample.txt") {
    repository {
      blobs {
        nodes {
          name
          rawBlob
          rawTextBlob
        }
      }
    }
  }
}
{
  "data": {
    "readFile": {
      "repository": {
        "blobs": {
          "nodes": [
            {
              "name": "sample.txt",
              "rawBlob": "hello world",
              "rawTextBlob": "hello world"
            }
          ]
        }
      }
    }
  }
}

Direct HTTP API Calls in lieu of GraphQL API Calls

The lib microservice also supports making API calls using HTTP POST requests. Simply send a POST request to the URL endpoint with the GraphQL query in the request body. Make sure to set the Content-Type header to "application/json".

The easiest way to perform HTTP requests is to use HTTPie desktop application. You can download the Ubuntu AppImage and run it. Select the following options:

Method: POST
URL: localhost:4001
Body: <<copy the json code from examples below>>
Content Type: text/json

Here are examples of the HTTP requests and responses for the HTTP API calls.

Directory listing

POST /lib HTTP/1.1
Host: localhost:4001
Content-Type: application/json
Content-Length: 388

{
   "query":"query {\n  listDirectory(path: \"user1\") {\n    repository {\n      tree {\n        blobs {\n          edges {\n            node {\n              name\n              type\n            }\n          }\n        }\n        trees {\n          edges {\n            node {\n              name\n              type\n            }\n          }\n        }\n      }\n    }\n  }\n}"
}

This HTTP POST request will generate the following HTTP response message.

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 306
Content-Type: application/json; charset=utf-8
Date: Tue, 26 Sep 2023 20:26:49 GMT
X-Powered-By: Express

{"data":{"listDirectory":{"repository":{"tree":{"blobs":{"edges":[]},"trees":{"edges":[{"node":{"name":"data","type":"tree"}},{"node":{"name":"digital twins","type":"tree"}},{"node":{"name":"functions","type":"tree"}},{"node":{"name":"models","type":"tree"}},{"node":{"name":"tools","type":"tree"}}]}}}}}}

Fetch a file

This query receives directory path and send the file contents to user in response.

To check this query, create a file files/user2/data/welcome.txt with content of hello world.

POST /lib HTTP/1.1
Host: localhost:4001
Content-Type: application/json
Content-Length: 217

{
   "query":"query {\n  readFile(path: \"user2/data/welcome.txt\") {\n    repository {\n      blobs {\n        nodes {\n          name\n          rawBlob\n          rawTextBlob\n        }\n      }\n    }\n  }\n}"
}
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: close
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Wed, 27 Sep 2023 09:17:18 GMT
X-Powered-By: Express

{"data":{"readFile":{"repository":{"blobs":{"nodes":[{"name":"welcome.txt","rawBlob":"hello world","rawTextBlob":"hello world"}]}}}}}

Details


Assets

  • libms-0.5.0.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0