From 4a1f42e6dbb305bd37ebff76bb5fbc3c01f1e419 Mon Sep 17 00:00:00 2001 From: Basit Date: Tue, 19 Dec 2023 20:27:20 +0100 Subject: [PATCH] Refactor connection generation and remove unused script --- .gitignore | 5 --- scripts/generate-connections.js | 72 --------------------------------- src/index.ts | 55 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 77 deletions(-) delete mode 100644 scripts/generate-connections.js diff --git a/.gitignore b/.gitignore index aed640e..3b8e6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -193,9 +193,4 @@ lib **/*.js.map !**/initdb/*.js !.eslintrc.js -!scripts/generate-connections.js *.tgz - - -# Ignore the generated connections -compass-connections.json \ No newline at end of file diff --git a/scripts/generate-connections.js b/scripts/generate-connections.js deleted file mode 100644 index 959b88c..0000000 --- a/scripts/generate-connections.js +++ /dev/null @@ -1,72 +0,0 @@ -const { default: createTestEnvironments } = require('./../src'); -const { v4 } = require('uuid'); -const path = require('path'); -const fs = require('fs/promises'); - -const FILE_PATH = path.resolve(__dirname, '..', 'compass-connections.json'); -const connectionsWithVariants = { - enterprise: ['enterprise'], - ldap: ['ldap'], - scram: [ - 'scramReadWriteAnyDatabase', - 'scramReadWriteAnyDatabaseScramSha1', - 'scramReadWriteAnyDatabaseScramSha256', - 'scramOnlyScramSha1', - 'scramOnlyScramSha256', - 'scramEncodedPassword', - 'scramPrivilegesOnNonExistingDatabases', - 'scramPrivilegesOnNonExistingCollections', - 'scramAlternateAuthDb', - ], - sharded: ['sharded'], - ssh: [ - 'sshPassword', - 'sshIdentityKey', - 'sshIdentityKeyWithPassphrase', - 'sshReplicaSetSeedlist', - 'sshReplicaSetByReplSetName', - ], - tls: [ - 'tlsUnvalidated', - 'tlsServerValidation', - 'tlsServerValidationSsh', - 'tlsServerAndClientValidation', - 'tlsServerAndClientValidationKeyCrt', - 'tlsX509', - 'tlsX509WithSsh', - ], - kerberos: ['kerberos', 'kerberosAlternate', 'kerberosCrossRealm'], -}; - -function generateConnections() { - const connections = []; - for (const [env, variants] of Object.entries(connectionsWithVariants)) { - const envConnections = createTestEnvironments([env]); - for (const variant of variants) { - connections.push({ - id: v4(), - favorite: { - name: variant, - }, - connectionOptions: envConnections.getConnectionOptions(variant), - }); - } - } - return { - type: 'Compass Connections', - version: 1, - connections, - }; -} - -async function writeConnections() { - const data = generateConnections(); - fs.writeFile(FILE_PATH, JSON.stringify(data, null, 2)); -} - -/** - * Creates a file with the connections for the Compass app, - * based on the test environments. These connections can be - * directly imported into Compass. - */ -void writeConnections(); diff --git a/src/index.ts b/src/index.ts index 6f2cb52..7222c0f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import { v4 } from 'uuid'; import TestEnvironment from './test-environment'; import TestEnvironments from './test-environments'; import { TestEnvironmentConfiguration } from './test-environment-configuration'; @@ -36,3 +37,57 @@ export default function createTestEnvironments( return new TestEnvironments(envs); } + +const connectionsWithVariants = { + enterprise: ['enterprise'], + ldap: ['ldap'], + scram: [ + 'scramReadWriteAnyDatabase', + 'scramReadWriteAnyDatabaseScramSha1', + 'scramReadWriteAnyDatabaseScramSha256', + 'scramOnlyScramSha1', + 'scramOnlyScramSha256', + 'scramEncodedPassword', + 'scramPrivilegesOnNonExistingDatabases', + 'scramPrivilegesOnNonExistingCollections', + 'scramAlternateAuthDb', + ], + sharded: ['sharded'], + ssh: [ + 'sshPassword', + 'sshIdentityKey', + 'sshIdentityKeyWithPassphrase', + 'sshReplicaSetSeedlist', + 'sshReplicaSetByReplSetName', + ], + tls: [ + 'tlsUnvalidated', + 'tlsServerValidation', + 'tlsServerValidationSsh', + 'tlsServerAndClientValidation', + 'tlsServerAndClientValidationKeyCrt', + 'tlsX509', + 'tlsX509WithSsh', + ], + kerberos: ['kerberos', 'kerberosAlternate', 'kerberosCrossRealm'], +}; + +/** + * @returns The list of test connections that are compatible with the docker configurations. + */ +export function getTestConnections() { + const connections = []; + for (const [env, variants] of Object.entries(connectionsWithVariants)) { + const envConnections = createTestEnvironments([env]); + for (const variant of variants) { + connections.push({ + id: v4(), + favorite: { + name: variant, + }, + connectionOptions: envConnections.getConnectionOptions(variant), + }); + } + } + return connections; +}