Skip to content

Commit 507681f

Browse files
committed
updat general solution for backend
1 parent 0d9d642 commit 507681f

File tree

14 files changed

+265
-143
lines changed

14 files changed

+265
-143
lines changed

src/main/java/io/github/guacsec/trustifyda/integration/report/ReportTemplate.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ public class ReportTemplate {
5858
@ConfigProperty(name = "telemetry.disabled", defaultValue = "false")
5959
Boolean disabled;
6060

61+
// Branding configuration
62+
@ConfigProperty(name = "exhort.branding.display.name", defaultValue = "Trustify")
63+
String brandingDisplayName;
64+
65+
@ConfigProperty(name = "exhort.branding.remediation.title", defaultValue = "Remediations")
66+
String brandingRemediationTitle;
67+
68+
@ConfigProperty(name = "exhort.branding.icon", defaultValue = "trustify")
69+
String brandingIcon;
70+
71+
@ConfigProperty(name = "exhort.branding.explore.url", defaultValue = "https://guac.sh/trustify/")
72+
String brandingExploreUrl;
73+
74+
@ConfigProperty(
75+
name = "exhort.branding.explore.title",
76+
defaultValue = "Learn more about Trustify")
77+
String brandingExploreTitle;
78+
79+
@ConfigProperty(
80+
name = "exhort.branding.explore.description",
81+
defaultValue =
82+
"The Trustify project is a collection of software components that enables you to store"
83+
+ " and retrieve Software Bill of Materials (SBOMs), and advisory documents.")
84+
String brandingExploreDescription;
85+
6186
@Inject ObjectMapper mapper;
6287

6388
public Map<String, Object> setVariables(
@@ -74,6 +99,7 @@ public Map<String, Object> setVariables(
7499
params.put("cveIssueTemplate", cveIssuePathRegex);
75100
params.put("imageMapping", getImageMapping());
76101
params.put("rhdaSource", rhdaSource);
102+
params.put("brandingConfig", getBrandingConfig());
77103
if (!disabled && writeKey.isPresent()) {
78104
params.put("userId", userId);
79105
params.put("anonymousId", anonymousId);
@@ -108,6 +134,17 @@ private String getImageMapping() throws JsonProcessingException {
108134
return objectWriter.writeValueAsString(urlMapping);
109135
}
110136

137+
private Map<String, String> getBrandingConfig() {
138+
Map<String, String> branding = new HashMap<>();
139+
branding.put("displayName", brandingDisplayName);
140+
branding.put("remediationTitle", brandingRemediationTitle);
141+
branding.put("icon", brandingIcon);
142+
branding.put("exploreUrl", brandingExploreUrl);
143+
branding.put("exploreTitle", brandingExploreTitle);
144+
branding.put("exploreDescription", brandingExploreDescription);
145+
return branding;
146+
}
147+
111148
@RegisterForReflection
112149
public static record IssueLinkFormatter(String issuePathRegex) {
113150

src/main/resources/application.properties

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,31 @@ quarkus.hibernate-orm.sql-load-script=no-file
6262
%prod.quarkus.datasource.jdbc.url=jdbc:postgresql://${db.postgres.host}:${db.postgres.port}/${db.postgres.database}?sslmode=${db.postgres.sslmode}
6363
%prod.quarkus.datasource.username=${db.postgres.user}
6464
%prod.quarkus.datasource.password=${db.postgres.password}
65+
66+
# ====================================================================
67+
# Branding Configuration Profiles
68+
# ====================================================================
69+
70+
# Default branding configuration (Community/Trustify)
71+
exhort.branding.display.name=Trustify
72+
exhort.branding.remediation.title=Remediations
73+
exhort.branding.icon=trustify
74+
exhort.branding.explore.url=https://guac.sh/trustify/
75+
exhort.branding.explore.title=Learn more about Trustify
76+
exhort.branding.explore.description=The Trustify project is a collection of software components that enables you to store and retrieve Software Bill of Materials (SBOMs), and advisory documents.
77+
78+
# Red Hat Enterprise branding profile
79+
%redhat.exhort.branding.display.name=Red Hat
80+
%redhat.exhort.branding.remediation.title=Red Hat Remediations
81+
%redhat.exhort.branding.icon=redhat
82+
%redhat.exhort.branding.explore.url=https://developers.redhat.com/products/trusted-profile-analyzer/overview
83+
%redhat.exhort.branding.explore.title=Join to explore Red Hat TPA
84+
%redhat.exhort.branding.explore.description=Check out our new Trustify to get visibility and insight into your software risk profile, for instance by exploring vulnerabilites or analyzing SBOMs.
85+
86+
# Community/Trustify branding profile (explicit)
87+
%community.exhort.branding.display.name=Trustify
88+
%community.exhort.branding.remediation.title=Remediations
89+
%community.exhort.branding.icon=trustify
90+
%community.exhort.branding.explore.url=https://guac.sh/trustify/
91+
%community.exhort.branding.explore.title=Learn more about Trustify
92+
%community.exhort.branding.explore.description=The Trustify project is a collection of software components that enables you to store and retrieve Software Bill of Materials (SBOMs), and advisory documents.

src/main/resources/freemarker/templates/generated/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/freemarker/templates/generated/vendor.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/resources/freemarker/templates/generated/vendor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/.env

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
GENERATE_SOURCEMAP=false
2-
3-
# Default branding mode when no specific profile is used
4-
# Options: community, redhat
5-
REACT_APP_BRANDING_MODE=community
1+
GENERATE_SOURCEMAP=false

ui/.env.community

Lines changed: 0 additions & 8 deletions
This file was deleted.

ui/.env.redhat

Lines changed: 0 additions & 8 deletions
This file was deleted.

ui/BRANDING.md

Lines changed: 152 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,177 @@
11
# Branding Configuration
22

3-
This project supports two branding modes: **Red Hat** (enterprise) and **Community** (Trustify).
3+
This project supports flexible branding through backend environment variables. The system defaults to **Trustify** branding and allows you to override specific elements as needed.
44

55
## Quick Start
66

7-
### Prerequisites
8-
Install the `env-cmd` package to enable environment-specific builds:
7+
### Using Predefined Profiles
8+
9+
**Community/Trustify branding (default):**
910
```bash
10-
npm install --save-dev env-cmd
11+
# Default profile - no additional flags needed
12+
./mvnw quarkus:dev
13+
14+
# Or explicitly use community profile
15+
./mvnw quarkus:dev -Dquarkus.profile=community
1116
```
1217

13-
### Development
18+
**Red Hat Enterprise branding:**
1419
```bash
15-
# Start development server with Community branding (default)
16-
npm run start:community
20+
./mvnw quarkus:dev -Dquarkus.profile=redhat
21+
```
1722

18-
# Start development server with Red Hat branding
19-
npm run start:redhat
23+
### Using Environment Variables (Alternative)
24+
```bash
25+
# Start development server (branding controlled by backend environment variables)
26+
npm start
2027
```
2128

2229
### Production Build
2330
```bash
24-
# Build Community version
25-
npm run build:community
31+
# Build for production (branding controlled by backend environment variables)
32+
npm run build
33+
```
34+
35+
## How It Works
36+
37+
1. **Backend Configuration**: Java backend reads `EXHORT_BRANDING_XXX` environment variables
38+
2. **Runtime Injection**: Branding configuration is passed to the React app through `appData`
39+
3. **Component Usage**: React components read branding configuration from the app context
40+
4. **Trustify-First**: All defaults are set to Trustify values, specific brands override as needed
41+
42+
## Available Environment Variables
43+
44+
Configure branding by setting these environment variables for the Java backend:
45+
46+
```bash
47+
# Brand identity
48+
EXHORT_BRANDING_DISPLAY_NAME=Your Brand Name # Used for conditional logic
49+
EXHORT_BRANDING_REMEDIATION_TITLE=Your Remediation Title # Title for remediation section
50+
EXHORT_BRANDING_ICON=icon_name # Icon identifier ('redhat' or 'trustify')
2651

27-
# Build Red Hat version
28-
npm run build:redhat
52+
# Explore section
53+
EXHORT_BRANDING_EXPLORE_URL=https://your-url.com # URL for "Take me there" button
54+
EXHORT_BRANDING_EXPLORE_TITLE=Your Explore Title # Title for explore section
55+
EXHORT_BRANDING_EXPLORE_DESCRIPTION=Your description text # Description text
2956
```
3057

31-
## Configuration Files
58+
## Branding Logic
3259

33-
### `.env.community` - Community/Trustify Version
34-
- Uses Trustify branding
35-
- Points to https://guac.sh/trustify/
36-
- Shows "Trustify Overview of security issues"
37-
- Uses Trustify icon for remediations
60+
The system uses `displayName` for all branding decisions:
3861

39-
### `.env.redhat` - Red Hat Enterprise Version
40-
- Uses Red Hat branding
41-
- Points to Red Hat developer portal
42-
- Shows "Red Hat Overview of security Issues"
43-
- Uses Red Hat icon for remediations
44-
- Includes "from Red Hat" in remediation text
62+
- **Red Hat branding**: Triggered when `displayName === 'Red Hat'`
63+
- **Community branding**: Default for any other `displayName` value (including fallback to 'Trustify')
4564

46-
## How It Works
65+
## Examples
66+
67+
### Method 1: Using Predefined Profiles (Recommended)
68+
69+
**Red Hat Enterprise branding:**
70+
```bash
71+
./mvnw quarkus:dev -Dquarkus.profile=redhat
72+
```
73+
74+
**Community/Trustify branding:**
75+
```bash
76+
# Default behavior (no profile needed)
77+
./mvnw quarkus:dev
78+
79+
# Or explicitly
80+
./mvnw quarkus:dev -Dquarkus.profile=community
81+
```
82+
83+
**Production builds with profiles:**
84+
```bash
85+
# Red Hat production build
86+
./mvnw clean package -Dquarkus.profile=redhat
4787

48-
1. **Environment Variables**: Different `.env` files define branding configuration
49-
2. **Branding Config**: `src/config/branding.ts` reads environment variables and provides typed configuration
50-
3. **Conditional Rendering**: Components use `getBrandingConfig()` to conditionally render content based on branding mode
88+
# Community production build
89+
./mvnw clean package -Dquarkus.profile=community
90+
```
91+
92+
### Method 2: Using Environment Variables
93+
94+
**Red Hat Enterprise Configuration:**
95+
```bash
96+
export EXHORT_BRANDING_DISPLAY_NAME="Red Hat"
97+
export EXHORT_BRANDING_REMEDIATION_TITLE="Red Hat Remediations"
98+
export EXHORT_BRANDING_ICON="redhat"
99+
export EXHORT_BRANDING_EXPLORE_URL="https://developers.redhat.com/products/trusted-profile-analyzer/overview"
100+
export EXHORT_BRANDING_EXPLORE_TITLE="Join to explore Red Hat TPA"
101+
export EXHORT_BRANDING_EXPLORE_DESCRIPTION="Check out our new Trustify to get visibility and insight into your software risk profile, for instance by exploring vulnerabilites or analyzing SBOMs."
102+
103+
./mvnw quarkus:dev
104+
```
51105

52-
## Customizing Branding
106+
**Community/Trustify Configuration:**
107+
```bash
108+
export EXHORT_BRANDING_DISPLAY_NAME="Trustify"
109+
export EXHORT_BRANDING_REMEDIATION_TITLE="Remediations"
110+
export EXHORT_BRANDING_ICON="trustify"
111+
export EXHORT_BRANDING_EXPLORE_URL="https://guac.sh/trustify/"
112+
export EXHORT_BRANDING_EXPLORE_TITLE="Learn more about Trustify"
113+
export EXHORT_BRANDING_EXPLORE_DESCRIPTION="The Trustify project is a collection of software components that enables you to store and retrieve Software Bill of Materials (SBOMs), and advisory documents."
53114

54-
To modify branding, edit the respective `.env` file:
115+
./mvnw quarkus:dev
116+
```
55117

118+
### Custom Branding
56119
```bash
57-
REACT_APP_BRANDING_MODE=community|redhat
58-
REACT_APP_BRAND_NAME=Your Brand Name
59-
REACT_APP_BRAND_TITLE=Your Overview Title
60-
REACT_APP_REMEDIATION_TITLE=Your Remediation Title
61-
REACT_APP_BRAND_ICON=icon_name
62-
REACT_APP_BRAND_URL=https://your-url.com
63-
REACT_APP_EXPLORE_TITLE=Your Explore Title
64-
REACT_APP_EXPLORE_DESCRIPTION=Your description text
65-
```
120+
export EXHORT_BRANDING_DISPLAY_NAME="My Company"
121+
export EXHORT_BRANDING_REMEDIATION_TITLE="My Company Remediations"
122+
export EXHORT_BRANDING_ICON="trustify" # Use trustify icon as fallback
123+
export EXHORT_BRANDING_EXPLORE_URL="https://mycompany.com"
124+
export EXHORT_BRANDING_EXPLORE_TITLE="Learn about My Company"
125+
export EXHORT_BRANDING_EXPLORE_DESCRIPTION="Custom description for our security platform."
126+
```
127+
128+
## Backend Integration
129+
130+
The branding configuration is handled in `ReportTemplate.java`:
131+
132+
```java
133+
@ConfigProperty(name = "exhort.branding.display.name", defaultValue = "Trustify")
134+
String brandingDisplayName;
135+
136+
@ConfigProperty(name = "exhort.branding.remediation.title", defaultValue = "Remediations")
137+
String brandingRemediationTitle;
138+
139+
// ... additional configuration properties
140+
141+
private Map<String, String> getBrandingConfig() {
142+
Map<String, String> branding = new HashMap<>();
143+
branding.put("displayName", brandingDisplayName);
144+
branding.put("remediationTitle", brandingRemediationTitle);
145+
branding.put("icon", brandingIcon);
146+
branding.put("exploreUrl", brandingExploreUrl);
147+
branding.put("exploreTitle", brandingExploreTitle);
148+
branding.put("exploreDescription", brandingExploreDescription);
149+
return branding;
150+
}
151+
```
152+
153+
The configuration is then passed to the frontend via the `appData` object in the Freemarker template.
154+
155+
## Profile Configuration
156+
157+
The branding profiles are defined in `src/main/resources/application.properties`:
158+
159+
```properties
160+
# Default branding configuration (Community/Trustify)
161+
exhort.branding.display.name=Trustify
162+
exhort.branding.remediation.title=Remediations
163+
exhort.branding.icon=trustify
164+
exhort.branding.explore.url=https://guac.sh/trustify/
165+
exhort.branding.explore.title=Learn more about Trustify
166+
exhort.branding.explore.description=The Trustify project is a collection of software components that enables you to store and retrieve Software Bill of Materials (SBOMs), and advisory documents.
167+
168+
# Red Hat Enterprise branding profile
169+
%redhat.exhort.branding.display.name=Red Hat
170+
%redhat.exhort.branding.remediation.title=Red Hat Remediations
171+
%redhat.exhort.branding.icon=redhat
172+
%redhat.exhort.branding.explore.url=https://developers.redhat.com/products/trusted-profile-analyzer/overview
173+
%redhat.exhort.branding.explore.title=Join to explore Red Hat TPA
174+
%redhat.exhort.branding.explore.description=Check out our new Trustify to get visibility and insight into your software risk profile, for instance by exploring vulnerabilites or analyzing SBOMs.
175+
```
176+
177+
Environment variables will override profile settings if both are provided.

ui/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
},
2727
"scripts": {
2828
"start": "craco start",
29-
"start:community": "env-cmd -f .env.community craco start",
30-
"start:redhat": "env-cmd -f .env.redhat craco start",
3129
"build": "craco build && yarn copy:js:main && yarn copy:js:vendor && yarn copy:css:main && yarn copy:css:vendor",
32-
"build:community": "env-cmd -f .env.community craco build && yarn copy:js:main && yarn copy:js:vendor && yarn copy:css:main && yarn copy:css:vendor",
33-
"build:redhat": "env-cmd -f .env.redhat craco build && yarn copy:js:main && yarn copy:js:vendor && yarn copy:css:main && yarn copy:css:vendor",
3430
"test": "react-scripts test",
3531
"eject": "react-scripts eject",
3632
"copy:js:main": "cp build/static/js/main.js ../src/main/resources/freemarker/templates/generated/main.js",
@@ -64,7 +60,6 @@
6460
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
6561
"@babel/plugin-transform-destructuring": "^7.25.9",
6662
"@craco/craco": "^7.1.0",
67-
"env-cmd": "^10.1.0",
6863
"prettier": "^3.0.1"
6964
}
7065
}

0 commit comments

Comments
 (0)