Skip to content

Commit

Permalink
Merge pull request #1027 from joshuagl/joshuagl/custom
Browse files Browse the repository at this point in the history
Improve error message and docstring for custom parameter in `add_target()`
  • Loading branch information
SantiagoTorres authored May 5, 2020
2 parents cf05221 + 8d4511a commit 808ac0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion tuf/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@
# The fileinfo format of targets specified in the repository and
# developer tools. The fields match that of FILEINFO_SCHEMA, only all
# fields are optional.
CUSTOM_SCHEMA = SCHEMA.Object()
CUSTOM_SCHEMA = SCHEMA.DictOf(
key_schema = SCHEMA.AnyString(),
value_schema = SCHEMA.Any()
)
LOOSE_FILEINFO_SCHEMA = SCHEMA.Object(
object_name = "LOOSE_FILEINFO_SCHEMA",
length = SCHEMA.Optional(LENGTH_SCHEMA),
Expand Down
22 changes: 13 additions & 9 deletions tuf/repository_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,12 +1929,6 @@ def add_target(self, filepath, custom=None, fileinfo=None):
Add a filepath (must be relative to the repository's targets directory)
to the Targets object.
This method does not access the file system. 'filepath' must already
exist on the file system.
If 'filepath' does not exist the file will still be added to 'roleinfo'.
Only later calls to write() and writeall() will fail.
If 'filepath' has already been added, it will be replaced with any new
file or 'custom' information.
Expand All @@ -1948,11 +1942,21 @@ def add_target(self, filepath, custom=None, fileinfo=None):
targets directory.
custom:
An optional object providing additional information about the file.
An optional dictionary providing additional information about the file.
NOTE: if a custom value is passed, the fileinfo parameter must be None.
This parameter will be deprecated in a future release of tuf, use of
the fileinfo parameter is preferred.
fileinfo:
An optional fileinfo object, conforming to tuf.formats.FILEINFO_SCHEMA,
providing full information about the file.
An optional fileinfo dictionary, conforming to
tuf.formats.FILEINFO_SCHEMA, providing full information about the
file, i.e:
{ 'length': 101,
'hashes': { 'sha256': '123EDF...' },
'version': 2, # optional
'custom': { 'permissions': '600'} # optional
}
NOTE: if a custom value is passed, the fileinfo parameter must be None.
<Exceptions>
securesystemslib.exceptions.FormatError, if 'filepath' is improperly
Expand Down

0 comments on commit 808ac0c

Please sign in to comment.