Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
feat(cli): use JSON file for connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Oct 27, 2020
1 parent 7270732 commit ef9fa43
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cli/device/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ export const connect = async ({
console.log(chalk.blue('endpoint: '), chalk.yellow(endpoint))
console.log(chalk.blue('deviceUiUrl: '), chalk.yellow(deviceUiUrl))
console.log(chalk.blue('CA cert: '), chalk.yellow(caCert))
console.log(chalk.blue('Private key: '), chalk.yellow(deviceFiles.key))
console.log(chalk.blue('Certificate: '), chalk.yellow(deviceFiles.certWithCA))
console.log(chalk.blue('Certificate: '), chalk.yellow(deviceFiles.json))

const certFiles = [deviceFiles.certWithCA, deviceFiles.key, caCert]
const certFiles = [deviceFiles.json, caCert]

try {
await Promise.all(
Expand Down Expand Up @@ -96,9 +95,13 @@ export const connect = async ({
console.timeLog(note)
}, 5000)

const { privateKey, clientCert } = JSON.parse(
await fs.readFile(deviceFiles.json, 'utf-8'),
)

const connection = new thingShadow({
privateKey: deviceFiles.key,
clientCert: deviceFiles.certWithCA,
privateKey: Buffer.from(privateKey),
clientCert: Buffer.from(clientCert),
caCert,
clientId: deviceId,
host: endpoint,
Expand Down

0 comments on commit ef9fa43

Please sign in to comment.