Skip to content

Commit

Permalink
feat: Add support for SafeDep cloud integration
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisek committed Oct 11, 2024
1 parent 8a0a3ce commit b3e6b52
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/vet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
- name: Run vet
id: vet
uses: ./
with:
cloud: true
cloud-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }}
cloud-tenant: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ inputs:
cloud-key:
description: API key to use for synchronizing report with SafeDep cloud
required: false
cloud-tenant:
description: Tenant ID to use for synchronizing report with SafeDep cloud
required: false
version:
description:
vet version to use for the scan. Defaults to using latest release
Expand Down
28 changes: 27 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export async function run(): Promise<void> {
trimWhitespace: true
})

const cloudTenant: string = core.getInput('cloud-tenant', {
required: false,
trimWhitespace: true
})

const version: string = core.getInput('version', {
required: false,
trimWhitespace: true
Expand Down Expand Up @@ -53,6 +58,7 @@ export async function run(): Promise<void> {

const vet = new Vet({
apiKey: cloudKey,
tenant: cloudTenant,
policy,
version,
cloudMode,
Expand Down
35 changes: 34 additions & 1 deletion src/vet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const tc = require('@actions/tool-cache')

interface VetConfig {
apiKey?: string
tenant?: string
policy?: string
cloudMode?: boolean
version?: string
Expand Down Expand Up @@ -102,6 +103,10 @@ export class Vet {
policyFilePath
]

if (this.config.cloudMode) {
this.applyCloudConfig(vetFinalScanArgs)
}

if (
this.config.trustedRegistries &&
this.config.trustedRegistries.length > 0
Expand Down Expand Up @@ -252,6 +257,10 @@ export class Vet {
vetFinalScanArgs.push('--exceptions-extra', this.config.exceptionFile)
}

if (this.config.cloudMode) {
this.applyCloudConfig(vetFinalScanArgs)
}

if (
this.config.trustedRegistries &&
this.config.trustedRegistries.length > 0
Expand Down Expand Up @@ -408,7 +417,7 @@ export class Vet {
private async getLatestRelease(): Promise<string> {
let versionToUse = this.config.version ?? ''
if (versionToUse.length === 0) {
versionToUse = 'v1.6.1'
versionToUse = 'v1.8.0'
}

return `https://github.com/safedep/vet/releases/download/${versionToUse}/vet_Linux_x86_64.tar.gz`
Expand Down Expand Up @@ -521,4 +530,28 @@ export class Vet {

return getDefaultVetPolicyFilePath()
}

private applyCloudConfig(args: string[]): void {
if (!this.config.apiKey) {
throw new Error('API key is required for cloud mode')
}

if (!this.config.tenant) {
throw new Error('Tenant is required for cloud mode')
}

core.info('Using cloud mode')
process.env.VET_API_KEY = this.config.apiKey

core.info(`Using tenant: ${this.config.tenant}`)
process.env.VET_CONTROL_TOWER_TENANT_ID = this.config.tenant

args.push('--report-sync')
args.push('--report-sync-project', process.env.GITHUB_REPOSITORY as string)

args.push(
'--report-sync-project-version',
process.env.GITHUB_REF_NAME as string
)
}
}

0 comments on commit b3e6b52

Please sign in to comment.