A node server to implement the IMF Media Management API with a choice of databases
The default behaviour is to provide a simple app that will scan one or more folders for IMF assets, build a database of those assets and then serve the locations of those assets based on the IDs or hash values found. New assets can be registered using the API.
The app is controlled via your system's default browser and has been tested with Chrome, Chromium Firefox and Edge on Windows & Linux. The cloud deployment is available at imf-mm-api.cloud.
You can modify the behaviour by changing the config (see below). This will allow you to disable certain funcitons or to mount the application on a server somethwere other than the root of the domain.
This app is meant to demonstrate the API functionality. The backend is not intended for production. Contact Mr MXF if you need something more robust.
cd into that foldernpm install --productionnpm audit fixnpm dedupe.env file with how you want to run the code and credentials for AWS if you
are going to use AWS SimpleDB as your database# run time environment variables for imf-mm-api (you can safely copy this to a .env file)
#
# what mode are we in? Uncomment one of these
#NODE_ENV=test
NODE_ENV=development
#NODE_ENV=staging
#NODE_ENV=beta
#NODE_ENV=production
export NODE_ENV
#
# Override any configuration property via environement JSON e.g. port or disable DB delete
NODE_CONFIG='{"port":3100,"log_options":{"level":"error","log_api_access":false},"enable":{"admin_delete_db":false}}'
export NODE_CONFIG
#
# AWS keys to access SimpleDB if you use your own cloud AWS SimpleDB database
AWS_ACCESS_KEY_ID=XxXxXxXxXxXxXxXxXxXx
AWS_SECRET_ACCESS_KEY=ZzZzZzZzZzZzZzZzZzZzZzZzZzZzZzZzZzZzZzZz
export AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY
#
# GIT url for this version for display in browser
GIT_URL=https://github.com/mrmxf/imf-mm-api/tree/1348034577d532bd0ea4a8b267a2a8b54feb5264
export GIT_URL
NODE_ENV in .envnpm startnpm install pm2 and then pm2 start src/start_localnpm installnpm install --global nodemon (makes changing the code easier)npm install --global gulp-cli (for documentation & deploy scripts).env file with NODE_ENV=development to turn on pretty logging and pull in the development.json config filedevelopment.json config file with the settings that you want.env file with your remote host if doing a sync to a cloud instancenodemon src/start_local and hack away. Server will restart with every code savenpm test to verify everything is working on your environment__test__ folder for your new components (there are examples for synchronous, asynchronous and API response tests)jest section of package.json to specify which tests to run and how to view the resultsThis is currently not working, so these are the right instructions but the repository won't run properly until a few bugs are ironed out. Probably August 2019 for that update.
npm install --global serverless/.vscode/runtime.env to set NODE_ENVserverless.yml to set NODE_ENV for the cloudformation deployed appThe project can be used as Docker container.
First build the image:
docker build -t imf-mm-api .
First build the image:
docker run -d -p 3100:3100 --name imf-mm imf-mm-api
Then simply access to the API: http://localhost:3100/demo/1/assets
To use the simpledb cloud database as the backend, you will need to provide AWS keys that allow the creation of a simpledb domain and access to Simpledb records.
All AWS credentials are taken from environment variables - it's up to you to make them right before executing the demo server if you're going to use the AWS facilities of the demo.
Region information is stored in the config files. The following permissions are needed if you're going to replicate the s3 bucket storage and replicated the SimpleDB back end:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:ListBucketByTags",
"s3:GetBucketTagging",
"s3:GetObjectVersionTagging",
"s3:ListBucketVersions",
"s3:GetBucketLogging",
"s3:ListBucket",
"s3:GetObjectTagging",
"s3:ListBucketMultipartUploads",
"s3:GetBucketWebsite",
"s3:GetBucketNotification",
"s3:GetObjectVersionForReplication",
"s3:GetBucketLocation",
"s3:GetObjectVersion",
"s3:GetAccountPublicAccessBlock",
"s3:ListAllMyBuckets",
"s3:HeadBucket"
],
"Resource": [
"arn:aws:s3:::*/*",
"arn:aws:s3:::imf-mm-api-media"
]
},
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sdb:ListDomains",
"Resource": "*"
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": "sdb:*",
"Resource": "arn:aws:sdb:eu-east-2:*:domain/myDomainName"
}
]
}
default.json has the master list of all the configuration options. These properties are
overloaded by NODE_ENV that controls the functiona mode of the app. For example, you might
make some changes and run the software with NODE_ENV set to staging so that you can test
the changes along side your main server.
port {number} controls the port that the server will respond toapp_name {string] used when GET admin/info is requestedapp_version {string] used when GET admin/info is requestedapp_authors {string] used when GET admin/info is requestedapi_prefix {string] controls the url prefix for API response e.g. GET staging/assetsdatabase {object}
database.type {string} is either local or aws-simple-db other values require updating src/db.jsdatabase.local_filename {string} relative filename for database when type is local e.g. db/imf-mm-api-lowdb.jsondatabase.simpledb_domain_name {string} domain name used for aws simpledb e.g. imf-mm-api-server-jsdefault_get_limit {number} paging control for GET responses. API default is 20enable {object} controls which functions are enabled or disabled
enable.admin {boolean}": global switch for the /admin route
GET admin/info information about the running appGET admin/db-info information about the database in useGET admin/readme the current (unprocessed) README.md for the appDELETE admin/db delete and recreate the current databaseenable.admin_delete_db {boolean} additional control to prevent database deletion when enable.admin is trueenable.assets {boolean} enable the assets APIenable.crawl {boolean} enable population of the database by crawling folders specified in the config filesenable.www {boolean} enable serving static pages for interactive useenable.load_home_page_on_boot {boolean} when the app is run, use the OS to open a browser (turn off in the cloud!)enable.extended_status_messages {boolean} append the description text from the assets API swagger document to error responsesenable.synth_local_test_data {boolean} recreate run time information for the local IMF test assets
(only needed if you make changes to the __test__/assets-xxx folders. Set to false if program folder is write protected)mount_point set the url to which all the end points are mounted - very handy with cloudfront
/ to respond to GET /assets/my_cloudfront_host/web_root to respond to GET /my_cloudfront_host/web_root/assetsimf_asset_sources {array} determines where the crawl function will search for IMF assets. If the array
element is a string then it is treated as a file root and search is performed hierarchically below that folder.
If the array element is an object, then is is treated as an s3 bucket object and the appropriate access
permissions should be available via the environment keys
[ "__test__/assets-imf" ] default value to search the test assets supplied with this app[ "\\\\unc_mount\\win\\doze\\folder", "/mnt/nfs/nix/folder" ] scanning network folders[{"arn": "arn:aws:s3:::imf-mm-api-media","bucket": "imf-mm-api-media","root": "media/bs500","region": "us-east-2"}]
object.arn {string} the arn of the bucket to be crawledobject.bucket {string} the name of the bucketobject.root {string} the path below which the crawler should crawl for IMF assetsobject.region {string the region in which the bucet is locatedlambda {object} The lambda functionality is currently not working - BO NOT USE
lambda.params.name {string} name of the lambda function implementing these end points e.g. "imf-api-staging-test",lambda.params.role {string role with access rights e.g. "arn:aws:iam::217890066136:role/service-role/mm-lambda-api-gateway-role"lambda.options.region {string} deployed region of the lambda function e.g. "eu-east-2"log_options {object} controls the logging of the server. Logs are created in JSON format by pino.
There are many adapters and converters to make the logs usable in elasticsearch, excel or whatever religion is your favourite.
log_options.level {string} minimum level of logs to be output. Values are: fatal, error, warn, info, debug, trace, silentlog_options.prettyPrint {boolean} makes the console output of the logs pretty. This slows the world down.log_options.show_config_sources {boolean} dumps the configuration sources in the order they were loaded. A security risk in a live systemlog_options.log_api_access {boolean} loads the logger into the server stack to log all access to the server.provider_id {string} The provider id that will be insered into the database when this app uses the POST or PUT methods
e.g. "imf-mm-api Demo App",assets and filter them by file typeconfig.mount_pointstaging, beta and 1/ end pointsContent type
Image
Digest
Size
123.2 MB
Last updated
almost 7 years ago
docker pull mediaio/imf-mm-api:devel