Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Rename Delegated to Delegation.
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Vacek <[email protected]>
  • Loading branch information
pattivacek committed Jan 29, 2019
1 parent 3b1f5af commit 4e955a5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/libaktualizr/primary/sotauptaneclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ bool SotaUptaneClient::updateImagesMeta() {
// Update Images delegated Targets Metadata
for (const std::string &delegation : images_repo.delegations("targets")) {
std::string images_delegated;
Uptane::Role delegated_role = Uptane::Role::Delegated(delegation);
Uptane::Role delegated_role = Uptane::Role::Delegation(delegation);

if (!uptane_fetcher->fetchLatestRole(&images_delegated, Uptane::kMaxImagesTargetsSize,
Uptane::RepositoryType::Image(), delegated_role)) {
Expand Down Expand Up @@ -712,7 +712,7 @@ bool SotaUptaneClient::checkImagesMetaOffline() {
// Update Images delegated Targets Metadata
for (const std::string &delegation : images_repo.delegations("targets")) {
std::string images_delegated;
Uptane::Role delegated_role = Uptane::Role::Delegated(delegation);
Uptane::Role delegated_role = Uptane::Role::Delegation(delegation);
if (!storage->loadDelegation(&images_delegated, delegated_role)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libaktualizr/uptane/imagesrepository.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ std::unique_ptr<Uptane::Target> ImagesRepository::getTarget(const Uptane::Target
if (it == toplevel.targets.cend()) {
// Check if the target matches any of the delegation paths.
for (const auto& delegate_name : toplevel.delegated_role_names_) {
Role delegate_role = Role::Delegated(delegate_name);
Role delegate_role = Role::Delegation(delegate_name);
std::vector<std::string> patterns = toplevel.paths_for_role_[delegate_role];
for (const auto& pattern : patterns) {
if (fnmatch(pattern.c_str(), director_target.filename().c_str(), 0) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/libaktualizr/uptane/role.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Role::Role(const std::string &role_name, const bool delegation) {
if (IsReserved(name_)) {
throw Uptane::Exception("", "Delegated role name " + role_name + " is reserved.");
}
role_ = RoleEnum::kDelegated;
role_ = RoleEnum::kDelegation;
name_ = role_name;
} else if (role_name_lower == ROOT) {
role_ = RoleEnum::kRoot;
Expand Down
2 changes: 1 addition & 1 deletion src/libaktualizr/uptane/tuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void Uptane::Targets::init(const Json::Value &json) {
const Json::Value role_list = json["signed"]["delegations"]["roles"];
for (Json::ValueIterator it = role_list.begin(); it != role_list.end(); it++) {
const std::string role_name = (*it)["name"].asString();
const Role role = Role::Delegated(role_name);
const Role role = Role::Delegation(role_name);
delegated_role_names_.insert(role_name);
ParseRole(Uptane::RepositoryType::Image(), it, role, name_);

Expand Down
8 changes: 4 additions & 4 deletions src/libaktualizr/uptane/tuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Role {
static Role Snapshot() { return Role{RoleEnum::kSnapshot}; }
static Role Targets() { return Role{RoleEnum::kTargets}; }
static Role Timestamp() { return Role{RoleEnum::kTimestamp}; }
static Role Delegated(const std::string &name) { return Role(name, true); }
static Role Delegation(const std::string &name) { return Role(name, true); }
static Role InvalidRole() { return Role{RoleEnum::kInvalidRole}; }
// Delegated is not included because this is only used for a metadata table
// Delegation is not included because this is only used for a metadata table
// that doesn't include delegations.
static std::vector<Role> Roles() { return {Root(), Snapshot(), Targets(), Timestamp()}; }
static bool IsReserved(const std::string &name) {
Expand All @@ -76,7 +76,7 @@ class Role {
explicit Role(const std::string &role_name, bool delegation = false);
std::string ToString() const;
int ToInt() const { return static_cast<int>(role_); }
bool IsDelegation() const { return role_ == RoleEnum::kDelegated; }
bool IsDelegation() const { return role_ == RoleEnum::kDelegation; }
bool operator==(const Role &other) const { return name_ == other.name_; }
bool operator!=(const Role &other) const { return !(*this == other); }
bool operator<(const Role &other) const { return name_ < other.name_; }
Expand All @@ -86,7 +86,7 @@ class Role {
private:
/** The four standard roles must match the meta_types table in sqlstorage.
* Delegations are special and handled differently. */
enum class RoleEnum { kRoot = 0, kSnapshot = 1, kTargets = 2, kTimestamp = 3, kDelegated = 4, kInvalidRole = -1 };
enum class RoleEnum { kRoot = 0, kSnapshot = 1, kTargets = 2, kTimestamp = 3, kDelegation = 4, kInvalidRole = -1 };

explicit Role(RoleEnum role) : role_(role) {
if (role_ == RoleEnum::kRoot) {
Expand Down
10 changes: 5 additions & 5 deletions src/libaktualizr/uptane/tuf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ TEST(Role, ValidateRoles) {

/* Delegated roles have custom names. */
TEST(Role, ValidateDelegation) {
Uptane::Role delegated = Uptane::Role::Delegated("whatever");
Uptane::Role delegated = Uptane::Role::Delegation("whatever");
EXPECT_EQ(delegated.ToString(), "whatever");
EXPECT_EQ(delegated.IsDelegation(), true);
}

/* Reject delegated role names that are identical to reserved role names. */
TEST(Role, InvalidDelegationName) {
EXPECT_THROW(Uptane::Role::Delegated("root"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegated("snapshot"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegated("targets"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegated("timestamp"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegation("root"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegation("snapshot"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegation("targets"), Uptane::Exception);
EXPECT_THROW(Uptane::Role::Delegation("timestamp"), Uptane::Exception);
}

#ifndef __NO_MAIN__
Expand Down

0 comments on commit 4e955a5

Please sign in to comment.