/* * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is * regenerated. */ import * as msRest from "@azure/ms-rest-js"; import { DefaultAzureCredential } from "@azure/identity" const getCredentials = async function (connectionString: string, userOptions?: any): Promise<[msRest.TokenCredentials, string, any]> { if (!connectionString) { throw new Error("Input 'connectionString' is missing"); } /* Read and parse endpoint */ const connectionPieces = connectionString.split(";").map((segment) => { return segment.split("=") }); const endpointPair = connectionPieces.find((segment) => { return segment[0].toLowerCase() == "endpoint"}); const endpoint = endpointPair && endpointPair[1]; if (!endpoint) { throw new Error("Property 'endpoint' is missing from connection string"); } const endpointComponents = endpoint.split("/").filter((value: string) => { return value; }); const connectionId = endpointComponents[endpointComponents.length - 1]; const baseUri = (endpoint.match(/(https:\/\/|http:\/\/).*(\.net|\.com)/g)|| [""])[0]; /* Read and parse auth */ const authPair = connectionPieces.find((segment) => { return segment[0].toLowerCase() == "auth"}); const auth = authPair && authPair[0]; const authValue = authPair && authPair[1]; if (!(auth && authValue)) { throw new Error("Property 'auth' (or value) is missing from connection string"); } let tokenCredential: msRest.TokenCredentials; if (authValue.toLowerCase() === "key") { const keyPair = connectionPieces.find((segment) => { return segment[0].toLowerCase() == "key"}); const key = keyPair && keyPair[1]; if (!key) { throw new Error("Property 'key' missing from connection string"); } tokenCredential = new msRest.TokenCredentials(key, "Key"); } else if (authValue.toLowerCase() === "managed") { const creds = new DefaultAzureCredential(); const accessToken = await creds.getToken("https://management.core.windows.net/"); tokenCredential = new msRest.TokenCredentials((accessToken && accessToken.token) || "", "Bearer"); } else { throw new Error("Auth value is " + authValue + " instead of 'key' or 'managed'"); } return [ tokenCredential, connectionId, Object.assign({ baseUri }, userOptions) ]; } let _connectorClient: TeradataConnector | undefined; export const createTeradataConnector = async function(connectionString: string, options?: Models.TeradataConnectorOptions): Promise { const creds = await getCredentials(connectionString); if (!_connectorClient) { _connectorClient = new TeradataConnector (...creds); } return _connectorClient; } import * as Models from "./models"; import * as Mappers from "./models/mappers"; import * as operations from "./operations"; import { TeradataConnectorContext } from "./teradataConnectorContext"; class TeradataConnector extends TeradataConnectorContext { // Operation groups teradataTable: operations.TeradataTable; teradataTableData: operations.TeradataTableData; /** * Initializes a new instance of the TeradataConnector class. * @param connectionId Unique identifier of the connection instance * @param credentials Subscription credentials which uniquely identify client subscription. * @param [options] The parameter options */ constructor(credentials: msRest.ServiceClientCredentials, connectionId: string, options?: Models.TeradataConnectorOptions) { super(credentials, connectionId, options); this.teradataTable = new operations.TeradataTable(this); this.teradataTableData = new operations.TeradataTableData(this); } } // Operation Specifications export { TeradataConnector, TeradataConnectorContext, Models as TeradataConnectorModels, Mappers as TeradataConnectorMappers }; export * from "./operations";