Skip to content

Commit

Permalink
Merge pull request #712 from snyk/feat/add-apprisk-flavor
Browse files Browse the repository at this point in the history
feat: add AppRisk flavor skeleton [HYB-463]
  • Loading branch information
aarlaud authored Mar 3, 2024
2 parents 7664861 + 55e94ca commit 15fe10f
Show file tree
Hide file tree
Showing 10 changed files with 1,019 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ commits = [
# false positive for pgp prefix and suffix blocks
"555fe920c97af38fa78a875fbb858d5588a6ec80",
"a8335efefaa9f483294554c5086702457b735651",
"0501dae214d6dc4d6fd574b57d06eee08042b18e"
]
38 changes: 38 additions & 0 deletions config.default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"BROKER_SERVER_UNIVERSAL_CONFIG_ENABLED": false,
"SUPPORTED_BROKER_TYPES": [
"apprisk",
"artifactory",
"azure-repos",
"bitbucket-server",
Expand All @@ -22,6 +23,37 @@
},
"required": {}
},
"apprisk": {
"validations": [
{
"url": "https://$CHECKMARX/cxrestapi/auth/identity/connect/token",
"body": {
"BROKER_VAR_SUB": ["username", "password"],
"username": "$CHECKMARX_USERNAME",
"password": "$CHECKMARX_PASSWORD",
"grant_type": "password",
"scope": "sast_rest_api",
"client_id": "resource_owner_client",
"client_secret": "014DF517-39D1-4453-B7B3-9930C563627C"
},
"method": "post",
"headers": {
"x-broker-content-type": "application/x-www-form-urlencoded"
}
}
],
"default": {
"CHECKMARX": "$CHECKMARX",
"CHECKMARX_USERNAME": "$CHECKMARX_USERNAME",
"CHECKMARX_PASSWORD": "$CHECKMARX_PASSWORD"
},
"required": {
"CHECKMARX": "checkmarx.customer.com",
"CHECKMARX_USERNAME": "<username>",
"CHECKMARX_PASSWORD": "<password>",
"BROKER_CLIENT_URL": "https://<broker.client.hostname>:<port>"
}
},
"artifactory": {
"validations": [
{
Expand Down Expand Up @@ -280,6 +312,7 @@
}
},
"FILTER_RULES_PATHS": {
"apprisk": "defaultFilters/apprisk.json",
"artifactory": "defaultFilters/artifactory.json",
"azure-repos": "defaultFilters/azure-repos.json",
"bitbucket-server": "defaultFilters/bitbucket-server.json",
Expand Down Expand Up @@ -427,6 +460,11 @@
"name": "Jira",
"type": "jira",
"brokerType": "jira-bearer-auth"
},
"apprisk": {
"name": "Apprisk",
"type": "apprisk",
"brokerType": "apprisk"
}
}
}
36 changes: 36 additions & 0 deletions defaultFilters/apprisk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"public": [
],
"private": [
{
"//": "Ask for Authentication token",
"method": "POST",
"path": "/cxrestapi/auth/identity/connect/token",
"origin": "https://${CHECKMARX}"
},
{
"//": "Get All Project Details",
"method": "GET",
"path": "/projects",
"origin": "https://${CHECKMARX}"
},
{
"//": "Get Remote Source Settings for GIT",
"method": "GET",
"path": "/projects/:id/sourceCode/remoteSettings/git",
"origin": "https://${CHECKMARX}"
},
{
"//": "Get All Scans for Project",
"method": "GET",
"path": "/sast/scans",
"origin": "https://${CHECKMARX}"
},
{
"//": "Get Statistic Results by Scan Id",
"method": "GET",
"path": "/sast/scans/:id/resultsStatistics",
"origin": "https://${CHECKMARX}"
}
]
}
1 change: 1 addition & 0 deletions lib/client/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface ConnectionValidation {
method?: string;
auth: ConnectionHeaderAuth | ConnectionBasicAuth;
body?: any;
headers?: Record<string, string>;
}

export interface ConnectionHeaderAuth {
Expand Down
2 changes: 1 addition & 1 deletion lib/client/utils/connectionValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const validateConnection = async (config: ConnectionConfig) => {
const validation = config.validations[i] ?? {};
const method = validation?.method ?? 'GET';
const { auth, url } = validation;
const headers: Record<string, string> = {};
const headers: Record<string, string> = validation?.headers ?? {};
headers['user-agent'] = `Snyk Broker client ${version}`;
switch (auth?.type) {
case 'basic':
Expand Down
16 changes: 16 additions & 0 deletions lib/common/relay/prepareRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ export const prepareRequestFromFilterResult = async (
logger.error({ error }, 'error while signing github commit');
}
}
if (
payload.headers &&
payload.headers['x-broker-content-type'] ===
'application/x-www-form-urlencoded'
) {
payload.headers['Content-Type'] = 'application/x-www-form-urlencoded';
if (payload.body) {
const jsonBody = JSON.parse(payload.body) as Record<string, any>;
const params = new URLSearchParams();
for (const [key, value] of Object.entries(jsonBody)) {
params.append(key, value.toString());
}
payload.body = params.toString();
}
}

if (options.config && options.config.LOG_ENABLE_BODY === 'true') {
logContext.requestBody = payload.body;
}
Expand Down
Loading

0 comments on commit 15fe10f

Please sign in to comment.