Giter Site home page Giter Site logo

cca / equella_cli Goto Github PK

View Code? Open in Web Editor NEW
0.0 15.0 0.0 323 KB

command-line interface to openEQUELLA REST APIs (npm)

Home Page: https://www.npmjs.com/package/equella-cli

License: Other

JavaScript 100.00%
equella javascript api-client institutional-repository

equella_cli's Introduction

EQUELLA CLI

npm version

Command line interface to the openEQUELLA REST APIs.

WARNING use at your own risk. In particular, PUT and POST requests do not lock the resources they're editing. Safe for GETting information, though.

Setup

Install node, install equella-cli globally with npm i -g equella-cli, and configure an .equellarc file. The rc file can live in your user's home directory, the working directory where you're running eq commands, or any parent of the working directory. Really, anywhere that rc looks. At a bare minimum, the rc file looks like:

{
    "root": "https://equella.mydomain.edu",
    "token": "abcd1234-ab12-1234-12ab-abcd1234abcd"
}

Any option listed in the endpoints documentation can also be given a default in the rc file; the name of the configuration option is simply the command line flag minus the two leading hyphens. Values specified on the command line override rc values. Here are some potential options:

{
    "debug": true, // log URLs of all requests to stderr
    "fullterm": false, // don't search full taxonomy term path
    "collections": "6b755832-4070-73d2-77b3-3febcc1f5fad", // search only this collection
}

Consult the openEQUELLA REST API guide for instructions on generating an OAUTH token. It involves configuring a client, then visiting https://equella.mydomain.edu/oauth/authorize?response_type=token&client_id=$CLIENT_ID&redirect_uri=default

Usage

Endpoints

See the endpoints document for documentation on options and shortcuts related to specific API endpoints like taxonomy, groups, search, and items.

Miscellaneous

Helpful things. URLs open in your default browser.

eq help - help docs for the command itself

eq login — sign into EQUELLA using credentials in .equellarc file or --username and --password flags passed on the command line

eq docs, eq apidocs — open the API documentation URL

eq launch - run the new admin console launcher, requires a launcherPath option that points to the script.

eq admin, eq console — opens the download URL for the EQUELLA admin console Java app

Raw URL Mode

If you don't use one of the shortcuts for the various API endpoints, eq defaults to making HTTP requests to your server. It defaults to HTTP GET but you can specify other methods with the --method flag. This fallback allows eq to work with API functionality that hasn't been implemented yet.

eq 'taxonomy/1234-4321-asda-asda-1231' # get specific taxonomy
eq 'collection/?privilege=VIEW_ITEM' # get collections for which you have VIEW_ITEM privilege
eq --method del 'taxonomy/1234-asdasd-1234/term/1231231-1231231' # delete a term
eq settings/advancedsearch # see a list of advanced searches

You can combine the endpoint shortcuts below with raw URL requests by appending the rest of the URL onto a shortcut. For instance:

# list all taxonomy terms using both a shortcut & a specific path
eq tax '1234-4321-asda/term'

The --path flag is also available for specifying a path that comes after the API endpoint and any UUID. So eq tax '1234-4321-asda/term is equivalent to eq tax 1234-4321-asda --path term.

Use jq

eq is at its best in combination with a UNIX JSON utility like jq. By piping API results through jq, it's easier to extract the specific information we want as well as to iterate over results. For this reason, eq will not focus on tooling for extracting common fields from EQUELLA's JSON responses. Instead, we use jq in combination to achieve want we want, e.g.

# get the text of all top-level terms in a taxonomy
eq tax --name 'semesters' --terms | jq '.[].term'
# retrieve all the members of a group by its name
# then iterate over them printing out all their usernames (FISH loop, not BASH)
for user in (eq group --name 'system administrators' | jq '.users[]' | tr -d '"'); eq user $user | jq '.username'; end

LICENSE

ECL Version 2.0

equella_cli's People

Contributors

phette23 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

equella_cli's Issues

add length param to tax endpoint

