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

RSTUF Interface refactoring (IServices) #389

Conversation

kairoaraujo
Copy link
Member

@kairoaraujo kairoaraujo commented Sep 14, 2023

  • The old repository.refresh_settings handling the IServices
    configuration was moved to the interfaces
  • Now the way to import a I{Services} uses the dynaconf directly
  • Adds better error messages for the wrong configuration
  • Support a service has one setting with multiple environment variables
    what is helpful for third-party libraries that use environment vars

@kairoaraujo kairoaraujo force-pushed the support_multiple_envs_for_setting branch from eb235a3 to 34b7a82 Compare September 20, 2023 11:19
@kairoaraujo kairoaraujo marked this pull request as ready for review September 20, 2023 11:20
@codecov
Copy link

codecov bot commented Sep 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.56% 🎉

Comparison is base (00fd8c2) 99.43% compared to head (e745c25) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #389      +/-   ##
===========================================
+ Coverage   99.43%   100.00%   +0.56%     
===========================================
  Files          12        12              
  Lines         884       898      +14     
===========================================
+ Hits          879       898      +19     
+ Misses          5         0       -5     
Files Changed Coverage Δ
repository_service_tuf_worker/interfaces.py 100.00% <100.00%> (ø)
repository_service_tuf_worker/repository.py 100.00% <100.00%> (+0.92%) ⬆️
...tory_service_tuf_worker/services/keyvault/local.py 100.00% <100.00%> (ø)
...itory_service_tuf_worker/services/storage/local.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- The old `repository.refresh_settings` handling the IServices
  configuration was moved to the `interfaces`
- Now the way to importa a `I{Services}` uses directly the dynaconf
- Adds better error mensages for wrong configuration
- Support a service has one setting with multiple environment variables
  what is helpful for third-part libraries that uses environment vars

Signed-off-by: Kairo de Araujo <[email protected]>
@kairoaraujo kairoaraujo force-pushed the support_multiple_envs_for_setting branch from 34b7a82 to 3c240a1 Compare September 20, 2023 11:26
repository_service_tuf_worker/interfaces.py Outdated Show resolved Hide resolved
@classmethod
def from_dynaconf(cls, settings: Dynaconf) -> None:
"""
Run actions to test, configure using the settings.
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
Run actions to test, configure using the settings.
Run actions to test and configure using the settings.

@@ -47,18 +55,26 @@ def get(self, public_key: Key) -> Signer:
class IStorage(ABC):
@classmethod
@abstractmethod
def configure(cls, settings: Any) -> None:
def configure(cls, settings: Dynaconf) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to annotate the settings arg at IkeyVault.configure as well?

@@ -79,3 +95,79 @@ def put(
Stores file bytes within a file with a specific filename.
"""
raise NotImplementedError # pragma: no cover


def _setup_service_dynaconf(cls: Any, backend: Any, settings: Dynaconf):
Copy link
Member

Choose a reason for hiding this comment

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

Nit: to be even more precise you can create a class called IService and make both IkeyVault and IStorage inherit it, then here the cls will be cls: IService.

Copy link
Member Author

Choose a reason for hiding this comment

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

As we have new contributors, it would be good to have it as a Good First Issue for someone who wants to understand the RSTUF Worker IServices.

Copy link
Member

Choose a reason for hiding this comment

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

repository_service_tuf_worker/interfaces.py Outdated Show resolved Hide resolved
repository_service_tuf_worker/interfaces.py Outdated Show resolved Hide resolved
test_cls, test_settings.RSTUF_FAKE_BACKEND, test_settings
)

assert "Invalid Interface IFake" in str(err)
Copy link
Member

Choose a reason for hiding this comment

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

I think this test function is duplicating the first one.

repository_service_tuf_worker/interfaces.py Outdated Show resolved Hide resolved
- Improve the comments
- Implement a better test for the all settings None
- Add asserts related to the stub

Signed-off-by: Kairo de Araujo <[email protected]>
@kairoaraujo kairoaraujo force-pushed the support_multiple_envs_for_setting branch from a2a69cf to e745c25 Compare September 20, 2023 15:02
@MVrachev
Copy link
Member

Superseded: #397.

@MVrachev MVrachev merged commit f91cf78 into repository-service-tuf:main Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

2 participants