Skip to content

Commit

Permalink
Add support for addon submission api
Browse files Browse the repository at this point in the history
  • Loading branch information
eviljeff committed Jul 13, 2022
1 parent f2a00e9 commit 183bc95
Show file tree
Hide file tree
Showing 7 changed files with 1,106 additions and 28 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@
"fs-extra": "10.1.0",
"fx-runner": "1.2.0",
"import-fresh": "3.3.0",
"jsonwebtoken": "8.5.1",
"mkdirp": "1.0.4",
"multimatch": "6.0.0",
"mz": "2.7.0",
"node-fetch": "3.2.6",
"node-notifier": "10.0.1",
"open": "8.4.0",
"parse-json": "6.0.2",
Expand Down Expand Up @@ -111,6 +113,7 @@
"git-rev-sync": "3.0.2",
"html-entities": "2.3.3",
"mocha": "10.0.0",
"nock": "13.2.8",
"nyc": "15.1.0",
"prettyjson": "1.2.5",
"shelljs": "0.8.5",
Expand Down
16 changes: 9 additions & 7 deletions scripts/audit-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ if (auditReport) {
}
}

for (const advId of Object.keys(auditReport.advisories)) {
const adv = auditReport.advisories[advId];

if (exceptions.includes(adv.url)) {
ignoredIssues.push(adv);
continue;
if (auditReport.advisories) {
for (const advId of Object.keys(auditReport.advisories)) {
const adv = auditReport.advisories[advId];

if (exceptions.includes(adv.url)) {
ignoredIssues.push(adv);
continue;
}
blockingIssues.push(adv);
}
blockingIssues.push(adv);
}
}

Expand Down
86 changes: 66 additions & 20 deletions src/cmd/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import path from 'path';
import {fs} from 'mz';
import {signAddon as defaultAddonSigner} from 'sign-addon';

import { signAddon as defaultSubmitAddonSigner } from '../util/submit-addon.js';
import type { SignResult } from '../util/submit-addon.js';
import defaultBuilder from './build.js';
import getValidatedManifest, {getManifestId} from '../util/manifest.js';
import {withTempDir} from '../util/temp-dir.js';
Expand All @@ -12,6 +14,8 @@ import {prepareArtifactsDir} from '../util/artifacts.js';
import {createLogger} from '../util/logger.js';
import type {ExtensionManifest} from '../util/manifest.js';

export type { SignResult };

const log = createLogger(import.meta.url);

const defaultAsyncFsReadFile: (string) => Promise<Buffer> =
Expand All @@ -26,6 +30,7 @@ export type SignParams = {|
apiProxy: string,
apiSecret: string,
apiUrlPrefix: string,
apiUseAddonSubmissionApi?: boolean,
artifactsDir: string,
id?: string,
ignoreFiles?: Array<string>,
Expand All @@ -38,22 +43,18 @@ export type SignParams = {|
export type SignOptions = {
build?: typeof defaultBuilder,
signAddon?: typeof defaultAddonSigner,
submitAddon?: typeof defaultSubmitAddonSigner,
preValidatedManifest?: ExtensionManifest,
shouldExitProgram?: boolean,
};

export type SignResult = {|
success: boolean,
id: string,
downloadedFiles: Array<string>,
|};

export default function sign(
{
apiKey,
apiProxy,
apiSecret,
apiUrlPrefix,
apiUseAddonSubmissionApi = false,
artifactsDir,
id,
ignoreFiles = [],
Expand All @@ -66,6 +67,7 @@ export default function sign(
build = defaultBuilder,
preValidatedManifest,
signAddon = defaultAddonSigner,
submitAddon = defaultSubmitAddonSigner,
}: SignOptions = {}
): Promise<SignResult> {
return withTempDir(
Expand All @@ -88,6 +90,19 @@ export default function sign(

const manifestId = getManifestId(manifestData);

if (apiUseAddonSubmissionApi && id && !manifestId) {
throw new UsageError(
`Cannot set custom ID ${id} - addon submission API requires a ` +
'custom id be specified in the manifest'
);
}
if (apiUseAddonSubmissionApi && idFromSourceDir && !manifestId) {
throw new UsageError(
'Cannot use previously auto-generated extension ID: ' +
`${idFromSourceDir} - addon submission API ` +
'requires a custom id be specified in the manifest'
);
}
if (id && manifestId) {
throw new UsageError(
`Cannot set custom ID ${id} because manifest.json ` +
Expand All @@ -111,27 +126,58 @@ export default function sign(
log.warn('No extension ID specified (it will be auto-generated)');
}

const signingResult = await signAddon({
apiKey,
apiSecret,
apiUrlPrefix,
apiProxy,
timeout,
verbose,
id,
xpiPath: buildResult.extensionPath,
version: manifestData.version,
downloadDir: artifactsDir,
channel,
});
let signingResult;
if (apiUseAddonSubmissionApi) {
if (
apiUrlPrefix.endsWith('/api/v3/') || apiUrlPrefix.endsWith('/api/v4')
) {
throw new UsageError(
'The addon submission API is only available under api/v5/ or higher'
);
}
if (!channel) {
throw new UsageError(
'channel is a required paremeter for the addon submission API'
);
}
if (!apiProxy) {
log.warn("apiProxy isn't yet supported for the addon submission API");
}
signingResult = await submitAddon({
apiKey,
apiSecret,
apiUrlPrefix,
// apiProxy,
timeout,
// verbose,
id,
xpiPath: buildResult.extensionPath,
downloadDir: artifactsDir,
channel,
});
} else {
signingResult = await signAddon({
apiKey,
apiSecret,
apiUrlPrefix,
apiProxy,
timeout,
verbose,
id,
xpiPath: buildResult.extensionPath,
version: manifestData.version,
downloadDir: artifactsDir,
channel,
});
}

if (signingResult.id) {
await saveIdToSourceDir(sourceDir, signingResult.id);
}

// All information about the downloaded files would have
// already been logged by signAddon().
if (signingResult.success) {
if (signingResult.success && signingResult.id) {
log.info(`Extension ID: ${signingResult.id}`);
log.info('SUCCESS');
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ Example: $0 --help run.
demandOption: false,
type: 'string',
},
'api-use-addon-submission-api': {
describe:
'[Experimental] sign using the addon submission api - /v5+ only',
demandOption: false,
type: 'boolean',
},
'id': {
describe:
'A custom ID for the extension. This has no effect if the ' +
Expand Down
Loading

0 comments on commit 183bc95

Please sign in to comment.