diff --git a/.gitignore b/.gitignore index 85cdc57..fd1545d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,4 @@ .DS_Store # Flowpipe variable files -*.pvars - -# Flowpipe mod dependencies -.flowpipe +*.pvars \ No newline at end of file diff --git a/README.md b/README.md index dbfc8c2..08bf652 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,16 @@ -# GitHub Mod for PagerDuty +# PagerDuty Mod for Flowpipe -Run pipelines and use triggers for GitHub resources. +A collection of [Flowpipe](https://flowpipe.io) pipelines that can be used to: + +- List Incidents +- List Users +- List Incident Log Entries +- And more! + +## Documentation + +- **[Pipelines →](https://hub.flowpipe.io/mods/turbot/pagerduty/pipelines)** +- **[Triggers →](https://hub.flowpipe.io/mods/turbot/pagerduty/triggers)** ## Getting started @@ -16,13 +26,30 @@ brew install flowpipe Clone: ```sh -git clone https://github.com/turbot/flowpipe-mod-github.git -cd flowpipe-mod-github +git clone https://github.com/turbot/flowpipe-mod-pagerduty.git +cd flowpipe-mod-pagerduty ``` +### Configuration + +Configure your credentials: + +```sh +cp flowpipe.pvars.example flowpipe.pvars +vi flowpipe.pvars +``` + +It's recommended to configure credentials through [input variables](https://flowpipe.io/docs/using-flowpipe/mod-variables) by setting them in the `flowpipe.pvars` file. + +**Note:** Credentials can also be passed in each pipeline run with `--pipeline-arg api_key=u+gLkyUh9sGsEGH3nmtw`. + +Additional input variables may be defined in the mod's `variables.hcl` file that can be configured to better match your environment and requirements. + +Variables with defaults set do not need to be explicitly set, but it may be helpful to override them. + ### Usage -Start your server to get started: +Start the Flowpipe server to get started: ```sh flowpipe service start @@ -31,35 +58,36 @@ flowpipe service start Run a pipeline: ```sh -flowpipe pipeline run user_get_current +flowpipe pipeline run list_incidents ``` -### Credentials - -This mod uses the credentials configured in `flowpipe.pvars` or passed through `--pipeline-args token`. - -### Configuration +## Passing pipeline arguments -Pipelines have [input variables](https://flowpipe.io/docs/using-flowpipe/mod-variables) that can be configured to better match your environment and requirements. Some variables have defaults defined in its source file, e.g., `variables.hcl`, but these can be overwritten in several ways: +To pass values into pipeline [parameters](https://flowpipe.io/docs/using-flowpipe/pipeline-parameters), use the following syntax: -- Copy and rename the `flowpipe.pvars.example` file to `flowpipe.pvars`, and then modify the variable values inside that file -- Pass in a value on the command line: +```sh +flowpipe pipeline run list_incidents --pipeline-arg api_key=u+gLkyUh9sGsEGH3nmtw +``` - ```shell - flowpipe pipeline run user_get_current --pipeline-arg token="ghp_Abc123" - ``` +Multiple pipeline args can be passed in with separate `--pipeline-arg` flags. -These are only some of the ways you can set variables. For a full list, please see [Passing Input Variables](https://flowpipe.io/docs/using-flowpipe/mod-variables#passing-input-variables). +For more information on passing arguments, please see [Pipeline Args](https://flowpipe.io/docs/using-flowpipe/pipeline-arguments). ## Contributing If you have an idea for additional controls or just want to help maintain and extend this mod ([or others](https://github.com/topics/flowpipe-mod)) we would love you to join the community and start contributing. -- **[Join our Slack community →](https://flowpipe.io/community/join)** and hang out with other Mod developers. +- **[Join #flowpipe in our Slack community ](https://flowpipe.io/community/join)** -Please see the [contribution guidelines](https://github.com/turbot/flowpipe/blob/main/CONTRIBUTING.md) and our [code of conduct](https://github.com/turbot/flowpipe/blob/main/CODE_OF_CONDUCT.md). All contributions are subject to the [Apache 2.0 open source license](https://github.com/turbot/flowpipe-mod-github/blob/main/LICENSE). +Please see the [contribution guidelines](https://github.com/turbot/flowpipe/blob/main/CONTRIBUTING.md) and our [code of conduct](https://github.com/turbot/flowpipe/blob/main/CODE_OF_CONDUCT.md). Want to help but not sure where to start? Pick up one of the `help wanted` issues: - [Flowpipe](https://github.com/turbot/flowpipe/labels/help%20wanted) -- [GitHub Mod](https://github.com/turbot/flowpipe-mod-github/labels/help%20wanted) +- [PagerDuty Mod](https://github.com/turbot/flowpipe-mod-pagerduty/labels/help%20wanted) + +## License + +This mod is licensed under the [Apache License 2.0](https://github.com/turbot/flowpipe-mod-pagerduty/blob/main/LICENSE). + +Flowpipe is licensed under the [AGPLv3](https://github.com/turbot/flowpipe/blob/main/LICENSE). diff --git a/docs/index.md b/docs/index.md index 05308f7..e5a87c1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,23 +1,20 @@ --- -repository: "https://github.com/turbot/flowpipe-mod-github" +repository: "https://github.com/turbot/flowpipe-mod-pagerduty" --- -# Flowpipe GitHub Mod +# PagerDuty Mod for Flowpipe -Run pipelines and use triggers for GitHub resources. +A collection of [Flowpipe](https://flowpipe.io) pipelines that can be used to: -## References - -[GitHub](https://github.com/) is a provider of Internet hosting for software development and version control using Git. - -[Flowpipe](https://flowpipe.io) is an open source workflow tool. - -[Flowpipe Mods](https://flowpipe.io/docs/reference/mod-resources#mod) are collections of `pipelines` and `triggers`. +- List Incidents +- List Users +- List Incident Log Entries +- And more! ## Documentation -- **[Pipelines →](https://hub.flowpipe.io/mods/turbot/github/pipelines)** -- **[Triggers →](https://hub.flowpipe.io/mods/turbot/github/triggers)** +- **[Pipelines →](https://hub.flowpipe.io/mods/turbot/pagerduty/pipelines)** +- **[Triggers →](https://hub.flowpipe.io/mods/turbot/pagerduty/triggers)** ## Getting started @@ -33,13 +30,30 @@ brew install flowpipe Clone: ```sh -git clone https://github.com/turbot/flowpipe-mod-github.git -cd flowpipe-mod-github +git clone https://github.com/turbot/flowpipe-mod-pagerduty.git +cd flowpipe-mod-pagerduty ``` +### Configuration + +Configure your credentials: + +```sh +cp flowpipe.pvars.example flowpipe.pvars +vi flowpipe.pvars +``` + +It's recommended to configure credentials through [input variables](https://flowpipe.io/docs/using-flowpipe/mod-variables) by setting them in the `flowpipe.pvars` file. + +**Note:** Credentials can also be passed in each pipeline run with `--pipeline-arg api_key=u+gLkyUh9sGsEGH3nmtw`. + +Additional input variables may be defined in the mod's `variables.hcl` file that can be configured to better match your environment and requirements. + +Variables with defaults set do not need to be explicitly set, but it may be helpful to override them. + ### Usage -Start your server to get started: +Start the Flowpipe server to get started: ```sh flowpipe service start @@ -48,35 +62,36 @@ flowpipe service start Run a pipeline: ```sh -flowpipe pipeline run user_get_current +flowpipe pipeline run list_incidents ``` -### Credentials - -This mod uses the credentials configured in `flowpipe.pvars` or passed through `--pipeline-args token`. - -### Configuration +## Passing pipeline arguments -Pipelines have [input variables](https://flowpipe.io/docs/using-flowpipe/mod-variables) that can be configured to better match your environment and requirements. Some variables have defaults defined in its source file, e.g., `variables.hcl`, but these can be overwritten in several ways: +To pass values into pipeline [parameters](https://flowpipe.io/docs/using-flowpipe/pipeline-parameters), use the following syntax: -- Copy and rename the `flowpipe.pvars.example` file to `flowpipe.pvars`, and then modify the variable values inside that file -- Pass in a value on the command line: +```sh +flowpipe pipeline run list_incidents --pipeline-arg api_key=u+gLkyUh9sGsEGH3nmtw +``` - ```shell - flowpipe pipeline run user_get_current --pipeline-arg token="ghp_Abc123" - ``` +Multiple pipeline args can be passed in with separate `--pipeline-arg` flags. -These are only some of the ways you can set variables. For a full list, please see [Passing Input Variables](https://flowpipe.io/docs/using-flowpipe/mod-variables#passing-input-variables). +For more information on passing arguments, please see [Pipeline Args](https://flowpipe.io/docs/using-flowpipe/pipeline-arguments). ## Contributing If you have an idea for additional controls or just want to help maintain and extend this mod ([or others](https://github.com/topics/flowpipe-mod)) we would love you to join the community and start contributing. -- **[Join our Slack community →](https://flowpipe.io/community/join)** and hang out with other Mod developers. +- **[Join #flowpipe in our Slack community ](https://flowpipe.io/community/join)** -Please see the [contribution guidelines](https://github.com/turbot/flowpipe/blob/main/CONTRIBUTING.md) and our [code of conduct](https://github.com/turbot/flowpipe/blob/main/CODE_OF_CONDUCT.md). All contributions are subject to the [Apache 2.0 open source license](https://github.com/turbot/flowpipe-mod-github/blob/main/LICENSE). +Please see the [contribution guidelines](https://github.com/turbot/flowpipe/blob/main/CONTRIBUTING.md) and our [code of conduct](https://github.com/turbot/flowpipe/blob/main/CODE_OF_CONDUCT.md). Want to help but not sure where to start? Pick up one of the `help wanted` issues: - [Flowpipe](https://github.com/turbot/flowpipe/labels/help%20wanted) -- [GitHub Mod](https://github.com/turbot/flowpipe-mod-github/labels/help%20wanted) +- [PagerDuty Mod](https://github.com/turbot/flowpipe-mod-pagerduty/labels/help%20wanted) + +## License + +This mod is licensed under the [Apache License 2.0](https://github.com/turbot/flowpipe-mod-pagerduty/blob/main/LICENSE). + +Flowpipe is licensed under the [AGPLv3](https://github.com/turbot/flowpipe/blob/main/LICENSE). diff --git a/locals.hcl b/locals.hcl index fe1f8fc..10c9465 100644 --- a/locals.hcl +++ b/locals.hcl @@ -1,4 +1,7 @@ +# Common descriptions locals { - repository_owner = split("/", var.repository_full_name)[0] - repository_name = split("/", var.repository_full_name)[1] -} + api_key_param_description = "The API token to authenticate to the PagerDuty APIs." + email_param_description = "The email address of a valid user associated with the account making the request." + incident_id_param_description = "The ID of the incident." + user_id_param_description = "The ID of the user." +} \ No newline at end of file diff --git a/mod.hcl b/mod.hcl index 41f0cc0..2dc3c51 100644 --- a/mod.hcl +++ b/mod.hcl @@ -1,14 +1,14 @@ -mod "pageduty" { - title = "PageDuty" - description = "Run pipelines and triggers that interact with PageDuty." - color = "#191717" +mod "pagerduty" { + title = "PagerDuty" + description = "Run pipelines and triggers that interact with PagerDuty." + color = "#06AC38" documentation = file("./docs/index.md") - icon = "/images/flowpipe/mods/turbot/github.svg" - categories = ["pageduty"] + icon = "/images/flowpipe/mods/turbot/pagerduty.svg" + categories = ["pagerduty", "library"] opengraph { - title = "PageDuty" - description = "Run pipelines and triggers that interact with PageDuty." - image = "/images/flowpipe/mods/turbot/github-social-graphic.png" + title = "PagerDuty" + description = "Run pipelines and triggers that interact with PagerDuty." + image = "/images/flowpipe/mods/turbot/pagerduty-social-graphic.png" } } diff --git a/pipelines/incident/create_incident.hcl b/pipelines/incident/create_incident.hcl new file mode 100644 index 0000000..c9da50a --- /dev/null +++ b/pipelines/incident/create_incident.hcl @@ -0,0 +1,100 @@ +pipeline "create_incident" { + title = "Create Incident" + description = "Create an incident." + + param "body" { + type = object({ + type = string + details = string + }) + description = "Additional incident details." + optional = true + } + + param "conference_bridge" { + type = object({ + conference_number = string + conference_url = string + }) + description = "Central channel for collaboration." + optional = true + } + + param "escalation_policy" { + type = object({ + id = string + type = string + }) + description = "The escalation policy for the incident." + optional = true + } + + param "from" { + type = string + description = local.email_param_description + } + + param "incident_key" { + type = string + description = "A string which identifies the incident. Sending subsequent requests referencing the same service and with the same incident_key will result in those requests being rejected if an open incident matches that incident_key." + optional = true + } + + param "priority" { + type = object({ + id = string + type = string + }) + description = "The priority of the incident." + optional = true + } + + param "service" { + type = object({ + id = string + type = string + }) + description = "The service detail for the incident." + } + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "title" { + type = string + description = "A succinct description of the nature, symptoms, cause, or effect of the incident." + } + + param "type" { + type = string + description = "The type of the incident." + } + + param "urgency" { + type = string + description = "The urgency of the incident." + optional = true + } + + step "http" "create_incident" { + method = "POST" + url = "https://api.pagerduty.com/incidents" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + From = "${param.from}" + } + request_body = jsonencode({ + incident = { + for name, value in param : name => value if value != null + } + }) + } + + output "incident" { + value = step.http.create_incident.response_body + } +} diff --git a/pipelines/incident/create_note_on_incident.hcl b/pipelines/incident/create_note_on_incident.hcl new file mode 100644 index 0000000..66e6312 --- /dev/null +++ b/pipelines/incident/create_note_on_incident.hcl @@ -0,0 +1,44 @@ +pipeline "create_note_on_incident" { + title = "Create Note on Incident" + description = "Create a note on an incident." + + param "content" { + type = string + description = "The note content of the incident." + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + param "from" { + type = string + description = local.email_param_description + } + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + step "http" "create_note_on_incident" { + method = "POST" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/notes" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + From = "${param.from}" + } + request_body = jsonencode({ + note = { + content = param.content + } + }) + } + + output "create_note_on_incident" { + value = step.http.create_note_on_incident.response_body + } +} diff --git a/pipelines/incident/create_status_update_on_incident.hcl b/pipelines/incident/create_status_update_on_incident.hcl new file mode 100644 index 0000000..f9793f3 --- /dev/null +++ b/pipelines/incident/create_status_update_on_incident.hcl @@ -0,0 +1,42 @@ +pipeline "create_status_update_on_incident" { + title = "Create Status Update on Incident" + description = "Create a status update on an incident." + + param "message" { + type = string + description = "The message to be posted as a status update." + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + param "from" { + type = string + description = local.email_param_description + } + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + step "http" "create_status_update_on_incident" { + method = "POST" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/status_updates" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + From = "${param.from}" + } + request_body = jsonencode({ + message = param.message + }) + } + + output "create_status_update_on_incident" { + value = step.http.create_status_update_on_incident.response_body + } +} diff --git a/pipelines/incident/get_incident.hcl b/pipelines/incident/get_incident.hcl new file mode 100644 index 0000000..d5a232d --- /dev/null +++ b/pipelines/incident/get_incident.hcl @@ -0,0 +1,28 @@ +pipeline "get_incident" { + title = "Get Incident" + description = "Get an incident." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + step "http" "get_incident" { + method = "GET" + url = "https://api.pagerduty.com/incidents/${param.incident_id}" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "incident" { + value = step.http.get_incident.response_body + } +} diff --git a/pipelines/incident/list_incident_alerts.hcl b/pipelines/incident/list_incident_alerts.hcl new file mode 100644 index 0000000..d504d8d --- /dev/null +++ b/pipelines/incident/list_incident_alerts.hcl @@ -0,0 +1,28 @@ +pipeline "list_incident_alerts" { + title = "List Incident Alerts" + description = "List incident alerts in Pagerduty." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + step "http" "list_incident_alerts" { + method = "GET" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/alerts" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "incident_alerts" { + value = step.http.list_incident_alerts.response_body + } +} diff --git a/pipelines/incident/list_incident_log_entries.hcl b/pipelines/incident/list_incident_log_entries.hcl new file mode 100644 index 0000000..5dc9cea --- /dev/null +++ b/pipelines/incident/list_incident_log_entries.hcl @@ -0,0 +1,28 @@ +pipeline "list_incident_log_entries" { + title = "List Incident Log Entries" + description = "List log entries for an incident." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + step "http" "list_incident_log_entries" { + method = "GET" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/log_entries" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "incident_log_entries" { + value = step.http.list_incident_log_entries.response_body + } +} diff --git a/pipelines/incident/list_incident_notes.hcl b/pipelines/incident/list_incident_notes.hcl new file mode 100644 index 0000000..f8611dc --- /dev/null +++ b/pipelines/incident/list_incident_notes.hcl @@ -0,0 +1,28 @@ +pipeline "list_incident_notes" { + title = "List Notes for Incident" + description = "List notes for an incident." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + step "http" "list_incident_notes" { + method = "GET" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/notes" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "list_incident_notes" { + value = step.http.list_incident_notes.response_body + } +} diff --git a/pipelines/incident/list_incidents.hcl b/pipelines/incident/list_incidents.hcl new file mode 100644 index 0000000..4d2c128 --- /dev/null +++ b/pipelines/incident/list_incidents.hcl @@ -0,0 +1,23 @@ +pipeline "list_incidents" { + title = "List Incidents" + description = "List incidents in Pagerduty." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + step "http" "list_incidents" { + method = "GET" + url = "https://api.pagerduty.com/incidents" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "incidents" { + value = step.http.list_incidents.response_body + } +} diff --git a/pipelines/incident/snooze_incident.hcl b/pipelines/incident/snooze_incident.hcl new file mode 100644 index 0000000..5cf9072 --- /dev/null +++ b/pipelines/incident/snooze_incident.hcl @@ -0,0 +1,42 @@ +pipeline "snooze_incident" { + title = "Snooze Incident" + description = "Snooze an incident." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "from" { + type = string + description = local.email_param_description + } + + param "duration" { + type = number + description = "The number of seconds to snooze the incident for. After this number of seconds has elapsed, the incident will return to the triggered state." + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + step "http" "snooze_incident" { + method = "POST" + url = "https://api.pagerduty.com/incidents/${param.incident_id}/snooze" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + From = "${param.from}" + } + request_body = jsonencode({ + duration = param.duration + }) + } + + output "snooze_incident" { + value = step.http.snooze_incident.response_body + } +} diff --git a/pipelines/incident/update_incident.hcl b/pipelines/incident/update_incident.hcl new file mode 100644 index 0000000..c46c550 --- /dev/null +++ b/pipelines/incident/update_incident.hcl @@ -0,0 +1,99 @@ +pipeline "update_incident" { + title = "Update Incident" + description = "Update an incident." + + param "conference_bridge" { + type = object({ + conference_number = string + conference_url = string + }) + description = "Details of the conference bridge." + optional = true + } + + param "escalation_level" { + type = number + description = "Escalate the incident to this level in the escalation policy." + optional = true + } + + param "escalation_policy" { + type = object({}) + description = "The escalation policy for the incident." + optional = true + } + + param "from" { + type = string + description = local.email_param_description + optional = true + } + + param "incident_id" { + type = string + description = local.incident_id_param_description + } + + param "priority" { + type = object({ + id = string + type = string + }) + description = "The priority of the incident." + optional = true + } + + param "resolution" { + type = string + description = "The resolution for this incident if status is set to resolved." + optional = true + } + + param "status" { + type = string + description = "The new status of the incident." + optional = true + } + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "title" { + type = string + description = "The new title of the incident." + optional = true + } + + param "type" { + type = string + description = "The incident type." + } + + param "urgency" { + type = string + description = "The urgency of the incident." + optional = true + } + + step "http" "update_incident" { + method = "PUT" + url = "https://api.pagerduty.com/incidents/${param.incident_id}" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + From = "${param.from}" + } + request_body = jsonencode({ + incident = { + for name, value in param : name => value if value != null + } + }) + } + + output "update_incident" { + value = step.http.update_incident.response_body + } +} diff --git a/pipelines/user/create_user.hcl b/pipelines/user/create_user.hcl new file mode 100644 index 0000000..940b710 --- /dev/null +++ b/pipelines/user/create_user.hcl @@ -0,0 +1,80 @@ +pipeline "create_user" { + title = "Create User" + description = "Create an user." + + param "color" { + type = string + description = "The schedule color." + optional = true + } + + param "description" { + type = string + description = "The user's bio." + optional = true + } + + param "email" { + type = string + description = "The user's email address." + } + + param "job_title" { + type = string + description = "The user's title." + optional = true + } + + param "license" { + type = object + description = "The License assigned to the user." + optional = true + } + + param "name" { + type = string + description = "The name of the user." + } + + param "role" { + type = string + description = "The user role. Account must have the read_only_users ability to set a user as a read_only_user or a read_only_limited_user, and must have advanced permissions abilities to set a user as observer or restricted_access." + optional = true + } + + param "time_zone" { + type = string + description = "The preferred time zone name. If null, the account's time zone will be used." + optional = true + } + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + step "http" "create_user" { + method = "POST" + url = "https://api.pagerduty.com/users" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + request_body = jsonencode({ + user = { + name = "${param.name}", + email = "${param.email}", + time_zone = "${param.time_zone}", + color = "${param.color}", + role = "${param.role}", + description = "${param.description}", + job_title = "${param.job_title}" + } + }) + } + + output "user" { + value = step.http.create_user.response_body + } +} diff --git a/pipelines/user/delete_user.hcl b/pipelines/user/delete_user.hcl new file mode 100644 index 0000000..d13144a --- /dev/null +++ b/pipelines/user/delete_user.hcl @@ -0,0 +1,28 @@ +pipeline "delete_user" { + title = "Delete User" + description = "Delete an user." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "user_id" { + type = string + description = local.user_id_param_description + } + + step "http" "delete_user" { + method = "DELETE" + url = "https://api.pagerduty.com/users/${param.user_id}" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "delete_user" { + value = step.http.delete_user.response_body + } +} diff --git a/pipelines/user/get_current_user.hcl b/pipelines/user/get_current_user.hcl new file mode 100644 index 0000000..a22dc00 --- /dev/null +++ b/pipelines/user/get_current_user.hcl @@ -0,0 +1,23 @@ +pipeline "get_current_user" { + title = "Get Current Authenticated User" + description = "Get the details of current auhhenticated user." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + step "http" "get_current_user" { + method = "GET" + url = "https://api.pagerduty.com/users/me" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "current_user" { + value = step.http.get_current_user.response_body + } +} diff --git a/pipelines/user/get_user.hcl b/pipelines/user/get_user.hcl new file mode 100644 index 0000000..40e8a4e --- /dev/null +++ b/pipelines/user/get_user.hcl @@ -0,0 +1,28 @@ +pipeline "get_user" { + title = "Get User" + description = "Get details about an existing user." + + param "api_key" { + type = string + description = local.api_key_param_description + default = var.api_key + } + + param "user_id" { + type = string + description = local.user_id_param_description + } + + step "http" "get_user" { + method = "GET" + url = "https://api.pagerduty.com/users/${param.user_id}" + request_headers = { + Content-Type = "application/json" + Authorization = "Token token=${param.api_key}" + } + } + + output "user" { + value = step.http.get_user.response_body + } +} diff --git a/pipelines/user/get_user_current.hcl b/pipelines/user/get_user_current.hcl deleted file mode 100644 index 940550d..0000000 --- a/pipelines/user/get_user_current.hcl +++ /dev/null @@ -1,51 +0,0 @@ -// usage: flowpipe pipeline run get_user_current --pipeline-arg "user_login=me" -pipeline "get_user_current" { - description = "Get the details of current auhhenticated user." - - param "token" { - type = string - default = var.token - } - - param "user_login" { - type = string - } - - step "http" "get_user_current" { - method = "post" - url = "https://api.pagerduty.com/graphql" - request_headers = { - Content-Type = "application/json" - Authorization = "Bearer ${param.token}" - } - - request_body = jsonencode({ - query = < value if value != null + } + }) + } + + output "update_user" { + value = step.http.update_user.response_body + } +} diff --git a/variables.hcl b/variables.hcl index 895286d..3d70ea3 100644 --- a/variables.hcl +++ b/variables.hcl @@ -1,17 +1,5 @@ -# TODO: Should these have defaults? -# Right now they do due to : -# panic: missing 2 variable values: -# repository_full_name not set -# token not set - -variable "repository_full_name" { +variable "api_key" { type = string - description = "The full name of the GitHub repository. Examples: turbot/steampipe, turbot/flowpipe" - default = "cbruno10/github-api-test" -} - -variable "token" { - type = string - description = "The GitHub personal access token to authenticate to the GitHub APIs, e.g., `github_pat_a1b2c3d4e5f6g7h8i9j10k11l12m13n14o15p16q17r18s19t20u21v22w23x24y25z26`. Please see https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens for more information." + description = "The PagerDuty API key to authenticate to the PagerDuty APIs, e.g., `u+gLkyUh9sGsEGH3nmtw`. Please see https://support.pagerduty.com/docs/api-access-keys for more information." default = "" }