eotdl 2023.11.3.post4__py3-none-any.whl → 2024.2.15__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.
Files changed (84) hide show
  1. eotdl/__init__.py +1 -1
  2. eotdl/access/__init__.py +0 -0
  3. eotdl/access/airbus/__init__.py +0 -0
  4. eotdl/access/airbus/client.py +0 -0
  5. eotdl/access/airbus/parameters.py +0 -0
  6. eotdl/access/airbus/utils.py +0 -0
  7. eotdl/access/download.py +0 -0
  8. eotdl/access/search.py +0 -0
  9. eotdl/access/sentinelhub/__init__.py +0 -0
  10. eotdl/access/sentinelhub/client.py +0 -0
  11. eotdl/access/sentinelhub/evalscripts.py +0 -4
  12. eotdl/access/sentinelhub/parameters.py +3 -4
  13. eotdl/access/sentinelhub/utils.py +2 -1
  14. eotdl/auth/__init__.py +0 -0
  15. eotdl/auth/auth.py +43 -29
  16. eotdl/auth/errors.py +0 -0
  17. eotdl/auth/is_logged.py +0 -0
  18. eotdl/auth/logout.py +0 -0
  19. eotdl/cli.py +0 -0
  20. eotdl/commands/__init__.py +0 -0
  21. eotdl/commands/auth.py +0 -0
  22. eotdl/commands/datasets.py +0 -0
  23. eotdl/commands/models.py +0 -0
  24. eotdl/curation/__init__.py +0 -0
  25. eotdl/curation/stac/__init__.py +0 -0
  26. eotdl/curation/stac/assets.py +3 -43
  27. eotdl/curation/stac/dataframe.py +14 -3
  28. eotdl/curation/stac/dataframe_bck.py +0 -0
  29. eotdl/curation/stac/dataframe_labeling.py +0 -0
  30. eotdl/curation/stac/extensions/__init__.py +0 -0
  31. eotdl/curation/stac/extensions/base.py +0 -0
  32. eotdl/curation/stac/extensions/dem.py +0 -0
  33. eotdl/curation/stac/extensions/eo.py +0 -0
  34. eotdl/curation/stac/extensions/label/__init__.py +0 -0
  35. eotdl/curation/stac/extensions/label/base.py +0 -0
  36. eotdl/curation/stac/extensions/label/image_name_labeler.py +0 -0
  37. eotdl/curation/stac/extensions/label/scaneo.py +3 -2
  38. eotdl/curation/stac/extensions/ml_dataset.py +0 -0
  39. eotdl/curation/stac/extensions/projection.py +0 -0
  40. eotdl/curation/stac/extensions/raster.py +0 -0
  41. eotdl/curation/stac/extensions/sar.py +0 -0
  42. eotdl/curation/stac/extent.py +0 -0
  43. eotdl/curation/stac/parsers.py +0 -0
  44. eotdl/curation/stac/stac.py +0 -0
  45. eotdl/datasets/__init__.py +0 -0
  46. eotdl/datasets/download.py +4 -6
  47. eotdl/datasets/ingest.py +6 -9
  48. eotdl/datasets/metadata.py +0 -0
  49. eotdl/datasets/retrieve.py +0 -0
  50. eotdl/files/__init__.py +0 -0
  51. eotdl/files/ingest.py +6 -6
  52. eotdl/models/__init__.py +0 -0
  53. eotdl/models/download.py +1 -10
  54. eotdl/models/ingest.py +2 -2
  55. eotdl/models/metadata.py +0 -0
  56. eotdl/models/retrieve.py +0 -0
  57. eotdl/repos/APIRepo.py +7 -0
  58. eotdl/repos/AuthAPIRepo.py +9 -2
  59. eotdl/repos/AuthRepo.py +7 -3
  60. eotdl/repos/DatasetsAPIRepo.py +10 -71
  61. eotdl/repos/FilesAPIRepo.py +17 -35
  62. eotdl/repos/ModelsAPIRepo.py +4 -4
  63. eotdl/repos/__init__.py +0 -0
  64. eotdl/shared/__init__.py +0 -0
  65. eotdl/shared/checksum.py +0 -0
  66. eotdl/tools/__init__.py +0 -0
  67. eotdl/tools/geo_utils.py +0 -0
  68. eotdl/tools/metadata.py +0 -0
  69. eotdl/tools/paths.py +0 -0
  70. eotdl/tools/stac.py +0 -0
  71. eotdl/tools/time_utils.py +0 -0
  72. eotdl/tools/tools.py +4 -4
  73. {eotdl-2023.11.3.post4.dist-info → eotdl-2024.2.15.dist-info}/METADATA +2 -5
  74. {eotdl-2023.11.3.post4.dist-info → eotdl-2024.2.15.dist-info}/RECORD +24 -32
  75. eotdl/datasets/usecases/__init__.py +0 -0
  76. eotdl/datasets/usecases/datasets/DownloadFile.py +0 -30
  77. eotdl/datasets/usecases/datasets/DownloadFileURL.py +0 -22
  78. eotdl/datasets/usecases/datasets/IngestDataset.py +0 -30
  79. eotdl/datasets/usecases/datasets/IngestLargeDataset.py +0 -43
  80. eotdl/datasets/usecases/datasets/IngestLargeDatasetParallel.py +0 -51
  81. eotdl/datasets/usecases/datasets/IngestSTAC.py +0 -77
  82. eotdl/datasets/usecases/datasets/__init__.py +0 -9
  83. {eotdl-2023.11.3.post4.dist-info → eotdl-2024.2.15.dist-info}/WHEEL +0 -0
  84. {eotdl-2023.11.3.post4.dist-info → eotdl-2024.2.15.dist-info}/entry_points.txt +0 -0
