/
policyInsightsClient.ts
137 lines (128 loc) · 4.45 KB
/
policyInsightsClient.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as coreClient from "@azure/core-client";
import * as coreRestPipeline from "@azure/core-rest-pipeline";
import * as coreAuth from "@azure/core-auth";
import {
PolicyTrackedResourcesImpl,
RemediationsImpl,
PolicyEventsImpl,
PolicyStatesImpl,
OperationsImpl,
PolicyMetadataOperationsImpl,
PolicyRestrictionsImpl,
AttestationsImpl
} from "./operations";
import {
PolicyTrackedResources,
Remediations,
PolicyEvents,
PolicyStates,
Operations,
PolicyMetadataOperations,
PolicyRestrictions,
Attestations
} from "./operationsInterfaces";
import { PolicyInsightsClientOptionalParams } from "./models";
export class PolicyInsightsClient extends coreClient.ServiceClient {
$host: string;
subscriptionId: string;
/**
* Initializes a new instance of the PolicyInsightsClient class.
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param subscriptionId Microsoft Azure subscription ID.
* @param options The parameter options
*/
constructor(
credentials: coreAuth.TokenCredential,
subscriptionId: string,
options?: PolicyInsightsClientOptionalParams
) {
if (credentials === undefined) {
throw new Error("'credentials' cannot be null");
}
if (subscriptionId === undefined) {
throw new Error("'subscriptionId' cannot be null");
}
// Initializing default values for options
if (!options) {
options = {};
}
const defaults: PolicyInsightsClientOptionalParams = {
requestContentType: "application/json; charset=utf-8",
credential: credentials
};
const packageDetails = `azsdk-js-arm-policyinsights/6.0.0-beta.2`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;
if (!options.credentialScopes) {
options.credentialScopes = ["https://management.azure.com/.default"];
}
const optionsWithDefaults = {
...defaults,
...options,
userAgentOptions: {
userAgentPrefix
},
baseUri:
options.endpoint ?? options.baseUri ?? "https://management.azure.com"
};
super(optionsWithDefaults);
let bearerTokenAuthenticationPolicyFound: boolean = false;
if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) {
const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies();
bearerTokenAuthenticationPolicyFound = pipelinePolicies.some(
(pipelinePolicy) =>
pipelinePolicy.name ===
coreRestPipeline.bearerTokenAuthenticationPolicyName
);
}
if (
!options ||
!options.pipeline ||
options.pipeline.getOrderedPolicies().length == 0 ||
!bearerTokenAuthenticationPolicyFound
) {
this.pipeline.removePolicy({
name: coreRestPipeline.bearerTokenAuthenticationPolicyName
});
this.pipeline.addPolicy(
coreRestPipeline.bearerTokenAuthenticationPolicy({
credential: credentials,
scopes: `${optionsWithDefaults.credentialScopes}`,
challengeCallbacks: {
authorizeRequestOnChallenge:
coreClient.authorizeRequestOnClaimChallenge
}
})
);
}
// Parameter assignments
this.subscriptionId = subscriptionId;
// Assigning values to Constant parameters
this.$host = options.$host || "https://management.azure.com";
this.policyTrackedResources = new PolicyTrackedResourcesImpl(this);
this.remediations = new RemediationsImpl(this);
this.policyEvents = new PolicyEventsImpl(this);
this.policyStates = new PolicyStatesImpl(this);
this.operations = new OperationsImpl(this);
this.policyMetadataOperations = new PolicyMetadataOperationsImpl(this);
this.policyRestrictions = new PolicyRestrictionsImpl(this);
this.attestations = new AttestationsImpl(this);
}
policyTrackedResources: PolicyTrackedResources;
remediations: Remediations;
policyEvents: PolicyEvents;
policyStates: PolicyStates;
operations: Operations;
policyMetadataOperations: PolicyMetadataOperations;
policyRestrictions: PolicyRestrictions;
attestations: Attestations;
}