Skip to content

Commit

Permalink
Allow transmitter calls to use caFilePath
Browse files Browse the repository at this point in the history
`caFilePath` config option was only used by the agent. With this change,
the certificate file will also be used by the diagnose transmitter to
validate the api key and to send the diagnose results to AppSignal.
  • Loading branch information
luismiramirez committed Dec 17, 2021
1 parent 95dd168 commit e96af09
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

The `caFilePath` config option now works for diagnose script external requests.
4 changes: 3 additions & 1 deletion packages/nodejs/src/diagnose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ export class DiagnoseTool {
" Error: Something went wrong while submitting the report to AppSignal."
)
console.error(` Response code: ${responseData["status"]}`)
console.error(` Response body:\n${responseData["body"]}`)
console.error(
` Response body:\n${JSON.stringify(responseData["body"])}`
)
})
}
}
Expand Down
18 changes: 15 additions & 3 deletions packages/nodejs/src/transmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ export class Transmitter {
"Content-Type": "application/json",
"Content-Length": this.#data.length
},
cert: fs.readFileSync(
path.resolve(__dirname, "../cert/cacert.pem"),
"utf-8"
ca: this.certificateFile()
}
}

private certificateFile(): string {
const configData = this.#config.data
const caFilePathFromConfig = configData["caFilePath"] || ""

try {
fs.accessSync(caFilePathFromConfig, fs.constants.R_OK)
return fs.readFileSync(caFilePathFromConfig, "utf-8").toString()
} catch {
console.warn(
`Provided caFilePath: '${caFilePathFromConfig}' is not readable.`
)
return ""
}
}
}

0 comments on commit e96af09

Please sign in to comment.