@azure/arm-resources
Version:
A generated SDK for ResourceManagementClient.
107 lines • 5.26 kB
JavaScript
;
/*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResourceManagementClient = void 0;
const tslib_1 = require("tslib");
const coreClient = tslib_1.__importStar(require("@azure/core-client"));
const coreRestPipeline = tslib_1.__importStar(require("@azure/core-rest-pipeline"));
const index_js_1 = require("./operations/index.js");
class ResourceManagementClient extends coreClient.ServiceClient {
constructor(credentials, subscriptionIdOrOptions, options) {
var _a, _b, _c;
if (credentials === undefined) {
throw new Error("'credentials' cannot be null");
}
let subscriptionId;
if (typeof subscriptionIdOrOptions === "string") {
subscriptionId = subscriptionIdOrOptions;
}
else if (typeof subscriptionIdOrOptions === "object") {
options = subscriptionIdOrOptions;
}
// Initializing default values for options
if (!options) {
options = {};
}
const defaults = {
requestContentType: "application/json; charset=utf-8",
credential: credentials,
};
const packageDetails = `azsdk-js-arm-resources/6.1.0`;
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
: `${packageDetails}`;
const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
userAgentPrefix,
}, endpoint: (_b = (_a = options.endpoint) !== null && _a !== void 0 ? _a : options.baseUri) !== null && _b !== void 0 ? _b : "https://management.azure.com" });
super(optionsWithDefaults);
let bearerTokenAuthenticationPolicyFound = false;
if ((options === null || options === void 0 ? void 0 : options.pipeline) && options.pipeline.getOrderedPolicies().length > 0) {
const pipelinePolicies = 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: (_c = optionsWithDefaults.credentialScopes) !== null && _c !== void 0 ? _c : `${optionsWithDefaults.endpoint}/.default`,
challengeCallbacks: {
authorizeRequestOnChallenge: coreClient.authorizeRequestOnClaimChallenge,
},
}));
}
// Parameter assignments
this.subscriptionId = subscriptionId;
// Assigning values to Constant parameters
this.$host = options.$host || "https://management.azure.com";
this.apiVersion = options.apiVersion || "2025-03-01";
this.operations = new index_js_1.OperationsImpl(this);
this.deployments = new index_js_1.DeploymentsImpl(this);
this.providers = new index_js_1.ProvidersImpl(this);
this.providerResourceTypes = new index_js_1.ProviderResourceTypesImpl(this);
this.resources = new index_js_1.ResourcesImpl(this);
this.resourceGroups = new index_js_1.ResourceGroupsImpl(this);
this.tagsOperations = new index_js_1.TagsOperationsImpl(this);
this.deploymentOperations = new index_js_1.DeploymentOperationsImpl(this);
this.addCustomApiVersionPolicy(options.apiVersion);
}
/** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */
addCustomApiVersionPolicy(apiVersion) {
if (!apiVersion) {
return;
}
const apiVersionPolicy = {
name: "CustomApiVersionPolicy",
async sendRequest(request, next) {
const param = request.url.split("?");
if (param.length > 1) {
const newParams = param[1].split("&").map((item) => {
if (item.indexOf("api-version") > -1) {
return "api-version=" + apiVersion;
}
else {
return item;
}
});
request.url = param[0] + "?" + newParams.join("&");
}
return next(request);
},
};
this.pipeline.addPolicy(apiVersionPolicy);
}
}
exports.ResourceManagementClient = ResourceManagementClient;
//# sourceMappingURL=resourceManagementClient.js.map