| 1 | package opsgeniescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 6 | "net/urlscip-go gomod github.com/golang/go/src . `net/url`/" |
| 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 OpsGenie service. |
| 14 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config# struct { |
| 15 | APIKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#APIKey. string `desc:"The OpsGenie API key" url:"path"` |
| 16 | Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Host. string `desc:"The OpsGenie API host. Use 'api.eu.opsgenie.com' for EU instances" url:"host" default:"api.opsgenie.com"` |
| 17 | Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Port. uint16 `desc:"The OpsGenie API port." url:"port" default:"443"` |
| 18 | Aliasscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Alias. string `desc:"Client-defined identifier of the alert" key:"alias" optional:"true"` |
| 19 | Descriptionscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Description. string `desc:"Description field of the alert" key:"description" optional:"true"` |
| 20 | Respondersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Responders. []Entityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Entity# `desc:"Teams, users, escalations and schedules that the alert will be routed to send notifications" key:"responders" optional:"true"` |
| 21 | VisibleToscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#VisibleTo. []Entityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Entity# `desc:"Teams and users that the alert will become visible to without sending any notification" key:"visibleTo" optional:"true"` |
| 22 | Actionsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Actions. []string `desc:"Custom actions that will be available for the alert" key:"actions" optional:"true"` |
| 23 | Tagsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Tags. []string `desc:"Tags of the alert" key:"tags" optional:"true"` |
| 24 | Detailsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Details. map[string]string `desc:"Map of key-value pairs to use as custom properties of the alert" key:"details" optional:"true"` |
| 25 | Entityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Entity. string `desc:"Entity field of the alert that is generally used to specify which domain the Source field of the alert" key:"entity" optional:"true"` |
| 26 | Sourcescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Source. string `desc:"Source field of the alert" key:"source" optional:"true"` |
| 27 | Priorityscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Priority. string `desc:"Priority level of the alert. Possible values are P1, P2, P3, P4 and P5" key:"priority" optional:"true"` |
| 28 | Notescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Note. string `desc:"Additional note that will be added while creating the alert" key:"note" optional:"true"` |
| 29 | Userscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#User. string `desc:"Display name of the request owner" key:"user" optional:"true"` |
| 30 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Title. string `desc:"notification title, optionally set by the sender" default:"" key:"title"` |
| 31 | } |
| 32 | |
| 33 | const ( |
| 34 | defaultPortscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/defaultPort. = 443 // defaultPort is the default port for OpsGenie API connections. |
| 35 | Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Scheme. = "opsgenie" // Scheme is the identifying part of this service's configuration URL. |
| 36 | ) |
| 37 | |
| 38 | // ErrAPIKeyMissing indicates that the API key is missing from the config URL path. |
| 39 | var ErrAPIKeyMissingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/ErrAPIKeyMissing. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("API key missing from config URL path") |
| 40 | |
| 41 | // Enums returns an empty map because the OpsGenie service doesn't use Enums. |
| 42 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#) Enumsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/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# { |
| 43 | 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#{} |
| 44 | } |
| 45 | |
| 46 | // GetURL returns a URL representation of the Config's current field values. |
| 47 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 48 | 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) |
| 49 | |
| 50 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#getURL().(&resolver) |
| 51 | } |
| 52 | |
| 53 | // SetURL updates the Config from a URL representation of its field values. |
| 54 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/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 { |
| 55 | 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) |
| 56 | |
| 57 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#setURL().(&resolver, serviceURL) |
| 58 | } |
| 59 | |
| 60 | // getURL constructs a URL from the Config's fields using the provided resolver. |
| 61 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/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# { |
| 62 | var host string |
| 63 | if c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Port. > 0 { |
| 64 | 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/opsgenie`/Config#Host., c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Port.) |
| 65 | } else { |
| 66 | host = c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Host. |
| 67 | } |
| 68 | |
| 69 | result := &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 70 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: host, |
| 71 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: "/" + c.APIKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#APIKey., |
| 72 | 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/opsgenie`/Scheme., |
| 73 | 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), |
| 74 | } |
| 75 | |
| 76 | return result |
| 77 | } |
| 78 | |
| 79 | // setURL updates the Config from a URL using the provided resolver. |
| 80 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/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 { |
| 81 | c.Hostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Host. = serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() |
| 82 | |
| 83 | if serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() != "opsgenie://[email protected]" { |
| 84 | if serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path. != "" { |
| 85 | c.APIKeyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#APIKey. = serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.[1:] |
| 86 | } else { |
| 87 | return ErrAPIKeyMissingscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/ErrAPIKeyMissing. |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().() != "" { |
| 92 | port, err := strconvscip-go gomod github.com/golang/go/src . strconv/.ParseUintscip-go gomod github.com/golang/go/src . strconv/ParseUint().( |
| 93 | serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().(), |
| 94 | 10, |
| 95 | 16, |
| 96 | ) |
| 97 | if err != nil { |
| 98 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("parsing port %q: %w", serviceURL.Portscip-go gomod github.com/golang/go/src . `net/url`/URL#Port().(), err) |
| 99 | } |
| 100 | |
| 101 | c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Port. = uint16(port) |
| 102 | } else { |
| 103 | c.Portscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/Config#Port. = defaultPortscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/incident/opsgenie`/defaultPort. |
| 104 | } |
| 105 | |
| 106 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 107 | 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 { |
| 108 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().( |
| 109 | "setting query parameter %q to %q: %w", |
| 110 | key, |
| 111 | vals[0], |
| 112 | err, |
| 113 | ) |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | return nil |
| 118 | } |