I often want to retrieve all taxonomies and it can be done with eq tax --path '?length=500' but that's tedious, we should just expose the length parameter on the CLI.

support `HEAD` and `OPTIONS` methods

They're simply converted to GET requests which return no information right now (or possibly throw a JSON parsing error on the empty response body?). Edit lib/req.js to have more conditions to support these and return HTTP header information.

launch doesn't seem to copy to clipboard consistantly

It seems like when eq is installed globally then the clipboard portion of eq launch doesn't work at all, while if I go inside the project directory and npm link it into place then it does work. Not sure what the the problem is, everything else works so the .equellarc file is being read correctly.

documentation

there's like basically no documentation on the command line right now, not from a --help flag nor for any of the API routes

work with pipes, check stdin

use a typical UNIX syntax with a special hyphen - argument to indicate we need to check stdin such that things like jq .uuid taxonomy.json | eq tax - work as expected

this might be tricky in terms of figuring out when stdin is a file being piped to eq or an argument and then what type of argument (e.g. we accept full URLs, shortcuts, shortcuts plus UUIDs, etc. there are many forms of arguments)

add `access` route with series of sub-routes

format: eq access liu opens the "logged in users" settings page, etc. Here's a list of valuable routes:

  • liu -> /access/liu.do
  • settings -> /access/settings.do
  • diag, diagnostics -> /access/diagnostics.do
  • theme -> /access/themesettings.do

could we use yargs for API endpoints?

The current infrastructure for API endpoints is messy. yargs has a nice, clean syntax for creating subcommands with aliases which would let us remove lots of horrible code.

My one question is how it would function alongside rc, whose syntax for arguments and the way it handles a default configuration file I really like and the project depends upon heavily. I'm not sure how easy those features would be to recreate under yargs.

add endpoint for new search v2 API

One of the more recent releases introduced a second search API https://vault.cca.edu/apidocs.do#operations-tag-Search_V2 to support the new UI. It might be faster than the original but it looks promising in other ways too:

  • has an identical set of parameters as the old search API, so we should get very far just copying the original code but replacing /search with /search2
  • has a new mimeTypes filter
  • has a new musts filter (examples: realthumb:true, videothumb:true, it says these are "search index key/value pairs" but I don't know what the list of those are, from the examples it seems like it is used to construct gallery type search results which require these sorts of preview derivatives)
  • has a new /search2/export endpoint which might be the backend implementation of the new search UI's CSV export; if so, this gives us a way to utilize this new feature without needing to switch to the new UI

endpoints documentation

The endpoints documentation is going to be really long, making the readme unmanageable as features are added. Should it be moved to:

  • GitHub wiki?
  • a separate markdown doc? (slight preference, don't like tying vital dox into GH platform)

requests & punycode are deprecated

Starting with node 21, punycode is deprecated and you receive a lot of warnings when running eq like this:

(node:67092) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

requests is the culprit, which is also deprecated. I need to switch to node-fetch.

shortcut to open launcher app

Since eq admin is no longer relevant, it makes sense to A) remove it from the main help documentation (but leave in the specific eq help admin for people who use it) and B) add a new shortcut command to run the launcher app, similar to my vadmin shortcut script that runs the launcher script in the background and pipes all its output to /dev/null.

add commands for logging in to EQUELLA as user

This opens up a whole slew of possibilities if it can be reduced to opening a particular URL, and I seem to recall there are query string parameters you can pass to the login page that are filled into the login form automatically. It'd be cool to set this up and allow users to define a login account in their .equellarc file.

After that's in place, could see a whole new command like eq access liu being useful which just opens directly to all the different settings pages (Logged In Users, Diagnostics, Theme Settings, etc.).

cache collections, groups JSON files

It might be too complicated but for data that doesn't change very often, like collections and groups (but obviously not items or taxonomies), it would be nice to cache their JSON data on disk so as to avoid HTTP requests. Could cache in ~/.equellacli or a EQ_CACHE env var, have a flag to override the cache, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.