| 1 | package pagerdutyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 5 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 6 | "regexpscip-go gomod github.com/golang/go/src . regexp/" |
| 7 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 8 | |
| 9 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 10 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 11 | ) |
| 12 | |
| 13 | // Config holds the configuration for the PagerDuty service. |
| 14 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config# struct { |
| 15 | IntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#IntegrationKey. string `desc:"The PagerDuty API integration key" url:"path"` |
| 16 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Host. string `desc:"The PagerDuty API host." url:"host" default:"events.pagerduty.com"` |
| 17 | Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Port. uint16 `desc:"The PagerDuty API port." url:"port" default:"443"` |
| 18 | Severityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Severity. string `desc:"The perceived severity of the status the event (critical, error, warning, or info); required" default:"error" key:"severity"` |
| 19 | Sourcescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Source. string `desc:"The unique location of the affected system, preferably a hostname or FQDN; required" default:"default" key:"source"` |
| 20 | Actionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Action. string `desc:"The type of event (trigger, acknowledge, or resolve)" default:"trigger" key:"action"` |
| 21 | DedupKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#DedupKey. string `desc:"A unique key used for incident deduplication" key:"dedup_key"` |
| 22 | Detailsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Details. string `desc:"Additional details about the incident (JSON string that will be parsed into an object)" key:"details"` |
| 23 | Contextsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Contexts. string `desc:"Additional context links or images" key:"contexts"` |
| 24 | Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Client. string `desc:"The name of the monitoring client that is triggering this event" key:"client"` |
| 25 | ClientURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#ClientURL. string `desc:"The URL of the monitoring client that is triggering this event" key:"client_url"` |
| 26 | } |
| 27 | |
| 28 | const ( |
| 29 | // Scheme is the identifying part of this service's configuration URL. |
| 30 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Scheme. = "pagerduty" |
| 31 | // integrationKeyRegex validates that integration keys are 32-character hexadecimal strings. |
| 32 | integrationKeyRegexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/integrationKeyRegex. = `^[a-fA-F0-9]{32}$` |
| 33 | ) |
| 34 | |
| 35 | // Enums returns an empty map because the PagerDuty service doesn't use Enums. |
| 36 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#) Enumsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Enums().() map[string]typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.EnumFormatterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/EnumFormatter# { |
| 37 | return map[string]typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.EnumFormatterscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/EnumFormatter#{} |
| 38 | } |
| 39 | |
| 40 | // GetURL returns a URL representation of the Config's current field values. |
| 41 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 42 | resolver := formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(c) |
| 43 | |
| 44 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#getURL().(&resolver) |
| 45 | } |
| 46 | |
| 47 | // SetURL updates the Config from a URL representation of its field values. |
| 48 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#SetURL().(serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 49 | resolver := formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.NewPropKeyResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/NewPropKeyResolver().(c) |
| 50 | |
| 51 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#setURL().(&resolver, serviceURL) |
| 52 | } |
| 53 | |
| 54 | // getURL constructs a URL from the Config's fields using the provided resolver. |
| 55 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#getURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#) *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 56 | var host string |
| 57 | if c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Port. > 0 { |
| 58 | host = fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("%s:%d", c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Host., c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Port.) |
| 59 | } else { |
| 60 | host = c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Host. |
| 61 | } |
| 62 | |
| 63 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 64 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: host, |
| 65 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: "/" + c.IntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#IntegrationKey., |
| 66 | Schemescip-go gomod github.com/golang/go/src . `net/url`/URL#Scheme.: Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Scheme., |
| 67 | RawQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#RawQuery.: formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.BuildQueryscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/BuildQuery().(resolver), |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // setURL updates the Config from a URL using the provided resolver. |
| 72 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#setURL().(resolver typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ConfigQueryResolverscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#, serviceURL *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#) error { |
| 73 | // Skip validation for dummy URLs used in docs generation |
| 74 | if serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() == "dummy.com" { |
| 75 | if len(serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.) > 1 { |
| 76 | c.IntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#IntegrationKey. = serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.[1:] |
| 77 | } |
| 78 | |
| 79 | return nil |
| 80 | } |
| 81 | |
| 82 | if len(serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.) <= 1 { |
| 83 | return errMissingIntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/errMissingIntegrationKey. |
| 84 | } |
| 85 | |
| 86 | c.IntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#IntegrationKey. = serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.[1:] |
| 87 | |
| 88 | // Validate integration key format |
| 89 | if matched, err := regexpscip-go gomod github.com/golang/go/src . regexp/.MatchStringscip-go gomod github.com/golang/go/src . regexp/MatchString().(integrationKeyRegexscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/integrationKeyRegex., c.IntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#IntegrationKey.); err != nil { |
| 90 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to validate integration key: %w", err) |
| 91 | } else if !matched { |
| 92 | return errInvalidIntegrationKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/errInvalidIntegrationKey. |
| 93 | } |
| 94 | |
| 95 | if serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() != "" { |
| 96 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Host. = serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() |
| 97 | } |
| 98 | |
| 99 | if serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().() != "" { |
| 100 | port, err := strconvscip-go gomod github.com/golang/go/src . strconv/.ParseUintscip-go gomod github.com/golang/go/src . strconv/ParseUint().(serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().(), 10, 16) |
| 101 | if err != nil { |
| 102 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to parse port: %w", err) |
| 103 | } |
| 104 | |
| 105 | c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/pagerduty`/Config#Port. = uint16(port) |
| 106 | } |
| 107 | |
| 108 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 109 | if err := resolver.Setscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ConfigQueryResolver#Set.(key, vals[0]); err != nil { |
| 110 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("failed to set query parameter %q: %w", key, err) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return nil |
| 115 | } |