Skip to content

Commit c06f41b

Browse files
committed
Update docs
1 parent fbc6b3f commit c06f41b

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

docs/how-to/config-server-guide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ You can then make a request through this client through its `get_file_contents`
1515
```python
1616
config_server.get_file_contents(FILE_PATH,reset_cached_result=True)
1717
```
18-
By default, this will return the file's raw string output - which includes things like linebreaks. It is up to you to format this output - using `splitlines()` will get you a list where each item is a line in the file. `get_file_contents` has a `desired_return_type` parameter where you can instead ask for a `dict` or `bytes`. The server will try and do the conversion, and respond with an HTTP error if the requested file is incompatible with that type.
18+
By default, this will return the file's raw string output - which includes things like linebreaks. It is up to you to format this output - using `splitlines()` will get you a list where each item is a line in the file. `get_file_contents` has a `desired_return_type` parameter where you can instead ask for a `dict`, `bytes` or a `pydantic model`. The server will try and do the conversion, and respond with an HTTP error if the requested file is incompatible with that type, or a pydantic validation error if the data cannot be converted to the pydantic model provided. Custom [file converters](#file-converters) can be used to specify how a file should be converted to a dict or pydantic model.
19+
20+
# File converters
21+
22+
Converters can be used to turn a file into a standard format server-side, reducing the complexity of reading config files client-side. Converters can convert config files to a `dict` or `pydantic model`, and the same `pydantic model` can be reconstructed client-side by the `get_file_contents` method. Available converters exist [here](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._converters.py) - see if there's a suitable converter you can use before adding your own. [This dictionary](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._file_converter_map.py) maps files to converters. Add the path of your config file and a suitable converter to this dictionary and it will automatically be used by the config server when a request for that file is made.
23+
24+
A request for `str` or `bytes` will fetch the raw file with no conversion.
1925

2026
# Adding files to the whitelist
2127

@@ -24,9 +30,3 @@ For [security reasons](../explanations/whitelist_info.md), only files existing o
2430
# Reading sensitive information
2531

2632
If you need to read a file which contains sensitive information, or `dls-dasc` doesn't have the permissions to read your file, you should encrypt this file as a [sealed secret](https://github.com/bitnami-labs/sealed-secrets) on your beamline cluster, and mount this in your BlueAPI service.
27-
28-
# File converters
29-
30-
Converters can be used to turn a file into a standard format server-side, reducing the complexity of reading config files client-side. Available converters exist [here](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._converters.py) - see if there's a suitable converter you can use before adding your own. [This dictionary](https://github.com/DiamondLightSource/daq-config-server/blob/main/converters._file_converter_map.py) maps files to converters. Add the path of your config file and a suitable converter to this dictionary and it will automatically be used by the config server when a request for that file is made.
31-
32-
A request for `str` or `bytes` will fetch the raw file with no conversion.

docs/reference/current_and_planned_features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Periodically check the main branch's to update the whitelist.
77
- Provide a client module for users to easily communicate with the server, with caching.
88
- Have this service hosted on diamond's central argus cluster - with url `https://daq-config-server.diamond.ac.uk`
9-
- Provide server-side formatting for commonly used configuration files - eg `beamline_parameters.txt` should be returned as a dictionary.
9+
- Provide server-side json and pydantic model formatting for commonly used configuration files - eg `beamline_parameters.txt` should be returned as a dictionary.
1010

1111

1212
## Future features

src/daq_config_server/converters/_converter_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def parse_value(value: str, convert_to: type | None = None) -> Any:
2828

2929

3030
def parse_lut(contents: str, *params: tuple[str, type | None]) -> GenericLut:
31-
"""Converts a lookup table to a dict, containing the names of each column and
32-
the rows as a 2D list.
31+
"""Converts a lookup table to a pydantic model, containing the names of each column
32+
and the rows as a 2D list.
3333
3434
Any args after the contents provide the column names and optionally, python types
3535
for values in a column to be converted to. e.g: (energy_EV, float), (pixels, int).

src/daq_config_server/converters/_converters.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,7 @@ def beamline_parameters_to_dict(contents: str) -> dict[str, Any]:
3535
return dict(config_pairs)
3636

3737

38-
def display_config_to_dict(contents: str) -> DisplayConfig:
39-
"""Converts a display config file into a dict. Every zoom level entry in the
40-
configuration file forms a key in the dict, with value being another dict. This
41-
inner dict contains all the key value pairs of the rows following each zoom level.
42-
43-
Example input:
44-
45-
zoomLevel = 1.0
46-
crosshairX = 500
47-
crosshairY = 600
48-
zoomLevel = 2.0
49-
crosshairX = 700
50-
crosshairY = 800
51-
52-
Example output:
53-
"""
38+
def display_config_to_model(contents: str) -> DisplayConfig:
5439
lines = contents.splitlines()
5540
config_dict: dict[float, dict[str, int | float]] = {}
5641
zoom_level = None

0 commit comments

Comments
 (0)