LD4P / sinopia_acl

node.js based code to interact with WebACL data on sinopia server
Apache License 2.0
0 stars 0 forks source link

npm CircleCI Test Coverage Maintainability

sinopia_acl

node.js based code to interact with WebACL data on Sinopia server.

WebACL (https://www.w3.org/wiki/WebAccessControl) is how we will gate access to various LDP containers on the server.

The "copy of record" of group/webID mappings will be in the Sinopia server.

Prerequisites

You will need to install the npm packages before running any of the code (which also requires that the npm package manager itself is installed)

$ npm install

Command Line

This code may have a simple CLI for Sinopia Server admins to use to be developed in a future work cycle (as of April, 2019).

Spinning up Trellis LDP Server

To spin up Trellis and its dependencies with the Sinopia container structure (root, repository, and group containers) and ACLs (declared on root container) pre-created, use the platformdata docker-compose service:

# Add -d flag to run containers in background
$ docker-compose up platformdata

NOTE: In order for the above to work, you will need to set COGNITO_ADMIN_PASSWORD, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY in a file named .env in the sinopia_acl root.

To spin up Trellis and its dependencies without the container structure and ACLs pre-created, use the platform docker-compose service:

# Add -d flag to run containers in background
$ docker-compose up platform

Migration Script to Populate existing Trellis LDP Server with Sinopia container structure and ACLs

There is a script to populate a running Trellis LDP server with the Sinopia container structure (root, repository, and group containers) and ACLs (declared on root container).

This script can be run repeatedly

Requirements:

These env vars must be set:

If the desired AWS Cognito pool is not the Cognito Sinopia development pool, these env vars are also needed:

Example:

$ COGNITO_ADMIN_USER=hoohah COGNITO_ADMIN_PASSWORD=foobar AWS_PROFILE=barfoo bin/migrate

Authenticate to AWS Cognito

You can use the bin/authenticate command-line tool to authenticate to an AWS Cognito instance. This command will create a new file called .cognitoToken which contains a JSON Web Token, which you can use to authorize HTTP requests to the Sinopia server (Trellis). How to authenticate:

$ AWS_PROFILE=name_of_aws_profile_used_in_~/.aws/config_file COGNITO_USER_POOL_ID=us-west-2_ABC123XYZ COGNITO_CLIENT_ID=abc123xyz456etc AWS_COGNITO_DOMAIN=https://sinopia-{ENV}.auth.us-west-2.amazoncognito.com bin/authenticate

NOTE: If you provide none of the above environment variables, bin/authenticate will default to the Sinopia development instance of Cognito and its sole user pool.

The JWT stored in .cognitoToken will be valid for approximately an hour.

Use JWT in HTTP Request

To use the JWT as stored in .cognitoToken to make authorized requests to Trellis, you can pass it along in the HTTP request as follows:

$ curl -i -H "Authorization: Bearer $(cat .cognitoToken)" http://localhost:8080/?ext=acl

Testing

Linter

To run the linter:

$ npm run eslint

Unit tests

To run unit tests:

$ COGNITO_ADMIN_PASSWORD=foobar AWS_PROFILE=barfoo npm test

Note that you will need to replace the value of

Integration

If you're going to be doing active development, you'll most likely want to spin up docker-compose services and run integration tests separately, since you will do this multiple times while getting the code right. If so, first spin up the integration environment—Trellis & its dependencies—in the background (via -d) using docker-compose:

$ docker-compose up -d platform

To run the integration tests, they must be invoked independent of the unit tests:

$ npm run jest-integration

To shut the containers down and clean up, run:

$ docker-compose down

Or if you just need to run the integration tests once (assuming you haven't already started up docker-compose services), you can do the following to spin up containers, run integration tests, and then spin containers down. (This is how integration tests are run in CI.)

$ docker-compose run integration
$ docker-compose down

Development Principles:

Build and push image

The CircleCI build is configured to perform these steps automatically on any successful build on the master branch. If you need to manually build and push an image, you can do this:

$ docker build -t ld4p/sinopia_acl:latest .
$ docker push ld4p/sinopia_acl:latest