@@ -54,14 +54,6 @@ public void configure() throws Exception {
54
54
55
55
from ("direct:events" )
56
56
57
- .onException (DecoderException .class )
58
- .onException (GeneralSecurityException .class )
59
- .handled (true )
60
- .removeHeaders ("*" )
61
- .setHeader (Exchange .HTTP_RESPONSE_CODE , constant (404 ))
62
- .transform (constant ("Not found" ))
63
- .end ()
64
-
65
57
.log ("Received event:" )
66
58
.log ("-> ${headers[X-Github-Event]}" )
67
59
.log ("-> ${body}" )
@@ -76,21 +68,40 @@ public void configure() throws Exception {
76
68
.when (PredicateBuilder .and (
77
69
header (X_EVENT ).isEqualTo ("installation" ),
78
70
simple ("${body[action]} == 'created'" )))
71
+ .to ("direct:handle-event" )
72
+ .otherwise ()
73
+ .removeHeaders ("*" )
74
+ .setBody (simple ("${null}" ));
75
+
76
+ from ("direct:handle-event" )
79
77
80
- .to ("direct:get-secret" )
81
- .bean (this , "validateSignature" )
82
- .log ("TODO" )
78
+ .onException (DecoderException .class )
79
+ .onException (GeneralSecurityException .class )
80
+ .handled (true )
81
+ .removeHeaders ("*" )
82
+ .setHeader (Exchange .HTTP_RESPONSE_CODE , constant (404 ))
83
+ .transform (constant ("Not found" ))
83
84
.end ()
84
- .removeHeaders ("*" )
85
- .setBody (simple ("${null}" ));
86
85
87
- from ("direct:get-secret" )
86
+ // save values for use
87
+ .setProperty ("app_id" , simple ("${body[installation][app_id]}" ))
88
+ .setProperty ("id" , simple ("${body[installation][id]}" ))
89
+
90
+ // get app secrets
91
+ .to ("direct:get-secret" )
92
+
93
+ .bean (this , "validateSignature" )
94
+ // TODO: generate JWT
95
+ // TODO: request access token
96
+
97
+ // restore original payload
98
+ .setBody (exchangeProperty ("payload" ))
99
+ .log ("TODO: ${body}" );
88
100
89
- // save original body
90
- .setProperty ("original" , body ())
101
+ from ("direct:get-secret" )
91
102
92
103
.setHeader (KubernetesConstants .KUBERNETES_NAMESPACE_NAME , simple ("${env:NAMESPACE}" ))
93
- .setHeader (KubernetesConstants .KUBERNETES_SECRET_NAME , simple ("github-app-${body[installation] [app_id]}" ))
104
+ .setHeader (KubernetesConstants .KUBERNETES_SECRET_NAME , simple ("github-app-${exchangeProperty [app_id]}" ))
94
105
95
106
.to ("kubernetes-secrets:///?kubernetesClient=#kubernetesClient&operation=getSecret" )
96
107
.process (exchange -> {
@@ -103,9 +114,6 @@ public void configure() throws Exception {
103
114
104
115
exchange .setProperty (GitHubApp .WEBHOOK_SECRET , decoder .decode (data .get (GitHubApp .WEBHOOK_SECRET )));
105
116
}
106
- })
107
-
108
- // restore original body
109
- .setBody (exchangeProperty ("original" ));
117
+ });
110
118
}
111
119
}
0 commit comments