Skip to content

Commit

Permalink
Address latest bootstrap payload changes (#521)
Browse files Browse the repository at this point in the history
* Remove target_base_url question and update docs

Signed-off-by: Martin Vrachev <[email protected]>

* Prepare ceremony to the bootstrap payload changes

Signed-off-by: Martin Vrachev <[email protected]>

---------

Signed-off-by: Martin Vrachev <[email protected]>
  • Loading branch information
MVrachev committed Mar 1, 2024
1 parent d8a75fb commit 3e4b0aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
19 changes: 3 additions & 16 deletions repository_service_tuf/cli/admin/ceremony.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
BootstrapSetup,
Roles,
RSTUFKey,
ServiceSettings,
TUFManagement,
_conform_rsa_key,
get_key,
Expand Down Expand Up @@ -236,12 +235,12 @@
Roles.TIMESTAMP: 1,
Roles.BINS: 1,
},
services=ServiceSettings(),
number_of_keys={Roles.ROOT: 2, Roles.TARGETS: 1},
threshold={
Roles.ROOT: 1,
Roles.TARGETS: 1,
},
number_of_delegated_bins=256,
root_keys={},
online_key=RSTUFKey(),
)
Expand Down Expand Up @@ -270,23 +269,14 @@ def _configure_role_target():
with console.pager(links=True):
console.print(markdown.Markdown(HASH_BINS_EXAMPLE), width=100)

setup.services.number_of_delegated_bins = prompt.IntPrompt.ask(
setup.number_of_delegated_bins = prompt.IntPrompt.ask(
"\nChoose the number of delegated hash bin roles",
default=256,
choices=[str(2**i) for i in range(1, 15)], # choices must be str
show_default=True,
show_choices=True,
)

targets_base_url = click.prompt(
"\nWhat is the targets base URL? (i.e.: "
"https://www.example.com/downloads/)"
)
if targets_base_url.endswith("/") is False:
targets_base_url = targets_base_url + "/"

setup.services.targets_base_url = targets_base_url


def _configure_role_root():
setup.number_of_keys[Roles.ROOT] = prompt.IntPrompt.ask(
Expand Down Expand Up @@ -544,15 +534,12 @@ def _add_row_keys_table(table: table.Table, key: RSTUFKey, storage: str):
)

if role == Roles.TARGETS:
base_url = setup.services.targets_base_url
role_table.add_row(
(
f"\n[white]Base URL:[/] [yellow]{base_url}[/]"
"\n"
"\n[orange1]DELEGATIONS[/]"
f"\n[aquamarine3]{role.value} -> bins[/]"
"\nNumber of bins: "
f"[yellow]{setup.services.number_of_delegated_bins}[/]"
f"[yellow]{setup.number_of_delegated_bins}[/]"
),
"",
)
Expand Down
33 changes: 16 additions & 17 deletions repository_service_tuf/helpers/tuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import base64
import copy
import json
from dataclasses import asdict, dataclass, field
from dataclasses import dataclass, field
from datetime import datetime, timedelta
from enum import Enum
from typing import Any, Dict, List, Literal, Optional, Tuple
Expand Down Expand Up @@ -47,16 +47,6 @@ class Roles(Enum):
BINS = "bins"


@dataclass
class ServiceSettings:
number_of_delegated_bins: int = 256
targets_base_url: str = ""
targets_online_key: bool = True

def to_dict(self):
return asdict(self)


@dataclass
class RSTUFKey:
key: dict = field(default_factory=dict)
Expand All @@ -81,17 +71,26 @@ def to_dict(self) -> Dict[str, Any]:
@dataclass
class BootstrapSetup:
expiration: Dict[Roles, int]
services: ServiceSettings
number_of_keys: Dict[Literal[Roles.ROOT, Roles.TARGETS], int]
threshold: Dict[Literal[Roles.ROOT, Roles.TARGETS], int]
number_of_delegated_bins: int = 256
root_keys: Dict[str, RSTUFKey] = field(default_factory=Dict)
online_key: RSTUFKey = field(default_factory=RSTUFKey)

def to_dict(self):
return {
"expiration": {k.value: v for k, v in self.expiration.items()},
"services": self.services.to_dict(),
}
def to_dict(self) -> Dict[str, Any]:
result: Dict[str, Any] = {"roles": {}}
for role in Roles:
if role.value == BINS:
result["roles"][BINS] = {
"expiration": self.expiration[role],
"number_of_delegated_bins": self.number_of_delegated_bins,
}
else:
result["roles"][role.value] = {
"expiration": self.expiration[role],
}

return result


class MetadataInfo:
Expand Down
4 changes: 1 addition & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
MetadataInfo,
Roles,
RSTUFKey,
ServiceSettings,
TUFManagement,
)

Expand Down Expand Up @@ -46,12 +45,12 @@ def test_setup() -> BootstrapSetup:
Roles.TIMESTAMP: 1,
Roles.BINS: 1,
},
services=ServiceSettings(),
number_of_keys={Roles.ROOT: 2, Roles.TARGETS: 1},
threshold={
Roles.ROOT: 1,
Roles.TARGETS: 1,
},
number_of_delegated_bins=256,
root_keys={},
online_key=RSTUFKey(),
)
Expand All @@ -75,7 +74,6 @@ def test_inputs() -> Tuple[List[str], List[str], List[str], List[str]]:
"", # What is the metadata expiration for the targets role?(Days) (365)? # noqa
"y", # Show example?
"16", # Choose the number of delegated hash bin roles
"http://www.example.com/repository", # What is the targets base URL
"", # What is the metadata expiration for the snapshot role?(Days) (365)? # noqa
"", # What is the metadata expiration for the timestamp role?(Days) (365)? # noqa
"", # What is the metadata expiration for the bins role?(Days) (365)?
Expand Down

0 comments on commit 3e4b0aa

Please sign in to comment.