@@ -129,6 +129,8 @@ use omicron_common::api::external::DataPageParams;
129
129
use omicron_common:: api:: external:: Generation ;
130
130
use omicron_common:: api:: external:: InstanceState ;
131
131
use omicron_common:: api:: external:: MacAddr ;
132
+ use omicron_common:: api:: external:: NameOrId ;
133
+ use omicron_common:: api:: external:: http_pagination:: PaginatedBy ;
132
134
use omicron_uuid_kinds:: CollectionUuid ;
133
135
use omicron_uuid_kinds:: DatasetUuid ;
134
136
use omicron_uuid_kinds:: GenericUuid ;
@@ -360,6 +362,8 @@ enum DbCommands {
360
362
Vmms ( VmmListArgs ) ,
361
363
/// Print information about the oximeter collector.
362
364
Oximeter ( OximeterArgs ) ,
365
+ /// Print information about webhooks
366
+ Webhook ( WebhookArgs ) ,
363
367
}
364
368
365
369
#[ derive( Debug , Args , Clone ) ]
@@ -905,6 +909,45 @@ struct VmmListArgs {
905
909
states : Vec < db:: model:: VmmState > ,
906
910
}
907
911
912
+ #[ derive( Debug , Args , Clone ) ]
913
+ struct WebhookArgs {
914
+ #[ command( subcommand) ]
915
+ command : WebhookCommands ,
916
+ }
917
+
918
+ #[ derive( Debug , Subcommand , Clone ) ]
919
+ enum WebhookCommands {
920
+ /// Get information on webhook receivers.
921
+ #[ clap( alias = "rx" ) ]
922
+ Receiver {
923
+ #[ command( subcommand) ]
924
+ command : WebhookRxCommands ,
925
+ } ,
926
+ /// Get information on webhook events
927
+ Event ,
928
+ }
929
+
930
+ #[ derive( Debug , Subcommand , Clone ) ]
931
+ enum WebhookRxCommands {
932
+ /// List webhook receivers
933
+ #[ clap( alias = "ls" ) ]
934
+ List ( WebhookRxListArgs ) ,
935
+
936
+ #[ clap( alias = "show" ) ]
937
+ Info ( WebhookRxInfoArgs ) ,
938
+ }
939
+
940
+ #[ derive( Debug , Args , Clone ) ]
941
+ struct WebhookRxInfoArgs {
942
+ receiver : NameOrId ,
943
+ }
944
+
945
+ #[ derive( Debug , Args , Clone ) ]
946
+ struct WebhookRxListArgs {
947
+ #[ clap( long, short) ]
948
+ start_at : Option < Uuid > ,
949
+ }
950
+
908
951
impl DbArgs {
909
952
/// Run a `omdb db` subcommand.
910
953
///
@@ -1165,6 +1208,7 @@ impl DbArgs {
1165
1208
DbCommands :: Oximeter ( OximeterArgs {
1166
1209
command : OximeterCommands :: ListProducers
1167
1210
} ) => cmd_db_oximeter_list_producers ( & datastore, fetch_opts) . await ,
1211
+ DbCommands :: Webhook ( WebhookArgs { command } ) => cmd_db_webhook ( & opctx, & datastore, & fetch_opts, command) . await ,
1168
1212
}
1169
1213
}
1170
1214
} ) . await
@@ -6863,6 +6907,93 @@ async fn cmd_db_oximeter_list_producers(
6863
6907
Ok ( ( ) )
6864
6908
}
6865
6909
6910
+ async fn cmd_db_webhook (
6911
+ opctx : & OpContext ,
6912
+ datastore : & DataStore ,
6913
+ fetch_opts : & DbFetchOptions ,
6914
+ command : & WebhookCommands ,
6915
+ ) -> anyhow:: Result < ( ) > {
6916
+ match command {
6917
+ WebhookCommands :: Receiver {
6918
+ command : WebhookRxCommands :: List ( args) ,
6919
+ } => cmd_db_webhook_rx_list ( opctx, datastore, fetch_opts, args) . await ,
6920
+ WebhookCommands :: Receiver {
6921
+ command : WebhookRxCommands :: Info ( args) ,
6922
+ } => cmd_db_webhook_rx_info ( opctx, datastore, fetch_opts, args) . await ,
6923
+ WebhookCommands :: Event => {
6924
+ Err ( anyhow:: anyhow!( "not yet implemented, sorry!" ) )
6925
+ }
6926
+ }
6927
+ }
6928
+
6929
+ async fn cmd_db_webhook_rx_list (
6930
+ opctx : & OpContext ,
6931
+ datastore : & DataStore ,
6932
+ fetch_opts : & DbFetchOptions ,
6933
+ args : & WebhookRxListArgs ,
6934
+ ) -> anyhow:: Result < ( ) > {
6935
+ let ctx = || {
6936
+ if let Some ( starting_at) = args. start_at {
6937
+ format ! ( "listing webhook receivers (starting at {starting_at}" )
6938
+ } else {
6939
+ "listing webhook_receivers" . to_string ( )
6940
+ }
6941
+ } ;
6942
+ let pagparams = DataPageParams {
6943
+ marker : args. start_at . as_ref ( ) ,
6944
+ ..first_page ( fetch_opts. fetch_limit )
6945
+ } ;
6946
+ let rxs = datastore
6947
+ . webhook_rx_list ( opctx, & PaginatedBy :: Id ( pagparams) )
6948
+ . await
6949
+ . with_context ( ctx) ?;
6950
+
6951
+ check_limit ( & rxs, fetch_opts. fetch_limit , ctx) ;
6952
+
6953
+ #[ derive( Tabled ) ]
6954
+ #[ tabled( rename_all = "SCREAMING_SNAKE_CASE" ) ]
6955
+ struct RxRow {
6956
+ id : Uuid ,
6957
+ #[ tabled( display_with = "datetime_rfc3339_concise" ) ]
6958
+ created : chrono:: DateTime < Utc > ,
6959
+ #[ tabled( display_with = "datetime_rfc3339_concise" ) ]
6960
+ modified : chrono:: DateTime < Utc > ,
6961
+ secrets : usize ,
6962
+ events : usize ,
6963
+ name : String ,
6964
+ endpoint : String ,
6965
+ }
6966
+
6967
+ let rows = rxs. into_iter ( ) . map (
6968
+ |db:: model:: WebhookReceiverConfig { rx, secrets, events } | RxRow {
6969
+ id : rx. id ( ) . into_untyped_uuid ( ) ,
6970
+ name : rx. identity . name . to_string ( ) ,
6971
+ created : rx. time_created ( ) ,
6972
+ modified : rx. time_modified ( ) ,
6973
+ secrets : secrets. len ( ) ,
6974
+ events : events. len ( ) ,
6975
+ endpoint : rx. endpoint ,
6976
+ } ,
6977
+ ) ;
6978
+
6979
+ let table = tabled:: Table :: new ( rows)
6980
+ . with ( tabled:: settings:: Style :: empty ( ) )
6981
+ . with ( tabled:: settings:: Padding :: new ( 0 , 1 , 0 , 0 ) )
6982
+ . to_string ( ) ;
6983
+ println ! ( "{table}" ) ;
6984
+
6985
+ Ok ( ( ) )
6986
+ }
6987
+
6988
+ async fn cmd_db_webhook_rx_info (
6989
+ _opctx : & OpContext ,
6990
+ _datastore : & DataStore ,
6991
+ _fetch_opts : & DbFetchOptions ,
6992
+ _args : & WebhookRxInfoArgs ,
6993
+ ) -> anyhow:: Result < ( ) > {
6994
+ anyhow:: bail!( "TODO: eliza, implement this one!" )
6995
+ }
6996
+
6866
6997
// Format a `chrono::DateTime` in RFC3339 with milliseconds precision and using
6867
6998
// `Z` rather than the UTC offset for UTC timestamps, to save a few characters
6868
6999
// of line width in tabular output.
0 commit comments