mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-06 11:10:10 +00:00
Switch from new Bluebird to native version
Change-type: patch
This commit is contained in:
parent
ef9c2e9c18
commit
984d1a3fd6
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import { flags } from '@oclif/command';
|
import { flags } from '@oclif/command';
|
||||||
import type * as BalenaSdk from 'balena-sdk';
|
import type * as BalenaSdk from 'balena-sdk';
|
||||||
import Bluebird = require('bluebird');
|
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import Command from '../../command';
|
import Command from '../../command';
|
||||||
|
@ -255,8 +255,6 @@ Examples:
|
|||||||
primary: true,
|
primary: true,
|
||||||
options: preloadOptions,
|
options: preloadOptions,
|
||||||
action(params, options, done) {
|
action(params, options, done) {
|
||||||
let certificates;
|
|
||||||
const Bluebird = require('bluebird');
|
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
const balenaPreload = require('balena-preload');
|
const balenaPreload = require('balena-preload');
|
||||||
const visuals = getVisuals();
|
const visuals = getVisuals();
|
||||||
@ -309,6 +307,7 @@ Examples:
|
|||||||
options.pinDevice = options['pin-device-to-release'] || false;
|
options.pinDevice = options['pin-device-to-release'] || false;
|
||||||
delete options['pin-device-to-release'];
|
delete options['pin-device-to-release'];
|
||||||
|
|
||||||
|
let certificates;
|
||||||
if (Array.isArray(options['add-certificate'])) {
|
if (Array.isArray(options['add-certificate'])) {
|
||||||
certificates = options['add-certificate'];
|
certificates = options['add-certificate'];
|
||||||
} else if (options['add-certificate'] === undefined) {
|
} else if (options['add-certificate'] === undefined) {
|
||||||
@ -358,7 +357,7 @@ Examples:
|
|||||||
preloader.on('progress', progressHandler);
|
preloader.on('progress', progressHandler);
|
||||||
preloader.on('spinner', spinnerHandler);
|
preloader.on('spinner', spinnerHandler);
|
||||||
|
|
||||||
return new Bluebird(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
preloader.on('error', reject);
|
preloader.on('error', reject);
|
||||||
|
|
||||||
return preloader
|
return preloader
|
||||||
|
@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import type { CommandDefinition } from 'capitano';
|
import type { CommandDefinition } from 'capitano';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { createServer, Server, Socket } from 'net';
|
import { createServer, Server, Socket } from 'net';
|
||||||
@ -196,7 +195,7 @@ export const tunnel: CommandDefinition<Args, Options> = {
|
|||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
(server) =>
|
(server) =>
|
||||||
new Bluebird.Promise<Server>((resolve, reject) => {
|
new Promise<Server>((resolve, reject) => {
|
||||||
server.on('error', reject);
|
server.on('error', reject);
|
||||||
server.listen(localPort, localAddress, () => {
|
server.listen(localPort, localAddress, () => {
|
||||||
resolve(server);
|
resolve(server);
|
||||||
|
@ -64,5 +64,7 @@ export const login = async () => {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
const balena = getBalenaSdk();
|
const balena = getBalenaSdk();
|
||||||
return awaitForToken(options).tap(balena.auth.loginWithToken);
|
const token = await awaitForToken(options)
|
||||||
|
await balena.auth.loginWithToken(token);
|
||||||
|
return token
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import type { Socket } from 'net';
|
import type { Socket } from 'net';
|
||||||
@ -79,10 +78,10 @@ export function shutdownServer() {
|
|||||||
export const awaitForToken = (options: {
|
export const awaitForToken = (options: {
|
||||||
path: string;
|
path: string;
|
||||||
port: number;
|
port: number;
|
||||||
}): Bluebird<string> => {
|
}): Promise<string> => {
|
||||||
const { app, server } = createServer({ port: options.port });
|
const { app, server } = createServer({ port: options.port });
|
||||||
|
|
||||||
return new Bluebird<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
app.post(options.path, async (request, response) => {
|
app.post(options.path, async (request, response) => {
|
||||||
server.close(); // stop listening for new connections
|
server.close(); // stop listening for new connections
|
||||||
try {
|
try {
|
||||||
|
@ -40,9 +40,10 @@ const bufferImage = function (docker, imageId, bufferFile) {
|
|||||||
image.get(),
|
image.get(),
|
||||||
imageMetadata.get('Size'),
|
imageMetadata.get('Size'),
|
||||||
(imageStream, imageSize) =>
|
(imageStream, imageSize) =>
|
||||||
streamUtils.buffer(imageStream, bufferFile).tap((bufferedStream) => {
|
streamUtils.buffer(imageStream, bufferFile).then((bufferedStream) => {
|
||||||
// @ts-ignore adding an extra property
|
// @ts-ignore adding an extra property
|
||||||
bufferedStream.length = imageSize;
|
bufferedStream.length = imageSize;
|
||||||
|
return bufferedStream
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -55,7 +56,7 @@ const showPushProgress = function (message) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uploadToPromise = (uploadRequest, logger) =>
|
const uploadToPromise = (uploadRequest, logger) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const handleMessage = function (data) {
|
const handleMessage = function (data) {
|
||||||
let obj;
|
let obj;
|
||||||
data = data.toString();
|
data = data.toString();
|
||||||
@ -88,7 +89,7 @@ const uploadToPromise = (uploadRequest, logger) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Bluebird<{ buildId: number }>}
|
* @returns {Promise<{ buildId: number }>}
|
||||||
*/
|
*/
|
||||||
const uploadImage = function (
|
const uploadImage = function (
|
||||||
imageStream,
|
imageStream,
|
||||||
|
@ -194,11 +194,11 @@ export class DeviceAPI {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getLogStream(): Bluebird<Stream.Readable> {
|
public getLogStream(): Promise<Stream.Readable> {
|
||||||
const url = this.getUrlForAction('logs');
|
const url = this.getUrlForAction('logs');
|
||||||
|
|
||||||
// Don't use the promisified version here as we want to stream the output
|
// Don't use the promisified version here as we want to stream the output
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = request.get(url);
|
const req = request.get(url);
|
||||||
|
|
||||||
req.on('error', reject).on('response', async (res) => {
|
req.on('error', reject).on('response', async (res) => {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import ColorHash = require('color-hash');
|
import ColorHash = require('color-hash');
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
@ -38,8 +37,8 @@ export function displayDeviceLogs(
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
system: boolean,
|
system: boolean,
|
||||||
filterServices?: string[],
|
filterServices?: string[],
|
||||||
): Bluebird<void> {
|
): Promise<void> {
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logs.on('data', (log) => {
|
logs.on('data', (log) => {
|
||||||
displayLogLine(log, logger, system, filterServices);
|
displayLogLine(log, logger, system, filterServices);
|
||||||
});
|
});
|
||||||
|
@ -44,7 +44,7 @@ export function copyQemu(context: string, arch: string) {
|
|||||||
.then(() => getQemuPath(arch))
|
.then(() => getQemuPath(arch))
|
||||||
.then(
|
.then(
|
||||||
(qemu) =>
|
(qemu) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const read = fs.createReadStream(qemu);
|
const read = fs.createReadStream(qemu);
|
||||||
const write = fs.createWriteStream(binPath);
|
const write = fs.createWriteStream(binPath);
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export function installQemu(arch: string) {
|
|||||||
|
|
||||||
return getQemuPath(arch).then(
|
return getQemuPath(arch).then(
|
||||||
(qemuPath) =>
|
(qemuPath) =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const installStream = fs.createWriteStream(qemuPath);
|
const installStream = fs.createWriteStream(qemuPath);
|
||||||
|
|
||||||
const qemuArch = balenaArchToQemuArch(arch);
|
const qemuArch = balenaArchToQemuArch(arch);
|
||||||
|
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
import type { BalenaSDK } from 'balena-sdk';
|
import type { BalenaSDK } from 'balena-sdk';
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import * as JSONStream from 'JSONStream';
|
import * as JSONStream from 'JSONStream';
|
||||||
import * as readline from 'readline';
|
import * as readline from 'readline';
|
||||||
import * as request from 'request';
|
import * as request from 'request';
|
||||||
@ -124,7 +123,7 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!build.opts.headless) {
|
if (!build.opts.headless) {
|
||||||
return new Bluebird((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Setup interrupt handlers so we can cancel the build if the user presses
|
// Setup interrupt handlers so we can cancel the build if the user presses
|
||||||
// ctrl+c
|
// ctrl+c
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import * as Bluebird from 'bluebird';
|
|
||||||
import { spawn, StdioOptions } from 'child_process';
|
import { spawn, StdioOptions } from 'child_process';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import { TypedError } from 'typed-error';
|
import { TypedError } from 'typed-error';
|
||||||
@ -71,7 +70,7 @@ export async function exec(
|
|||||||
'inherit',
|
'inherit',
|
||||||
];
|
];
|
||||||
|
|
||||||
const exitCode = await new Bluebird<number>((resolve, reject) => {
|
const exitCode = await new Promise<number>((resolve, reject) => {
|
||||||
const ps = spawn(program, args, { stdio })
|
const ps = spawn(program, args, { stdio })
|
||||||
.on('error', reject)
|
.on('error', reject)
|
||||||
.on('close', resolve);
|
.on('close', resolve);
|
||||||
|
@ -14,20 +14,19 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import Bluebird = require('bluebird');
|
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
|
|
||||||
export function buffer(
|
export function buffer(
|
||||||
stream: NodeJS.ReadableStream,
|
stream: NodeJS.ReadableStream,
|
||||||
bufferFile: string,
|
bufferFile: string,
|
||||||
): Bluebird<NodeJS.ReadableStream> {
|
): Promise<NodeJS.ReadableStream> {
|
||||||
const fileWriteStream = fs.createWriteStream(bufferFile);
|
const fileWriteStream = fs.createWriteStream(bufferFile);
|
||||||
|
|
||||||
return new Bluebird(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
stream.on('error', reject).on('end', resolve).pipe(fileWriteStream);
|
stream.on('error', reject).on('end', resolve).pipe(fileWriteStream);
|
||||||
}).then(
|
}).then(
|
||||||
() =>
|
() =>
|
||||||
new Bluebird(function (resolve, reject) {
|
new Promise(function (resolve, reject) {
|
||||||
const fstream = fs.createReadStream(bufferFile);
|
const fstream = fs.createReadStream(bufferFile);
|
||||||
|
|
||||||
fstream.on('open', () => resolve(fstream)).on('error', reject);
|
fstream.on('open', () => resolve(fstream)).on('error', reject);
|
||||||
|
@ -52,7 +52,7 @@ export const tunnelConnectionToDevice = (
|
|||||||
password: token,
|
password: token,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (client: Socket): Bluebird<void> =>
|
return (client: Socket): Promise<void> =>
|
||||||
openPortThroughProxy(vpnUrl, 3128, auth, uuid, port)
|
openPortThroughProxy(vpnUrl, 3128, auth, uuid, port)
|
||||||
.then((remote) => {
|
.then((remote) => {
|
||||||
client.pipe(remote);
|
client.pipe(remote);
|
||||||
@ -72,8 +72,9 @@ export const tunnelConnectionToDevice = (
|
|||||||
remote.end();
|
remote.end();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.tapCatch(() => {
|
.catch((e) => {
|
||||||
client.end();
|
client.end();
|
||||||
|
throw e
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -95,7 +96,7 @@ const openPortThroughProxy = (
|
|||||||
httpHeaders.push(`Proxy-Authorization: Basic ${credentials}`);
|
httpHeaders.push(`Proxy-Authorization: Basic ${credentials}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Bluebird.Promise<Socket>((resolve, reject) => {
|
return new Promise<Socket>((resolve, reject) => {
|
||||||
const proxyTunnel = new Socket();
|
const proxyTunnel = new Socket();
|
||||||
proxyTunnel.on('error', reject);
|
proxyTunnel.on('error', reject);
|
||||||
proxyTunnel.connect(proxyPort, proxyServer, () => {
|
proxyTunnel.connect(proxyPort, proxyServer, () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user