@cardano-sdk/cardano-services
Advanced tools
Comparing version 0.5.0-nightly.1 to 0.5.0-nightly.2
@@ -69,2 +69,3 @@ #!/usr/bin/env node | ||
.option('--postgres-password <postgresPassword>', Program_1.ProgramOptionDescriptions.PostgresPassword) | ||
.option('--postgres-ssl-ca-file <postgresSslCaFile>', Program_1.ProgramOptionDescriptions.PostgresSslCaFile) | ||
.action(async (serviceNames, options) => { | ||
@@ -71,0 +72,0 @@ const { apiUrl, ...rest } = options; |
{ | ||
"name": "@cardano-sdk/cardano-services", | ||
"version": "0.5.0-nightly.1", | ||
"version": "0.5.0-nightly.2", | ||
"description": "Cardano GraphQL Services", | ||
@@ -124,3 +124,3 @@ "engines": { | ||
], | ||
"gitHead": "e45098de243a6aa8b23f328e1059981f565833c3" | ||
"gitHead": "e4c7c74573a297f091e98057dd6b2f0f050a8679" | ||
} |
@@ -16,2 +16,3 @@ import { CommonProgramOptions } from '../ProgramsCommon'; | ||
postgresPassword?: string; | ||
postgresSslCaFile?: string; | ||
dbCacheTtl: number; | ||
@@ -18,0 +19,0 @@ } |
@@ -13,2 +13,3 @@ import { CommonOptionDescriptions } from '../ProgramsCommon'; | ||
PostgresPassword = "PostgreSQL password when using service discovery", | ||
PostgresSslCaFile = "PostgreSQL SSL CA file path", | ||
PostgresServiceDiscoveryArgs = "Postgres SRV service name, db, user and password", | ||
@@ -32,2 +33,3 @@ RabbitMQUrl = "RabbitMQ URL", | ||
PostgresPassword: HttpServerOptionDescriptions.PostgresPassword; | ||
PostgresSslCaFile: HttpServerOptionDescriptions.PostgresSslCaFile; | ||
PostgresServiceDiscoveryArgs: HttpServerOptionDescriptions.PostgresServiceDiscoveryArgs; | ||
@@ -34,0 +36,0 @@ RabbitMQUrl: HttpServerOptionDescriptions.RabbitMQUrl; |
@@ -17,2 +17,3 @@ "use strict"; | ||
HttpServerOptionDescriptions["PostgresPassword"] = "PostgreSQL password when using service discovery"; | ||
HttpServerOptionDescriptions["PostgresSslCaFile"] = "PostgreSQL SSL CA file path"; | ||
HttpServerOptionDescriptions["PostgresServiceDiscoveryArgs"] = "Postgres SRV service name, db, user and password"; | ||
@@ -19,0 +20,0 @@ HttpServerOptionDescriptions["RabbitMQUrl"] = "RabbitMQ URL"; |
@@ -20,3 +20,4 @@ import { ClientConfig, Pool } from 'pg'; | ||
export declare type DnsResolver = ReturnType<typeof createDnsResolver>; | ||
export declare const getPoolWithServiceDiscovery: (dnsResolver: DnsResolver, logger: Logger, { host, database, password, user }: ClientConfig) => Promise<Pool>; | ||
export declare const getPoolWithServiceDiscovery: (dnsResolver: DnsResolver, logger: Logger, { host, database, password, ssl, user }: ClientConfig) => Promise<Pool>; | ||
export declare const loadSecret: (path: string) => string; | ||
export declare const getPool: (dnsResolver: DnsResolver, logger: Logger, options?: HttpServerOptions) => Promise<Pool | undefined>; | ||
@@ -23,0 +24,0 @@ export declare const isOgmiosConnectionError: (error: any) => boolean; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getRabbitMqTxSubmitProvider = exports.rabbitMqTxSubmitProviderWithDiscovery = exports.srvRecordToRabbitmqURL = exports.getOgmiosTxSubmitProvider = exports.ogmiosTxSubmitProviderWithDiscovery = exports.isOgmiosConnectionError = exports.getPool = exports.getPoolWithServiceDiscovery = exports.createDnsResolver = exports.resolveSrvRecord = exports.onFailedAttemptFor = exports.DNS_SRV_CACHE_KEY = exports.SERVICE_DISCOVERY_TIMEOUT_DEFAULT = exports.SERVICE_DISCOVERY_BACKOFF_FACTOR_DEFAULT = void 0; | ||
exports.getRabbitMqTxSubmitProvider = exports.rabbitMqTxSubmitProviderWithDiscovery = exports.srvRecordToRabbitmqURL = exports.getOgmiosTxSubmitProvider = exports.ogmiosTxSubmitProviderWithDiscovery = exports.isOgmiosConnectionError = exports.getPool = exports.loadSecret = exports.getPoolWithServiceDiscovery = exports.createDnsResolver = exports.resolveSrvRecord = exports.onFailedAttemptFor = exports.DNS_SRV_CACHE_KEY = exports.SERVICE_DISCOVERY_TIMEOUT_DEFAULT = exports.SERVICE_DISCOVERY_BACKOFF_FACTOR_DEFAULT = void 0; | ||
const pg_1 = require("pg"); | ||
@@ -17,2 +17,3 @@ const ProgramsCommon_1 = require("../ProgramsCommon"); | ||
const dns_1 = __importDefault(require("dns")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const p_retry_1 = __importDefault(require("p-retry")); | ||
@@ -43,5 +44,5 @@ exports.SERVICE_DISCOVERY_BACKOFF_FACTOR_DEFAULT = 1.1; | ||
exports.createDnsResolver = createDnsResolver; | ||
const getPoolWithServiceDiscovery = async (dnsResolver, logger, { host, database, password, user }) => { | ||
const getPoolWithServiceDiscovery = async (dnsResolver, logger, { host, database, password, ssl, user }) => { | ||
const { name, port } = await dnsResolver(host); | ||
let pool = new pg_1.Pool({ database, host: name, password, port, user }); | ||
let pool = new pg_1.Pool({ database, host: name, password, port, ssl, user }); | ||
return new Proxy({}, { | ||
@@ -56,3 +57,3 @@ get(_, prop) { | ||
logger.info(`DNS resolution for Postgres service, resolved with record: ${JSON.stringify(record)}`); | ||
pool = new pg_1.Pool({ database, host: record.name, password, port: record.port, user }); | ||
pool = new pg_1.Pool({ database, host: record.name, password, port: record.port, ssl, user }); | ||
return await pool.query(args, values); | ||
@@ -71,7 +72,10 @@ } | ||
exports.getPoolWithServiceDiscovery = getPoolWithServiceDiscovery; | ||
const loadSecret = (path) => fs_1.default.readFileSync(path, 'utf8').toString(); | ||
exports.loadSecret = loadSecret; | ||
const getPool = async (dnsResolver, logger, options) => { | ||
const ssl = options?.postgresSslCaFile ? { ca: (0, exports.loadSecret)(options.postgresSslCaFile) } : undefined; | ||
if (options?.postgresConnectionString && options.postgresSrvServiceName) | ||
throw new errors_1.InvalidArgsCombination(ProgramOptionDescriptions_1.ProgramOptionDescriptions.PostgresConnectionString, ProgramOptionDescriptions_1.ProgramOptionDescriptions.PostgresServiceDiscoveryArgs); | ||
if (options?.postgresConnectionString) | ||
return new pg_1.Pool({ connectionString: options.postgresConnectionString }); | ||
return new pg_1.Pool({ connectionString: options.postgresConnectionString, ssl }); | ||
if (options?.postgresSrvServiceName && options.postgresUser && options.postgresDb && options.postgresPassword) { | ||
@@ -82,2 +86,3 @@ return (0, exports.getPoolWithServiceDiscovery)(dnsResolver, logger, { | ||
password: options.postgresPassword, | ||
ssl, | ||
user: options.postgresUser | ||
@@ -84,0 +89,0 @@ }); |
@@ -65,2 +65,3 @@ #!/usr/bin/env node | ||
POSTGRES_SRV_SERVICE_NAME: envalid.str({ default: undefined }), | ||
POSTGRES_SSL_CA_FILE: existingFileValidator({ default: undefined }), | ||
POSTGRES_USER: envalid.str({ default: undefined }), | ||
@@ -77,3 +78,2 @@ POSTGRES_USER_FILE: existingFileValidator({ default: undefined }), | ||
}; | ||
const loadSecret = (path) => fs_1.default.readFileSync(path, 'utf8').toString(); | ||
void (async () => { | ||
@@ -98,5 +98,5 @@ (0, dotenv_1.config)(); | ||
const epochPollInterval = env.EPOCH_POLL_INTERVAL; | ||
const dbName = env.POSTGRES_DB_FILE ? loadSecret(env.POSTGRES_DB_FILE) : undefined; | ||
const dbPassword = env.POSTGRES_PASSWORD_FILE ? loadSecret(env.POSTGRES_PASSWORD_FILE) : undefined; | ||
const dbUser = env.POSTGRES_USER_FILE ? loadSecret(env.POSTGRES_USER_FILE) : undefined; | ||
const dbName = env.POSTGRES_DB_FILE ? (0, Program_1.loadSecret)(env.POSTGRES_DB_FILE) : undefined; | ||
const dbPassword = env.POSTGRES_PASSWORD_FILE ? (0, Program_1.loadSecret)(env.POSTGRES_PASSWORD_FILE) : undefined; | ||
const dbUser = env.POSTGRES_USER_FILE ? (0, Program_1.loadSecret)(env.POSTGRES_USER_FILE) : undefined; | ||
let postgresConnectionString; | ||
@@ -111,2 +111,3 @@ if (env.POSTGRES_CONNECTION_STRING) { | ||
const serviceNames = env.SERVICE_NAMES.split(','); | ||
const postgresSslCaFile = env.POSTGRES_SSL_CA_FILE; | ||
try { | ||
@@ -127,2 +128,3 @@ const server = await (0, Program_1.loadHttpServer)({ | ||
postgresSrvServiceName, | ||
postgresSslCaFile, | ||
postgresUser, | ||
@@ -129,0 +131,0 @@ rabbitmqSrvServiceName, |
{ | ||
"name": "@cardano-sdk/cardano-services", | ||
"version": "0.5.0-nightly.1", | ||
"version": "0.5.0-nightly.2", | ||
"description": "Cardano GraphQL Services", | ||
@@ -124,3 +124,3 @@ "engines": { | ||
], | ||
"gitHead": "e45098de243a6aa8b23f328e1059981f565833c3" | ||
"gitHead": "e4c7c74573a297f091e98057dd6b2f0f050a8679" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
742295
8420
8