alan-turing-institute / data-safe-haven

https://data-safe-haven.readthedocs.io
BSD 3-Clause "New" or "Revised" License
61 stars 15 forks source link

Show invalid config #2189

Closed JimMadge closed 2 months ago

JimMadge commented 2 months ago

:white_check_mark: Checklist

:vertical_traffic_light: Depends on

:arrow_heading_up: Summary

:closed_umbrella: Related issues

Closes #2006

:microscope: Tests

Tested locally after editing configurations in Azure storage.

github-actions[bot] commented 2 months ago

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  data_safe_haven/commands
  config.py
  data_safe_haven/config
  __init__.py
  data_safe_haven/serialisers
  azure_serialisable_model.py
  yaml_serialisable_model.py
Project Total  

This report was generated by python-coverage-comment-action

JimMadge commented 2 months ago

This looks sensible but it doesn't fix the biggest issue: we need a way to overwrite an existing config (which might not parse correctly) in the upload() method. Currently, this fails when trying to obtain a diff.

Ah, good point!

I think we can leave the other commands though. I think most of the time the program terminating when it encounter an invalid configuration is a feature.

JimMadge commented 2 months ago

I've added a --force option to upload,

❯ hatch run dsh config upload ./sre-oda.yaml
You are logged into the Azure CLI as:
        user: Jim Madge (…)
        tenant: turing.ac.uk (…)
Are these details correct? [y/n] (y): y
Found 2 validation errors when trying to load SREConfig.
dockerhub.username: {'access_token': '…'} - Field required
name: {'azure': {'location': 'uksouth', 'subscription_id':
'…', 'tenant_id': '…'},
'description': 'Oda', 'dockerhub': {'access_token': '…'},
'sre': {'admin_email_address': '…', 'admin_ip_addresses':
['…'], 'data_provider_ip_addresses': ['…'], 'databases': [],
'remote_desktop': {'allow_copy': False, 'allow_paste': False}, 'research_user_ip_addresses':
['…'], 'software_packages': 'pre-approved', 'storage_quota_gb': {'home': 100,
'shared': 100}, 'timezone': 'Europe/London', 'workspace_skus': ['Standard_D8s_v5']}} - Field
required
SREConfig configuration is invalid.
'sre-oda.yaml' does not contain a valid SREConfig configuration.
Remote configuration for SRE 'oda' is not valid. Dumping remote file.
azure:
  location: uksouth
  subscription_id: …
  tenant_id: …
description: Oda
dockerhub:
  access_token: …
sre:
  admin_email_address: …
  admin_ip_addresses:
  - …
  data_provider_ip_addresses:
  - …
  databases: []
  remote_desktop:
    allow_copy: false
    allow_paste: false
  research_user_ip_addresses:
  - …
  software_packages: pre-approved
  storage_quota_gb:
    home: 100
    shared: 100
  timezone: Europe/London
  workspace_skus:
  - Standard_D8s_v5

To overwrite the remote config, use `dsh config upload --force`
❯ hatch run dsh config upload --force ./sre-oda.yaml
You are logged into the Azure CLI as:
        user: Jim Madge (…)
        tenant: turing.ac.uk (…)
Are these details correct? [y/n] (y): y
❯ hatch run dsh config show oda
You are logged into the Azure CLI as:
        user: Jim Madge (…)
        tenant: turing.ac.uk (…)
Are these details correct? [y/n] (y): y
azure:
  location: uksouth
  subscription_id: …
  tenant_id: …
description: Oda
dockerhub:
  access_token: …
  username: …
name: oda
sre:
  admin_email_address: …
  admin_ip_addresses:
  - …
  data_provider_ip_addresses:
  - …
  databases: []
  remote_desktop:
    allow_copy: false
    allow_paste: false
  research_user_ip_addresses:
  - …
  software_packages: pre-approved
  storage_quota_gb:
    home: 100
    shared: 100
  timezone: Europe/London
  workspace_skus:
  - Standard_D8s_v5