@azure/arm-mysql-flexible
Version:
A generated SDK for MySQLManagementFlexibleServerClient.
110 lines • 5.67 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.
*/
import { __awaiter } from "tslib";
import * as coreClient from "@azure/core-client";
import * as coreRestPipeline from "@azure/core-rest-pipeline";
import { ServersImpl, ReplicasImpl, BackupsImpl, FirewallRulesImpl, DatabasesImpl, ConfigurationsImpl, LocationBasedCapabilitiesImpl, CheckVirtualNetworkSubnetUsageImpl, CheckNameAvailabilityImpl, GetPrivateDnsZoneSuffixImpl, OperationsImpl } from "./operations";
export class MySQLManagementFlexibleServerClient extends coreClient.ServiceClient {
/**
* Initializes a new instance of the MySQLManagementFlexibleServerClient class.
* @param credentials Subscription credentials which uniquely identify client subscription.
* @param subscriptionId The ID of the target subscription.
* @param options The parameter options
*/
constructor(credentials, subscriptionId, options) {
var _a, _b, _c;
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 = {
requestContentType: "application/json; charset=utf-8",
credential: credentials
};
const packageDetails = `azsdk-js-arm-mysql-flexible/3.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 || "2021-05-01";
this.servers = new ServersImpl(this);
this.replicas = new ReplicasImpl(this);
this.backups = new BackupsImpl(this);
this.firewallRules = new FirewallRulesImpl(this);
this.databases = new DatabasesImpl(this);
this.configurations = new ConfigurationsImpl(this);
this.locationBasedCapabilities = new LocationBasedCapabilitiesImpl(this);
this.checkVirtualNetworkSubnetUsage = new CheckVirtualNetworkSubnetUsageImpl(this);
this.checkNameAvailability = new CheckNameAvailabilityImpl(this);
this.getPrivateDnsZoneSuffix = new GetPrivateDnsZoneSuffixImpl(this);
this.operations = new OperationsImpl(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",
sendRequest(request, next) {
return __awaiter(this, void 0, void 0, function* () {
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);
}
}
//# sourceMappingURL=mySQLManagementFlexibleServerClient.js.map