Skip to content

Commit

Permalink
module packaging (#291)
Browse files Browse the repository at this point in the history
Co-authored-by: sergiyv-bitquill <[email protected]>
  • Loading branch information
sergiyvamz and sergiyv-improving authored Nov 6, 2024
1 parent 7177a5c commit faf75af
Show file tree
Hide file tree
Showing 33 changed files with 1,702 additions and 482 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": [
["babel-plugin-transform-rewrite-imports", {
"appendExtension": ".js"
}]
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ out
# Nuxt.js build / generate output
.nuxt
dist
build/**/*

# Gatsby files
.cache/
Expand Down
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
gradle
dist
coverage
build
.babelrc
.github

Empty file added build/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Messages } from "../utils/messages";
import { logger } from "../../logutils";

export class IamAuthenticationPluginFactory implements ConnectionPluginFactory {
async getInstance(pluginService: PluginService, properties: object): Promise<ConnectionPlugin> {
async getInstance(pluginService: PluginService, properties: Map<string, any>): Promise<ConnectionPlugin> {
try {
const iamAuthenticationPlugin = await import("./iam_authentication_plugin");
return new iamAuthenticationPlugin.IamAuthenticationPlugin(pluginService);
Expand Down
5 changes: 4 additions & 1 deletion common/lib/aws_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { DatabaseDialect, DatabaseType } from "./database_dialect/database_diale
import { ConnectionUrlParser } from "./utils/connection_url_parser";
import { HostListProvider } from "./host_list_provider/host_list_provider";
import { PluginManager } from "./plugin_manager";
import { EventEmitter } from "stream";

import pkgStream from "stream";
const { EventEmitter } = pkgStream;

import { DriverConnectionProvider } from "./driver_connection_provider";
import { ClientWrapper } from "./client_wrapper";
import { ConnectionProviderManager } from "./connection_provider_manager";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ConnectionStringHostListProvider implements StaticHostListProvider
throw new AwsWrapperError("ConnectionStringHostListProvider does not support getHostRole.");
}

async identifyConnection(client: ClientWrapper): Promise<HostInfo | void | null> {
async identifyConnection(client: ClientWrapper): Promise<HostInfo | null> {
if (!client.client) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion common/lib/host_list_provider/host_list_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface HostListProvider {

getHostRole(client: AwsClient, dialect: DatabaseDialect): Promise<HostRole>;

identifyConnection(targetClient: ClientWrapper, dialect: DatabaseDialect): Promise<HostInfo | void | null>;
identifyConnection(targetClient: ClientWrapper, dialect: DatabaseDialect): Promise<HostInfo | null>;

createHost(host: string, isWriter: boolean, weight: number, lastUpdateTime: number, port?: number): HostInfo;

Expand Down
2 changes: 1 addition & 1 deletion common/lib/plugin_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ import { PluginService } from "./plugin_service";
import { ConnectionPlugin } from "./connection_plugin";

export interface ConnectionPluginFactory {
getInstance(pluginService: PluginService, properties: object): Promise<ConnectionPlugin>;
getInstance(pluginService: PluginService, properties: Map<string, any>): Promise<ConnectionPlugin>;
}
4 changes: 2 additions & 2 deletions common/lib/plugin_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ export class PluginService implements ErrorHandler, HostListProviderService {
}
}

identifyConnection(targetClient: ClientWrapper): Promise<HostInfo | void | null> {
identifyConnection(targetClient: ClientWrapper): Promise<HostInfo | null> {
const provider: HostListProvider | null = this.getHostListProvider();
if (provider === null) {
if (!provider) {
return Promise.reject();
}
return provider.identifyConnection(targetClient, this.dialect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { ConnectionPluginFactory } from "../plugin_factory";
import { PluginService } from "../plugin_service";
import { AwsWrapperError } from "../utils/errors";
import { Messages } from "../utils/messages";
import { ConnectionPlugin } from "../connection_plugin";

export class AuroraInitialConnectionStrategyFactory implements ConnectionPluginFactory {
async getInstance(pluginService: PluginService, props: Map<string, any>) {
async getInstance(pluginService: PluginService, props: Map<string, any>): Promise<ConnectionPlugin> {
try {
const auroraInitialConnectionStrategyPlugin = await import("./aurora_initial_connection_strategy_plugin");
return new auroraInitialConnectionStrategyPlugin.AuroraInitialConnectionStrategyPlugin(pluginService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class HostMonitoringConnectionPlugin extends AbstractConnectionPlugin imp
private readonly properties: Map<string, any>;
private pluginService: PluginService;
private rdsUtils: RdsUtils;
private monitoringHostInfo: HostInfo | void | null = null;
private monitoringHostInfo: HostInfo | null = null;
private monitorService: MonitorService;

constructor(pluginService: PluginService, properties: Map<string, any>, rdsUtils: RdsUtils = new RdsUtils(), monitorService?: MonitorServiceImpl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import { SamlCredentialsProviderFactory } from "./saml_credentials_provider_factory";
import { WrapperProperties } from "../../wrapper_property";
import { SamlUtils } from "../../utils/saml_utils";
import axios from "axios";
import { Axios } from "axios";
import { logger } from "../../../logutils";
import { Messages } from "../../utils/messages";
import { AwsWrapperError } from "../../utils/errors";
import https from "https";
import { Agent } from "https";
import { PluginService } from "../../plugin_service";
import { TelemetryFactory } from "../../utils/telemetry/telemetry_factory";
import { TelemetryTraceLevel } from "../../utils/telemetry/telemetry_trace_level";
Expand All @@ -33,11 +33,13 @@ export class OktaCredentialsProviderFactory extends SamlCredentialsProviderFacto
private static readonly TELEMETRY_FETCH_SAML = "Fetch OKTA SAML Assertion";
private readonly pluginService: PluginService;
private readonly telemetryFactory: TelemetryFactory;
private readonly axios: Axios;

constructor(pluginService: PluginService) {
constructor(pluginService: PluginService, axios?: Axios) {
super();
this.pluginService = pluginService;
this.telemetryFactory = this.pluginService.getTelemetryFactory();
this.axios = axios ?? new Axios();
}

getSamlUrl(props: Map<string, any>) {
Expand All @@ -53,7 +55,7 @@ export class OktaCredentialsProviderFactory extends SamlCredentialsProviderFacto
const idpUser = WrapperProperties.IDP_USERNAME.get(props);
const idpPassword = WrapperProperties.IDP_PASSWORD.get(props);

const httpsAgent = new https.Agent(WrapperProperties.HTTPS_AGENT_OPTIONS.get(props));
const httpsAgent = new Agent(WrapperProperties.HTTPS_AGENT_OPTIONS.get(props));

const sessionTokenEndpoint = `${idpHost}/api/v1/authn`;

Expand All @@ -75,7 +77,7 @@ export class OktaCredentialsProviderFactory extends SamlCredentialsProviderFacto

let resp;
try {
resp = await axios.request(postConfig);
resp = await this.axios.request(postConfig);
} catch (e: any) {
throw new AwsWrapperError(Messages.get("OktaCredentialsProviderFactory.sessionTokenRequestFailed"));
}
Expand All @@ -98,7 +100,7 @@ export class OktaCredentialsProviderFactory extends SamlCredentialsProviderFacto

logger.debug(Messages.get("OktaCredentialsProviderFactory.samlAssertionUrl", uri));

const httpsAgent = new https.Agent(WrapperProperties.HTTPS_AGENT_OPTIONS.get(props));
const httpsAgent = new Agent(WrapperProperties.HTTPS_AGENT_OPTIONS.get(props));
const getConfig = {
method: "get",
url: uri,
Expand All @@ -110,7 +112,7 @@ export class OktaCredentialsProviderFactory extends SamlCredentialsProviderFacto

let resp;
try {
resp = await axios.request(getConfig);
resp = await this.axios.request(getConfig);
} catch (e: any) {
if (Math.floor(e.response.status / 100) !== 2) {
throw new AwsWrapperError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import { CredentialsProviderFactory } from "./credentials_provider_factory";
import { AssumeRoleWithSAMLCommand, STSClient } from "@aws-sdk/client-sts";
import { WrapperProperties } from "../../wrapper_property";
import { Credentials } from "aws-sdk";

import pkgAwsSdk from "aws-sdk";
const { Credentials } = pkgAwsSdk;

import { AwsWrapperError } from "../../utils/errors";
import { AwsCredentialIdentityProvider, AwsCredentialIdentity } from "@smithy/types/dist-types/identity/awsCredentialIdentity";
import { decode } from "entities";
Expand Down
3 changes: 3 additions & 0 deletions common/lib/round_robin_host_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { CacheMap } from "./utils/cache_map";
import { HostAvailability } from "./host_availability/host_availability";
import { Messages } from "./utils/messages";

import pkgLodash from "lodash";
const { isInteger } = pkgLodash;

export class RoundRobinHostSelector implements HostSelector {
static DEFAULT_ROUND_ROBIN_CACHE_EXPIRE_NANO = 10 * 60_000_000_000; // 10 minutes
static DEFAULT_WEIGHT = 1;
Expand Down
6 changes: 5 additions & 1 deletion common/lib/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

import path from "path";
import { I18n } from "i18n";
import { fileURLToPath } from "url";

export class Messages {
static __filename = fileURLToPath(import.meta.url);
static __dirname = path.dirname(Messages.__filename);

static i18n = new I18n({
locales: ["en"],
directory: path.join(__dirname, "locales")
directory: path.join(Messages.__dirname, "locales")
});

static get(key: string, ...val: string[]) {
Expand Down
4 changes: 3 additions & 1 deletion common/lib/utils/telemetry/default_telemetry_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import { TelemetryGauge } from "./telemetry_gauge";
import { TelemetryTraceLevel } from "./telemetry_trace_level";
import { TelemetryContext } from "./telemetry_context";
import { NullTelemetryFactory } from "./null_telemetry_factory";
import { toLower } from "lodash";
import { Messages } from "../messages";

import pkgLodash from "lodash";
const { toLower } = pkgLodash;

export class DefaultTelemetryFactory implements TelemetryFactory {
private readonly enableTelemetry: boolean;
private readonly telemetryTracesBackend: string;
Expand Down
5 changes: 4 additions & 1 deletion jest.unit.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
"^.+\\.ts$": [
"ts-jest",
{
"diagnostics": false
"diagnostics": false,
"useESM": true
}
]
},
"transformIgnorePatterns": ["node_modules"],
"moduleNameMapper": {
"^uuid$": "uuid"
},
"testEnvironment": "node",
"extensionsToTreatAsEsm": [".ts"],
"reporters": ["default"]
}
2 changes: 1 addition & 1 deletion mysql/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

import { QueryOptions } from "mysql2/typings/mysql/lib/protocol/sequences/Query";
import { QueryOptions } from "mysql2";
import { AwsClient } from "../../common/lib/aws_client";
import { Query } from "mysql2/promise";
import { MySQLErrorHandler } from "./mysql_error_handler";
Expand Down
Loading

0 comments on commit faf75af

Please sign in to comment.