Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide data inline to WNM #568

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading