Skip to content

Commit

Permalink
[Enhancement] Handle self signed cert, add provision to skip TLS vali…
Browse files Browse the repository at this point in the history
…dation (#1)

*Changes are:
**Handle cert properly.
**Add provison to skip TLS validation.
**Handle self signed cert.

Co-authored-by: Aravind N <[email protected]>
  • Loading branch information
aravind-opsverse and aravindnswamy authored Feb 8, 2024
1 parent 864df8a commit 3fa8cb6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
12 changes: 11 additions & 1 deletion dist/index.js

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

12 changes: 9 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
},
"dependencies": {
"@actions/core": "^1.10.1",
"axios": "^1.6.7"
"axios": "^1.6.7",
"https": "^1.0.0"
},
"devDependencies": {
"@types/jest": "^29.5.11",
Expand Down
23 changes: 18 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as core from '@actions/core'
const axios = require('axios')
import { OpaResponse } from './opa-response'
import { Agent } from 'https'

export async function run(): Promise<void> {
try {
const opaServerUrl = core.getInput('opaServerUrl')
const opaServerAuthToken = core.getInput('opaServerAuthToken')
const opaServerInput = core.getInput('opaServerInput')
const opaServerPackageName = core.getInput('opaServerPackageName')
const skipTlsValidation = core.getInput('skipTlsValidation')

const headers = {
Authorization: `Bearer ${opaServerAuthToken}`,
Expand All @@ -19,11 +21,22 @@ export async function run(): Promise<void> {
core.info(`📥 Input to server: ${opaServerInput}`)
core.info(`-----------------------------------------`)

const response = await axios.post(
`${opaServerUrl}/v1/data/${opaServerPackageName}`,
{ opaServerInput },
{ headers }
)
const httpsAgent = new Agent({
rejectUnauthorized: skipTlsValidation ? false : true
})
skipTlsValidation
? core.warning(
'❗🔓 Skip TLS Validation enabled. Please be careful while using this.'
)
: core.info('💚🔒 Skip TLS Validation disabled.')

const response = await axios
.create({ httpsAgent })
.post(
`${opaServerUrl}/v1/data/${opaServerPackageName}`,
{ opaServerInput },
{ headers }
)
if (response.status === 200) {
const opaResponseObj = response.data as OpaResponse
// core.info(`Response from OPA Server: ${JSON.stringify(opaResponseObj)}`)
Expand Down

0 comments on commit 3fa8cb6

Please sign in to comment.