Skip to content

Commit 38d96c7

Browse files
committed
fmt
1 parent 502eb9f commit 38d96c7

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/bin/sops-gitops-github-action/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use sops_gitops_github_action::update_sops_config;
66

77
/// CLI arguments for the sops-gitops-github-action
88
#[derive(Debug, Parser)]
9-
#[command(name = "sops-gitops-github-action")]
9+
#[command(name = "sops-gitops-github-action1")]
1010
struct MyArgs {
1111
/// The base64-encoded private GPG key
1212
#[arg(long)]

src/lib.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
use anyhow::{Error, anyhow, Context as AnyhowContext};
1+
use anyhow::{Context as AnyhowContext, Error, anyhow};
22
use base64::Engine;
33
use clap::Parser;
44
use glob::glob;
5+
use gpgme::{Context as GpgmeContext, Protocol};
6+
use openpgp::{Cert, parse::Parse};
7+
use pgp::ser::Serialize;
8+
use pgp::types::PublicKeyTrait;
9+
use pgp::{Deserializable, Message, SignedPublicKey};
10+
use sequoia_openpgp as openpgp;
511
use serde_yaml::Value;
612
use std::fs;
713
use std::fs::File;
8-
use gpgme::{Context as GpgmeContext, Protocol};
914
use std::io::{Read, Write};
1015
use std::path::Path;
1116
use std::process::{Command, Stdio};
12-
use pgp::{SignedPublicKey, Message, Deserializable};
13-
use pgp::ser::Serialize;
14-
use pgp::types::PublicKeyTrait;
15-
use sequoia_openpgp as openpgp;
16-
use openpgp::{parse::Parse, Cert};
1717
#[derive(Parser, Debug)]
1818
struct Args {
1919
/// Base64-encoded private GPG key
@@ -35,10 +35,10 @@ pub fn gpg_mock_private_key() -> Result<String, Error> {
3535

3636
pub fn read_public_key(pub_key_file: &str) -> String {
3737
let key_string = fs::read_to_string(pub_key_file).unwrap();
38-
return key_string
38+
return key_string;
3939
}
4040

41-
pub fn get_pubkey_fingerprint(armored_pubkey: &str) -> Result<String, Error> {
41+
pub fn get_pubkey_fingerprint(armored_pubkey: &str) -> Result<String, Error> {
4242
let cert = Cert::from_reader(armored_pubkey.as_bytes())
4343
.map_err(|err| anyhow!("Failed to parse armored public key: {err}"))?;
4444

@@ -57,7 +57,10 @@ pub fn import_gpg_key(key_data: &str) -> anyhow::Result<(), anyhow::Error> {
5757
let key = SignedPublicKey::from_bytes(key_data.as_bytes())
5858
.map_err(|e| anyhow!("Failed to parse PGP key: {e}"))?;
5959

60-
key.fingerprint().as_bytes().iter().for_each(|byte| print!("{:02X}", byte));
60+
key.fingerprint()
61+
.as_bytes()
62+
.iter()
63+
.for_each(|byte| print!("{:02X}", byte));
6164

6265
Ok(())
6366
}
@@ -94,7 +97,6 @@ pub fn update_sops_config(public_keys: &str) -> anyhow::Result<(), anyhow::Error
9497
Ok(())
9598
}
9699

97-
98100
pub fn get_key_fingerprint(encoded_key: &str) -> anyhow::Result<String> {
99101
let decoded_key = base64::engine::general_purpose::STANDARD
100102
.decode(encoded_key)
@@ -125,8 +127,7 @@ pub fn get_key_fingerprint(encoded_key: &str) -> anyhow::Result<String> {
125127
.wait_with_output()
126128
.context("Failed to wait for gpg process")?;
127129

128-
let output_str =
129-
String::from_utf8(output.stdout).context("Failed to parse gpg output")?;
130+
let output_str = String::from_utf8(output.stdout).context("Failed to parse gpg output")?;
130131

131132
let fingerprint = output_str
132133
.lines()
@@ -139,7 +140,6 @@ pub fn get_key_fingerprint(encoded_key: &str) -> anyhow::Result<String> {
139140
Ok(encoded)
140141
}
141142

142-
143143
#[allow(unused)]
144144
pub fn setup_workspace() -> anyhow::Result<(), anyhow::Error> {
145145
println!("Setting up workspace...");

tests/tests.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010
)]
1111

1212
use base64::Engine;
13-
use sops_gitops_github_action::{create_default_sops_config_file, create_secret_file, find_secret_files, get_key_fingerprint, get_pubkey_fingerprint, gpg_mock_private_key, import_gpg_key, public_keys_provided, read_public_key, set_message, sops_config_file_exists, update_secret_file, update_sops_config};
13+
use pgp::ser::Serialize;
14+
use pgp::{Deserializable, Message, SignedPublicKey};
15+
use sops_gitops_github_action::{
16+
create_default_sops_config_file, create_secret_file, find_secret_files, get_key_fingerprint,
17+
get_pubkey_fingerprint, gpg_mock_private_key, import_gpg_key, public_keys_provided,
18+
read_public_key, set_message, sops_config_file_exists, update_secret_file, update_sops_config,
19+
};
1420
use std::fs;
1521
use std::fs::File;
1622
use std::io::Read;
1723
use std::sync::LazyLock;
1824
use tempfile::tempdir;
19-
use pgp::{SignedPublicKey, Message, Deserializable};
20-
use pgp::ser::Serialize;
2125

2226
const MOCK_KEY_FOOTPRINT: &str = "9C243A3FDC4EF1474372915F9C1B6F1F746AF12C";
23-
static GPG_MOCK_PUBLIC_KEY: LazyLock<String> = LazyLock::new(|| read_public_key("tests/mock-public.key.asc"));
27+
static GPG_MOCK_PUBLIC_KEY: LazyLock<String> =
28+
LazyLock::new(|| read_public_key("tests/mock-public.key.asc"));
2429

2530
#[test]
2631
fn test_read_public_key() {
@@ -35,7 +40,6 @@ fn test_get_key_fingerprint() {
3540
assert_eq!(result, MOCK_KEY_FOOTPRINT);
3641
}
3742

38-
3943
#[test]
4044
fn test_set_message() {
4145
let result = set_message();

0 commit comments

Comments
 (0)