-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
createClientPipeline.ts
57 lines (50 loc) · 1.79 KB
/
createClientPipeline.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
createPipelineFromOptions,
InternalPipelineOptions,
ServiceClientOptions,
bearerTokenAuthenticationPolicy,
isTokenCredential
} from "@azure/core-http";
import { TokenCredential } from "@azure/core-auth";
import {
LIB_INFO,
DEFAULT_COGNITIVE_SCOPE,
MetricsAdvisorLoggingAllowedHeaderNames,
MetricsAdvisorLoggingAllowedQueryParameters
} from "./constants";
import { logger } from "./logger";
import { MetricsAdvisorClientOptions } from "./metricsAdvisorClient";
import {
createMetricsAdvisorKeyCredentialPolicy,
MetricsAdvisorKeyCredential
} from "./metricsAdvisorKeyCredentialPolicy";
export function createClientPipeline(
credential: TokenCredential | MetricsAdvisorKeyCredential,
options: MetricsAdvisorClientOptions = {}
): ServiceClientOptions {
const { ...pipelineOptions } = options;
if (!pipelineOptions.userAgentOptions) {
pipelineOptions.userAgentOptions = {};
}
if (pipelineOptions.userAgentOptions.userAgentPrefix) {
pipelineOptions.userAgentOptions.userAgentPrefix = `${pipelineOptions.userAgentOptions.userAgentPrefix} ${LIB_INFO}`;
} else {
pipelineOptions.userAgentOptions.userAgentPrefix = LIB_INFO;
}
const authPolicy = isTokenCredential(credential)
? bearerTokenAuthenticationPolicy(credential, DEFAULT_COGNITIVE_SCOPE)
: createMetricsAdvisorKeyCredentialPolicy(credential);
const internalPipelineOptions: InternalPipelineOptions = {
...pipelineOptions,
...{
loggingOptions: {
logger: logger.info,
allowedHeaderNames: MetricsAdvisorLoggingAllowedHeaderNames,
allowedQueryParameters: MetricsAdvisorLoggingAllowedQueryParameters
}
}
};
return createPipelineFromOptions(internalPipelineOptions, authPolicy);
}