Skip to content

Commit e375bbf

Browse files
committed
Pull request feedback
1 parent 61223f3 commit e375bbf

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ module.exports = function (argv: string[]): void {
321321
process.env['VSCE_PAT']
322322
)
323323
.option('--azure-credential', 'Use Microsoft Entra ID for authentication')
324-
.action((name, { pat, azureCredential }) => main(verifyPat(pat, azureCredential, name)));
324+
.action((publisherName, { pat, azureCredential }) => main(verifyPat({ publisherName, pat, azureCredential })));
325325

326326
program
327327
.command('show <extensionid>')

src/publish.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as semver from 'semver';
44
import { ExtensionQueryFlags, PublishedExtension } from 'azure-devops-node-api/interfaces/GalleryInterfaces';
55
import { pack, readManifest, versionBump, prepublish } from './package';
66
import * as tmp from 'tmp';
7-
import { getPublisher } from './store';
7+
import { IVerifyPatOptions, getPublisher } from './store';
88
import { getGalleryAPI, read, getPublishedUrl, log, getHubUrl, patchOptionsWithManifest, getAzureCredentialAccessToken } from './util';
99
import { Manifest } from './manifest';
1010
import { readVSIXPackage } from './zip';
@@ -314,7 +314,7 @@ function validateMarketplaceRequirements(manifest: Manifest, options: IInternalP
314314
}
315315
}
316316

317-
export async function getPAT(publisher: string, options: IPublishOptions | IUnpublishOptions): Promise<string> {
317+
export async function getPAT(publisher: string, options: IPublishOptions | IUnpublishOptions | IVerifyPatOptions): Promise<string> {
318318
if (options.pat) {
319319
return options.pat;
320320
}

src/store.ts

+12-20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { homedir } from 'os';
44
import { read, getGalleryAPI, getSecurityRolesAPI, log, getMarketplaceUrl, getAzureCredentialAccessToken } from './util';
55
import { validatePublisher } from './validation';
66
import { readManifest } from './package';
7+
import { getPAT } from './publish';
78

89
export interface IPublisher {
910
readonly name: string;
@@ -39,7 +40,7 @@ export class FileStore implements IStore {
3940
return this.publishers.length;
4041
}
4142

42-
private constructor(readonly path: string, private publishers: IPublisher[]) {}
43+
private constructor(readonly path: string, private publishers: IPublisher[]) { }
4344

4445
private async save(): Promise<void> {
4546
await fs.promises.writeFile(this.path, JSON.stringify({ publishers: this.publishers }), { mode: '0600' });
@@ -92,7 +93,7 @@ export class KeytarStore implements IStore {
9293
private readonly keytar: typeof import('keytar'),
9394
private readonly serviceName: string,
9495
private publishers: IPublisher[]
95-
) {}
96+
) { }
9697

9798
get(name: string): IPublisher {
9899
return this.publishers.filter(p => p.name === name)[0];
@@ -113,24 +114,15 @@ export class KeytarStore implements IStore {
113114
}
114115
}
115116

116-
export async function verifyPat(pat: string, azureCredential?: boolean, publisherName?: string): Promise<void> {
117-
if (!pat && !azureCredential) {
118-
throw new Error('The Personal Access Token or the `--azure-credential` option is mandatory.');
119-
}
120-
121-
if (azureCredential) {
122-
pat = await getAzureCredentialAccessToken();
123-
}
117+
export interface IVerifyPatOptions {
118+
readonly publisherName?: string;
119+
readonly pat?: string;
120+
readonly azureCredential?: boolean;
121+
}
124122

125-
if (!publisherName) {
126-
try {
127-
publisherName = (await readManifest()).publisher;
128-
} catch (error) {
129-
throw new Error(
130-
`Can not read the publisher's name. Either supply it as an argument or run vsce from the extension folder. Additional information:\n\n${error}`
131-
);
132-
}
133-
}
123+
export async function verifyPat(options: IVerifyPatOptions): Promise<void> {
124+
const publisherName = options.publisherName ?? (await readManifest()).publisher;
125+
const pat = await getPAT(publisherName, options);
134126

135127
try {
136128
// If the caller of the `getRoleAssignments` API has any of the roles
@@ -149,7 +141,7 @@ async function requestPAT(publisherName: string): Promise<string> {
149141
console.log(`${getMarketplaceUrl()}/manage/publishers/`);
150142

151143
const pat = await read(`Personal Access Token for publisher '${publisherName}':`, { silent: true, replace: '*' });
152-
await verifyPat(pat, false, publisherName);
144+
await verifyPat({ publisherName, pat });
153145
return pat;
154146
}
155147

0 commit comments

Comments
 (0)