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

pubsys: allow refresh-repo to use default key path #1575

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ pubsys \
--variant "${BUILDSYS_VARIANT}" \
\
--root-role-path "${PUBLISH_REPO_ROOT_JSON}" \
--default-key-path "${PUBLISH_REPO_KEY}" \
--repo-expiration-policy-path "${PUBLISH_EXPIRATION_POLICY_PATH}" \
${REPO_UNSAFE_REFRESH_ARG} \
--outdir "${PUBLISH_REPO_OUTPUT_DIR}"
Expand Down
32 changes: 22 additions & 10 deletions tools/pubsys/src/repo/refresh_repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::fs::File;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use tough::editor::RepositoryEditor;
use tough::key_source::KeySource;
use tough::key_source::{KeySource, LocalKeySource};
use tough::{ExpirationEnforcement, RepositoryLoader};
use url::Url;

Expand All @@ -42,6 +42,10 @@ pub(crate) struct RefreshRepoArgs {
/// Path to root.json for this repo
root_role_path: PathBuf,

#[structopt(long, parse(from_os_str))]
/// If we generated a local key, we'll find it here; used if Infra.toml has no key defined
default_key_path: PathBuf,

#[structopt(long, parse(from_os_str))]
/// Path to file that defines when repo non-root metadata should expire
repo_expiration_policy_path: PathBuf,
Expand Down Expand Up @@ -143,15 +147,23 @@ pub(crate) fn run(args: &Args, refresh_repo_args: &RefreshRepoArgs) -> Result<()
missing: format!("definition for repo {}", &refresh_repo_args.repo),
})?;

// Get signing key config from repository configuration
let signing_key_config =
repo_config
.signing_keys
.as_ref()
.context(repo_error::MissingConfig {
missing: "signing_keys",
})?;
let key_source = get_signing_key_source(signing_key_config);
// Check if we have a signing key defined in Infra.toml; if not, we'll fall back to the
// generated local key.
let signing_key_config = repo_config.signing_keys.as_ref();

let key_source = if let Some(signing_key_config) = signing_key_config {
get_signing_key_source(signing_key_config)
} else {
ensure!(
refresh_repo_args.default_key_path.exists(),
repo_error::MissingConfig {
missing: "signing_keys in repo config, and we found no local key",
}
);
Box::new(LocalKeySource {
path: refresh_repo_args.default_key_path.clone(),
})
};

// Get the expiration policy
info!(
Expand Down