-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yftacherzog/add-protocols
chore(RHTAPWATCH-636): add compose protocols
- Loading branch information
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from dataclasses import dataclass | ||
|
||
from .protocols import ( | ||
ComposeConfigurations, | ||
ComposeConfigurationsGenerator, | ||
ComposeFetcher, | ||
ComposeReference, | ||
ComposeRequester, | ||
) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ComposeGenerator: | ||
""" | ||
Given implementations to all building blocks if a compose generator, generate a | ||
compose and return its reference. | ||
:param configurations_generator: an object to generate the configurations used for | ||
requesting a new compose | ||
:param requestor: an object to request a new composed | ||
:param fetcher: an object to fetch a compose once it's ready | ||
""" | ||
configurations_generator: ComposeConfigurationsGenerator | ||
requestor: ComposeRequester | ||
fetcher: ComposeFetcher | ||
|
||
def __call__(self) -> ComposeReference: | ||
configs: ComposeConfigurations = self.configurations_generator() | ||
request_reference: ComposeReference = self.requestor(configs=configs) | ||
result_reference: ComposeReference = self.fetcher( | ||
request_reference=request_reference | ||
) | ||
return result_reference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from .odcs_fetcher import ODCSFetcher | ||
from .odcs_requester import ODCSRequester | ||
from .odcs_configurations_generator import ODCSConfigurationsGenerator | ||
from .compose_generator import ComposeGenerator | ||
|
||
|
||
def main(): | ||
""" | ||
Get inputs from container and content_sets yamls and relay them to an ODCS | ||
compose generator that will request a compose and store it in a TBD location. | ||
""" | ||
# Get inputs from container and content_sets yamls | ||
container_data = {} | ||
content_sets_data = {} | ||
|
||
compose_generator = ComposeGenerator( | ||
configurations_generator=ODCSConfigurationsGenerator( | ||
container_data=container_data, | ||
content_sets_data=content_sets_data, | ||
), | ||
requestor=ODCSRequester(), | ||
fetcher=ODCSFetcher(), | ||
) | ||
compose_generator() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from dataclasses import dataclass | ||
|
||
from .protocols import ComposeConfigurations, ComposeConfigurationsGenerator | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSConfigurations(ComposeConfigurations): | ||
""" | ||
Configurations to be used for requesting an ODCS compose | ||
""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSConfigurationsGenerator(ComposeConfigurationsGenerator): | ||
""" | ||
Generate odcs configurations based on container and content_sets yamls. | ||
:param container_data: data loaded from container.yaml | ||
:param content_sets_data: data loaded from content_sets.yaml | ||
""" | ||
container_data: dict | ||
content_sets_data: dict | ||
|
||
def __call__(self) -> ODCSConfigurations: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
|
||
from .protocols import ComposeFetcher, ComposeReference | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSResultReference(ComposeReference): | ||
""" | ||
Reference to a locally-stored compose result | ||
""" | ||
compose_path: Path | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSFetcher(ComposeFetcher): | ||
""" | ||
Fetch ODCS compose based on a remote compose-reference and store it locally | ||
""" | ||
def __call__(self, request_reference: ComposeReference) -> ODCSResultReference: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dataclasses import dataclass | ||
|
||
from .protocols import ComposeConfigurations, ComposeReference, ComposeRequester | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSRequestReference(ComposeReference): | ||
""" | ||
Reference to a remotely-stored compose data | ||
""" | ||
compose_url: str | ||
|
||
|
||
@dataclass(frozen=True) | ||
class ODCSRequester(ComposeRequester): | ||
""" | ||
Request a new ODCS compose based on compose configurations and return a reference | ||
to the remote compose location. | ||
""" | ||
def __call__(self, configs: ComposeConfigurations) -> ODCSRequestReference: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Protocol | ||
|
||
|
||
class ComposeConfigurations(Protocol): | ||
""" | ||
Data class for storing compose configurations | ||
""" | ||
|
||
|
||
class ComposeConfigurationsGenerator(Protocol): | ||
""" | ||
Generate compose configurations | ||
""" | ||
def __call__(self) -> ComposeConfigurations: | ||
pass | ||
|
||
|
||
class ComposeReference(Protocol): | ||
""" | ||
Data class for storing compose reference | ||
""" | ||
|
||
|
||
class ComposeRequester(Protocol): | ||
""" | ||
Given compose configurations, return a remote compose reference | ||
""" | ||
def __call__(self, configs: ComposeConfigurations) -> ComposeReference: | ||
pass | ||
|
||
|
||
class ComposeFetcher(Protocol): | ||
""" | ||
Given remote compose reference, return a local compose reference | ||
""" | ||
|
||
def __call__(self, request_reference: ComposeReference) -> ComposeReference: | ||
pass |