mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-20 06:07:55 +00:00
Modify push to pass app slug to builder
Change-type: patch Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
parent
43b93e7fd4
commit
e6b85c9cf8
@ -20,7 +20,7 @@ import Command from '../command';
|
||||
import * as cf from '../utils/common-flags';
|
||||
import { getBalenaSdk, stripIndent } from '../utils/lazy';
|
||||
import { dockerignoreHelp, registrySecretsHelp } from '../utils/messages';
|
||||
import type { BalenaSDK, Application, Organization } from 'balena-sdk';
|
||||
import type { BalenaSDK } from 'balena-sdk';
|
||||
import { ExpectedError, instanceOf } from '../errors';
|
||||
import { isV13 } from '../utils/version';
|
||||
import { RegistrySecrets } from 'resin-multibuild';
|
||||
@ -353,32 +353,9 @@ export default class PushCmd extends Command {
|
||||
sdk.settings.get('balenaUrl'),
|
||||
]);
|
||||
|
||||
const application = (await getApplication(sdk, appNameOrSlug, {
|
||||
$expand: {
|
||||
organization: {
|
||||
$select: ['handle'],
|
||||
},
|
||||
},
|
||||
const application = await getApplication(sdk, appNameOrSlug, {
|
||||
$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,
|
||||
@ -390,8 +367,7 @@ export default class PushCmd extends Command {
|
||||
convertEol: !options['noconvert-eol'],
|
||||
};
|
||||
const args = {
|
||||
app: application.app_name,
|
||||
owner: application.organization[0].handle,
|
||||
appSlug: application.slug,
|
||||
source: options.source,
|
||||
auth: token,
|
||||
baseUrl,
|
||||
|
@ -45,16 +45,13 @@ export interface BuildOpts {
|
||||
}
|
||||
|
||||
export interface RemoteBuild {
|
||||
app: string;
|
||||
owner: string;
|
||||
appSlug: string;
|
||||
source: string;
|
||||
auth: string;
|
||||
baseUrl: string;
|
||||
nogitignore: boolean;
|
||||
opts: BuildOpts;
|
||||
|
||||
sdk: BalenaSDK;
|
||||
|
||||
// For internal use
|
||||
releaseId?: number;
|
||||
hadError?: boolean;
|
||||
@ -85,14 +82,12 @@ export class RemoteBuildFailedError extends ExpectedError {
|
||||
|
||||
async function getBuilderEndpoint(
|
||||
baseUrl: string,
|
||||
owner: string,
|
||||
app: string,
|
||||
appSlug: string,
|
||||
opts: BuildOpts,
|
||||
): Promise<string> {
|
||||
const querystring = await import('querystring');
|
||||
const args = querystring.stringify({
|
||||
owner,
|
||||
app,
|
||||
slug: appSlug,
|
||||
dockerfilePath: opts.dockerfilePath,
|
||||
emulated: opts.emulated,
|
||||
nocache: opts.nocache,
|
||||
@ -384,8 +379,7 @@ async function getRemoteBuildStream(
|
||||
): Promise<[request.Request, Stream.Stream]> {
|
||||
const builderUrl = await getBuilderEndpoint(
|
||||
build.baseUrl,
|
||||
build.owner,
|
||||
build.app,
|
||||
build.appSlug,
|
||||
build.opts,
|
||||
);
|
||||
let stream: Stream.Stream;
|
||||
|
@ -66,8 +66,7 @@ const commonResponseLines = {
|
||||
};
|
||||
|
||||
const commonQueryParams = [
|
||||
['owner', 'gh_user'],
|
||||
['app', 'testApp'],
|
||||
['slug', 'gh_user/testApp'],
|
||||
['dockerfilePath', ''],
|
||||
['emulated', 'false'],
|
||||
['nocache', 'false'],
|
||||
|
Loading…
Reference in New Issue
Block a user