Skip to content

Commit

Permalink
provide data inline to WNM (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis authored Nov 14, 2023
1 parent 8ead341 commit cbcf5bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/source/reference/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
22 changes: 17 additions & 5 deletions wis2box-management/wis2box/pubsub/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit cbcf5bc

Please sign in to comment.