@@ -4,6 +4,7 @@ import { homedir } from 'os';
4
4
import { read , getGalleryAPI , getSecurityRolesAPI , log , getMarketplaceUrl , getAzureCredentialAccessToken } from './util' ;
5
5
import { validatePublisher } from './validation' ;
6
6
import { readManifest } from './package' ;
7
+ import { getPAT } from './publish' ;
7
8
8
9
export interface IPublisher {
9
10
readonly name : string ;
@@ -39,7 +40,7 @@ export class FileStore implements IStore {
39
40
return this . publishers . length ;
40
41
}
41
42
42
- private constructor ( readonly path : string , private publishers : IPublisher [ ] ) { }
43
+ private constructor ( readonly path : string , private publishers : IPublisher [ ] ) { }
43
44
44
45
private async save ( ) : Promise < void > {
45
46
await fs . promises . writeFile ( this . path , JSON . stringify ( { publishers : this . publishers } ) , { mode : '0600' } ) ;
@@ -92,7 +93,7 @@ export class KeytarStore implements IStore {
92
93
private readonly keytar : typeof import ( 'keytar' ) ,
93
94
private readonly serviceName : string ,
94
95
private publishers : IPublisher [ ]
95
- ) { }
96
+ ) { }
96
97
97
98
get ( name : string ) : IPublisher {
98
99
return this . publishers . filter ( p => p . name === name ) [ 0 ] ;
@@ -113,24 +114,15 @@ export class KeytarStore implements IStore {
113
114
}
114
115
}
115
116
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
+ }
124
122
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 ) ;
134
126
135
127
try {
136
128
// If the caller of the `getRoleAssignments` API has any of the roles
@@ -149,7 +141,7 @@ async function requestPAT(publisherName: string): Promise<string> {
149
141
console . log ( `${ getMarketplaceUrl ( ) } /manage/publishers/` ) ;
150
142
151
143
const pat = await read ( `Personal Access Token for publisher '${ publisherName } ':` , { silent : true , replace : '*' } ) ;
152
- await verifyPat ( pat , false , publisherName ) ;
144
+ await verifyPat ( { publisherName , pat } ) ;
153
145
return pat ;
154
146
}
155
147
0 commit comments