-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
azure-graph.ts
83 lines (68 loc) · 2.73 KB
/
azure-graph.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import tl = require('azure-pipelines-task-lib/task');
import msRestAzure = require("./azure-arm-common");
import azureServiceClient = require("./AzureServiceClient");
import azureServiceClientBase = require("./AzureServiceClientBase");
import webClient = require("./webClient");
import util = require("util");
import Q = require("q");
export class GraphManagementClient extends azureServiceClient.ServiceClient {
public servicePrincipals: ServicePrincipals;
constructor(credentials: msRestAzure.ApplicationTokenCredentials, baseUri?: any, options?: any) {
super(credentials, null);
this.apiVersion = '1.6';
this.acceptLanguage = 'en-US';
this.generateClientRequestId = true;
if (!options)
options = {};
if (baseUri) {
this.baseUri = baseUri;
}
if (options.acceptLanguage) {
this.acceptLanguage = options.acceptLanguage;
}
if (options.longRunningOperationRetryTimeout) {
this.longRunningOperationRetryTimeout = options.longRunningOperationRetryTimeout;
}
if (options.generateClientRequestId) {
this.generateClientRequestId = options.generateClientRequestId;
}
this.servicePrincipals = new ServicePrincipals(this);
}
//Since there is no subscriptionId so keeping the check here and empty.
protected validateInputs(subscriptionId: string) {
}
}
export class ServicePrincipals {
private client: GraphManagementClient;
constructor(graphClient: GraphManagementClient) {
this.client = graphClient;
}
public async GetServicePrincipal(options): Promise<any> {
var httpRequest = new webClient.WebRequest();
httpRequest.method = 'GET';
httpRequest.headers = this.client.setCustomHeaders(options);
var filterQuery = util.format("appId eq '%s'", this.client.getCredentials().getClientId());
httpRequest.uri = this.client.getRequestUri("{tenantId}/servicePrincipals",
{
'{tenantId}': this.client.getCredentials().getDomain()
},
['$filter=' + encodeURIComponent(filterQuery)]
);
var deferred = Q.defer<any>();
this.client.beginRequest(httpRequest).then(async function(response) {
if (response.statusCode == 200) {
var result = null;
if (response.body.value) {
result = response.body.value[0];
}
deferred.resolve(result);
}
else {
deferred.reject(azureServiceClientBase.ToError(response));
}
}).catch(function(error) {
deferred.reject(error);
});
return deferred.promise;
}
}