Skip to main content

A CLI for the EarthScope API

Reason this release was yanked:

bug in code causing release to be unusable

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-idm.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
.
.

Use the CLI with machine-to-machine client credentials

Requires permissions. Contact software@unavco.org to inquire about obtaining a machine to machine application.

# Set required environment variables
export ES_CLI_M2M_CLIENT_ID=my_m2m_client_id
export ES_CLI_M2M_CLIENT_SECRET=my_m2m_client_secret

# Login to EarthScope with Client Credentials Flow using one of the following
es m2m login
es m2m login --token

# Get access token
es m2m access --token

# Lookup a user's anonymous profile information
es user lookup --id 'google-oauth2|115207392315468355758'

# Explore the CLI
es m2m --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-idm.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-idm.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.8.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earthscope_cli-0.8.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file earthscope-cli-0.8.0.tar.gz.

File metadata

  • Download URL: earthscope-cli-0.8.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.8

File hashes

Hashes for earthscope-cli-0.8.0.tar.gz
Algorithm Hash digest
SHA256 5368cf70a7a3bd7cd439cca9ed3186a2807825db2c570d61f3d9f19edb4739b5
MD5 48eef9f63cd220cef8fc428aa58ef85c
BLAKE2b-256 1420556d40a55d6b6c38b4efd14abc1e86eb170a085167e88a35a5da4cf5f8d7

See more details on using hashes here.

File details

Details for the file earthscope_cli-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: earthscope_cli-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.8

File hashes

Hashes for earthscope_cli-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb1c14172eda77db9d0db40931aa2dec441b379b96867a77080cf5b2e660bc3c
MD5 a7ac682cd275ba7c41cd79233cea000e
BLAKE2b-256 0727eb1e8e8731704878ff27b92f8edcf9a1c5dca8a4b6e4f19fa9dfb629bb48

See more details on using hashes here.

Supported by

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