Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for providing secret #288

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format of this file is based on [Keep a Changelog](https://keepachangelog.co
### Added

- Added `workspaces integrations list` command (#284)
- Allow user to specify the secret instead of receiving it from the api (#288)

## [2.23.0] - 2024-03-01

Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions src/integrations/pagerduty_receivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ struct CreateArgs {
#[clap(long, short)]
incident_created_template: Option<Name>,

/// An optional secret to set on the PagerDuty receiver. If this is set,
/// then any incoming webhook will be verified against this secret.
#[clap(long)]
secret: Option<String>,

/// Output of the webhooks
#[clap(long, short, default_value = "table", value_enum)]
output: PagerDutyWebhookOutput,
Expand Down Expand Up @@ -106,6 +111,7 @@ async fn handle_create(args: CreateArgs) -> Result<()> {

let new_pagerduty_receiver = NewPagerDutyReceiver::builder()
.incident_created_template_name(args.incident_created_template)
.secret(args.secret)
.build();
let pagerduty_receiver = client
.pagerduty_receiver_create(workspace_id, &name, new_pagerduty_receiver)
Expand Down Expand Up @@ -178,8 +184,14 @@ struct UpdateArgs {
#[clap(long, env, conflicts_with = "incident_creation_template")]
clear_incident_creation_template: bool,

#[clap(long, short)]
regenerate_security_key: bool,
/// An optional secret to set on the PagerDuty receiver. If this is set,
/// then any incoming webhook will be verified against this secret
#[clap(long, env, conflicts_with = "clear_secret")]
secret: Option<String>,

/// Clear the secret on the PagerDuty receiver.
#[clap(long, env, conflicts_with = "secret")]
clear_secret: bool,

/// Output of the webhooks
#[clap(long, short, default_value = "table", value_enum)]
Expand Down Expand Up @@ -211,9 +223,11 @@ async fn handle_update(args: UpdateArgs) -> Result<()> {
args.incident_creation_template,
);

let secret = clear_or_update(args.clear_secret, args.secret);

let update_pagerduty_receiver = UpdatePagerDutyReceiver::builder()
.incident_created_template_name(incident_created_template_name)
.regenerate_security_key(args.regenerate_security_key)
.secret(secret)
.build();

let pagerduty_receiver = client
Expand Down Expand Up @@ -373,7 +387,8 @@ impl GenericKeyValue {
.map(|name| name.to_string())
.unwrap_or_else(|| String::from("<none>")),
),
GenericKeyValue::new("Security key:", pagerduty_receiver.security_key),
GenericKeyValue::new("Webhook URL:", pagerduty_receiver.webhook_url),
GenericKeyValue::new("Secret set:", pagerduty_receiver.secret_set.to_string()),
GenericKeyValue::new(
"Created at:",
pagerduty_receiver
Expand Down
Loading