Skip to content

Commit 68c22b4

Browse files
committed
Remove get_filepaths_in_directory() from tutorial
Replace the absolute paths returned by get_filepaths_in_directory() in the tutorial with a hard-coded list of relaive filepaths since add_target(s) and delegate() methods raise excception on absolute paths. Remove an obsolete warning about path pattern's location. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent a584d1d commit 68c22b4

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

docs/TUTORIAL.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,8 @@ the target filepaths to metadata.
352352
# in targets metadata.
353353
>>> repository = load_repository('repository')
354354

355-
# get_filepaths_in_directory() returns a list of file paths in a directory. It
356-
# can also return files in sub-directories if 'recursive_walk' is True.
357-
>>> list_of_targets = repository.get_filepaths_in_directory(
358-
... "repository/targets/", recursive_walk=False, followlinks=True)
359-
360-
# Note: Since we set the 'recursive_walk' argument to false, the 'myproject'
361-
# sub-directory is excluded from 'list_of_targets'.
362-
>>> list_of_targets
363-
['/path/to/repository/targets/file2.txt', '/path/to/repository/targets/file1.txt', '/path/to/repository/targets/file3.txt']
355+
# Create a list of all targets in the directory.
356+
>>> list_of_targets = ['file1.txt', 'file2.txt', 'file3.txt']
364357

365358
# Add the list of target paths to the metadata of the top-level Targets role.
366359
# Any target file paths that might already exist are NOT replaced, and
@@ -376,10 +369,12 @@ the target filepaths to metadata.
376369
# (octal number specifying file access for owner, group, others e.g., 0755) is
377370
# added alongside the default fileinfo. All target objects in metadata include
378371
# the target's filepath, hash, and length.
372+
# Note: target path passed to add_target() method has to be relative
373+
# to the targets directory or an exception is raised.
379374
>>> target4_filepath = os.path.abspath("repository/targets/myproject/file4.txt")
380375
>>> octal_file_permissions = oct(os.stat(target4_filepath).st_mode)[4:]
381376
>>> custom_file_permissions = {'file_permissions': octal_file_permissions}
382-
>>> repository.targets.add_target(target4_filepath, custom_file_permissions)
377+
>>> repository.targets.add_target('myproject/file4.txt', custom_file_permissions)
383378
```
384379

385380
The private keys of roles affected by the changes above must now be imported and
@@ -498,7 +493,6 @@ targets and generate signed metadata.
498493

499494
# Make a delegation (delegate trust of 'myproject/*.txt' files) from "targets"
500495
# to "unclaimed", where "unclaimed" initially contains zero targets.
501-
# NOTE: Please ignore the warning about the path pattern's location (see #963)
502496
>>> repository.targets.delegate('unclaimed', [public_unclaimed_key], ['myproject/*.txt'])
503497

504498
# Thereafter, we can access the delegated role by its name to e.g. add target
@@ -635,8 +629,7 @@ to some role.
635629
>>> repository.targets('unclaimed').remove_target("myproject/file4.txt")
636630

637631
# Get a list of target paths for the hashed bins.
638-
>>> targets = repository.get_filepaths_in_directory(
639-
... 'repository/targets/myproject', recursive_walk=True)
632+
>>> targets = ['myproject/file4.txt']
640633

641634
# Delegate trust to 32 hashed bin roles. Each role is responsible for the set
642635
# of target files, determined by the path hash prefix. TUF evenly distributes

0 commit comments

Comments
 (0)