Skip to content

Commit 3004ac9

Browse files
feat(COD-5797): add link back to ui in markdown (#230)
1 parent 117ded2 commit 3004ac9

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repository contains a GitHub Action for using FortiCNAPP's code security of
88

99
### Creating secrets
1010

11-
Before attempting to run this action, you should add three secrets `LW_ACCOUNT_NAME`, `LW_API_KEY` and `LW_API_SECRET` to your GitHub repository (or, better yet, your GitHub organization so they can be shared accross all your repositories). The value for these secrets can be obtained by following the instructions [here](https://docs.lacework.com/console/api-access-keys) to create an API key and then download it.
11+
Before attempting to run this action, you should add three secrets `LW_ACCOUNT_NAME`, `LW_SUBACCOUNT_NAME` (When using a subaccount) `LW_API_KEY` and `LW_API_SECRET` to your GitHub repository (or, better yet, your GitHub organization so they can be shared across all your repositories). The value for these secrets can be obtained by following the instructions [here](https://docs.lacework.com/console/api-access-keys) to create an API key and then download it.
1212

1313
### Running on pull requests
1414

@@ -24,6 +24,7 @@ permissions:
2424

2525
env:
2626
LW_ACCOUNT_NAME: ${{ secrets.LW_ACCOUNT_NAME }}
27+
LW_SUBACCOUNT_NAME: ${{ secrets.LW_SUBACCOUNT_NAME }}
2728
LW_API_KEY: ${{ secrets.LW_API_KEY }}
2829
LW_API_SECRET: ${{ secrets.LW_API_SECRET }}
2930

src/tool.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { existsSync, readFileSync } from 'fs'
44
import { simpleGit, SimpleGitOptions } from 'simple-git'
55
import { getPrApi } from './actions'
66
import { LWJSON } from './lw-json'
7-
import { callLaceworkCli, debug, getOptionalEnvVariable, getRequiredEnvVariable } from './util'
7+
import {
8+
callLaceworkCli,
9+
debug,
10+
generateUILink,
11+
getOptionalEnvVariable,
12+
getRequiredEnvVariable,
13+
} from './util'
814

915
export function splitStringAtFirstSlash(inputString: string | undefined): [string, string] {
1016
if (inputString != null) {
@@ -193,6 +199,10 @@ export async function compareResults(
193199
'--deployment',
194200
'ci',
195201
]
202+
203+
const uiLink = generateUILink()
204+
if (uiLink) args.push(...['--ui-link', uiLink])
205+
196206
if (debug()) args.push('--debug')
197207
await callLaceworkCli(...args)
198208
endGroup()

src/util.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { error, getInput, info, isDebug } from '@actions/core'
2+
import { context } from '@actions/github'
23
import { spawn } from 'child_process'
34
import { TelemetryCollector } from './telemetry'
5+
import { readFileSync } from 'fs'
46

57
export const telemetryCollector = new TelemetryCollector()
68

@@ -83,3 +85,25 @@ export function getOrDefault(name: string, defaultValue: string) {
8385
if (setTo !== undefined && setTo.length > 0) return setTo
8486
return defaultValue
8587
}
88+
89+
export function generateUILink() {
90+
const eventPath = process.env.GITHUB_EVENT_PATH!
91+
const eventData = JSON.parse(readFileSync(eventPath, 'utf8'))
92+
const defaultBranch = eventData.repository?.default_branch
93+
94+
const targetBranch = getRequiredEnvVariable('GITHUB_BASE_REF')
95+
96+
if (targetBranch !== defaultBranch) return ''
97+
98+
let url =
99+
`https://${process.env.LW_ACCOUNT_NAME}.lacework.net` +
100+
`/ui/investigation/codesec/applications/repositories/` +
101+
`${context.repo.owner}%2F${context.repo.repo}` +
102+
`/${defaultBranch}`
103+
104+
if (process.env.LW_SUBACCOUNT_NAME) {
105+
url += '?accountName=' + process.env.LW_SUBACCOUNT_NAME
106+
}
107+
108+
return url
109+
}

0 commit comments

Comments
 (0)