| 1 | package pushbulletscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/ |
| 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 | "stringsscip-go gomod github.com/golang/go/src . strings/" |
| 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/services/standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/" |
| 11 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 12 | ) |
| 13 | |
| 14 | // Config holds the configuration for the Pushbullet service. |
| 15 | type Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config# struct { |
| 16 | standardscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/standard`/.EnumlessConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#EnumlessConfig. |
| 17 | |
| 18 | Targetsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Targets. []string `url:"path"` |
| 19 | Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Token. string `url:"host"` |
| 20 | Titlescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Title. string ` default:"Shoutrrr notification" key:"title"` |
| 21 | } |
| 22 | |
| 23 | // Scheme is the scheme part of the service configuration URL. |
| 24 | const Schemescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Scheme. = "pushbullet" |
| 25 | |
| 26 | // ExpectedTokenLength is the required length for a valid Pushbullet token. |
| 27 | const ExpectedTokenLengthscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/ExpectedTokenLength. = 34 |
| 28 | |
| 29 | // ErrTokenIncorrectSize indicates that the token has an incorrect size. |
| 30 | var ErrTokenIncorrectSizescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/ErrTokenIncorrectSize. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("token has incorrect size") |
| 31 | |
| 32 | // GetURL returns a URL representation of the Config's current field values. |
| 33 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#) GetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#GetURL().() *urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL# { |
| 34 | 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) |
| 35 | |
| 36 | return c.getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#getURL().(&resolver) |
| 37 | } |
| 38 | |
| 39 | // SetURL updates the Config from a URL representation of its field values. |
| 40 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#) SetURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/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 { |
| 41 | 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) |
| 42 | |
| 43 | return c.setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#setURL().(&resolver, serviceURL) |
| 44 | } |
| 45 | |
| 46 | // getURL constructs a URL from the Config's fields using the provided resolver. |
| 47 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#) getURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/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# { |
| 48 | return &urlscip-go gomod github.com/golang/go/src . `net/url`/.URLscip-go gomod github.com/golang/go/src . `net/url`/URL#{ |
| 49 | Hostscip-go gomod github.com/golang/go/src . `net/url`/URL#Host.: c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Token., |
| 50 | Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path.: "/" + stringsscip-go gomod github.com/golang/go/src . strings/.Joinscip-go gomod github.com/golang/go/src . strings/Join().(c.Targetsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Targets., "/"), |
| 51 | 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/push/pushbullet`/Scheme., |
| 52 | ForceQueryscip-go gomod github.com/golang/go/src . `net/url`/URL#ForceQuery.: false, |
| 53 | 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), |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // setURL updates the Config from a URL using the provided resolver. |
| 58 | func (c *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#) setURLscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/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 { |
| 59 | path := serviceURL.Pathscip-go gomod github.com/golang/go/src . `net/url`/URL#Path. |
| 60 | if path != "" && path[0] == '/' { |
| 61 | path = path[1:] |
| 62 | } |
| 63 | |
| 64 | if serviceURL.Fragmentscip-go gomod github.com/golang/go/src . `net/url`/URL#Fragment. != "" { |
| 65 | path += "/#" + serviceURL.Fragmentscip-go gomod github.com/golang/go/src . `net/url`/URL#Fragment. |
| 66 | } |
| 67 | |
| 68 | targets := stringsscip-go gomod github.com/golang/go/src . strings/.Splitscip-go gomod github.com/golang/go/src . strings/Split().(path, "/") |
| 69 | |
| 70 | token := serviceURL.Hostnamescip-go gomod github.com/golang/go/src . `net/url`/URL#Hostname().() |
| 71 | if serviceURL.Stringscip-go gomod github.com/golang/go/src . `net/url`/URL#String().() != "pushbullet://[email protected]" { |
| 72 | if err := validateTokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/validateToken().(token); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | c.Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Token. = token |
| 78 | c.Targetsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/Config#Targets. = targets |
| 79 | |
| 80 | for key, vals := range serviceURL.Queryscip-go gomod github.com/golang/go/src . `net/url`/URL#Query().() { |
| 81 | 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 { |
| 82 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("setting query parameter %q to %q: %w", key, vals[0], err) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // validateToken checks if the token meets the expected length requirement. |
| 90 | func validateTokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/validateToken().(token string) error { |
| 91 | if len(token) != ExpectedTokenLengthscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/ExpectedTokenLength. { |
| 92 | return ErrTokenIncorrectSizescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/pushbullet`/ErrTokenIncorrectSize. |
| 93 | } |
| 94 | |
| 95 | return nil |
| 96 | } |