Skip to content

Commit

Permalink
Merge pull request #194 from Gronner/output_get_public_key_example
Browse files Browse the repository at this point in the history
Improve public key output and add file output
  • Loading branch information
flavio authored Jan 26, 2023
2 parents fbd1498 + bc370a4 commit d0744c8
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions examples/rekor/get_public_key/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{fs::write, process};

use clap::{Arg, Command};
use sigstore::rekor::apis::{configuration::Configuration, pubkey_api};

Expand All @@ -29,14 +31,34 @@ async fn main() {
.arg(Arg::new("tree_id")
.long("tree_id")
.value_name("TREE_ID")
.help("The tree ID of the tree that you wish to prove consistency for. To use the default value, do not input any value."));
.help("The tree ID of the tree that you wish to prove consistency for. To use the default value, do not input any value."))
.arg(Arg::new("output")
.short('o')
.long("output")
.value_name("OUTPUT_FILE")
.num_args(0..=1)
.require_equals(true)
.default_missing_value("key.pub")
.help("The path to the output file that you wish to store the public key in. To use the default value (pub.key), do not provide OUTPUT_FILE."));

let flags = matches.get_matches();
let configuration = Configuration::default();
let pubkey = pubkey_api::get_public_key(
&configuration,
flags.get_one::<String>("tree_id").map(|s| s.as_str()),
)
.await;
println!("{:#?}", pubkey.unwrap());
.await
.expect("Unable to retrieve public key");

if let Some(out_path) = flags.get_one::<String>("output") {
match write(out_path, pubkey) {
Ok(_) => (),
Err(e) => {
eprintln!("Could not write to {out_path}: {e}");
process::exit(1);
}
}
} else {
print!("{}", pubkey);
}
}

0 comments on commit d0744c8

Please sign in to comment.