@@ -8,19 +8,20 @@ import { ConnectedCodeCatalystClient } from '../shared/clients/codecatalystClien
8
8
import { isCloud9 } from '../shared/extensionUtilities'
9
9
import { Auth , isBuilderIdConnection , Connection , SsoConnection , codecatalystScopes } from '../credentials/auth'
10
10
import { getSecondaryAuth } from '../credentials/secondaryAuth'
11
+ import { getLogger } from '../shared/logger'
11
12
12
13
// Secrets stored on the macOS keychain appear as individual entries for each key
13
14
// This is fine so long as the user has only a few accounts. Otherwise this should
14
15
// store secrets as a map.
15
16
export class CodeCatalystAuthStorage {
16
17
public constructor ( private readonly secrets : vscode . SecretStorage ) { }
17
18
18
- public async getPat ( id : string ) : Promise < string | undefined > {
19
- return this . secrets . get ( `codecatalyst.pat.${ id } ` )
19
+ public async getPat ( username : string ) : Promise < string | undefined > {
20
+ return this . secrets . get ( `codecatalyst.pat.${ username } ` )
20
21
}
21
22
22
- public async storePat ( id : string , pat : string ) : Promise < void > {
23
- await this . secrets . store ( `codecatalyst.pat.${ id } ` , pat )
23
+ public async storePat ( username : string , pat : string ) : Promise < void > {
24
+ await this . secrets . store ( `codecatalyst.pat.${ username } ` , pat )
24
25
}
25
26
}
26
27
@@ -46,19 +47,34 @@ export class CodeCatalystAuthenticationProvider {
46
47
}
47
48
48
49
// Get rid of this? Not sure where to put PAT code.
49
- public async getPat ( client : ConnectedCodeCatalystClient ) : Promise < string > {
50
- const stored = await this . storage . getPat ( client . identity . id )
50
+ public async getPat ( client : ConnectedCodeCatalystClient , username = client . identity . name ) : Promise < string > {
51
+ const stored = await this . storage . getPat ( username )
51
52
52
53
if ( stored ) {
53
54
return stored
54
55
}
55
56
56
57
const resp = await client . createAccessToken ( { name : 'aws-toolkits-vscode-token' } )
57
- await this . storage . storePat ( client . identity . id , resp . secret )
58
+ await this . storage . storePat ( username , resp . secret )
58
59
59
60
return resp . secret
60
61
}
61
62
63
+ public async getCredentialsForGit ( client : ConnectedCodeCatalystClient ) {
64
+ getLogger ( ) . verbose ( `codecatalyst (git): attempting to provide credentials` )
65
+
66
+ const username = client . identity . name
67
+
68
+ try {
69
+ return {
70
+ username,
71
+ password : await this . getPat ( client , username ) ,
72
+ }
73
+ } catch ( err ) {
74
+ getLogger ( ) . verbose ( `codecatalyst (git): failed to get credentials for user "${ username } ": %s` , err )
75
+ }
76
+ }
77
+
62
78
public async removeSavedConnection ( ) {
63
79
await this . secondaryAuth . removeConnection ( )
64
80
}
0 commit comments