@@ -7,6 +7,8 @@ use crate::constants::{
77 NATS_HEADER_EVENT ,
88} ;
99use crate :: signature;
10+ use trogon_nats:: NatsToken ;
11+ use trogon_std:: SecretString ;
1012#[ cfg( not( coverage) ) ]
1113use async_nats:: jetstream:: context:: CreateStreamError ;
1214use axum:: {
@@ -68,25 +70,23 @@ fn outcome_to_status<E: fmt::Display>(outcome: PublishOutcome<E>) -> StatusCode
6870#[ derive( Clone ) ]
6971struct AppState < P : JetStreamPublisher , S : ObjectStorePut > {
7072 publisher : ClaimCheckPublisher < P , S > ,
71- webhook_secret : String ,
72- subject_prefix : String ,
73+ webhook_secret : SecretString ,
74+ subject_prefix : NatsToken ,
7375 nats_ack_timeout : Duration ,
7476}
7577
7678pub async fn provision < C : JetStreamContext > ( js : & C , config : & GithubConfig ) -> Result < ( ) , C :: Error > {
7779 js. get_or_create_stream ( async_nats:: jetstream:: stream:: Config {
78- name : config. stream_name . clone ( ) ,
80+ name : config. stream_name . as_str ( ) . to_owned ( ) ,
7981 subjects : vec ! [ format!( "{}.>" , config. subject_prefix) ] ,
8082 max_age : config. stream_max_age ,
8183 ..Default :: default ( )
8284 } )
8385 . await ?;
8486
87+ let stream = config. stream_name . as_str ( ) ;
8588 let max_age_secs = config. stream_max_age . as_secs ( ) ;
86- info ! (
87- stream = config. stream_name,
88- max_age_secs, "JetStream stream ready"
89- ) ;
89+ info ! ( stream, max_age_secs, "JetStream stream ready" ) ;
9090 Ok ( ( ) )
9191}
9292
@@ -170,7 +170,7 @@ async fn handle_webhook_inner<P: JetStreamPublisher, S: ObjectStorePut>(
170170
171171 match sig {
172172 Some ( sig) => {
173- if let Err ( e) = signature:: verify ( & state. webhook_secret , & body, sig) {
173+ if let Err ( e) = signature:: verify ( state. webhook_secret . as_str ( ) , & body, sig) {
174174 warn ! ( reason = %e, "GitHub webhook signature validation failed" ) ;
175175 return StatusCode :: UNAUTHORIZED ;
176176 }
@@ -253,10 +253,10 @@ mod tests {
253253
254254 fn test_config ( ) -> GithubConfig {
255255 GithubConfig {
256- webhook_secret : TEST_SECRET . to_string ( ) ,
256+ webhook_secret : SecretString :: new ( TEST_SECRET ) . unwrap ( ) ,
257257 port : 0 ,
258- subject_prefix : "github" . to_string ( ) ,
259- stream_name : "GITHUB" . to_string ( ) ,
258+ subject_prefix : NatsToken :: new ( "github" ) . unwrap ( ) ,
259+ stream_name : NatsToken :: new ( "GITHUB" ) . unwrap ( ) ,
260260 stream_max_age : Duration :: from_secs ( 3600 ) ,
261261 nats_ack_timeout : Duration :: from_secs ( 10 ) ,
262262 nats : trogon_nats:: NatsConfig :: from_env ( & trogon_std:: env:: InMemoryEnv :: new ( ) ) ,
@@ -470,8 +470,8 @@ mod tests {
470470
471471 let state = AppState {
472472 publisher : wrap_publisher ( publisher. clone ( ) ) ,
473- webhook_secret : TEST_SECRET . to_string ( ) ,
474- subject_prefix : "custom" . to_string ( ) ,
473+ webhook_secret : SecretString :: new ( TEST_SECRET ) . unwrap ( ) ,
474+ subject_prefix : NatsToken :: new ( "custom" ) . unwrap ( ) ,
475475 nats_ack_timeout : Duration :: from_secs ( 10 ) ,
476476 } ;
477477
@@ -641,8 +641,8 @@ mod tests {
641641 "test-bucket" . to_string ( ) ,
642642 MaxPayload :: from_server_limit ( usize:: MAX ) ,
643643 ) ,
644- webhook_secret : TEST_SECRET . to_string ( ) ,
645- subject_prefix : "github" . to_string ( ) ,
644+ webhook_secret : SecretString :: new ( TEST_SECRET ) . unwrap ( ) ,
645+ subject_prefix : NatsToken :: new ( "github" ) . unwrap ( ) ,
646646 nats_ack_timeout : Duration :: from_secs ( 10 ) ,
647647 } ;
648648
@@ -676,8 +676,8 @@ mod tests {
676676 "test-bucket" . to_string ( ) ,
677677 MaxPayload :: from_server_limit ( usize:: MAX ) ,
678678 ) ,
679- webhook_secret : TEST_SECRET . to_string ( ) ,
680- subject_prefix : "github" . to_string ( ) ,
679+ webhook_secret : SecretString :: new ( TEST_SECRET ) . unwrap ( ) ,
680+ subject_prefix : NatsToken :: new ( "github" ) . unwrap ( ) ,
681681 nats_ack_timeout : Duration :: from_millis ( 10 ) ,
682682 } ;
683683
0 commit comments