From a1cf602f6f0f556f46780509be1d61a473c4b469 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Fri, 15 Jan 2021 17:47:39 +0100 Subject: [PATCH] Handle 'push' edge case with application access Change-type: patch Signed-off-by: Scott Lowe --- lib/commands/push.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/commands/push.ts b/lib/commands/push.ts index 7ac5ae67..b4b36bfa 100644 --- a/lib/commands/push.ts +++ b/lib/commands/push.ts @@ -359,11 +359,27 @@ export default class PushCmd extends Command { $select: ['handle'], }, }, - $select: ['app_name'], + $select: ['app_name', 'slug'], })) as Application & { organization: [Organization]; }; + // * Temporary fix * + // When doing `$expand organization` on a public app (when not the owner) + // a partial document is returned without any organization data. + // So e.g. `balena push balena-sound` will break this commands logic. + // The balena cloud builder api will soon change to accept application slugs + // instead of `owner, app`, after which we will not need to do the expand + // + // Users should not be pushing to public apps anyway, so for now catch this situation: + if (!application.organization[0]) { + throw new ExpectedError(stripIndent` + You do not have permissions to push to application ${application.slug}. + If you are trying to deploy a public app, please make sure that you have created + your own application first. + `); + } + const opts = { dockerfilePath, emulated: options.emulated,