-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
97 lines (83 loc) · 3.26 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright 2018 BlackRock, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package aws_sns
import (
"github.com/sirupsen/logrus"
"time"
gwcommon "github.com/argoproj/argo-events/gateways/common"
snslib "github.com/aws/aws-sdk-go/service/sns"
"github.com/ghodss/yaml"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
)
const ArgoEventsEventSourceVersion = "v0.10"
const (
messageTypeSubscriptionConfirmation = "SubscriptionConfirmation"
messageTypeNotification = "Notification"
)
var (
snsProtocol = "http"
)
// SNSEventSourceExecutor implements Eventing
type SNSEventSourceExecutor struct {
Log *logrus.Logger
// Clientset is kubernetes client
Clientset kubernetes.Interface
// Namespace where gateway is deployed
Namespace string
}
// RouteConfig contains information for a route
type RouteConfig struct {
Route *gwcommon.Route
snses *snsEventSource
session *snslib.SNS
subscriptionArn *string
clientset kubernetes.Interface
namespace string
}
// Json http notifications
// SNS posts those to your http url endpoint if http is selected as delivery method.
// http://docs.aws.amazon.com/sns/latest/dg/json-formats.html#http-subscription-confirmation-json
// http://docs.aws.amazon.com/sns/latest/dg/json-formats.html#http-notification-json
// http://docs.aws.amazon.com/sns/latest/dg/json-formats.html#http-unsubscribe-confirmation-json
type httpNotification struct {
Type string `json:"Type"`
MessageId string `json:"MessageId"`
Token string `json:"Token,omitempty"` // Only for subscribe and unsubscribe
TopicArn string `json:"TopicArn"`
Subject string `json:"Subject,omitempty"` // Only for Notification
Message string `json:"Message"`
SubscribeURL string `json:"SubscribeURL,omitempty"` // Only for subscribe and unsubscribe
Timestamp time.Time `json:"Timestamp"`
SignatureVersion string `json:"SignatureVersion"`
Signature string `json:"Signature"`
SigningCertURL string `json:"SigningCertURL"`
UnsubscribeURL string `json:"UnsubscribeURL,omitempty"` // Only for notifications
}
// snsEventSource contains configuration to subscribe to SNS topic
type snsEventSource struct {
// Hook defines a webhook.
Hook *gwcommon.Webhook `json:"hook"`
TopicArn string `json:"topicArn"`
AccessKey *corev1.SecretKeySelector `json:"accessKey" protobuf:"bytes,5,opt,name=accessKey"`
SecretKey *corev1.SecretKeySelector `json:"secretKey" protobuf:"bytes,6,opt,name=secretKey"`
Region string `json:"region"`
}
func parseEventSource(es string) (interface{}, error) {
var ses *snsEventSource
err := yaml.Unmarshal([]byte(es), &ses)
if err != nil {
return nil, err
}
return ses, nil
}