Skip to main content

A CLI for the EarthScope API

Project description

EarthScope CLI

A Typer CLI for authenticating with the EarthScope API

Getting Started

Requirements

To use the CLI you must have:

Installation

  1. (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
    
  2. Install the CLI:

    pip install earthscope-cli
    
  3. Use the CLI. The package has a console_scripts section which makes a shortcut called es 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.

Example using cURL:

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.

Example using Wget:

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 command es sso refresh. If your access token is compromised, you can revoke your refresh token using es sso refresh --revoke. Once your access token expires, it can no longer be renewed and you will need to re-login.
  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

earthscope-cli-0.9.0.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distribution

earthscope_cli-0.9.0-py3-none-any.whl (16.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page