Compare commits

...

20 Commits

Author SHA1 Message Date
Jonathan Christison 9510e768dc Added working covscan example 3 years ago
Jonathan Christison 094c81bc47 Disable Kerberos and other Auths in dev profile 3 years ago
Jonathan Christison 63e1d8b01c Add non-working examples 3 years ago
Nicholas Caughey 8553cfb22c Merge branch 'main' into 'tekton_work' 3 years ago
Nicholas Caughey 1c1007b811 changing the groupid to be associated with the project 3 years ago
Nicholas Caughey 0d7678a990 Merge branch 'kerberos_auth' into 'main' 3 years ago
Jonathan Christison fa4ea264e2 Add a comment on how the file was created 3 years ago
Jonathan Christison e755fe945c Use edge TLS termination 3 years ago
Jonathan Christison c15a0c5ee1 Add example deploy and set TLS to edge 3 years ago
Jonathan Christison b1942b512a Change kerberos settings 3 years ago
Jonathan Christison e3fcecac06 Change to osh rather than osh-stage 3 years ago
Jonathan Christison 2e38ec0461 Add krb5.conf to container as config map 3 years ago
Jonathan Christison 4526231088 Secure volume mount example 3 years ago
jperezde fee2bd340f Added Kerberos auth to methods 3 years ago
jperezde 1ab0639941 Test keytab 3 years ago
jperezde af4a80b04a Added Kerberos dependency 3 years ago
jperezde d3e2990851 Modified application.properties 3 years ago
jperezde 94d72b95c8 Added kerberos dependendency in pom.xml 3 years ago
jperezde 22c0be081b Test install Kerberos 3 years ago
jperezde 6df7da6c10 Test Dependency 3 years ago
  1. 127
      README.md
  2. 12
      hack/examples/covscan.sh
  3. 10
      hack/examples/example_pssaas_payload.json
  4. 4
      hack/examples/quarkus.sh
  5. 36
      k8s/linux-krb5.conf
  6. 21
      k8s/stage/edgeroute.yml
  7. 44
      k8s/stage/kerberos-config.yaml
  8. 137
      pom.xml
  9. 1
      src/main/docker/Dockerfile.jvm
  10. 2
      src/main/java/dto/BrewObj.java
  11. 12
      src/main/java/dto/BrewObjPayload.java
  12. 6
      src/main/java/dto/ConnectDB.java
  13. 2
      src/main/java/dto/GitObj.java
  14. 12
      src/main/java/dto/GitObjPayload.java
  15. 2
      src/main/java/dto/PncObj.java
  16. 12
      src/main/java/dto/PncObjPayload.java
  17. 3
      src/main/java/dto/ScanObj.java
  18. 12
      src/main/java/dto/ScanObjPayload.java
  19. 51
      src/main/java/rest/CreateGetResource.java
  20. 32
      src/main/java/rest/CreateScanRequest.java
  21. 39
      src/main/java/rest/CreateScanResource.java
  22. 32
      src/main/java/rest/CreateStartScan.java
  23. 30
      src/main/java/rest/RemoveScan.java
  24. 6
      src/main/java/rest/Scan.java
  25. 84
      src/main/java/rest/StoreData.java
  26. 38
      src/main/java/rest/UsersResource.java
  27. 46
      src/main/resources/application.properties

127
README.md

