Skip to content

ngclient constants and configuration - #1470

Merged
jku merged 3 commits into
theupdateframework:developfrom
sechkova:ngclient-settings
Jul 7, 2021
Merged

ngclient constants and configuration#1470
jku merged 3 commits into
theupdateframework:developfrom
sechkova:ngclient-settings

Conversation

@sechkova

Copy link
Copy Markdown
Contributor

Fixes#1402

Description of the changes being introduced by the pull request:
Adds a new public config module ngclient/config.py.

  • containing a dataclass UpdaterConfig with all client settings
  • Initializes updater with the default settings if no other config is provided.

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

@jkujku 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.

The RequestsFetcher changes do not belong here IMO: RequestsFetcher is only one fetcher implementation:

  • If we think these values must be supported by every implementation we should make that part of the interface, not sneak them in like this
  • If these are just RequestsFetcher config, then they shouldn't be in UpdaterConfig

I would just make the requestsfetcher configuration instance attributes of RequestsFetcher: The user can always instantiate one and then modify the attributes before giving the fetcher to updater.

Comment threadtuf/ngclient/config.py Outdated
Comment on lines +12 to +17
MAX_ROOT_ROTATIONS: int = 32
MAX_DELEGATIONS: int = 32
DEFAULT_ROOT_MAX_LENGTH: int = 512000 # bytes
DEFAULT_TIMESTAMP_MAX_LENGTH: int = 16384 # bytes
DEFAULT_SNAPSHOT_MAX_LENGTH: int = 2000000 # bytes
DEFAULT_TARGETS_MAX_LENGTH: int = 5000000 # bytes

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.

since these are now not intended to be constants or scary we can lowercase them... that removes a pylint disable as well

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

yes, I did and and I think it even looks better f5b61ec Thanks for the proposal!

Comment threadtuf/ngclient/updater.py Outdated
Comment on lines +68 to +71
if config is None:
self.config = UpdaterConfig()
else:
self.config = config

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.

Suggested change
ifconfigisNone:
self.config=UpdaterConfig()
else:
self.config=config
self.config=configorUpdaterConfig()

should work in this case?

Add a config module containing a dataclass
UpdaterConfig with all client settings.
Initialize updater with default settings
if no other condig is provided.
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
@sechkova

Copy link
Copy Markdown
ContributorAuthor

Rebased on develop.
Also reworked all commits after the review suggestions so another one will be needed.

@sechkova
sechkova marked this pull request as ready for review July 6, 2021 10:12
@sechkovasechkova changed the title WIP: ngclient constants and configurationngclient constants and configurationJul 6, 2021

@jkujku 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.

Looks good. I'm not super into adding optional things into the constructors... but if others like the config object pattern I'm OK with it.

We should get rid of sleep_before_round: if we're "hogging CPU" as the comment says, let's fix that instead. I don't think we are though: I'm sure requests does not require us to poll constantly. Can you file an issue on that?

self._sessions = {}

# Default settings
self.sleep_before_round: int = 4 # seconds

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.

er, I think you mixed up sleep_before_round and socket_timeout: this is going to make life painful

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

oh 🤦

Comment threadtuf/ngclient/config.py Outdated
Comment on lines +14 to +17
default_root_max_length: int = 512000 # bytes
default_timestamp_max_length: int = 16384 # bytes
default_snapshot_max_length: int = 2000000 # bytes
default_targets_max_length: int = 5000000 # bytes

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.

None one of the variables should be called "default" i think -- looks a bit odd in the code since they might be set by the user and they're still called "default"?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Maybe default makes sense for snapshot and targets where this is the value used if the one in metadata is not se but I renamed all anyway 520b344.

@sechkovasechkova mentioned this pull request Jul 6, 2021
3 tasks
Since configuration constants are now part of a
config class, make them lower case. This also avoids
pylint's invalid-name error for class attributes.
Remove the 'default' prefix as they are now configurable
options.
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Stop using the settings module and add the RequestsFetcher
specific config as instance attributes.
Users of the requests-based fetcher implementation can
modify them after instantiating a RequestsFetcher
object if needed.
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
jku
jku approved these changes Jul 6, 2021
@jku
jku merged commit f8046d8 into theupdateframework:developJul 7, 2021
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.

ngclient: client-level constants

2 participants

@sechkova@jku