jstests/libs/override_methods/inject_tenant_prefix.js
/**
 * Prepend a tenant prefix to all namespaces within a provided command object, and record a comment
 * indicating that the command object has alrady been modified.
 */
Prepend a tenant prefix to all namespaces within a provided command object, and record a comment
indicating that the command object has alrady been modified.
Prepend a tenant prefix to all namespaces within a provided command object and record a comment indicating that the command object has alrady been modified .
function createCmdObjWithTenantId(cmdObj) {
    const cmdName = Object.keys(cmdObj)[0];
    let cmdObjWithTenantId = TransactionsUtil.deepCopyObject({}, cmdObj);
    if (isCmdObjWithTenantId(cmdObj)) {
        return cmdObjWithTenantId;
    }
    if (kCmdsWithNsAsFirstField.has(cmdName)) {
        cmdObjWithTenantId[cmdName] = prependTenantIdToNsIfApplicable(cmdObjWithTenantId[cmdName]);
    }
    switch (cmdName) {
        case "renameCollection":
            cmdObjWithTenantId.to = prependTenantIdToNsIfApplicable(cmdObjWithTenantId.to);
            break;
        case "internalRenameIfOptionsAndIndexesMatch":
            cmdObjWithTenantId.from = prependTenantIdToNsIfApplicable(cmdObjWithTenantId.from);
            cmdObjWithTenantId.to = prependTenantIdToNsIfApplicable(cmdObjWithTenantId.to);
            break;
        case "configureFailPoint":
            if (cmdObjWithTenantId.data) {
                if (cmdObjWithTenantId.data.namespace) {
                    cmdObjWithTenantId.data.namespace =
                        prependTenantIdToNsIfApplicable(cmdObjWithTenantId.data.namespace);
                } else if (cmdObjWithTenantId.data.ns) {
                    cmdObjWithTenantId.data.ns =
                        prependTenantIdToNsIfApplicable(cmdObjWithTenantId.data.ns);
                }
            }
            break;
        case "applyOps":
            for (let op of cmdObjWithTenantId.applyOps) {
                if (typeof op.ns === "string" && op.ns.endsWith("system.views") && op.o._id &&
                    typeof op.o._id === "string") {
                    op.o._id = prependTenantIdToNsIfApplicable(op.o._id);
                }
            }
            break;
        default:
            break;
    }
    if (cmdName != "configureFailPoint") {
        prependTenantId(cmdObjWithTenantId);
    }
    cmdObjWithTenantId.comment = Object.assign(
        cmdObjWithTenantId.comment ? cmdObjWithTenantId.comment : {}, {isCmdObjWithTenantId: true});
    return cmdObjWithTenantId;
}
function createCmdObjWithTenantId ( cmdObj ) { const cmdName = Object . keys ( cmdObj ) [ 0 ] ; let cmdObjWithTenantId = TransactionsUtil . deepCopyObject ( { } , cmdObj ) ; if ( isCmdObjWithTenantId ( cmdObj ) ) { return cmdObjWithTenantId ; } if ( kCmdsWithNsAsFirstField . has ( cmdName ) ) { cmdObjWithTenantId [ cmdName ] = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId [ cmdName ] ) ; } switch ( cmdName ) { case "renameCollection" : cmdObjWithTenantId . to = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId . to ) ; break ; case "internalRenameIfOptionsAndIndexesMatch" : cmdObjWithTenantId . from = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId . from ) ; cmdObjWithTenantId . to = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId . to ) ; break ; case "configureFailPoint" : if ( cmdObjWithTenantId . data ) { if ( cmdObjWithTenantId . data . namespace ) { cmdObjWithTenantId . data . namespace = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId . data . namespace ) ; } else if ( cmdObjWithTenantId . data . ns ) { cmdObjWithTenantId . data . ns = prependTenantIdToNsIfApplicable ( cmdObjWithTenantId . data . ns ) ; } } break ; case "applyOps" : for ( let op of cmdObjWithTenantId . applyOps ) { if ( typeof op . ns === "string" && op . ns . endsWith ( "system.views" ) && op . o . _id && typeof op . o . _id === "string" ) { op . o . _id = prependTenantIdToNsIfApplicable ( op . o . _id ) ; } } break ; default : break ; } if ( cmdName != "configureFailPoint" ) { prependTenantId ( cmdObjWithTenantId ) ; } cmdObjWithTenantId . comment = Object . assign ( cmdObjWithTenantId . comment ? cmdObjWithTenantId . comment : { } , { isCmdObjWithTenantId : true } ) ; return cmdObjWithTenantId ; }
Prepend a tenant prefix to all namespaces within a provided command object, and record a comment
 indicating that the command object has alrady been modified.
Prepend a tenant prefix to all namespaces within a provided command object and record a comment indicating that the command object has alrady been modified .
// Handle commands with special database and namespace field names. // For views, op.ns and op.o._id must be equal. // Recursively override the database name and namespace fields. Exclude 'configureFailPoint' // since data.errorExtraInfo.namespace or data.errorExtraInfo.ns can sometimes refer to // collection name instead of namespace.