How to use the node-opcua-status-code.StatusCodes.BadInvalidArgument function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server-discovery / src / opcua_discovery_server.js View on Github external
function __internalRegisterServer(RegisterServerXResponse, discoveryServer, server, discoveryConfiguration) {

    function sendError(statusCode) {
        ///Xx xconsole.log(chalk.red("_on_RegisterServerRequest error"), statusCode.toString());
        const response = new RegisterServerXResponse({responseHeader: {serviceResult: statusCode}});
        return response;
    }

    // check serverType is valid
    if (!_isValidServerType(server.serverType)) {
        return sendError(StatusCodes.BadInvalidArgument);
    }

    // BadServerUriInvalid
    // TODO

    // BadServerNameMissing
    if (server.serverNames.length === 0) {
        return sendError(StatusCodes.BadServerNameMissing);
    }

    // BadDiscoveryUrlMissing
    if (server.discoveryUrls.length === 0) {
        return sendError(StatusCodes.BadDiscoveryUrlMissing);
    }

    const key = server.serverUri;
github node-opcua / node-opcua / packages / node-opcua-address-space / src / argument_list.js View on Github external
// it is possible to not provide inputArguments when method  has no arguments
        return {statusCode: StatusCodes.Good};
    }
    if (methodInputArguments.length > 0 && !inputArguments) {
         return {statusCode: StatusCodes.BadArgumentsMissing};
    }
    inputArguments = inputArguments ||[];
    if (methodInputArguments.length > inputArguments.length) {
        // istanbul ignore next
        if (doDebug) {
            console.log("xxxxxxxx verifyArguments_ArgumentList " +
                "\n       The client did  specify too many input arguments for the method.  " +
                "\n        expected : " +methodInputArguments.length + "" +
                "\n        actual   : " + inputArguments.length );
        }
        return {statusCode: StatusCodes.BadInvalidArgument};
    }

    if (methodInputArguments.length < inputArguments.length) {
        // istanbul ignore next
        if (doDebug) {
            console.log("xxxxxxxx verifyArguments_ArgumentList " +
                "\n        The client did not specify all of the input arguments for the method. " +
                "\n        expected : " + methodInputArguments.length + "" +
                "\n        actual   : " + inputArguments.length);
        }
        return {statusCode: StatusCodes.BadArgumentsMissing};
    }

    let errorCount = 0;
    for (let i = 0; i < methodInputArguments.length; i++) {
github node-opcua / node-opcua / packages / node-opcua-server-discovery / source / opcua_discovery_server.ts View on Github external
delete previousConfMap[discoveryConfiguration.mdnsServerName!];
                (discoveryConfiguration as any).bonjourHolder = prevConf.bonjourHolder;
            }

            // let's announce the server on the  multicast DNS
            await _announcedOnMulticastSubnet(discoveryConfiguration, announcement);
            return StatusCodes.Good;
        }

        // check serverType is valid
        if (!_isValidServerType(server.serverType)) {
            return sendError(StatusCodes.BadInvalidArgument);
        }

        if (!server.serverUri) {
            return sendError(StatusCodes.BadInvalidArgument);
        }

        // BadServerUriInvalid
        // TODO
        server.serverNames = server.serverNames || [];
        // BadServerNameMissing
        if (server.serverNames.length === 0) {
            return sendError(StatusCodes.BadServerNameMissing);
        }

        // BadDiscoveryUrlMissing
        server.discoveryUrls = server.discoveryUrls || [];
        if (server.discoveryUrls.length === 0) {
            return sendError(StatusCodes.BadDiscoveryUrlMissing);
        }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / argument_list.js View on Github external
if (doDebug) {
                console.log("xxxxxxxx verifyArguments_ArgumentList \n" +
                            "         The client did specify a argument with the wrong data type.\n" +
                            "          expected : ".white + argDefinition.dataType + "\n" +
                            "          actual   :".cyan + arg.dataType);
            }
            inputArgumentResults.push(StatusCodes.BadTypeMismatch);
            errorCount += 1;
        } else {
            inputArgumentResults.push(StatusCodes.Good);
        }
    }
    assert(inputArgumentResults.length === methodInputArguments.length);

    const ret = {
        statusCode: errorCount === 0 ? StatusCodes.Good : StatusCodes.BadInvalidArgument,
        inputArgumentResults: inputArgumentResults
    };

    return ret;
}
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / push_certificate_manager_helpers.ts View on Github external
const nonceVariant = inputArguments[4];

    if (!expected(certificateGroupIdVariant, DataType.NodeId, VariantArrayType.Scalar)) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }
    if (!expected(certificateTypeIdVariant, DataType.NodeId, VariantArrayType.Scalar)) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }
    if (!expected(subjectNameVariant, DataType.String, VariantArrayType.Scalar)) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }
    if (!expected(regeneratePrivateKeyVariant, DataType.Boolean, VariantArrayType.Scalar)) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }
    if (!expected(regeneratePrivateKeyVariant, DataType.Boolean, VariantArrayType.Scalar)) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }

    if (!hasEncryptedChannel(context)) {
        return { statusCode: StatusCodes.BadSecurityModeInsufficient };
    }

    if (!hasExpectedUserAccess(context)) {
        return { statusCode: StatusCodes.BadUserAccessDenied };
    }

    const certificateGroupId = certificateGroupIdVariant.value as NodeId;
    const certificateTypeId = certificateTypeIdVariant.value as NodeId;
    const subjectName = subjectNameVariant.value as string;
    const regeneratePrivateKey = regeneratePrivateKeyVariant.value as boolean;
    const nonce = nonceVariant.value as Buffer;
github node-opcua / node-opcua / packages / node-opcua-address-space / source / helpers / argument_list.ts View on Github external
debugLog("verifyArguments_ArgumentList \n" +
                  "         The client did specify a argument with the wrong data type.\n" +
                  chalk.white("          expected : ") + argDefinition.dataType + "\n" +
                  chalk.cyan("          actual   :") + arg.dataType);
            }
            inputArgumentResults.push(StatusCodes.BadTypeMismatch);
            errorCount += 1;
        } else {
            inputArgumentResults.push(StatusCodes.Good);
        }
    }
    assert(inputArgumentResults.length === methodInputArguments.length);

    const ret = {
        inputArgumentResults,
        statusCode: errorCount === 0 ? StatusCodes.Good : StatusCodes.BadInvalidArgument
    };

    return ret;
}
github node-opcua / node-opcua / packages / node-opcua-file-transfer / source / server / file_type_helpers.ts View on Github external
async function _setPositionFile(
    this: UAMethod,
    inputArguments: Variant[],
    context: SessionContext
): Promise {

    const addressSpace = this.addressSpace;

    const fileHandle: UInt32 = inputArguments[0].value as UInt32;
    const position: UInt64 = inputArguments[1].value as UInt64;

    const _fileInfo = _getFileInfo(addressSpace, context, fileHandle);
    if (!_fileInfo) {
        return { statusCode: StatusCodes.BadInvalidArgument };
    }
    _fileInfo.position = position;
    return { statusCode: StatusCodes.Good };
}