Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngclient constants and configuration #1470

Merged
merged 3 commits into from
Jul 7, 2021

Conversation

sechkova
Copy link
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

Copy link
Member

@jku jku left a comment

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 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
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
Contributor Author

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 on lines 68 to 71
if config is None:
self.config = UpdaterConfig()
else:
self.config = config
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if config is None:
self.config = UpdaterConfig()
else:
self.config = config
self.config = config or UpdaterConfig()

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
Contributor Author

sechkova commented Jul 6, 2021

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
@sechkova sechkova changed the title WIP: ngclient constants and configuration ngclient constants and configuration Jul 6, 2021
Copy link
Member

@jku jku left a comment

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?

@@ -47,6 +48,11 @@ def __init__(self):
# Some cookies may not be HTTP-safe.
self._sessions = {}

# Default settings
self.sleep_before_round: int = 4 # seconds
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

oh 🤦

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
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
Contributor Author

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.

@sechkova sechkova 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 merged commit f8046d8 into theupdateframework:develop Jul 7, 2021
Sign up for free to 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