Skip to content

api: Add Metadata.from_bytes() - #1354

Merged
jku merged 1 commit into
theupdateframework:developfrom
jku:metadata-from-string
Apr 21, 2021
Merged

api: Add Metadata.from_bytes()#1354
jku merged 1 commit into
theupdateframework:developfrom
jku:metadata-from-string

Conversation

@jku

@jkujku commented Apr 16, 2021

Copy link
Copy Markdown
Member

This is essentially short-hand for

JSONDeserializer().deserialize(data)

but seems easier for the API user so may be worth it.

Metadata.from_file() now uses Metadata.from_bytes() internally.


(message and title edited later to replace string with bytes)

Fixes#1336

I think adding this makes sense in that we're trying to "hide" serialization details from the default use case and currently that wasn't possible if you just have a string (and not a file).

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@avelichkaavelichka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :)

@MVrachevMVrachev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@joshuagljoshuagl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Minor question inline.

Comment threadtuf/api/metadata.py

Arguments:
data: metadata content as string.
deserializer: Optional; A MetadataDeserializer instance that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this notation standard? Would we be better off just relying on the typing annotations to indicate optional arguments?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that in a google style guide example -- could leave that out as well, it does duplicate the annotation...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it for now. Could you create an issue to ensure we review docstrings and make sure they are consistent before we cut a release.

@jku

jku commented Apr 19, 2021

Copy link
Copy Markdown
MemberAuthor

Let's not merge just yet, I'm still going to doublecheck whether str is the correct type -- the Metadata API seems to use bytes in some places

This is essentially short-hand for
JSONDeserializer().deserialize(data)
but seems much easier for the API user so may be worth it.
Metadata.from_file() now uses Metadata.from_bytes() internally.
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
@jku
jkuforce-pushed the metadata-from-string branch from 238264e to 4e8738fCompareApril 21, 2021 06:44
@jkujku changed the title api: Add Metadata.from_string()api: Add Metadata.from_bytes()Apr 21, 2021
@jku

jku commented Apr 21, 2021

Copy link
Copy Markdown
MemberAuthor

I had another look and decided bytes makes more sense than str:

  • a hypothetical serializer could take a binary format
  • Existing code already uses bytes (see api/serialization/)

@joshuagl want to have another look? (mostly this was a literal replace of string with bytes)

Comment threadtests/test_api.py
# Assert that it chokes correctly on an unknown metadata type
bad_metadata_path = 'bad-metadata.json'
bad_metadata = {'signed': {'_type': 'bad-metadata'}}
bad_string = json.dumps(bad_metadata).encode('utf-8')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is indentation off here, or is it just the GitHub app?

Comment threadtuf/api/metadata.py

Arguments:
data: metadata content as string.
deserializer: Optional; A MetadataDeserializer instance that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it for now. Could you create an issue to ensure we review docstrings and make sure they are consistent before we cut a release.

@joshuagl

Copy link
Copy Markdown
Member

Looks good to me, thanks for the str->bytes change.

@jku

jku commented Apr 21, 2021

Copy link
Copy Markdown
MemberAuthor

GitHub Actions has encountered an internal error when running your job. Seems to be https://www.githubstatus.com/incidents/cj7gzzj30411
Re-running...

@jku
jku merged commit 41f7e80 into theupdateframework:developApr 21, 2021
@jku
jku deleted the metadata-from-string branch December 30, 2024 09:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement from_object/from_string method in Metadata class

4 participants

@jku@joshuagl@MVrachev@avelichka