azure-kusto-ingest
Version:
Azure Data Explorer Ingestion SDK
65 lines • 2.15 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { IngestionProperties } from "./ingestionProperties.js";
import isIP from "is-ip";
const INGEST_PREFIX = "ingest-";
const PROTOCOL_SUFFIX = "://";
export class AbstractKustoClient {
constructor(defaultProps) {
this._isClosed = false;
if (!defaultProps) {
this.defaultProps = new IngestionProperties({});
}
else if (!(defaultProps instanceof IngestionProperties)) {
this.defaultProps = new IngestionProperties(defaultProps);
}
else {
this.defaultProps = new IngestionProperties(defaultProps);
}
}
_getMergedProps(newProperties) {
const props = this.defaultProps.merge(newProperties);
props.setDefaults();
if (!props.database) {
props.database = this.defaultDatabase;
}
props.validate();
return props;
}
close() {
this._isClosed = true;
}
ensureOpen() {
if (this._isClosed) {
throw new Error("Client is closed");
}
}
getIngestionEndpoint(clusterUrl) {
if (!clusterUrl || clusterUrl.includes(INGEST_PREFIX) || this.isReservedHostname(clusterUrl)) {
return clusterUrl;
}
return clusterUrl.replace(PROTOCOL_SUFFIX, PROTOCOL_SUFFIX + INGEST_PREFIX);
}
getQueryEndpoint(clusterUrl) {
if (clusterUrl && clusterUrl.includes(INGEST_PREFIX)) {
return clusterUrl.replace(INGEST_PREFIX, "");
}
return clusterUrl;
}
isReservedHostname(clusterUrl) {
try {
const parsedUrl = new URL(clusterUrl);
const authority = parsedUrl.hostname;
if (!authority) {
return true;
}
const is_ip = isIP(authority);
const is_localhost = authority.includes("localhost");
return is_localhost || is_ip || authority.toLowerCase() === "onebox.dev.kusto.windows.net";
}
catch (_a) {
return false;
}
}
}
//# sourceMappingURL=abstractKustoClient.js.map