mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-18 21:27:51 +00:00
Remove no longer needed references and tests for mixpanel
Change-type: patch
This commit is contained in:
parent
3ac89b236a
commit
09e653692b
@ -1,215 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as _ from 'lodash';
|
||||
import * as semver from 'semver';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { throttling } from '@octokit/plugin-throttling';
|
||||
|
||||
const { GITHUB_TOKEN } = process.env;
|
||||
|
||||
/** Return a cached Octokit instance, creating a new one as needed. */
|
||||
const getOctokit = _.once(function () {
|
||||
const OctokitConstructor = Octokit.plugin(throttling);
|
||||
return new OctokitConstructor({
|
||||
auth: GITHUB_TOKEN,
|
||||
throttle: {
|
||||
onRateLimit: (retryAfter: number, options: any) => {
|
||||
console.warn(
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`,
|
||||
);
|
||||
// retries 3 times
|
||||
if (options.request.retryCount < 3) {
|
||||
console.log(`Retrying after ${retryAfter} seconds!`);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
onAbuseLimit: (_retryAfter: number, options: any) => {
|
||||
// does not retry, only logs a warning
|
||||
console.warn(
|
||||
`Abuse detected for request ${options.method} ${options.url}`,
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Extract pagination information (current page, total pages, ordinal number)
|
||||
* from the 'link' response header (example below), using the parse-link-header
|
||||
* npm package:
|
||||
* "link": "<https://api.github.com/repositories/187370853/releases?per_page=2&page=2>; rel=\"next\",
|
||||
* <https://api.github.com/repositories/187370853/releases?per_page=2&page=3>; rel=\"last\""
|
||||
*
|
||||
* @param response Octokit response object (including response.headers.link)
|
||||
* @param perPageDefault Default per_page pagination value if missing in URL
|
||||
* @return Object where 'page' is the current page number (1-based),
|
||||
* 'pages' is the total number of pages, and 'ordinal' is the ordinal number
|
||||
* (3rd, 4th, 5th...) of the first item in the current page.
|
||||
*/
|
||||
async function getPageNumbers(
|
||||
response: any,
|
||||
perPageDefault: number,
|
||||
): Promise<{ page: number; pages: number; ordinal: number }> {
|
||||
const res = { page: 1, pages: 1, ordinal: 1 };
|
||||
if (!response.headers.link) {
|
||||
return res;
|
||||
}
|
||||
const parse = await import('parse-link-header');
|
||||
|
||||
const parsed = parse(response.headers.link);
|
||||
if (parsed == null) {
|
||||
throw new Error(`Failed to parse link header: '${response.headers.link}'`);
|
||||
}
|
||||
let perPage = perPageDefault;
|
||||
if (parsed.next) {
|
||||
if (parsed.next.per_page) {
|
||||
perPage = parseInt(parsed.next.per_page, 10);
|
||||
}
|
||||
res.page = parseInt(parsed.next.page!, 10) - 1;
|
||||
res.pages = parseInt(parsed.last!.page!, 10);
|
||||
} else {
|
||||
if (parsed.prev!.per_page) {
|
||||
perPage = parseInt(parsed.prev!.per_page, 10);
|
||||
}
|
||||
res.page = res.pages = parseInt(parsed.prev!.page!, 10) + 1;
|
||||
}
|
||||
res.ordinal = (res.page - 1) * perPage + 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate over every GitHub release in the given owner/repo, check whether
|
||||
* its tag_name matches against the affectedVersions semver spec, and if so
|
||||
* replace its release description (body) with the given newDescription value.
|
||||
* @param owner GitHub repo owner, e.g. 'balena-io' or 'pdcastro'
|
||||
* @param repo GitHub repo, e.g. 'balena-cli'
|
||||
* @param affectedVersions Semver spec, e.g. '2.6.1 - 7.10.9 || 8.0.0'
|
||||
* @param newDescription New release description (body)
|
||||
* @param editID Short string present in newDescription, e.g. '[AA101]', that
|
||||
* can be searched to determine whether that release has already been updated.
|
||||
*/
|
||||
async function updateGitHubReleaseDescriptions(
|
||||
owner: string,
|
||||
repo: string,
|
||||
affectedVersions: string,
|
||||
newDescription: string,
|
||||
editID: string,
|
||||
) {
|
||||
const perPage = 30;
|
||||
const octokit = getOctokit();
|
||||
const options = octokit.repos.listReleases.endpoint.merge({
|
||||
owner,
|
||||
repo,
|
||||
per_page: perPage,
|
||||
});
|
||||
let errCount = 0;
|
||||
type Release =
|
||||
import('@octokit/rest').RestEndpointMethodTypes['repos']['listReleases']['response']['data'][0];
|
||||
for await (const response of octokit.paginate.iterator<Release>(options)) {
|
||||
const {
|
||||
page: thisPage,
|
||||
pages: totalPages,
|
||||
ordinal,
|
||||
} = await getPageNumbers(response, perPage);
|
||||
let i = 0;
|
||||
for (const cliRelease of response.data) {
|
||||
const prefix = `[#${ordinal + i++} pg ${thisPage}/${totalPages}]`;
|
||||
if (!cliRelease.id) {
|
||||
console.error(
|
||||
`${prefix} Error: missing release ID (errCount=${++errCount})`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const skipMsg = `${prefix} skipping release "${cliRelease.tag_name}" (${cliRelease.id})`;
|
||||
if (cliRelease.draft === true) {
|
||||
console.info(`${skipMsg}: draft release`);
|
||||
continue;
|
||||
} else if (cliRelease.body && cliRelease.body.includes(editID)) {
|
||||
console.info(`${skipMsg}: already updated`);
|
||||
continue;
|
||||
} else if (!semver.satisfies(cliRelease.tag_name, affectedVersions)) {
|
||||
console.info(`${skipMsg}: outside version range`);
|
||||
continue;
|
||||
} else {
|
||||
const updatedRelease = {
|
||||
owner,
|
||||
repo,
|
||||
release_id: cliRelease.id,
|
||||
body: newDescription,
|
||||
};
|
||||
let oldBodyPreview = cliRelease.body;
|
||||
if (oldBodyPreview) {
|
||||
oldBodyPreview = oldBodyPreview.replace(/\s+/g, ' ').trim();
|
||||
if (oldBodyPreview.length > 12) {
|
||||
oldBodyPreview = oldBodyPreview.substring(0, 9) + '...';
|
||||
}
|
||||
}
|
||||
console.info(
|
||||
`${prefix} updating release "${cliRelease.tag_name}" (${cliRelease.id}) old body="${oldBodyPreview}"`,
|
||||
);
|
||||
try {
|
||||
await octokit.repos.updateRelease(updatedRelease);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`${skipMsg}: Error: ${err.message} (count=${++errCount})`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a warning description to CLI releases affected by a mixpanel tracking
|
||||
* security issue (#1359). This function can be executed "manually" with the
|
||||
* following command line:
|
||||
*
|
||||
* npx ts-node --type-check -P automation/tsconfig.json automation/run.ts fix1359
|
||||
*/
|
||||
export async function updateDescriptionOfReleasesAffectedByIssue1359() {
|
||||
// Run only on Linux/Node10, instead of all platform/Node combinations.
|
||||
// (It could have been any other platform, as long as it only runs once.)
|
||||
if (process.platform !== 'linux' || semver.major(process.version) !== 10) {
|
||||
return;
|
||||
}
|
||||
const owner = 'balena-io';
|
||||
const repo = 'balena-cli';
|
||||
const affectedVersions =
|
||||
'2.6.1 - 7.10.9 || 8.0.0 - 8.1.0 || 9.0.0 - 9.15.6 || 10.0.0 - 10.17.5 || 11.0.0 - 11.7.2';
|
||||
const editID = '[AA100]';
|
||||
let newDescription = `
|
||||
Please note: the "login" command in this release is affected by a
|
||||
security issue fixed in versions
|
||||
[7.10.10](https://github.com/balena-io/balena-cli/releases/tag/v7.10.10),
|
||||
[8.1.1](https://github.com/balena-io/balena-cli/releases/tag/v8.1.1),
|
||||
[9.15.7](https://github.com/balena-io/balena-cli/releases/tag/v9.15.7),
|
||||
[10.17.6](https://github.com/balena-io/balena-cli/releases/tag/v10.17.6),
|
||||
[11.7.3](https://github.com/balena-io/balena-cli/releases/tag/v11.7.3)
|
||||
and later. If you need to use this version, avoid passing your password,
|
||||
keys or tokens as command-line arguments. ${editID}`;
|
||||
// remove line breaks and collapse white space
|
||||
newDescription = newDescription.replace(/\s+/g, ' ').trim();
|
||||
await updateGitHubReleaseDescriptions(
|
||||
owner,
|
||||
repo,
|
||||
affectedVersions,
|
||||
newDescription,
|
||||
editID,
|
||||
);
|
||||
}
|
@ -24,7 +24,6 @@ import {
|
||||
signFilesForNotarization,
|
||||
testShrinkwrap,
|
||||
} from './build-bin';
|
||||
import { updateDescriptionOfReleasesAffectedByIssue1359 } from './deploy-bin';
|
||||
|
||||
// DEBUG set to falsy for negative values else is truthy
|
||||
process.env.DEBUG = ['0', 'no', 'false', '', undefined].includes(
|
||||
@ -54,7 +53,6 @@ async function parse(args?: string[]) {
|
||||
'sign:binaries': signFilesForNotarization,
|
||||
'catch-uncommitted': catchUncommitted,
|
||||
'test-shrinkwrap': testShrinkwrap,
|
||||
fix1359: updateDescriptionOfReleasesAffectedByIssue1359,
|
||||
};
|
||||
for (const arg of args) {
|
||||
if (!Object.hasOwn(commands, arg)) {
|
||||
|
@ -59,7 +59,6 @@ export async function trackCommand(commandSignature: string) {
|
||||
});
|
||||
});
|
||||
}
|
||||
// Don't actually call mixpanel.track() while running test cases, or if suppressed
|
||||
if (
|
||||
!process.env.BALENA_CLI_TEST_TYPE &&
|
||||
!process.env.BALENARC_NO_ANALYTICS
|
||||
@ -75,9 +74,6 @@ export async function trackCommand(commandSignature: string) {
|
||||
|
||||
const TIMEOUT = 4000;
|
||||
|
||||
/**
|
||||
* Make the event tracking HTTPS request to balenaCloud's '/mixpanel' endpoint.
|
||||
*/
|
||||
async function sendEvent(balenaUrl: string, event: string, username?: string) {
|
||||
const { default: got } = await import('got');
|
||||
const trackData = {
|
||||
|
@ -36,7 +36,6 @@ describe('balena app create', function () {
|
||||
// Temporarily skipped because of parse/checking order issue with -h
|
||||
it.skip('should print help text with the -h flag', async () => {
|
||||
api.expectGetWhoAmI({ optional: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
|
||||
const { out, err } = await runCommand('app create -h');
|
||||
|
||||
|
@ -91,7 +91,6 @@ describe('balena build', function () {
|
||||
api = new BalenaAPIMock();
|
||||
docker = new DockerMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
docker.expectGetPing();
|
||||
docker.expectGetVersion({ persist: true });
|
||||
});
|
||||
@ -619,7 +618,6 @@ describe('balena build: project validation', function () {
|
||||
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -82,7 +82,6 @@ describe('balena deploy', function () {
|
||||
api = new BalenaAPIMock();
|
||||
docker = new DockerMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
api.expectGetApplication({ expandArchitecture: true });
|
||||
api.expectGetRelease();
|
||||
api.expectGetUser();
|
||||
@ -515,7 +514,6 @@ describe('balena deploy: project validation', function () {
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -25,7 +25,6 @@ describe('balena device move', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -27,7 +27,6 @@ describe('balena device', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -27,7 +27,6 @@ describe('balena devices', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -26,7 +26,6 @@ describe('balena devices supported', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
1
tests/commands/env/add.spec.ts
vendored
1
tests/commands/env/add.spec.ts
vendored
@ -28,7 +28,6 @@ describe('balena env add', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
1
tests/commands/env/envs.spec.ts
vendored
1
tests/commands/env/envs.spec.ts
vendored
@ -31,7 +31,6 @@ describe('balena envs', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
// Random device UUID used to frustrate _.memoize() in utils/cloud.ts
|
||||
fullUUID = randomBytes(16).toString('hex');
|
||||
shortUUID = fullUUID.substring(0, 7);
|
||||
|
1
tests/commands/env/rename.spec.ts
vendored
1
tests/commands/env/rename.spec.ts
vendored
@ -26,7 +26,6 @@ describe('balena env rename', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
1
tests/commands/env/rm.spec.ts
vendored
1
tests/commands/env/rm.spec.ts
vendored
@ -26,7 +26,6 @@ describe('balena env rm', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -111,7 +111,6 @@ describe.skip('balena help', function () {
|
||||
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -31,7 +31,6 @@ describe('balena logs', function () {
|
||||
api = new BalenaAPIMock();
|
||||
supervisor = new SupervisorMock();
|
||||
api.expectGetWhoAmI();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -35,7 +35,6 @@ if (process.platform !== 'win32') {
|
||||
beforeEach(async () => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
tmpPath = (await tmpNameAsync()) as string;
|
||||
await fs.copyFile('./tests/test-data/dummy.img', tmpPath);
|
||||
});
|
||||
|
@ -89,7 +89,6 @@ describe('balena push', function () {
|
||||
api = new BalenaAPIMock();
|
||||
builder = new BuilderMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
api.expectGetApplication();
|
||||
});
|
||||
|
||||
@ -518,7 +517,6 @@ describe('balena push: project validation', function () {
|
||||
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -26,7 +26,6 @@ describe('balena release', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -76,7 +76,6 @@ describe('balena ssh', function () {
|
||||
|
||||
this.beforeEach(function () {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(function () {
|
||||
|
@ -28,7 +28,6 @@ describe('balena tag set', function () {
|
||||
beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -30,7 +30,6 @@ describe('balena version', function () {
|
||||
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(() => {
|
||||
|
@ -24,7 +24,6 @@ describe('balena whoami', function () {
|
||||
|
||||
this.beforeEach(() => {
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
});
|
||||
|
||||
this.afterEach(async () => {
|
||||
|
@ -68,7 +68,6 @@ describe('DeprecationChecker', function () {
|
||||
npm = new NpmMock();
|
||||
api = new BalenaAPIMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
checker = new DeprecationChecker(packageJSON.version);
|
||||
|
||||
getStub = sandbox.stub(mockStorage, 'get').withArgs(checker.cacheFile);
|
||||
|
@ -74,7 +74,6 @@ export class BalenaAPIMock extends NockMock {
|
||||
"vpnEndpoint":"vpn.balena-cloud.com",
|
||||
"registryEndpoint":"registry2.balena-cloud.com",
|
||||
"deltaEndpoint":"https://delta.balena-cloud.com",
|
||||
"mixpanelToken":"",
|
||||
"apiKey":"nothingtoseehere"
|
||||
}`),
|
||||
);
|
||||
@ -465,10 +464,6 @@ export class BalenaAPIMock extends NockMock {
|
||||
public expectWhoAmIFail(opts: ScopeOpts = { optional: true }) {
|
||||
this.optGet('/actor/v1/whoami', opts).reply(401);
|
||||
}
|
||||
|
||||
public expectGetMixpanel(opts: ScopeOpts = {}) {
|
||||
this.optGet(/^\/mixpanel\/track/, opts).reply(200, {});
|
||||
}
|
||||
}
|
||||
|
||||
const appServiceVarsByService: { [key: string]: any } = {
|
||||
|
Loading…
Reference in New Issue
Block a user