diff --git a/docs/source/reference/quickstart.rst b/docs/source/reference/quickstart.rst index fa00eb534..2877e9078 100644 --- a/docs/source/reference/quickstart.rst +++ b/docs/source/reference/quickstart.rst @@ -64,7 +64,7 @@ Setup observation collections from discovery metadata: wis2box data add-collection $WIS2BOX_DATADIR/metadata/discovery/ita-surface-weather-observations.yml wis2box data add-collection $WIS2BOX_DATADIR/metadata/discovery/dza-surface-weather-observations.yml wis2box data add-collection $WIS2BOX_DATADIR/metadata/discovery/rou-synoptic-weather-observations.yml - wis2box metadata discovery publish $WIS2BOX_DATADIR/metadata/discovery/cog-surface-weather-observations.yml + wis2box data add-collection $WIS2BOX_DATADIR/metadata/discovery/cog-surface-weather-observations.yml Load initial stations: diff --git a/tests/integration/test_workflow.py b/tests/integration/test_workflow.py index 392ffa30f..82da62418 100644 --- a/tests/integration/test_workflow.py +++ b/tests/integration/test_workflow.py @@ -258,6 +258,9 @@ def test_message_api(): assert not props['data_id'].startswith('wis2') assert not props['data_id'].startswith('origin/a/wis2') assert props['data_id'].startswith('cog') + assert props['content']['size'] == 257 + assert props['content']['encoding'] == 'base64' + assert props['content']['value'] is not None link_rel = msg['links'][0] diff --git a/wis2box-management/wis2box/pubsub/message.py b/wis2box-management/wis2box/pubsub/message.py index c409fe43d..461bc8cd1 100644 --- a/wis2box-management/wis2box/pubsub/message.py +++ b/wis2box-management/wis2box/pubsub/message.py @@ -69,6 +69,8 @@ def __init__(self, type_: str, identifier: str, topic: str, filepath: str, :returns: `wis2box.pubsub.message.PubSubMessage` message object """ + self.filebytes = None + self.type = type_ self.identifier = identifier self.filepath = filepath @@ -79,14 +81,14 @@ def __init__(self, type_: str, identifier: str, topic: str, filepath: str, ) self.checksum_type = SecureHashAlgorithms.SHA512.value # needs to get bytes to calc checksum and get length - filebytes = None if isinstance(self.filepath, Path): with self.filepath.open('rb') as fh: - filebytes = fh.read() + self.filebytes = fh.read() else: - filebytes = get_data(filepath) - self.length = len(filebytes) - self.checksum_value = self._generate_checksum(filebytes, self.checksum_type) # noqa + self.filebytes = get_data(filepath) + self.length = len(self.filebytes) + self.checksum_value = self._generate_checksum( + self.filebytes, self.checksum_type) self.message = {} def prepare(self): @@ -172,6 +174,16 @@ def __init__(self, identifier: str, topic: str, filepath: str, }] } + if self.length < 4096: + LOGGER.debug('Including data inline via properties.content') + content_value = base64.b64encode(self.filebytes) + + self.message['properties']['content'] = { + 'encoding': 'base64', + 'value': content_value, + 'size': self.length + } + if wigos_station_identifier is not None: self.message['properties']['wigos_station_identifier'] = wigos_station_identifier # noqa link = {