Skip to content

Commit

Permalink
feat: ability to pass auth-token in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Oct 12, 2023
1 parent fda7929 commit 24fcef9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ordhook-sdk-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ jobs:
working-directory: ./components/ordhook-sdk-js
steps:
- uses: actions/checkout@v3
- name: Change directory
working-directory: ./components/ordhook-sdk-js
- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
Expand Down
12 changes: 10 additions & 2 deletions components/ordhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ struct ScanBlocksCommand {
/// HTTP Post activity to a URL
#[clap(long = "post-to")]
pub post_to: Option<String>,
/// HTTP Auth token
#[clap(long = "auth-token")]
pub auth_token: Option<String>,
}

#[derive(Parser, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -284,6 +287,9 @@ struct StartCommand {
/// Block height where ordhook will start posting Ordinals activities
#[clap(long = "start-at-block")]
pub start_at_block: Option<u64>,
/// HTTP Auth token
#[clap(long = "auth-token")]
pub auth_token: Option<String>,
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -499,6 +505,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
&post_to,
cmd.start_block,
Some(cmd.end_block),
cmd.auth_token
)?
.into_selected_network_specification(&config.network.bitcoin_network)?;
scan_bitcoin_chainstate_via_rpc_using_predicate(
Expand Down Expand Up @@ -640,7 +647,7 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
let mut predicates = vec![];

for post_to in cmd.post_to.iter() {
let predicate = build_predicate_from_cli(&config, post_to, start_block, None)?;
let predicate = build_predicate_from_cli(&config, post_to, start_block, None, cmd.auth_token.clone())?;
predicates.push(ChainhookFullSpecification::Bitcoin(predicate));
}

Expand Down Expand Up @@ -835,6 +842,7 @@ pub fn build_predicate_from_cli(
post_to: &str,
start_block: u64,
end_block: Option<u64>,
auth_token: Option<String>,
) -> Result<BitcoinChainhookFullSpecification, String> {
let mut networks = BTreeMap::new();
// Retrieve last block height known, and display it
Expand All @@ -852,7 +860,7 @@ pub fn build_predicate_from_cli(
predicate: BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed),
action: HookAction::HttpPost(HttpHook {
url: post_to.to_string(),
authorization_header: "".to_string(),
authorization_header: format!("Bearer {}", auth_token.unwrap_or("".to_string())),
}),
},
);
Expand Down

0 comments on commit 24fcef9

Please sign in to comment.