15
15
#
16
16
17
17
18
- # construct a camel source specification from a rayvens source config
19
- def construct_source (config , endpoint , inverted = False ):
20
- if 'kind' not in config :
21
- raise TypeError ('A Camel source needs a kind.' )
22
- if config ['kind' ] not in ['http-source' ]:
23
- raise TypeError ('Unsupported Camel source.' )
18
+ def http_source (config ):
24
19
if 'url' not in config :
25
20
raise TypeError ('Kind http-source requires a url.' )
26
21
url = config ['url' ]
27
22
period = config .get ('period' , 1000 )
23
+ return {'uri' : f'timer:tick?period={ period } ' , 'steps' : [{'to' : url }]}
24
+
25
+
26
+ def generic_source (config ):
27
+ if 'spec' not in config :
28
+ raise TypeError ('Kind generic-source requires a spec.' )
29
+ return config ['spec' ]
30
+
31
+
32
+ sources = {'http-source' : http_source , 'generic-source' : generic_source }
33
+
28
34
35
+ # construct a camel source specification from a rayvens source config
36
+ def construct_source (config , endpoint , inverted = False ):
37
+ if 'kind' not in config :
38
+ raise TypeError ('A Camel source needs a kind.' )
39
+ kind = config ['kind' ]
40
+ f = sources .get (kind )
41
+ if f is None :
42
+ raise TypeError (f'Unsupported Camel source: { kind } .' )
43
+ spec = f (config )
29
44
if inverted :
30
- return [{
31
- 'from' : {
32
- 'uri' : f'timer:tick?period={ period } ' ,
33
- 'steps' : [{
34
- 'to' : url
35
- }, {
36
- 'bean' : 'addToQueue'
37
- }]
38
- },
45
+ spec ['steps' ].append ({'bean' : 'addToQueue' })
46
+ spec = [{
47
+ 'from' : spec
39
48
}, {
40
49
'from' : {
41
50
'uri' : endpoint ,
@@ -44,37 +53,48 @@ def construct_source(config, endpoint, inverted=False):
44
53
}]
45
54
}
46
55
}]
47
-
48
- return [{
49
- 'from' : {
50
- 'uri' : f'timer:tick?period={ period } ' ,
51
- 'steps' : [{
52
- 'to' : url
53
- }, {
54
- 'to' : endpoint
55
- }]
56
- }
57
- }]
56
+ else :
57
+ spec ['steps' ].append ({'to' : endpoint })
58
+ spec = [{'from' : spec }]
59
+ print (spec )
60
+ return spec
58
61
59
62
60
- # construct a camel sink specification from a rayvens sink config
61
- def construct_sink (config , endpoint ):
62
- if 'kind' not in config :
63
- raise TypeError ('A Camel sink needs a kind.' )
64
- if config ['kind' ] not in ['slack-sink' ]:
65
- raise TypeError ('Unsupported Camel sink.' )
63
+ def slack_sink (config ):
66
64
if 'channel' not in config :
67
65
raise TypeError ('Kind slack-sink requires a channel.' )
68
66
if 'webhookUrl' not in config :
69
67
raise TypeError ('Kind slack-sink requires a webhookUrl.' )
70
68
channel = config ['channel' ]
71
69
webhookUrl = config ['webhookUrl' ]
72
70
73
- return [{
74
- 'from' : {
75
- 'uri' : endpoint ,
76
- 'steps' : [{
77
- 'to' : f'slack:{ channel } ?webhookUrl={ webhookUrl } ' ,
78
- }]
79
- }
80
- }]
71
+ return {
72
+ 'steps' : [{
73
+ 'to' : f'slack:{ channel } ?webhookUrl={ webhookUrl } ' ,
74
+ }]
75
+ }
76
+
77
+
78
+ def generic_sink (config ):
79
+ if 'spec' not in config :
80
+ raise TypeError ('Kind generic-sink requires a spec.' )
81
+ return config ['spec' ]
82
+
83
+
84
+ sinks = {'slack-sink' : slack_sink , 'generic-sink' : generic_sink }
85
+
86
+
87
+ # construct a camel sink specification from a rayvens sink config
88
+ def construct_sink (config , endpoint ):
89
+ if 'kind' not in config :
90
+ raise TypeError ('A Camel sink needs a kind.' )
91
+ kind = config ['kind' ]
92
+ f = sinks .get (kind )
93
+ if f is None :
94
+ raise TypeError (f'Unsupported Camel sink: { kind } .' )
95
+
96
+ spec = f (config )
97
+ spec ['uri' ] = endpoint
98
+ spec = [{'from' : spec }]
99
+ print (spec )
100
+ return spec
0 commit comments