Skip to content

Commit 813223f

Browse files
committed
wip
1 parent 21f2cb9 commit 813223f

File tree

9 files changed

+492
-13
lines changed

9 files changed

+492
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ test/lambda/env.json
9999

100100
# files generated by tooling in drivers-evergreen-tools
101101
secrets-export.sh
102+
secrets-export.fish
102103
mo-expansion.sh
103104
mo-expansion.yml
104105
expansions.sh

etc/bash_to_fish.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { createReadStream, promises as fs } from 'node:fs';
2+
import path from 'node:path';
3+
import readline from 'node:readline/promises';
4+
5+
/**
6+
* Takes an "exports" only bash script file
7+
* and converts it to fish syntax.
8+
* Will crash on any line that isn't:
9+
* - a comment
10+
* - an empty line
11+
* - a bash 'set' call
12+
* - export VAR=VAL
13+
*/
14+
15+
const fileName = process.argv[2];
16+
const outFileName = path.basename(fileName, '.sh') + '.fish';
17+
const input = createReadStream(process.argv[2]);
18+
const lines = readline.createInterface({ input });
19+
const output = await fs.open(outFileName, 'w');
20+
21+
for await (let line of lines) {
22+
line = line.trim();
23+
24+
if (!line.startsWith('export ')) {
25+
if (line.startsWith('#')) continue;
26+
if (line === '') continue;
27+
if (line.startsWith('set')) continue;
28+
throw new Error('Cannot translate: ' + line);
29+
}
30+
31+
const varVal = line.slice('export '.length);
32+
const variable = varVal.slice(0, varVal.indexOf('='));
33+
const value = varVal.slice(varVal.indexOf('=') + 1);
34+
output.appendFile(`set -x ${variable} ${value}\n`);
35+
}
36+
37+
output.close();
38+
input.close();
39+
lines.close();

src/client-side-encryption/state_machine.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import {
1212
} from '../bson';
1313
import { type ProxyOptions } from '../cmap/connection';
1414
import { CursorTimeoutContext } from '../cursor/abstract_cursor';
15+
import { type ListCollectionsCursor } from '../cursor/list_collections_cursor';
1516
import { getSocks, type SocksLib } from '../deps';
1617
import { MongoOperationTimeoutError } from '../error';
1718
import { type MongoClient, type MongoClientOptions } from '../mongo_client';
1819
import { type Abortable } from '../mongo_types';
20+
import { type CollectionInfo } from '../operations/list_collections';
1921
import { Timeout, type TimeoutContext, TimeoutError } from '../timeout';
2022
import {
2123
addAbortListener,
@@ -218,14 +220,15 @@ export class StateMachine {
218220
);
219221
}
220222

221-
const collInfo = await this.fetchCollectionInfo(
223+
const collInfoCursor = this.fetchCollectionInfo(
222224
metaDataClient,
223225
context.ns,
224226
filter,
225227
options
226228
);
227-
if (collInfo) {
228-
context.addMongoOperationResponse(collInfo);
229+
230+
for await (const collInfo of collInfoCursor) {
231+
context.addMongoOperationResponse(serialize(collInfo));
229232
}
230233

231234
context.finishMongoOperation();
@@ -527,29 +530,24 @@ export class StateMachine {
527530
* @param filter - A filter for the listCollections command
528531
* @param callback - Invoked with the info of the requested collection, or with an error
529532
*/
530-
async fetchCollectionInfo(
533+
fetchCollectionInfo(
531534
client: MongoClient,
532535
ns: string,
533536
filter: Document,
534537
options?: { timeoutContext?: TimeoutContext } & Abortable
535-
): Promise<Uint8Array | null> {
538+
): ListCollectionsCursor<CollectionInfo> {
536539
const { db } = MongoDBCollectionNamespace.fromString(ns);
537540

538541
const cursor = client.db(db).listCollections(filter, {
539542
promoteLongs: false,
540543
promoteValues: false,
541544
timeoutContext:
542545
options?.timeoutContext && new CursorTimeoutContext(options?.timeoutContext, Symbol()),
543-
signal: options?.signal
546+
signal: options?.signal,
547+
nameOnly: false
544548
});
545549

546-
// There is always exactly zero or one matching documents, so this should always exhaust the cursor
547-
// in a single batch. We call `toArray()` just to be safe and ensure that the cursor is always
548-
// exhausted and closed.
549-
const collections = await cursor.toArray();
550-
551-
const info = collections.length > 0 ? serialize(collections[0]) : null;
552-
return info;
550+
return cursor;
553551
}
554552

555553
/**

0 commit comments

Comments
 (0)