glam-processing 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
glam_processing/cli.py ADDED
@@ -0,0 +1,51 @@
1
+ import sys
2
+
3
+ import click
4
+
5
+
6
+ @click.group()
7
+ def cli():
8
+ """Glam Processing Tools"""
9
+ pass
10
+
11
+
12
+ @cli.command()
13
+ @click.option("-s", "--strategy", default="interactive", type=str)
14
+ @click.option("-p", "--persist", default=True, type=bool)
15
+ def auth(strategy, persist):
16
+ """Authenticate earthaccess with NASA Earthdata credentials"""
17
+ from .earthdata import authenticate
18
+
19
+ authenticated = authenticate()
20
+
21
+ click.echo(
22
+ "Successfully authenticated!" if authenticated else "Failed to authenticate"
23
+ )
24
+
25
+
26
+ @cli.command()
27
+ def list():
28
+ """List supported products"""
29
+ from .download import SUPPORTED_DATASETS
30
+
31
+ click.echo(f"Supported product datasets: {SUPPORTED_DATASETS}")
32
+
33
+
34
+ @cli.command()
35
+ @click.argument("dataset-id", type=str)
36
+ def info(dataset_id):
37
+ """Get info on supported products"""
38
+ from .download import Downloader, SUPPORTED_DATASETS, EARTHDATA_DATASETS
39
+
40
+ if dataset_id in SUPPORTED_DATASETS:
41
+ if dataset_id in EARTHDATA_DATASETS:
42
+ downloader = Downloader(dataset_id)
43
+ click.echo(downloader.info())
44
+ else:
45
+ click.echo(f"Summary information for {dataset_id} not available")
46
+ else:
47
+ click.echo(f"Dataset {dataset_id} not found in list of supported datasets")
48
+
49
+
50
+ if __name__ == "__main__":
51
+ cli()
File without changes
@@ -0,0 +1,39 @@
1
+ import os
2
+ import json
3
+ import requests
4
+ import jwt
5
+ import time
6
+
7
+ CLMS_URL = "https://land.copernicus.eu"
8
+
9
+
10
+ def get_clms_token():
11
+ # Load saved key from filesystem
12
+
13
+ service_key_file = os.environ.get("CLMS_KEY_FILE", "clms-key.json")
14
+ service_key = json.load(open(service_key_file, "rb"))
15
+
16
+ private_key = service_key["private_key"].encode("utf-8")
17
+
18
+ claim_set = {
19
+ "iss": service_key["client_id"],
20
+ "sub": service_key["user_id"],
21
+ "aud": service_key["token_uri"],
22
+ "iat": int(time.time()),
23
+ "exp": int(time.time() + (60 * 60)),
24
+ }
25
+ grant = jwt.encode(claim_set, private_key, algorithm="RS256")
26
+
27
+ resp = requests.post(
28
+ f"{CLMS_URL}/@@oauth2-token",
29
+ headers={
30
+ "Accept": "application/json",
31
+ "Content-Type": "application/x-www-form-urlencoded",
32
+ },
33
+ data={
34
+ "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
35
+ "assertion": grant,
36
+ },
37
+ )
38
+
39
+ return resp.json().get("access_token", None)
@@ -0,0 +1 @@
1
+