itg-cli-functions
v0.0.1
Published
A CLI for itg.cognite.ai
Downloads
2
Readme
itg - A CLI for https://itg.cognite.ai
Install
npm install -g @cognite/itg-cli
Commands
# Creates a new project and dumps details in .itgrc
itg init
itg schema view
# Also includes all generated types and queries
itg schema view --full
itg schema view --type=Equipment
# Check if a schema is valid graphql and fits ITG requirements
itg schema validate -f mymodel.graphql
# For CI/CD, add flag to fail when invalid schema detected
itg schema validate --fail-on-invalid -f mymodel.graphql
# Add and replace a schema in itg
itg schema update -f mymodel.graphql
itg nodes add --type Equipment -f equipment.csv
itg nodes add --type Document -f documents.csv
itg relations add Equipment.documents -f relations.csv
# Delete the project, including the .itgrc
itg prune
# Deploying a function requires the dir folder to have a file called handler.js
itg functions deploy \
--dir my-function \
--name look-at-assets \
--tenant cognite
# Create a schedule for a function. The external id is returned from functions deploy
itg functions schedule create \
--name night-job \
--cron "0 3 * * *" \
--extid function-external-id \
--tenant cognite
Global variables
Set the COGNITE_CREDENTIALS variable with an api key for the respective cdf project to get access
CI/CD
We expect the main use of the CLI for CI/CD will be validating and updating schemas. The validate step should be added to the create pr
workflow, while the update step should be added to the merge to master
workflow. Remember to include the --fail-on-invalid
flag in the validate command to avoid false positives in the workflow.
Options:
--api-key [default: $COGNITE_CREDENTIALS]
--base-url [default: "https://itg.cognite.ai"]
Functions
The function file in the folder needs to be named handler.js
, and has the following structure
async function handle({ client, data, secrets }) {
const assets = await client.assets.list().autoPagingToArray();
console.log(`Got ${assets.length} assets: `);
return { status: 'success' };
}
module.exports = handle;
Example:
$ ls
my-function
$ ls my-function
handler.js package.json