@ -1,112 +1,51 @@
See https://docs.google.com/document/d/15yod6K_ZbNkJ_ern7gwpxjBkdJIlHXORfYZ3CGQhnEM/edit?usp=sharing for a full version with images
# code-with-quarkus
# Introduction
Currently we rely on CPaaS to submit requests to PSSaaS which then invokes the PSSC scanning container. The idea behind the ScanChain api is to act as an interaction point for services to be able to directly access our scan tooling.
This project uses Quarkus, the Supersonic Subatomic Java Framework.
Our api will be written in Quarkus for ease of use and deployment to OpenShift, we will also use Tekton to assist with CI/CD.
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
# How to build
## Running the application in dev mode
To set up the environment. After cloning the repository:
```
cd <repository>/
quarkus create app quarkus:dev
mvn -N io.takari:maven:wrapper
```
Also, it is necessary to create a local PostgreSQL instance. For development purposes, the parameters are:
```
username = postgresql
password = password
```
ToDo: Create Database Model
To run the Quarkus build in dev mode simply run:
````
You can run your application in dev mode that enables live coding using:
```shell script
./mvnw compile quarkus:dev
````
All end points should be avaliable on localhost:8080/{endpoint}. The endpoints are listed in the endpoints section
# Deploying to OpenShift (https://quarkus.io/guides/deploying-to-openshift)
Part of the advantage of working with quarkus is the ease of which we can deploy it to OpenShift. We have the OpenShift extension already installed via the pom,
All that should be required to build and deploy OpenShift is to login to OpenShift via the usual method (oc login (creds) for example). Before running a build command:
You can then expose the routes (oc expose {route}), then your application should be accessible on the OpenShift cluster. This is verifiable either by using the console to request which services are running (oc get svc) or by using the web console which should display the service graphically.
# Design diagram
API endpoint diagram with all endpoints DB links, connections to further services (PNC API etc)
# API endpoints
## /{scanId} - GET request for retrieving scans
This is a simple request for retrieving scans that are stored in our postgresql database. The assigned scanId will return the whole scan payload in JSON format.
## / - POST request takes a JSON payload to start scans (Maybe isnt relevant/shouldnt be included in the future)
Creating scans via passing fully formed JSON payloads. The standard JSON format should contain:
product-id
event-id
is-managed-service
component-list
See appendix 1 for a provided example
## /scanRequest - Post request for starting scans
There are several different types of build that should be retrieved from the backend source. Different inputs are required based off the build source.
The required fields for BREW builds are:
buildSystemType
brewId
brewNVR - matches brewId
pncId
artifactType
fileName
builtFromSource
The required fields for git builds are:
buildSystemType
repository
reference
commitId
The required fields for PNC builds are:
buildSystemType
buildId
```
This information should allow us to have all the requirements for retrieving and then starting a scan when requested from the required sources.
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
## /startScan - PUT request to start off the relevant scan
## Packaging and running the application
Only requires the scanId and should start off the relevant scan, should return a success only on finished or failure if there's no further response after timeout.
## /removeScan - DELETE request to remove a scan build from DB
The application can be packaged using:
```shell script
./mvnw package
```
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.
Only requires the scanId should remove the relevant scan from our DB. Should return a success or failure.
The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.
# Expanded work to do
If you want to build an _über-jar_, execute the following command:
```shell script
./mvnw package -Dquarkus.package.type=uber-jar
```
## Jenkins
The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.
Haven't looked into the correct way for the API to interact with Jenkins needs more investigation.
## Creating a native executable
## Jira tickets still to do:
https://issues.redhat.com/browse/PSSECMGT-1548
https://issues.redhat.com/browse/PSSECMGT-1549
https://issues.redhat.com/browse/PSSECMGT-1550
https://issues.redhat.com/browse/PSSECMGT-1551
https://issues.redhat.com/browse/PSSECMGT-1552
https://issues.redhat.com/browse/PSSECMGT-1553
https://issues.redhat.com/browse/PSSECMGT-1554
You can create a native executable using:
```shell script
./mvnw package -Pnative
```
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
```shell script
./mvnw package -Pnative -Dquarkus.native.container-build=true
```
# Appendix
You can then execute your native executable with: `./target/code-with-quarkus-1.0.0-SNAPSHOT-runner`
Appendix 1
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.
## Related Guides

12
hack/examples/covscan.sh

@ -0,0 +1,12 @@
#!/bin/bash
#Scan a RPM builds for quarkus with Snyk
#Doesn't work - interprets as tar
#covscan mock-build -p snyk-only-unstable --tarball-build-script=: --brew-build quarkus-mandrel-22-22.3.2.1_1-4.el8qks
#Doesn't work requires profile tuning/further mock env setup
#covscan mock-build -p snyk-only-unstable --brew-build quarkus-mandrel-22-22.3.2.1_1-4.el8qks
#Working but using wrong mockenv
covscan mock-build -p snyk-only-unstable --brew-build xterm-366-8.el9

