api-key-cli
v1.0.4
Published
CLI app to provide various helpers for working with ArcGIS API keys
Maintainers
Readme
ArcGIS API key tool
Node.js CLI app to provide various helpers for working with ArcGIS API keys.
- Get a list of your API keys and OAuth apps.
- Get a report of your API key and OAuth app service usage.
- Get a list of your API keys that are about to expire.
- Revoke keys.
- Regenerate keys.
- Update the item meta data.
- Create new keys.
Accounts
You need an ArcGIS account in order to use this tool. There are two possibilities:
- ArcGIS Location Platform account. You can sign up for a free account if you do not have one.
- ArcGIS Online account of type Creator (or high privilege level).
Set up
Node.js is required.
Run
npm installto install the project dependencies.Create or edit
.envto set your ArcGIS account credentials. See.env.samplefor a sample. Edit this file with your information and save it as.env.Run
npm start
Command line arguments
- ✅
-a genkeys: generate new API keys using API key options template (see YAML file format below).-nnumberOfKeys-coptionsFilePath to the API key options YAML formatted file, default is./api-key-attributes.yaml-foutput format CSV|JSON|STDOUT-ooutput file path, if empty and not STDOUT then "api-keys" - ✅
-a inspect: show properties for a single api key.-ttoken or an existing API key access token or user OAuth access token-iitemId and ArcGIS portal item identifier-foutput format CSV|JSON|STDOUT-ooutput file path, if empty and not STDOUT then "api-keys" - ✅
-a report: generate API keys report as CSV file.-foutput format CSV|JSON|STDOUT-ooutput file path, if empty and not STDOUT then "api-keys" - ✅
-a expire: generate API keys report ordered by expiration date.-ddate or daysUntilExpiration, default is 30-foutput format CSV|JSON|STDOUT-ooutput file path, if empty and not STDOUT then "api-keys-expiration" - ✅
-a revoke: revoke a token on an existing api key.-iArcGIS portal item identifier of the API key to revoke-k1|2|all for which token to revoke, token 1, 2 or all tokens - ✅
-a regen: generate new tokens for an existing api key.-iArcGIS portal item identifier of the API key to update-k1|2|all for which token to regenerate-ddate or daysUntilExpiration key 1-edate or daysUntilExpiration key 2 - ✅
-a update: update an API key meta data such as title, description, tags, privileges, referrers, or redirect URIs.-iArcGIS portal item identifier of the API key to update-coptionsFilePath to the API key options YAML formatted file, or use the following command line options (NOTE: not easy to do this on the CLI if using any special characters):-ttitle-ddescription-ktags comma separated string-pprivileges comma separated string-rreferrers comma separated string-uredirect URIs comma separated string - ✅
-a delete: delete an existing api key.-iArcGIS portal item identifier of the API key to delete -vverbose output, will send extra information to STDOUT. Will mess up CSV or JSON output when not saving to a file.--helpshow help on CLI arguments.--versionshow version information.
.env tokens
Certain parameters can be sent in via environment variables. These will override a command line parameter or default. Create or edit a .env file using the .env.sample for a sample.
ARCGIS_USER_NAME: Set to the account user name of the account to use.ARCGIS_USER_PASSWORD: Password to account.ARCGIS_TOKEN: An ArcGIS access token or API key, this will override any-tCLI argument.ARCGIS_ITEM_ID: An ArcGIS portal item identifier, this will override any-iCLI argument.
API key attributes
When using the genkeys or update actions, the -c CLI argument is a file path to the API key options YAML formatted file. This describes the meta data that defines your API key portal item. It uses the following format:
options:
title: "title" - string describing the title of the item.
description: "description" - string providing the description of the item.
tags: ["tag"] - array of strings, each string is a single tag.
privileges: ["privilege"] - array of strings, each string is an ArcGIS privilege. See [Privileges](https://developers.arcgis.com/documentation/security-and-authentication/reference/privileges/location-platform/).
httpReferrers: ["domain"] - array of strings, each string is a referring URL.
redirect_uris: [] - array of string, each string is a redirect URI.
generateToken1: true|false - optional boolean, true to generate access token 1. Then one of `apiToken1ExpirationDate` or `apiToken1ExpirationDays` is required.
apiToken1ExpirationDate: "date" - string representing a date in the future when the generated access token will expire, e.g. "2026-12-31". Must be less than 1 year from today. Used only if `generateToken1` is true. If not provided, will look for `apiToken1ExpirationDays`. If neither is provided will default to 7 days from today.
apiToken1ExpirationDays: 1 - integer number of days from today when the generated access token will expire. Must be less than 366. If not provided and `generateToken1` is true will look for `apiToken1ExpirationDate`. If neither is provided will default to 7 days from today.
generateToken2: - same as `generateToken1` for access token 2.
apiToken2ExpirationDate: - same as `apiToken1ExpirationDate` for access token 2.
apiToken2ExpirationDays: - same as `apiToken1ExpirationDays` for access token 2.Test cases
npm start -- -a inspect -o my_keys.csv -f csv -t YOUR_API_KEYnpm start -- -a inspect -i YOUR_ITEM_IDnpm start -- -a genkeys -n 5 -c api-key-attributes.yaml -o api-keys.json -f json
CLI
To run as a command line app:
npm link
Then you can run the command as api-key-helper.
