12
12
13
13
import org .apache .commons .io .IOUtils ;
14
14
import org .apache .commons .text .StringSubstitutor ;
15
+ import org .eclipse .microprofile .config .ConfigProvider ;
15
16
import org .eclipse .microprofile .rest .client .inject .RestClient ;
16
17
import org .slf4j .Logger ;
17
18
import org .slf4j .LoggerFactory ;
27
28
import io .fabric8 .kubernetes .client .KubernetesClient ;
28
29
import io .fabric8 .tekton .pipeline .v1 .PipelineRun ;
29
30
import io .quarkus .oidc .client .OidcClient ;
31
+ import lombok .Setter ;
30
32
31
33
@ RequestScoped
32
34
public class Driver {
33
35
34
36
private static final Logger logger = LoggerFactory .getLogger (Driver .class );
35
37
38
+ private static final ObjectMapper yamlMapper = new ObjectMapper (new YAMLFactory ());
39
+
36
40
@ Inject
37
41
OidcClient oidcClient ;
38
42
@@ -43,25 +47,26 @@ public class Driver {
43
47
@ Inject
44
48
KubernetesClient client ;
45
49
46
- ObjectMapper yamlMapper = new ObjectMapper (new YAMLFactory ());
47
-
50
+ @ Setter
48
51
private String accessToken ;
49
- private String quayRepo ;
50
- private String processor ;
51
52
52
- public void addValues ( String accessToken , String quayRepo , String processor ) {
53
- this . accessToken = accessToken ;
54
- this . quayRepo = quayRepo ;
55
- this . processor = processor ;
56
- }
53
+ @ Setter
54
+ private String quayRepo = "quay.io/redhat-user-workloads/konflux-jbs-pnc-tenant/jvm-build-service/build-request-processor:latest" ;
55
+
56
+ @ Setter
57
+ private String processor = "quay.io/redhat-user-workloads-stage/pnc-devel-tenant/pnc" ;
57
58
58
- public void create (BuildRequest buildRequest ) throws IOException {
59
+ public void create (BuildRequest buildRequest ) {
59
60
IndyTokenResponseDTO tokenResponseDTO = new IndyTokenResponseDTO (accessToken );
60
61
61
62
if (isEmpty (accessToken )) {
63
+ logger .info ("Establishing token from Indy using clientId {}" ,
64
+ ConfigProvider .getConfig ().getConfigValue ("quarkus.oidc.client-id" ).getValue ());
62
65
tokenResponseDTO = indyService .getAuthToken (
63
66
new IndyTokenRequestDTO (buildRequest .getRepositoryBuildContentId ()),
64
67
"Bearer " + getFreshAccessToken ());
68
+ logger .debug ("### new access token: {}" , tokenResponseDTO .getToken ()); // TODO: REMOVE
69
+
65
70
}
66
71
67
72
Map <String , String > templateProperties = new HashMap <>();
@@ -79,14 +84,17 @@ public void create(BuildRequest buildRequest) throws IOException {
79
84
templateProperties .put ("ACCESS_TOKEN" , tokenResponseDTO .getToken ());
80
85
templateProperties .put ("BUILD_ID" , buildRequest .getRepositoryBuildContentId ());
81
86
82
- String pipeline = IOUtils .resourceToString ("pipeline.yaml" , StandardCharsets .UTF_8 ,
83
- Thread .currentThread ().getContextClassLoader ());
87
+ String pipeline = "" ;
88
+ try {
89
+ pipeline = IOUtils .resourceToString ("pipeline.yaml" , StandardCharsets .UTF_8 ,
90
+ Thread .currentThread ().getContextClassLoader ());
91
+ } catch (IOException e ) {
92
+ // TODO: process
93
+ }
84
94
85
95
PipelineRun run = createModelNode (pipeline , templateProperties , PipelineRun .class );
86
96
87
97
var created = client .resource (run ).inNamespace (buildRequest .getNamespace ()).create ();
88
-
89
- System .err .println ("### " + created );
90
98
}
91
99
92
100
/**
@@ -97,7 +105,7 @@ public void create(BuildRequest buildRequest) throws IOException {
97
105
*/
98
106
public String getFreshAccessToken () {
99
107
var result = oidcClient .getTokens ().await ().indefinitely ().getAccessToken ();
100
- System . err . println ("### result " + result );
108
+ logger . debug ("### access token: {}" , result ); // TODO: REMOVE
101
109
return result ;
102
110
}
103
111
0 commit comments