10
hack/examples/example_pssaas_payload.json

@ -0,0 +1,10 @@
{
"product-id": "jochrist-dev-test-rhbq-mandrel",
"is-managed-service": false,
"cpaas-version": "latest",
"component-list":[
{"build-id":"quarkus-mandrel-22-22.3.2.1_1-4.el8qks",
"type":"brew"}
]
}

4
hack/examples/quarkus.sh

@ -0,0 +1,4 @@
#!/bin/bash
curl -X POST -H "PSSC-Secret-Key: pig" -H "PSSC-Secret-Value: FOO" -d '@example_pssaas_payload.json' http://el-pssc-scan-listener-pssaas-service.apps.pssaas.07fi.p1.openshiftapps.com

36
k8s/linux-krb5.conf

@ -0,0 +1,36 @@
includedir /etc/krb5.conf.d/
# depending on your config, you may wish to uncomment the following:
# includedir /var/lib/sss/pubconf/krb5.include.d/
[libdefaults]
default_realm = IPA.REDHAT.COM
dns_lookup_realm = true
dns_lookup_kdc = true
rdns = false
dns_canonicalize_hostname = false
ticket_lifetime = 24h
forwardable = true
udp_preference_limit = 1
default_ccache_name = KEYRING:persistent:%{uid}
max_retries = 1
kdc_timeout = 1500
[realms]
REDHAT.COM = {
default_domain = redhat.com
dns_lookup_kdc = true
master_kdc = kerberos.corp.redhat.com
admin_server = kerberos.corp.redhat.com
}
IPA.REDHAT.COM = {
default_domain = ipa.redhat.com
dns_lookup_kdc = true
# Trust tickets issued by legacy realm on this host
auth_to_local = RULE:[1:$1@$0](.*@REDHAT\.COM)s/@.*//
auth_to_local = DEFAULT
}
#DO NOT ADD A [domain_realms] section
#https://mojo.redhat.com/docs/DOC-1166841

21
k8s/stage/edgeroute.yml

@ -0,0 +1,21 @@
#oc create route edge --service=osh --dry-run=client -o yaml > edgeroute.yml
apiVersion: route.openshift.io/v1
kind: Route
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: osh
app.kubernetes.io/version: 1.0.0-SNAPSHOT
app.openshift.io/runtime: quarkus
env: stage
name: osh
spec:
port:
targetPort: http
tls:
termination: edge
to:
kind: ""
name: osh
weight: null
status: {}

44
k8s/stage/kerberos-config.yaml

@ -0,0 +1,44 @@
#oc create configmap kerberos-config --from-file=linux-krb5.conf --dry-run=client -o yaml > kerberos-config.yaml
apiVersion: v1
data:
linux-krb5.conf: |
includedir /etc/krb5.conf.d/
# depending on your config, you may wish to uncomment the following:
# includedir /var/lib/sss/pubconf/krb5.include.d/
[libdefaults]
default_realm = IPA.REDHAT.COM
dns_lookup_realm = true
dns_lookup_kdc = true
rdns = false
dns_canonicalize_hostname = false
ticket_lifetime = 24h
forwardable = true
udp_preference_limit = 1
default_ccache_name = KEYRING:persistent:%{uid}
max_retries = 1
kdc_timeout = 1500
[realms]
REDHAT.COM = {
default_domain = redhat.com
dns_lookup_kdc = true
master_kdc = kerberos.corp.redhat.com
admin_server = kerberos.corp.redhat.com
}
IPA.REDHAT.COM = {
default_domain = ipa.redhat.com
dns_lookup_kdc = true
# Trust tickets issued by legacy realm on this host
auth_to_local = RULE:[1:$1@$0](.*@REDHAT\.COM)s/@.*//
auth_to_local = DEFAULT
}
#DO NOT ADD A [domain_realms] section
#https://mojo.redhat.com/docs/DOC-1166841
kind: ConfigMap
metadata:
creationTimestamp: null
name: kerberos-config

137
pom.xml

