Allow 'balena push <deviceIpAddress>' when not logged in to balenaCloud.

Change-type: patch
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-03-25 15:16:23 +00:00
parent 0fac8d8d3b
commit 6b21f5aa5a
3 changed files with 25 additions and 20 deletions

View File

@ -138,7 +138,6 @@ export const push: CommandDefinition<
$ balena push 10.0.0.1 --source <source directory>
$ balena push 10.0.0.1 -s <source directory>
`,
permission: 'user',
options: [
{
signature: 'source',
@ -172,7 +171,10 @@ export const push: CommandDefinition<
const Bluebird = await import('bluebird');
const remote = await import('../utils/remote-build');
const deviceDeploy = await import('../utils/device/deploy');
const { exitWithExpectedError } = await import('../utils/patterns');
const {
exitIfNotLoggedIn,
exitWithExpectedError,
} = await import('../utils/patterns');
const { parseRegistrySecrets } = await import('../utils/compose_ts');
const { BuildError } = await import('../utils/device/errors');
@ -194,6 +196,7 @@ export const push: CommandDefinition<
switch (buildTarget) {
case BuildTarget.Cloud:
const app = appOrDevice;
await exitIfNotLoggedIn();
await Bluebird.join(
sdk.auth.getToken(),
sdk.settings.get('balenaUrl'),

View File

@ -75,7 +75,7 @@ actions = require('./actions')
errors = require('./errors')
events = require('./events')
update = require('./utils/update')
{ exitWithExpectedError } = require('./utils/patterns')
{ exitIfNotLoggedIn } = require('./utils/patterns')
# Assign bluebird as the global promise library
# stream-to-promise will produce native promises if not
@ -84,17 +84,8 @@ update = require('./utils/update')
require('any-promise/register/bluebird')
capitano.permission 'user', (done) ->
balena = BalenaSdk.fromSharedOptions()
balena.auth.isLoggedIn().then (isLoggedIn) ->
if not isLoggedIn
exitWithExpectedError('''
You have to log in to continue
Run the following command to go through the login wizard:
$ balena login
''')
.nodeify(done)
exitIfNotLoggedIn()
.then(done, done)
capitano.command
signature: '*'

View File

@ -14,8 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import BalenaSdk = require('balena-sdk');
import Promise = require('bluebird');
import Bluebird = require('bluebird');
import chalk from 'chalk';
import { stripIndent } from 'common-tags';
import _ = require('lodash');
import _form = require('resin-cli-form');
import _visuals = require('resin-cli-visuals');
@ -28,7 +29,7 @@ const getBalenaSdk = _.once(() => BalenaSdk.fromSharedOptions());
const getForm = _.once((): typeof _form => require('resin-cli-form'));
const getVisuals = _.once((): typeof _visuals => require('resin-cli-visuals'));
export function authenticate(options: {}): Promise<void> {
export function authenticate(options: {}): Bluebird<void> {
const balena = getBalenaSdk();
return getForm()
.run(
@ -75,6 +76,16 @@ export function authenticate(options: {}): Promise<void> {
});
}
export async function exitIfNotLoggedIn(): Promise<void> {
const balena = getBalenaSdk();
if (!(await balena.auth.isLoggedIn())) {
exitWithExpectedError(stripIndent`
You have to log in to continue
Run the following command to go through the login wizard:
$ balena login`);
}
}
export function askLoginType() {
return getForm().ask({
message: 'How would you like to login?',
@ -122,7 +133,7 @@ export function confirm(
message: string,
yesMessage?: string,
) {
return Promise.try(function() {
return Bluebird.try(function() {
if (yesOption) {
if (yesMessage) {
console.log(yesMessage);
@ -219,7 +230,7 @@ export function awaitDevice(uuid: string) {
`Waiting for ${deviceName} to come online`,
);
const poll = (): Promise<void> => {
const poll = (): Bluebird<void> => {
return balena.models.device.isOnline(uuid).then(function(isOnline) {
if (isOnline) {
spinner.stop();
@ -230,7 +241,7 @@ export function awaitDevice(uuid: string) {
// not start again if it was already started
spinner.start();
return Promise.delay(3000).then(poll);
return Bluebird.delay(3000).then(poll);
}
});
};
@ -274,7 +285,7 @@ export function inferOrSelectDevice(preferredUuid: string) {
export function selectFromList<T>(
message: string,
choices: Array<T & { name: string }>,
): Promise<T> {
): Bluebird<T> {
return getForm().ask({
message,
type: 'list',