eotdl/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2023.11.03-4"
1
+ __version__ = "2024.02.15"
eotdl/access/__init__.py CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
eotdl/access/download.py CHANGED
File without changes
eotdl/access/search.py CHANGED
File without changes
File without changes
File without changes
@@ -54,10 +54,6 @@ class EvalScripts:
54
54
  };
55
55
  }
56
56
 
57
- function updateOutputMetadata(scenes, inputMetadata, outputMetadata) {
58
- outputMetadata.userData = {"scenes" : scenes};
59
- }
60
-
61
57
  function evaluatePixel(sample) {
62
58
  return [sample.B01,
63
59
  sample.B02,
@@ -51,8 +51,8 @@ class SHS1Parameters(SHParameters):
51
51
  DATA_COLLECTION = DataCollection.SENTINEL1
52
52
  RESOLUTION = 3
53
53
  EVALSCRIPT = EvalScripts.SENTINEL_1
54
- FIELDS = (
55
- {
54
+ MOSAICKING_ORDER = None
55
+ FIELDS = {
56
56
  "include": [
57
57
  "id",
58
58
  "properties.datetime",
@@ -63,8 +63,7 @@ class SHS1Parameters(SHParameters):
63
63
  "s1:timeliness",
64
64
  ],
65
65
  "exclude": [],
66
- },
67
- )
66
+ }
68
67
  FILTER = None
69
68
 
70
69
 
@@ -55,7 +55,8 @@ def imagery_from_tmp_to_dir(
55
55
  Copy imagery from tmp to output dir
56
56
  """
57
57
  downloaded_files = glob(f"{tmp_dir}/**/response.tiff")
58
- assert len(downloaded_files) > 0, "No files downloaded"
58
+ if len(downloaded_files) == 0:
59
+ return
59
60
 
60
61
  makedirs(output_dir, exist_ok=True)
61
62
 
eotdl/auth/__init__.py CHANGED
File without changes
eotdl/auth/auth.py CHANGED
@@ -1,43 +1,57 @@
1
1
  import time
2
+ import os
2
3
 
3
4
  from ..repos import AuthRepo, AuthAPIRepo
4
5
  from .errors import LoginError, AuthTimeOut
5
6
  from .is_logged import is_logged
6
7
 
7
8
 
8
- def auth(max_t=30, interval=2):
9
+ def auth(max_t=60, interval=2):
9
10
  user = is_logged()
10
11
  if user:
11
12
  return user
12
13
  repo, api_repo = AuthRepo(), AuthAPIRepo()
13
- response = api_repo.login()
14
- if response.status_code != 200:
15
- raise LoginError()
16
- data = response.json()
17
- print("On your computer or mobile device navigate to: ", data["login_url"])
18
- authenticated = False
19
- t0 = time.time()
20
- while not authenticated and time.time() - t0 < max_t:
21
- response = api_repo.token(data["code"])
22
- token_data = response.json()
23
- if response.status_code == 200:
24
- print("Authenticated!")
25
- print("- Id Token: {}...".format(token_data["id_token"][:10]))
26
- # get user credentials
27
- credentials = api_repo.retrieve_credentials(token_data["id_token"])[0]
28
- if credentials:
29
- token_data.update(credentials)
30
- # save token data in file
31
- creds_path = repo.save_creds(token_data)
32
- print("Saved credentials to: ", creds_path)
33
- current_user = repo.decode_token(token_data)
34
- authenticated = True
35
- current_user["id_token"] = token_data["id_token"]
36
- return current_user
37
- else:
38
- time.sleep(interval)
39
- if not authenticated:
40
- raise AuthTimeOut()
14
+ api_key = os.environ.get("EOTDL_API_KEY", None)
15
+ if api_key:
16
+ print("Using API Key")
17
+ user = {"api_key": api_key}
18
+ user_data, error = api_repo.retrieve_user_data(user)
19
+ if error:
20
+ raise LoginError()
21
+ user.update({"email": user_data["email"], "uid": user_data["uid"]})
22
+ else:
23
+ response = api_repo.login()
24
+ if response.status_code != 200:
25
+ raise LoginError()
26
+ data = response.json()
27
+ print("On your computer or mobile device navigate to: ", data["login_url"])
28
+ authenticated = False
29
+ t0 = time.time()
30
+ while not authenticated and time.time() - t0 < max_t:
31
+ response = api_repo.token(data["code"])
32
+ token_data = response.json()
33
+ if response.status_code == 200:
34
+ print("Authenticated!")
35
+ print("- Id Token: {}...".format(token_data["id_token"][:10]))
36
+ user = repo.decode_token(token_data)
37
+ authenticated = True
38
+ user = {
39
+ "id_token": token_data["id_token"],
40
+ "email": user["email"],
41
+ "uid": user["sub"],
42
+ }
43
+ else:
44
+ time.sleep(interval)
45
+ if not authenticated:
46
+ raise AuthTimeOut()
47
+ # get user credentials
48
+ credentials = api_repo.retrieve_credentials(user)[0]
49
+ if credentials:
50
+ user.update(credentials)
51
+ # save token data in file
52
+ creds_path = repo.save_creds(user)
53
+ print("Saved credentials to: ", creds_path)
54
+ return user
41
55
 
42
56
 
43
57
  # auth decorator
eotdl/auth/errors.py CHANGED
File without changes
eotdl/auth/is_logged.py CHANGED
File without changes
eotdl/auth/logout.py CHANGED
File without changes
eotdl/cli.py CHANGED
File without changes
File without changes
eotdl/commands/auth.py CHANGED
File without changes
File without changes
eotdl/commands/models.py CHANGED
File without changes
File without changes
File without changes
@@ -3,7 +3,7 @@ Module for STAC Asset Generators
3
3
  """
4
4
 
5
5
  from os import remove, listdir
6
- from os.path import dirname, join, basename, abspath
6
+ from os.path import dirname, join, basename, abspath, basename
7
7
 
8
8
  import pandas as pd
9
9
  import rasterio
@@ -78,6 +78,7 @@ class BandsAssetGenerator(STACAssetGenerator):
78
78
 
79
79
  if bands:
80
80
  with rasterio.open(raster_path, "r") as raster:
81
+ raster_name = basename(raster_path).split(".")[0]
81
82
  if isinstance(bands, str):
82
83
  bands = [bands]
83
84
  for band in bands:
@@ -89,7 +90,7 @@ class BandsAssetGenerator(STACAssetGenerator):
89
90
  single_band = raster.read(i + 1)
90
91
  except IndexError:
91
92
  single_band = raster.read(1)
92
- band_name = f"{band}.{raster_format}"
93
+ band_name = f"{raster_name}_{band}.{raster_format}"
93
94
  output_band = join(dirname(raster_path), band_name)
94
95
  # Copy the metadata
95
96
  metadata = raster.meta.copy()
@@ -106,45 +107,4 @@ class BandsAssetGenerator(STACAssetGenerator):
106
107
  )
107
108
  )
108
109
 
109
- # Remove the original raster file and its metadata
110
- remove(raster_path)
111
- remove_raster_metadata(dirname(raster_path))
112
-
113
110
  return asset_list
114
-
115
-
116
- class ExtractedAssets(STACAssetGenerator):
117
- """
118
- Extracted STAC Asset Generator
119
- """
120
-
121
- type = "Extracted"
122
-
123
- def __init__(self) -> None:
124
- super().__init__()
125
-
126
- def extract_assets(self, obj_info: pd.DataFrame):
127
- """
128
- Get all the files with the same extension as the image file as assets
129
- """
130
- asset_list = []
131
- # File path
132
- raster_path = obj_info["image"].values[0]
133
- raster_dir = dirname(raster_path)
134
- # Get the files with the same extension as the image file
135
- files = [
136
- f for f in listdir(raster_dir) if f.endswith(raster_path.split(".")[-1])
137
- ]
138
- # Instantiate pystac asset and append it to the list
139
- for file in files:
140
- # Get the file extension
141
- raster_format = file.split(".")[-1]
142
- asset_list.append(
143
- pystac.Asset(
144
- href=join(raster_dir, file),
145
- title=basename(file),
146
- media_type=MEDIA_TYPES_DICT[raster_format],
147
- )
148
- )
149
-
150
- return asset_list
@@ -22,6 +22,7 @@ class STACDataFrame(gpd.GeoDataFrame):
22
22
  """
23
23
  STACDataFrame class
24
24
  """
25
+
25
26
  def __init__(self, *args, **kwargs):
26
27
  super().__init__(*args, **kwargs)
27
28
 
@@ -61,7 +62,9 @@ class STACDataFrame(gpd.GeoDataFrame):
61
62
  # Curate the json row
62
63
  row_json = self.curate_json_row(row_json, stac_id_exists)
63
64
 
64
- with open(join(root_output_folder, "catalog.json"), "w", encoding="utf-8") as f:
65
+ with open(
66
+ join(root_output_folder, "catalog.json"), "w", encoding="utf-8"
67
+ ) as f:
65
68
  json.dump(row_json, f)
66
69
 
67
70
  # Second, create the collections and their folders, if exist
@@ -76,7 +79,9 @@ class STACDataFrame(gpd.GeoDataFrame):
76
79
  # Curate the json row
77
80
  row_json = self.curate_json_row(row_json, stac_id_exists)
78
81
 
79
- with open(join(stac_output_folder, "collection.json"), "w", encoding="utf-8") as f:
82
+ with open(
83
+ join(stac_output_folder, "collection.json"), "w", encoding="utf-8"
84
+ ) as f:
80
85
  json.dump(row_json, f)
81
86
 
82
87
  # Then, create the items and their folders, if exist
@@ -94,7 +99,11 @@ class STACDataFrame(gpd.GeoDataFrame):
94
99
  # Curate the json row
95
100
  row_json = self.curate_json_row(row_json, stac_id_exists)
96
101
 
97
- with open(join(stac_output_folder, f'{row_json["id"]}.json'), "w", encoding="utf-8") as f:
102
+ with open(
103
+ join(stac_output_folder, f'{row_json["id"]}.json'),
104
+ "w",
105
+ encoding="utf-8",
106
+ ) as f:
98
107
  json.dump(row_json, f)
99
108
 
100
109
  def curate_json_row(self, row: dict, stac_id_exists: bool) -> dict:
@@ -148,7 +157,9 @@ def read_stac(
148
157
  """
149
158
  if isinstance(stac_file, (str, Path)):
150
159
  stac_file = pystac.read_file(stac_file) # we assume this is always a catalog
160
+ print(stac_file)
151
161
  stac_file.make_all_asset_hrefs_absolute()
162
+ print("ie")
152
163
  children = get_all_children(stac_file)
153
164
 
154
165
  # Convert Dataframe to STACDataFrame
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -161,8 +161,9 @@ class ScaneoLabeler(LabelExtensionObject):
161
161
  """
162
162
  label_classes = []
163
163
 
164
- labels_json = glob(join(root_folder, "labels.json"))[0]
165
- if exists(labels_json):
164
+ labels_json = glob(join(root_folder, "labels.json"))
165
+ if len(labels_json) > 0 and exists(labels_json[0]):
166
+ labels_json = labels_json[0]
166
167
  with open(labels_json, "r", encoding="utf-8") as f:
167
168
  labels = json.load(f)
168
169
  for value in labels["labels"]:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -54,7 +54,7 @@ def download_dataset(
54
54
  dst_path = repo.download_file(
55
55
  dataset["id"],
56
56
  filename,
57
- user["id_token"],
57
+ user,
58
58
  download_path,
59
59
  file_version,
60
60
  progress=True,
@@ -70,7 +70,7 @@ def download_dataset(
70
70
  repo = DatasetsAPIRepo()
71
71
  gdf, error = repo.download_stac(
72
72
  dataset["id"],
73
- user["id_token"],
73
+ user,
74
74
  )
75
75
  if error:
76
76
  raise Exception(error)
@@ -89,7 +89,7 @@ def download_dataset(
89
89
  _, filename = href.split("/download/")
90
90
  # will overwrite assets with same name :(
91
91
  repo.download_file_url(
92
- href, filename, f"{download_path}/assets", user["id_token"]
92
+ href, filename, f"{download_path}/assets", user
93
93
  )
94
94
  else:
95
95
  if verbose:
@@ -101,6 +101,4 @@ def download_dataset(
101
101
  def download_file_url(url, path, progress=True, logger=print, user=None):
102
102
  repo = FilesAPIRepo()
103
103
  _, filename = url.split("/download/")
104
- return repo.download_file_url(
105
- url, filename, f"{path}/assets", user["id_token"], progress
106
- )
104
+ return repo.download_file_url(url, filename, f"{path}/assets", user, progress)
eotdl/datasets/ingest.py CHANGED
@@ -24,11 +24,11 @@ def retrieve_dataset(metadata, user):
24
24
  repo = DatasetsAPIRepo()
25
25
  data, error = repo.retrieve_dataset(metadata.name)
26
26
  # print(data, error)
27
- if data and data["uid"] != user["sub"]:
27
+ if data and data["uid"] != user["uid"]:
28
28
  raise Exception("Dataset already exists.")
29
29
  if error and error == "Dataset doesn't exist":
30
30
  # create dataset
31
- data, error = repo.create_dataset(metadata.dict(), user["id_token"])
31
+ data, error = repo.create_dataset(metadata.dict(), user)
32
32
  # print(data, error)
33
33
  if error:
34
34
  raise Exception(error)
@@ -54,11 +54,11 @@ def retrieve_stac_dataset(dataset_name, user):
54
54
  repo = DatasetsAPIRepo()
55
55
  data, error = repo.retrieve_dataset(dataset_name)
56
56
  # print(data, error)
57
- if data and data["uid"] != user["sub"]:
57
+ if data and data["uid"] != user["uid"]:
58
58
  raise Exception("Dataset already exists.")
59
59
  if error and error == "Dataset doesn't exist":
60
60
  # create dataset
61
- data, error = repo.create_stac_dataset(dataset_name, user["id_token"])
61
+ data, error = repo.create_stac_dataset(dataset_name, user)
62
62
  # print(data, error)
63
63
  if error:
64
64
  raise Exception(error)
@@ -82,13 +82,12 @@ def ingest_stac(stac_catalog, logger=None, user=None):
82
82
  logger("New version created, version: " + str(version))
83
83
  df2 = df.dropna(subset=["assets"])
84
84
  for row in tqdm(df2.iterrows(), total=len(df2)):
85
- # for asset in df.assets.dropna().values[:10]:
86
85
  try:
87
86
  for k, v in row[1]["assets"].items():
88
87
  data, error = files_repo.ingest_file(
89
88
  v["href"],
90
89
  dataset_id,
91
- user["id_token"],
90
+ user,
92
91
  calculate_checksum(v["href"]), # is always absolute?
93
92
  "datasets",
94
93
  version,
@@ -102,9 +101,7 @@ def ingest_stac(stac_catalog, logger=None, user=None):
102
101
  break
103
102
  # ingest the STAC catalog into geodb
104
103
  logger("Ingesting STAC catalog...")
105
- data, error = repo.ingest_stac(
106
- json.loads(df.to_json()), dataset_id, user["id_token"]
107
- )
104
+ data, error = repo.ingest_stac(json.loads(df.to_json()), dataset_id, user)
108
105
  if error:
109
106
  # TODO: delete all assets that were uploaded
110
107
  raise Exception(error)
File without changes
File without changes
eotdl/files/__init__.py CHANGED
File without changes
eotdl/files/ingest.py CHANGED
@@ -88,7 +88,7 @@ def generate_files_lists(
88
88
 
89
89
 
90
90
  def create_new_version(repo, dataset_or_model_id, user):
91
- data, error = repo.create_version(dataset_or_model_id, user["id_token"])
91
+ data, error = repo.create_version(dataset_or_model_id, user)
92
92
  if error:
93
93
  raise Exception(error)
94
94
  return data["version"]
@@ -117,7 +117,7 @@ def ingest_files(repo, dataset_or_model_id, folder, verbose, logger, user, endpo
117
117
  file["path"],
118
118
  dataset_or_model_id,
119
119
  file["checksum"],
120
- user["id_token"],
120
+ user,
121
121
  endpoint,
122
122
  )
123
123
  # print(upload_id, parts)
@@ -125,11 +125,11 @@ def ingest_files(repo, dataset_or_model_id, folder, verbose, logger, user, endpo
125
125
  file["absolute_path"],
126
126
  file["size"],
127
127
  upload_id,
128
- user["id_token"],
128
+ user,
129
129
  parts,
130
130
  endpoint,
131
131
  )
132
- files_repo.complete_upload(user["id_token"], upload_id, version, endpoint)
132
+ files_repo.complete_upload(user, upload_id, version, endpoint)
133
133
  # ingest new small files in batches
134
134
  if len(upload_files) > 0:
135
135
  logger("generating batches...")
@@ -148,7 +148,7 @@ def ingest_files(repo, dataset_or_model_id, folder, verbose, logger, user, endpo
148
148
  memory_file,
149
149
  [f["checksum"] for f in batch],
150
150
  dataset_or_model_id,
151
- user["id_token"],
151
+ user,
152
152
  endpoint,
153
153
  version,
154
154
  )
@@ -165,7 +165,7 @@ def ingest_files(repo, dataset_or_model_id, folder, verbose, logger, user, endpo
165
165
  batch,
166
166
  dataset_or_model_id,
167
167
  version,
168
- user["id_token"],
168
+ user,
169
169
  endpoint,
170
170
  )
171
171
  if error:
eotdl/models/__init__.py CHANGED
File without changes
eotdl/models/download.py CHANGED
@@ -68,7 +68,7 @@ def download_model(
68
68
  dst_path = repo.download_file(
69
69
  model["id"],
70
70
  filename,
71
- user["id_token"],
71
+ user,
72
72
  download_path,
73
73
  file_version,
74
74
  endpoint="models",
@@ -108,12 +108,3 @@ def download_model(
108
108
  # else:
109
109
  # logger("To download assets, set assets=True or -a in the CLI.")
110
110
  # return Outputs(dst_path=path)
111
-
112
-
113
- # @with_auth
114
- # def download_file_url(url, path, progress=True, logger=None, user=None):
115
- # api_repo = APIRepo()
116
- # download = DownloadFileURL(api_repo, logger, progress)
117
- # inputs = DownloadFileURL.Inputs(url=url, path=path, user=user)
118
- # outputs = download(inputs)
119
- # return outputs.dst_path
eotdl/models/ingest.py CHANGED
@@ -21,11 +21,11 @@ def retrieve_model(metadata, user):
21
21
  repo = ModelsAPIRepo()
22
22
  data, error = repo.retrieve_model(metadata.name)
23
23
  # print(data, error)
24
- if data and data["uid"] != user["sub"]:
24
+ if data and data["uid"] != user["uid"]:
25
25
  raise Exception("Model already exists.")
26
26
  if error and error == "Model doesn't exist":
27
27
  # create dataset
28
- data, error = repo.create_model(metadata.dict(), user["id_token"])
28
+ data, error = repo.create_model(metadata.dict(), user)
29
29
  # print(data, error)
30
30
  if error:
31
31
  raise Exception(error)
eotdl/models/metadata.py CHANGED
File without changes
eotdl/models/retrieve.py CHANGED
File without changes
eotdl/repos/APIRepo.py CHANGED
@@ -11,3 +11,10 @@ class APIRepo:
11
11
  if response.status_code == 200:
12
12
  return response.json(), None
13
13
  return None, response.json()["detail"]
14
+
15
+ def generate_headers(self, data):
16
+ if "api_key" in data:
17
+ return {"X-API-Key": data["api_key"]}
18
+ if "id_token" in data:
19
+ return {"Authorization": "Bearer " + data["id_token"]}
20
+ raise Exception("Invalid headers")
@@ -16,11 +16,18 @@ class AuthAPIRepo(APIRepo):
16
16
  response = requests.get(self.url + "auth/logout")
17
17
  return response.json()["logout_url"]
18
18
 
19
- def retrieve_credentials(self, id_token):
19
+ def retrieve_credentials(self, auth):
20
20
  response = requests.get(
21
21
  self.url + "auth/credentials",
22
- headers={"Authorization": "Bearer " + id_token},
22
+ headers=self.generate_headers(auth),
23
23
  )
24
24
  if response.status_code == 200:
25
25
  return response.json(), None
26
26
  return None, response.json()["detail"]
27
+
28
+ def retrieve_user_data(self, auth):
29
+ response = requests.get(
30
+ self.url + "auth/me",
31
+ headers=self.generate_headers(auth),
32
+ )
33
+ return self.format_response(response)
eotdl/repos/AuthRepo.py CHANGED
@@ -20,9 +20,13 @@ class AuthRepo:
20
20
  if os.path.exists(self.creds_path):
21
21
  with open(self.creds_path, "r") as f:
22
22
  creds = json.load(f)
23
- user = self.decode_token(creds)
24
- user["id_token"] = creds["id_token"]
25
- return user
23
+ if not "id_token" in creds and not "api_key" in creds:
24
+ return None
25
+ if "api_key" in creds and creds["api_key"] != os.getenv(
26
+ "EOTDL_API_KEY", None
27
+ ):
28
+ return None
29
+ return creds
26
30
  return None
27
31
 
28
32
  def decode_token(self, token_data):