Skip to content

Commit

Permalink
Add validation of parameters during registration
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-davis committed Sep 10, 2024
1 parent 43236d3 commit 61daba6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/azure_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def _get_cmip6_data(model, scenario, variable, start_date, end_date, lb, ub):
result[start_gidx:end_gidx,:,:] = data[start_iidx:end_iidx,lb[0]:ub[0],lb[1]:ub[1]]
return(result)

def validate(url, **kwargs):
pass

def reg_query(name, version, lb, ub, params, url, var_name):
array = _get_azure_url(url, var_name)
if lb:
Expand Down
1 change: 1 addition & 0 deletions modules/ds_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def Add(self, reg_id, reg_type, name, data):
else:
res = cursor.execute("SELECT id FROM type WHERE name == ?", (reg_type,))
type_id, = res.fetchone()
self.modules[reg_type].validate(**json.loads(data))
res = cursor.execute("SELECT id FROM registry WHERE reg_type == ? AND name == ?", (type_id, name)).fetchone()
if res is None:
cursor.execute("INSERT INTO registry(id, reg_type, name, data) VALUES(?, ?, ?, ?) ON CONFLICT DO NOTHING", (reg_id, type_id, name, data))
Expand Down
4 changes: 4 additions & 0 deletions modules/s3nc_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def build_cache_entry(dir_base, file_base, fcount):
cache_file = f'{file_base}_G17_{fcount}.nc'
return(f'{cache_dir}/{cache_file}')

def validate(bucket, path):
if not path.endswith('.nc'):
raise ValueError("S3 module can only access netCDF files.")

def reg_query(name, version, lb, ub, params, bucket, path):
if 'var_name' not in params:
raise ValueError
Expand Down

0 comments on commit 61daba6

Please sign in to comment.