2020
2121import  java .util .Base64 ;
2222import  java .util .List ;
23+ import  java .util .Optional ;
2324
2425import  org .apache .camel .Exchange ;
2526import  org .apache .camel .builder .AggregationStrategies ;
3940@ ApplicationScoped 
4041public  class  OssIndexIntegration  extends  EndpointRouteBuilder  {
4142
42-   @ ConfigProperty (name  = "api.ossindex.timeout" , defaultValue  = "1000s" )
43+   private  static  final  String  TRUSTIFICATION_SOURCE  = "trustification" ;
44+ 
45+   @ ConfigProperty (name  = "api.ossindex.timeout" , defaultValue  = "10s" )
4346  String  timeout ;
4447
48+   @ ConfigProperty (name  = "api.ossindex.trustification.user" )
49+   Optional <String > trustificationUser ;
50+ 
51+   @ ConfigProperty (name  = "api.ossindex.trustification.token" )
52+   Optional <String > trustificationToken ;
53+ 
4554  @ Inject  VulnerabilityProvider  vulnerabilityProvider ;
4655
4756  @ Inject  OssIndexResponseHandler  responseHandler ;
@@ -55,6 +64,7 @@ public void configure() {
5564    from (direct ("ossIndexScan" ))
5665      .routeId ("ossIndexScan" )
5766      .transform (method (OssIndexRequestBuilder .class , "split" ))
67+       .process (this ::authenticateTrustificationSource )
5868      .choice ()
5969        .when (method (OssIndexRequestBuilder .class , "missingAuthHeaders" ))
6070          .setBody (method (OssIndexResponseHandler .class , "unauthenticatedResponse" ))
@@ -117,4 +127,17 @@ private void processComponentRequest(Exchange exchange) {
117127    message .removeHeader (Constants .OSS_INDEX_USER_HEADER );
118128    message .removeHeader (Constants .OSS_INDEX_TOKEN_HEADER );
119129  }
130+ 
131+   private  void  authenticateTrustificationSource (Exchange  exchange ) {
132+     var  headers  = exchange .getIn ().getHeaders ();
133+     var  source  = headers .get (Constants .RHDA_SOURCE_HEADER );
134+     if  (!TRUSTIFICATION_SOURCE .equals (source )) {
135+       return ;
136+     }
137+     if  (!headers .containsKey (Constants .OSS_INDEX_USER_HEADER )
138+         && !headers .containsKey (Constants .OSS_INDEX_TOKEN_HEADER )) {
139+       headers .put (Constants .OSS_INDEX_USER_HEADER , trustificationUser .orElse (null ));
140+       headers .put (Constants .OSS_INDEX_TOKEN_HEADER , trustificationToken .orElse (null ));
141+     }
142+   }
120143}
0 commit comments