@ -1,17 +1,16 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<repositories>
<repository>
<id>jboss</id>
<name>JBoss repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
<repositories>
<repository>
<id>jboss</id>
<name>JBoss repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
<modelVersion>4.0.0</modelVersion>
<groupId>com.redhat.ncaughey</groupId>
<artifactId>rest-json-quickstart</artifactId>
<groupId>com.redhat.pctOshWrapper</groupId>
<artifactId>osh</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.10.1</compiler-plugin.version>
@ -33,20 +32,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<!-- https://mvnrepository.com/artifact/org.json/json -->
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.1</version>
</dependency> -->
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.1</version>
</dependency> -->
</dependencies>
</dependencyManagement>
<dependencies>
@ -55,6 +40,11 @@
<artifactId>tekton-client</artifactId>
<version>6.7.2</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.kerberos</groupId>
<artifactId>quarkus-kerberos</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-openshift</artifactId>
@ -79,17 +69,32 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
@ -104,39 +109,32 @@
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<!-- Bean Validation API and RI -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.microprofile.rest.client/microprofile-rest-client-api -->
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
<version>3.0.1</version>
</dependency>
<!-- <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.2</version>
</dependency> -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<scope>provided</scope>
</dependency>
<!-- Bean Validation API and RI -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.microprofile.rest.client/microprofile-rest-client-api -->
<dependency>
<groupId>org.eclipse.microprofile.rest.client</groupId>
<artifactId>microprofile-rest-client-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
@ -193,6 +191,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>

1
src/main/docker/Dockerfile.jvm

