Skip to content

New API: Add a constants module #1241

Description

@MVrachev

Description of issue or feature request:
I think it will be useful to have a constant module in the new API.
This will help us to minimize the errors when writing hardcoded strings.
For example, the "snapshot.json" string is used often in the Timestamp class in tuf/api/metadata.py.

@joshuagl raised awareness for that in this comment:
#1223 (comment)

Current behavior:
Harcoded strings.

Expected behavior:
Use constant containing the string.

Activity

  1. jku commented on Dec 15, 2020

    @jku
    Member

    For the specific case mentioned, could it not be Snapshot.filename in metadata.py as the filename seems to be a specified feature of snapshot metadata? That Snapshot.filename could be a "getter-only" property to underline how it's not supposed to be changed...

    EDIT: actually the property might not be a good idea as you can't have class properties... Snapshot.filename (not instantiating Snapshot) only works if filename is a plain class variable. But that's Python: could make it Snapshot.FILENAME to make it look more constant

  2. MVrachev commented on Aug 27, 2021

    @MVrachev
    CollaboratorAuthor

    Do we need a separate module other than the one added in #1470?

  3. MVrachev commented on Oct 4, 2021

    @MVrachev
    CollaboratorAuthor

    @jku any opinions?

  4. MVrachev commented on Jan 12, 2022

    @MVrachev
    CollaboratorAuthor

    The Metadata API and the updater implementation have evolved sufficiently that we don't need one central place for constants.
    Currently, we write the constants directly in the metadata API module itself and we have a separate one inside the updater here.
    If in the future we decide we need one central place or to minimize the length of Metadata API we will create other issues for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions