A CLI for the EarthScope API
Project description
EarthScope CLI
A Typer CLI for authenticating with the EarthScope API
- Getting Started
- Requirements
- Installation
- [Use the CLI with your user profile](#Use the CLI with your user profile)
- Example - Retrieve a file from the UNAVCO Data File Server
- FAQ/troubleshooting
Getting Started
Requirements
To use the CLI you must have:
- Registered an account with Earthscope (sign up now!). See here for more information
- Python >= 3.7
- A bash-like shell (see bash for windows)
Installation
-
(Optional) Suggest setting up and activating a python virtual environment so as to not clutter your system python
python3 -m venv venv . venv/bin/activate
-
Install the CLI:
pip install earthscope-cli
-
Use the CLI. The package has a
console_scripts
section which makes a shortcut calledes
available in your python environment.es --help
Use the CLI with your user profile
Login to EarthScope with Device Authorization Flow:
es sso login
This will prompt your browser to open a device confirmation page with the same code displayed in the url shown on your command line. If you are on a device that does not have a web browser, you can copy the displayed url in a browser on another device (personal computer, mobile device, etc...) and complete the confirmation there.
The login command will save your token locally. If this token is deleted, you will need to re-authenticate (login) to retrieve your token again. Run the following command to see where your token is stored:
es sso state --path
get/refresh your access token
es sso access --token
The access command will display your access token. If your access token is close to expiration or expired, the default behavior is to automatically refresh your token.
If you want to manually refresh your token:
es sso refresh
Never share your tokens. If you think your token has been compromised, please revoke your refresh token and re-authenticate (login):
es sso refresh --revoke
es sso login
Get your user profile from the user-management-api
running behind https://data.unavco.org/user/profile/
es user get
Explore the CLI
Use --help
on any command to see more information on available commands and options.
es --help
es sso --help
es access --help
.
.
Example: Retrieve a file from the UNAVCO Data File Server with cURL or Wget
- Step 1: login. This step is only required once (the first time you run the cli on your device) unless your access token is deleted from your device.
- Step 2: Retrieve your token using
es sso access --token
. Add this access token as an Authorization header with your cURL or Wget command.
curl -L -O -f --url https://data.unavco.org/archive/gnss/rinex/obs/1992/001/algo0010.92d.Z --header "authorization: Bearer $(es sso access --token)"
where
-L : follow redirects
-O : uses server filename
-f : (HTTP) Fail on error without server output. Error code 22 -- good for scripting
Make sure to include the -f or it will be difficult to tell if an error occured.
wget https://data.unavco.org/archive/gnss/rinex/obs/2022/060/p1230600.22d.Z --header "authorization: Bearer $(es sso access --token)"
See more file server access examples
If you would like to access files using python - please check out the earthscope-sdk
FAQ/troubleshooting
- How long does my access token last?
- Your access token lasts 8 hours. Once it is expired, your refresh token will need to be used to refresh your access token.
- How long does my refresh token last?
- Your refresh token will never expire - unless you are inactive (do not use it) for one year. If it does expire, you will need to re-authenticate to get a new access and refresh token.
- What is a refresh token and how does the CLI use it?
- A refresh token is a special token that is used to renew your access token without you needing to log in again.
The refresh token is obtained from your access token, and using the
es sso access
command will automatically renew your access token if it is close to expiration. You can 'manually' refresh your access token by using the commandes sso refresh
. If your access token is compromised, you can revoke your refresh token usinges sso refresh --revoke
. Once your access token expires, it can no longer be renewed and you will need to re-login.
- A refresh token is a special token that is used to renew your access token without you needing to log in again.
The refresh token is obtained from your access token, and using the
- Should I hard-code my access token into my script?
- No. We recommend you use the cli commands to retrieve your access tokens in your scripts. This way your access token will not be compromised by anyone viewing your script. The access token only lasts 8 hours and cannot be used afterwards unless refreshed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file earthscope-cli-0.9.0.tar.gz
.
File metadata
- Download URL: earthscope-cli-0.9.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69ea743dc85d0867e4753e0c0fe6552bc4f8d3799711cf56d9eb632c2a00d78a |
|
MD5 | a866493ad693b1bd049b341050e2a805 |
|
BLAKE2b-256 | 06d54a3cb5cf88db9f981016d6b6f0099e940eada4337c961837b3fcb1dda012 |
File details
Details for the file earthscope_cli-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: earthscope_cli-0.9.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac278baa4c611bb446127c4b5ba8416d79f7c2fc259477c3806f4fa5649e05dd |
|
MD5 | 630a9d9adf839dc262f3ac1ed6303684 |
|
BLAKE2b-256 | aaaa18ff61a51444eeebaca5870bd5300d1023cbce754a1eff799e7af80f4881 |