Skip to content

Commit 808ac0c

Browse files
Merge pull request #1027 from joshuagl/joshuagl/custom
Improve error message and docstring for custom parameter in `add_target()`
2 parents cf05221 + 8d4511a commit 808ac0c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

tuf/formats.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@
300300
# The fileinfo format of targets specified in the repository and
301301
# developer tools. The fields match that of FILEINFO_SCHEMA, only all
302302
# fields are optional.
303-
CUSTOM_SCHEMA = SCHEMA.Object()
303+
CUSTOM_SCHEMA = SCHEMA.DictOf(
304+
key_schema = SCHEMA.AnyString(),
305+
value_schema = SCHEMA.Any()
306+
)
304307
LOOSE_FILEINFO_SCHEMA = SCHEMA.Object(
305308
object_name = "LOOSE_FILEINFO_SCHEMA",
306309
length = SCHEMA.Optional(LENGTH_SCHEMA),

tuf/repository_tool.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,6 @@ def add_target(self, filepath, custom=None, fileinfo=None):
19291929
Add a filepath (must be relative to the repository's targets directory)
19301930
to the Targets object.
19311931
1932-
This method does not access the file system. 'filepath' must already
1933-
exist on the file system.
1934-
1935-
If 'filepath' does not exist the file will still be added to 'roleinfo'.
1936-
Only later calls to write() and writeall() will fail.
1937-
19381932
If 'filepath' has already been added, it will be replaced with any new
19391933
file or 'custom' information.
19401934
@@ -1948,11 +1942,21 @@ def add_target(self, filepath, custom=None, fileinfo=None):
19481942
targets directory.
19491943
19501944
custom:
1951-
An optional object providing additional information about the file.
1945+
An optional dictionary providing additional information about the file.
1946+
NOTE: if a custom value is passed, the fileinfo parameter must be None.
1947+
This parameter will be deprecated in a future release of tuf, use of
1948+
the fileinfo parameter is preferred.
19521949
19531950
fileinfo:
1954-
An optional fileinfo object, conforming to tuf.formats.FILEINFO_SCHEMA,
1955-
providing full information about the file.
1951+
An optional fileinfo dictionary, conforming to
1952+
tuf.formats.FILEINFO_SCHEMA, providing full information about the
1953+
file, i.e:
1954+
{ 'length': 101,
1955+
'hashes': { 'sha256': '123EDF...' },
1956+
'version': 2, # optional
1957+
'custom': { 'permissions': '600'} # optional
1958+
}
1959+
NOTE: if a custom value is passed, the fileinfo parameter must be None.
19561960
19571961
<Exceptions>
19581962
securesystemslib.exceptions.FormatError, if 'filepath' is improperly

0 commit comments

Comments
 (0)