This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
tfsgit.ts
43 lines (34 loc) · 1.53 KB
/
tfsgit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import scmm = require('./lib/scmprovider');
import gitm = require('./git');
import cm = require('../common');
import agentifm = require('vso-node-api/interfaces/TaskAgentInterfaces');
export function getProvider(ctx: cm.IExecutionContext, endpoint: agentifm.ServiceEndpoint): cm.IScmProvider {
return new GitTfsScmProvider(ctx, endpoint);
}
export class GitTfsScmProvider extends gitm.GitScmProvider {
// override since TfsGit uses the generated OAuth token
public setAuthorization(authorization: agentifm.EndpointAuthorization) {
if (this.ctx.config.settings.basic) {
this.ctx.info('Using cfgcreds');
this.username = (<any>this.ctx.config).creds.username;
this.password = (<any>this.ctx.config).creds.password;
}
else if (authorization && authorization['scheme']) {
var scheme = authorization['scheme'];
this.ctx.info('Using auth scheme: ' + scheme);
switch (scheme) {
case 'Basic':
this.username = this.getAuthParameter(authorization, 'Username') || 'not supplied';
this.password = this.getAuthParameter(authorization, 'Password') || 'not supplied';
break;
case 'OAuth':
this.username = process.env['VSO_GIT_USERNAME'] || 'OAuth';
this.password = process.env['VSO_GIT_PASSWORD'] ||
this.getAuthParameter(authorization, 'AccessToken') || 'not supplied';
break;
default:
this.ctx.warning('invalid auth scheme: ' + scheme);
}
}
}
}