Merge pull request #2175 from balena-io/cloud-build-orgs

Modify push to pass app slug to builder
This commit is contained in:
bulldozer-balena[bot] 2021-02-04 13:56:31 +00:00 committed by GitHub
commit 6fb58a25fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 40 deletions

View File

@ -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,

View File

@ -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;

View File

@ -66,8 +66,7 @@ const commonResponseLines = {
};
const commonQueryParams = [
['owner', 'gh_user'],
['app', 'testApp'],
['slug', 'gh_user/testApp'],
['dockerfilePath', ''],
['emulated', 'false'],
['nocache', 'false'],