Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: generate test connections COMPASS-7546 #25

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -193,4 +193,9 @@ lib
**/*.js.map
!**/initdb/*.js
!.eslintrc.js
!scripts/generate-connections.js
*.tgz


# Ignore the generated connections
compass-connections.json
72 changes: 72 additions & 0 deletions scripts/generate-connections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: we probably want to write this in the same folder where you ar running this from (or from an argument with this being a default, but this complicates things too much)

Suggested change
const FILE_PATH = path.resolve(__dirname, '..', 'compass-connections.json');
const FILE_PATH = path.resolve(process.cwd(), 'compass-connections.json');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed this one. will add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added in #27

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();
await 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();