@ -86,6 +86,7 @@ COPY --chown=185 target/quarkus-app/*.jar /deployments/
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
EXPOSE 8080
USER 185
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"

2
src/main/java/dto/BrewObj.java

@ -6,8 +6,6 @@ import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
// import org.jboss.pnc.api.dto.Request;
import java.io.Serializable;
@ToString

12
src/main/java/dto/BrewObjPayload.java

@ -1,20 +1,12 @@
package dto;
import org.eclipse.microprofile.config.ConfigProvider;
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
// import org.jboss.pnc.api.dto.HeartbeatConfig;
// import org.jboss.pnc.api.dto.Request;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.Struct;
import java.util.*;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.net.URISyntaxException;
public class BrewObjPayload {
public static BrewObj constructScanPayload(JSONObject brewObj) throws URISyntaxException {

6
src/main/java/dto/ConnectDB.java

@ -1,14 +1,10 @@
package dto;
import constants.PSGQL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import static constants.PSGQL.user;
import static constants.PSGQL.password;
import static constants.PSGQL.url;
import static constants.PSGQL.*;
public class ConnectDB{

2
src/main/java/dto/GitObj.java

@ -6,8 +6,6 @@ import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
// import org.jboss.pnc.api.dto.Request;
import java.io.Serializable;
@ToString

12
src/main/java/dto/GitObjPayload.java

@ -1,20 +1,12 @@
package dto;
import org.eclipse.microprofile.config.ConfigProvider;
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
// import org.jboss.pnc.api.dto.HeartbeatConfig;
// import org.jboss.pnc.api.dto.Request;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.Struct;
import java.util.*;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.net.URISyntaxException;
public class GitObjPayload {
public static GitObj constructScanPayload(JSONObject gitObj) throws URISyntaxException {

2
src/main/java/dto/PncObj.java

@ -6,8 +6,6 @@ import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
// import org.jboss.pnc.api.dto.Request;
import java.io.Serializable;
@ToString

12
src/main/java/dto/PncObjPayload.java

@ -1,20 +1,12 @@
package dto;
import org.eclipse.microprofile.config.ConfigProvider;
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
// import org.jboss.pnc.api.dto.HeartbeatConfig;
// import org.jboss.pnc.api.dto.Request;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.Struct;
import java.util.*;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.net.URISyntaxException;
public class PncObjPayload {
public static PncObj constructScanPayload(JSONObject pncObj) throws URISyntaxException {

3
src/main/java/dto/ScanObj.java

@ -6,9 +6,6 @@ import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;
// import org.jboss.pnc.api.dto.Request;
//still need to fix all the scan objects to be significantly less poorly written
//TODO add interface for the scan objects (is probably the cleanest solution)
import java.io.Serializable;
@ToString

12
src/main/java/dto/ScanObjPayload.java

@ -1,20 +1,12 @@
package dto;
import org.eclipse.microprofile.config.ConfigProvider;
// import org.jboss.pnc.api.deliverablesanalyzer.dto.AnalyzePayload;
// import org.jboss.pnc.api.dto.HeartbeatConfig;
// import org.jboss.pnc.api.dto.Request;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.sql.Struct;
import java.util.*;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONObject;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.net.URISyntaxException;
public class ScanObjPayload {
public static ScanObj constructScanPayload(JSONObject scanObj) throws URISyntaxException {

51
src/main/java/rest/CreateGetResource.java

@ -1,55 +1,34 @@
package rest;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
import dto.ScanObj;
import dto.ConnectDB;
import dto.ScanObj;
import io.quarkus.arc.profile.UnlessBuildProfile;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import io.quarkiverse.kerberos.KerberosPrincipal;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import java.sql.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
// import org.hibernate.EntityManager;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.QueryHint;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
// @Path("/api/v1/[osh-scan]")
@Path("/scanGet")
@Authenticated
public class CreateGetResource {
// @Inject
// EntityManager em;
CreateScanService createScanService;
@ -82,4 +61,4 @@ public class CreateGetResource {
}
return Scans;
}
}
}

32
src/main/java/rest/CreateScanRequest.java

@ -1,45 +1,25 @@
package rest;
import dto.*;
import io.quarkus.security.Authenticated;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ScanObj;
import org.json.JSONObject;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.BrewObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import dto.BrewObjPayload;
import dto.GitObj;
import dto.GitObjPayload;
import dto.PncObj;
import dto.PncObjPayload;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@Authenticated
@Path("/scanRequest")
public class CreateScanRequest {
//all of these need cleaning up to be a more sensible soution
//all of these need cleaning up to be a more sensible solution
@RestClient
CreateScanService createScanService;

39
src/main/java/rest/CreateScanResource.java

@ -1,35 +1,29 @@
package rest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ConnectDB;
import dto.ScanObj;
import dto.ScanObjPayload;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.json.JSONObject;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.ws.rs.Produces;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import io.quarkiverse.kerberos.KerberosPrincipal;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
@Authenticated
@Path("/")
public class CreateScanResource {
@ -55,4 +49,11 @@ public class CreateScanResource {
}
return scanObj;
}
@Path("/ping")
@GET
@Produces("text/plain")
public String ping() {
return "pong";
}
}

32
src/main/java/rest/CreateStartScan.java

@ -1,38 +1,20 @@
package rest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ConnectDB;
import dto.ScanObj;
import io.quarkus.security.Authenticated;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@Authenticated
@Path("/startScan")
public class CreateStartScan {

30
src/main/java/rest/RemoveScan.java

@ -1,37 +1,15 @@
package rest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ConnectDB;
import dto.ScanObj;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.DELETE;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
@Path("/deleteScan")

6
src/main/java/rest/Scan.java

@ -1,8 +1,6 @@
package rest;
package rest;
import javax.persistence.Entity;
public class Scan {
public class Scan {
private int scanId;
private String productId;
private String eventId;

84
src/main/java/rest/StoreData.java

@ -1,91 +1,21 @@
package rest;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
import dto.ScanObj;
// import dto.ConnectDB;
// import dto.Scan;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.util.Set;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import java.sql.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
// import org.hibernate.EntityManager;
import jakarta.persistence.EntityManager;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.NamedQuery;
import jakarta.persistence.QueryHint;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import dto.ScanObj;
import javax.inject.Inject;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
import org.json.JSONArray;
import dto.ScanObj;
import dto.ConnectDB;
import dto.ScanObjPayload;
import javax.ws.rs.PathParam;
import static constants.HttpHeaders.AUTHORIZATION_STRING;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
@Path("/storeData")
public class StoreData {

38
src/main/java/rest/UsersResource.java

@ -0,0 +1,38 @@
package rest;
import dto.ConnectDB;
import dto.ScanObj;
import io.quarkus.arc.profile.UnlessBuildProfile;
import io.quarkiverse.kerberos.KerberosPrincipal;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;
import javax.ws.rs.Produces;
@UnlessBuildProfile("dev")
@Path("/testKerberos")
@Authenticated
public class UsersResource {
@Inject
SecurityIdentity identity;
@Inject
KerberosPrincipal kerberosPrincipal;
@GET
@Path("/me")
@Produces("text/plain")
public String me() {
return identity.getPrincipal().getName();
}
}

46
src/main/resources/application.properties

@ -1,7 +1,51 @@
#Example deploy - mvn deploy -Dquarkus.profile=stage -Dquarkus.kubernetes.deploy=true
# quarkus.rest-client."rest.CreateScanService".url=https://localhost:8080/
# quarkus.rest-client."rest.CreateScanService".scope=javax.inject.Singleton
# couchdb.name=scan-results
# couchdb.url=https://localhost:5984
# quarkus.hibernate-orm.database.generation=drop-and-create
# quarkus.hibernate-orm.database.generation=drop-and-create
#temporary fix, we need to enable it with a working devservices setup
%dev.quarkus.kerberos.enabled=false
%dev.quarkus.security.auth.enabled-in-dev-mode=false
#Also tried
#%dev.quarkus.security.enabled=false
#%dev.quarkus.http.auth.proactive=false
#%dev.quarkus.http.auth.basic=false
#%dev.quarkus.http.auth.permission.permit1.paths=/Ping/Ping
#%dev.quarkus.http.auth.permission.permit1.policy=permit
#%dev.quarkus.http.auth.permission.permit1.methods=GET,HEAD
#%quarkus.arc.unremovable-types=io.quarkiverse.kerberos.*,io.quarkiverse.kerberos.KerberosPrincipal
#%dev.quarkus.kerberos.keytab-path= HTTP_osh-pct-security-tooling.apps.ocp-c1.prod.psi.redhat.com@IPA.REDHAT.COM.keytab
#%dev.quarkus.kerberos.service-principal-name= HTTP/osh-pct-security-tooling.apps.ocp-c1.prod.psi.redhat.com@IPA.REDHAT.COM
%stage.quarkus.openshift.name=osh
%stage.quarkus.openshift.labels.env=stage
%stage.quarkus.log.level=DEBUG
#Only in Quarkus > 3.x
%stage.quarkus.openshift.route.tls.termination=edge
#As we cant create a edge terminated route (quarkus <3.x) lets disable route creation for now
%stage.quarkus.openshift.route.expose=false
%stage.quarkus.openshift.route.target-port=https
%stage.quarkus.openshift.route.tls.insecure-edge-termination-policy=redirect
##########################################
# Kerberos Specifics #
##########################################
%stage.quarkus.openshift.secret-volumes.osh-wrapper.secret-name=kerberos-keytab-osh
%stage.quarkus.openshift.mounts.osh-wrapper.path=/kerberos
%stage.quarkus.openshift.mounts.osh-wrapper.read-only=true
%stage.quarkus.kerberos.keytab-path= /kerberos/kerberos-keytab-osh
%stage.quarkus.kerberos.service-principal-name= HTTP/osh-pct-security-tooling.apps.ocp-c1.prod.psi.redhat.com@IPA.REDHAT.COM
%stage.quarkus.openshift.mounts.osh-wrapper-config-vol.path=/etc/krb5.conf
%stage.quarkus.openshift.mounts.osh-wrapper-config-vol.sub-path=linux-krb5.conf
%stage.quarkus.openshift.config-map-volumes.osh-wrapper-config-vol.config-map-name=kerberos-config
%stage.quarkus.openshift.config-map-volumes.osh-wrapper-config-vol.items."linux-krb5.conf".path=linux-krb5.conf
%stage.quarkus.openshift.mounts.osh-wrapper-config-vol.read-only=true

Loading…
Cancel
Save