Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeJSONMessage(req *http.Request, v interface{}) ([]byte, error)
- func Metrics() []xmetrics.Metric
- func SetUpTestNotifier() (Notifier, *MockSVC, *MockValidator, *mux.Router)
- type AWSConfig
- type AWSMetrics
- type ErrResp
- type MockSVC
- func (m *MockSVC) ConfirmSubscription(input *sns.ConfirmSubscriptionInput) (*sns.ConfirmSubscriptionOutput, error)
- func (m *MockSVC) ListSubscriptionsByTopic(input *sns.ListSubscriptionsByTopicInput) (*sns.ListSubscriptionsByTopicOutput, error)
- func (m *MockSVC) Publish(input *sns.PublishInput) (*sns.PublishOutput, error)
- func (m *MockSVC) Subscribe(input *sns.SubscribeInput) (*sns.SubscribeOutput, error)
- func (m *MockSVC) Unsubscribe(input *sns.UnsubscribeInput) (*sns.UnsubscribeOutput, error)
- type MockValidator
- type MsgAttr
- type Notifier
- type SNSConfig
- type SNSMessage
- type SNSServer
- func (ss *SNSServer) DnsReady() (e error)
- func (ss *SNSServer) Initialize(rtr *mux.Router, selfUrl *url.URL, soaProvider string, handler http.Handler, ...)
- func (ss *SNSServer) ListSubscriptionsByMatchingEndpoint() (*list.List, error)
- func (ss *SNSServer) NotificationHandle(rw http.ResponseWriter, req *http.Request) []byte
- func (ss *SNSServer) PrepareAndStart()
- func (ss *SNSServer) PublishMessage(message string) error
- func (ss *SNSServer) SNSNotificationReceivedCounter(code int)
- func (ss *SNSServer) SNSNotificationReceivedInit() chan int
- func (ss *SNSServer) SetSNSRoutes(urlPath string, r *mux.Router, handler http.Handler)
- func (ss *SNSServer) Subscribe()
- func (ss *SNSServer) SubscribeConfirmHandle(rw http.ResponseWriter, req *http.Request)
- func (ss *SNSServer) Unsubscribe(subArn string)
- func (ss *SNSServer) UnsubscribeOldSubscriptions()
- func (ss *SNSServer) ValidateSubscriptionArn(reqSubscriptionArn string) bool
- type SNSValidator
- type Validator
Constants ¶
const ( DnsReadyQueryCount = "dns_ready_query_count" DnsReady = "dns_ready" SNSNotificationReceived = "webhook_sns_notification_received_count" SNSNotificationSent = "webhook_sns_notification_sent_count" SNSSubscribeAttempt = "webhook_sns_subscribe_attempt_count" SNSSubscribed = "webhook_sns_subscribed_value" )
const ( MSG_ATTR = "scytale.env" SNS_VALIDATION_ERR = "SNS signature validation error" )
const ( TEST_AWS_CONFIG = `` /* 338-byte string literal not displayed */ TEST_SUB_MSG = `` /* 1317-byte string literal not displayed */ TEST_HOOK = `` /* 224-byte string literal not displayed */ NOTIFY_HOOK_MSG = `` /* 1017-byte string literal not displayed */ TEST_NOTIF_ERR_MSG = `` /* 816-byte string literal not displayed */ )
const (
// AWSKey is the subkey used to load AWS configuration (e.g. AWSConfig)
AWSKey = "aws"
)
Variables ¶
var (
ErrJsonEmpty = errors.New("JSON payload is empty")
)
Functions ¶
func SetUpTestNotifier ¶
func SetUpTestNotifier() (Notifier, *MockSVC, *MockValidator, *mux.Router)
Types ¶
type AWSConfig ¶
type AWSMetrics ¶
type AWSMetrics struct { DnsReadyQueryCount metrics.Counter DnsReady metrics.Gauge SNSNotificationReceived metrics.Counter SNSNotificationSent metrics.Counter SNSSubscribeAttempt metrics.Counter SNSSubscribed metrics.Gauge }
func ApplyMetricsData ¶
func ApplyMetricsData(registry xmetrics.Registry) (m AWSMetrics)
ApplyMetricsData is used for setting the counter values on the AWSMetrics when stored and accessing for later use
type MockSVC ¶
func (*MockSVC) ConfirmSubscription ¶
func (m *MockSVC) ConfirmSubscription(input *sns.ConfirmSubscriptionInput) (*sns.ConfirmSubscriptionOutput, error)
func (*MockSVC) ListSubscriptionsByTopic ¶
func (m *MockSVC) ListSubscriptionsByTopic(input *sns.ListSubscriptionsByTopicInput) (*sns.ListSubscriptionsByTopicOutput, error)
func (*MockSVC) Publish ¶
func (m *MockSVC) Publish(input *sns.PublishInput) (*sns.PublishOutput, error)
func (*MockSVC) Subscribe ¶
func (m *MockSVC) Subscribe(input *sns.SubscribeInput) (*sns.SubscribeOutput, error)
func (*MockSVC) Unsubscribe ¶
func (m *MockSVC) Unsubscribe(input *sns.UnsubscribeInput) (*sns.UnsubscribeOutput, error)
type MockValidator ¶
func (*MockValidator) Validate ¶
func (m *MockValidator) Validate(msg *SNSMessage) (bool, error)
type MsgAttr ¶
http://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.html
POST / HTTP/1.1 x-amz-sns-message-type: SubscriptionConfirmation x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic Content-Length: 1336 Content-Type: text/plain; charset=UTF-8 Host: example.com Connection: Keep-Alive User-Agent: Amazon Simple Notification Service Agent
{ "Type" : "SubscriptionConfirmation", "MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b", "Token" : "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736", "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic", "Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.", "SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736", "Timestamp" : "2012-04-26T20:45:04.751Z", "SignatureVersion" : "1", "Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=", "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem" }
POST / HTTP/1.1 x-amz-sns-message-type: Notification x-amz-sns-message-id: 22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324 x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96 Content-Length: 773 Content-Type: text/plain; charset=UTF-8 Host: example.com Connection: Keep-Alive User-Agent: Amazon Simple Notification Service Agent
{ "Type" : "Notification", "MessageId" : "22b80b92-fdea-4c2c-8f9d-bdfb0c7bf324", "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic", "Subject" : "My First Message", "Message" : "Hello world!", "Timestamp" : "2012-05-02T00:54:06.655Z", "SignatureVersion" : "1", "Signature" : "EXAMPLEw6JRNwm1LFQL4ICB0bnXrdB8ClRMTQFGBqwLpGbM78tJ4etTwC5zU7O3tS6tGpey3ejedNdOJ+1fkIp9F2/LmNVKb5aFlYq+9rk9ZiPph5YlLmWsDcyC5T+Sy9/umic5S0UQc2PEtgdpVBahwNOdMW4JPwk0kAJJztnc=", "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem", "UnsubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:c9135db0-26c4-47ec-8998-413945fb5a96" }
type Notifier ¶
type Notifier interface { Initialize(*mux.Router, *url.URL, string, http.Handler, log.Logger, xmetrics.Registry, func() time.Time) PrepareAndStart() Subscribe() PublishMessage(string) error Unsubscribe(string) NotificationHandle(http.ResponseWriter, *http.Request) []byte ValidateSubscriptionArn(string) bool SNSNotificationReceivedCounter(int) DnsReady() error }
Notifier interface implements the various notification server functionalities like Subscribe, Unsubscribe, Publish, NotificationHandler
type SNSMessage ¶
type SNSServer ¶
type SNSServer struct { Config AWSConfig SVC snsiface.SNSAPI SelfUrl *url.URL SOAProvider string SNSValidator // contains filtered or unexported fields }
func NewSNSServer ¶
NewSNSServer creates SNSServer instance using viper config
func (*SNSServer) DnsReady ¶
DnsReady blocks until the primary server's DNS is up and running or until the timeout is reached if timeout value is 0s it will try forever
func (*SNSServer) Initialize ¶
func (ss *SNSServer) Initialize(rtr *mux.Router, selfUrl *url.URL, soaProvider string, handler http.Handler, logger log.Logger, registry xmetrics.Registry, now func() time.Time)
Initialize initializes the SNSServer fields selfURL represents the webhook server URL &url.URL{Scheme:secure,Host:fqdn+port,Path:urlPath} handler is the webhook handler to update webhooks @monitor SNS POST Notification handler will directly update webhooks list
func (*SNSServer) ListSubscriptionsByMatchingEndpoint ¶
func (*SNSServer) NotificationHandle ¶
Decodes SNS Notification message and returns the actual message which is json webhook content
func (*SNSServer) PrepareAndStart ¶
func (ss *SNSServer) PrepareAndStart()
Prepare the SNSServer to receive Notifications This better be called after the endpoint http server is started and ready to receive AWS SNS POST messages subscribe to the SNS topic
func (*SNSServer) PublishMessage ¶
Publish Notification message to AWS SNS topic
func (*SNSServer) SNSNotificationReceivedCounter ¶
SNSNotificationReceivedCounter relays response code data to be aggregated in metrics
func (*SNSServer) SNSNotificationReceivedInit ¶
SNSNotificationReceivedInit initializes metrics counters and returns a channel to send response codes to count
func (*SNSServer) SetSNSRoutes ¶
Define handlers for various AWS SNS POST calls
func (*SNSServer) Subscribe ¶
func (ss *SNSServer) Subscribe()
Subscribe to AWS SNS Topic to receive notifications
func (*SNSServer) SubscribeConfirmHandle ¶
func (ss *SNSServer) SubscribeConfirmHandle(rw http.ResponseWriter, req *http.Request)
POST handler to receive SNS Confirmation Message
func (*SNSServer) Unsubscribe ¶
Unsubscribe from receiving notifications
func (*SNSServer) UnsubscribeOldSubscriptions ¶
func (ss *SNSServer) UnsubscribeOldSubscriptions()
func (*SNSServer) ValidateSubscriptionArn ¶
Validate that SubscriptionArn received in AWS request matches the cached config data
type SNSValidator ¶
type SNSValidator interface {
Validate(*SNSMessage) (bool, error)
}
func NewSNSValidator ¶
func NewSNSValidator() SNSValidator
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}