Skip to content

Commit f64f5d5

Browse files
authored
allow verifyPat to use extension's publisher name (#966)
1 parent 57edfae commit f64f5d5

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ module.exports = function (argv: string[]): void {
316316
'Personal Access Token (defaults to VSCE_PAT environment variable)',
317317
process.env['VSCE_PAT']
318318
)
319-
.action((name, { pat }) => main(verifyPat(pat, name)));
319+
.action((publisherName, { pat }) => main(verifyPat({ publisherName, pat })));
320320

321321
program
322322
.command('show <extensionid>')

src/store.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class FileStore implements IStore {
3939
return this.publishers.length;
4040
}
4141

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

4444
private async save(): Promise<void> {
4545
await fs.promises.writeFile(this.path, JSON.stringify({ publishers: this.publishers }), { mode: '0600' });
@@ -92,7 +92,7 @@ export class KeytarStore implements IStore {
9292
private readonly keytar: typeof import('keytar'),
9393
private readonly serviceName: string,
9494
private publishers: IPublisher[]
95-
) {}
95+
) { }
9696

9797
get(name: string): IPublisher {
9898
return this.publishers.filter(p => p.name === name)[0];
@@ -113,20 +113,14 @@ export class KeytarStore implements IStore {
113113
}
114114
}
115115

116-
export async function verifyPat(pat: string, publisherName?: string): Promise<void> {
117-
if (!pat) {
118-
throw new Error('The Personal Access Token is mandatory.');
119-
}
116+
export interface IVerifyPatOptions {
117+
readonly publisherName?: string;
118+
readonly pat?: string;
119+
}
120120

121-
if (!publisherName) {
122-
try {
123-
publisherName = (await readManifest()).publisher;
124-
} catch (error) {
125-
throw new Error(
126-
`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}`
127-
);
128-
}
129-
}
121+
export async function verifyPat(options: IVerifyPatOptions): Promise<void> {
122+
const publisherName = options.publisherName ?? (await readManifest()).publisher;
123+
const pat = options.pat ?? (await getPublisher(publisherName)).pat;
130124

131125
try {
132126
// If the caller of the `getRoleAssignments` API has any of the roles
@@ -145,7 +139,7 @@ async function requestPAT(publisherName: string): Promise<string> {
145139
console.log(`${getMarketplaceUrl()}/manage/publishers/`);
146140

147141
const pat = await read(`Personal Access Token for publisher '${publisherName}':`, { silent: true, replace: '*' });
148-
await verifyPat(pat, publisherName);
142+
await verifyPat({ publisherName, pat });
149143
return pat;
150144
}
151145

0 commit comments

Comments
 (0)