(argv: ArgumentsCamelCase<CommandArgs>)
| 91 | .epilog(buildEpilog({ command })) |
| 92 | |
| 93 | const handler = async (argv: ArgumentsCamelCase<CommandArgs>): Promise<void> => { |
| 94 | const command = await apiCommand(argv) |
| 95 | |
| 96 | const askUserForHub = async (): Promise<string> => { |
| 97 | const hubId = await chooseHub(command, undefined, { useConfigDefault: true }) |
| 98 | const hubDevice = await command.client.devices.get(hubId) |
| 99 | const localIP = hubDevice.hub?.hubData.localIP |
| 100 | if (!localIP) { |
| 101 | return fatalError('Could not find hub IP address.') |
| 102 | } |
| 103 | return localIP |
| 104 | } |
| 105 | |
| 106 | const hubIpAddress = argv.hubAddress ?? await askUserForHub() |
| 107 | const [ipv4, port] = parseIpAndPort(hubIpAddress) |
| 108 | const liveLogPort = port ?? defaultLiveLogPort |
| 109 | const authority = `${ipv4}:${liveLogPort}` |
| 110 | const spinner = ora() |
| 111 | const verifier = (cert: PeerCertificate): Promise<void> => checkServerIdentity(command, authority, cert) |
| 112 | const timeout = argv.connectTimeout ?? defaultLiveLogTimeout |
| 113 | |
| 114 | const baseURL = new URL(`https://${authority}`) |
| 115 | |
| 116 | const driversURL = new URL('drivers', baseURL) |
| 117 | const logsURL = new URL('drivers/logs', baseURL) |
| 118 | let hostVerified = false |
| 119 | const logger = log4js.getLogger('cli') |
| 120 | |
| 121 | const getCertificate = (response: AxiosResponse): PeerCertificate => |
| 122 | ((response.request as ClientRequest).socket as TLSSocket).getPeerCertificate() |
| 123 | |
| 124 | const unsafeAgent = new Agent({ |
| 125 | connect: { |
| 126 | rejectUnauthorized: false, |
| 127 | }, |
| 128 | }) |
| 129 | const request = async (url: string, method: Method = 'GET'): Promise<AxiosResponse> => { |
| 130 | // Even though we are using `fetch` from `undici` below, sticking to axios here, at least |
| 131 | // for now, because I have been unable to make `fetch` work here. |
| 132 | const authHeaders = await command.authenticator.authenticate() |
| 133 | const requestConfig = { |
| 134 | url, |
| 135 | method, |
| 136 | httpsAgent: new AxiosAgent({ rejectUnauthorized: false }), |
| 137 | timeout, |
| 138 | // eslint-disable-next-line @typescript-eslint/naming-convention |
| 139 | headers: { 'User-Agent': userAgent, ...authHeaders }, |
| 140 | transitional: { |
| 141 | silentJSONParsing: true, |
| 142 | forcedJSONParsing: true, |
| 143 | // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts |
| 144 | clarifyTimeoutError: true, |
| 145 | }, |
| 146 | } |
| 147 | |
| 148 | try { |
| 149 | const response = await axios.request(requestConfig) |
| 150 | if (!hostVerified) { |
nothing calls this directly
no test coverage detected