How to use the ms-rest.WebResource function in ms-rest

To help you get started, we’ve selected a few ms-rest 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 microsoft / vscode-iot-workbench / src / Models / AzureUtility.ts View on Github external
static async request(
      // tslint:disable-next-line: no-any
      method: HttpMethods, resource: string, body: any = null) {
    const session = await AzureUtility._getSession();
    if (!session) {
      return undefined;
    }

    const credential = session.credentials;
    const httpRequest = new WebResource();
    httpRequest.method = method;
    httpRequest.url = 'https://management.azure.com' + resource;
    httpRequest.body = body;
    if (method === 'GET' || method === 'DELETE') {
      delete httpRequest.body;
    }

    const httpRequestOption: (rq.UrlOptions&request.RequestPromiseOptions) =
        httpRequest;
    httpRequestOption.simple = false;
    httpRequestOption.json = true;

    return new Promise((resolve, reject) => {
      credential.signRequest(httpRequest, async err => {
        if (!err) {
          const res = await request(httpRequestOption);
github microsoft / vscode-azuretools / appservice / src / startStreamingLogs.ts View on Github external
const kuduClient: KuduClient = await getKuduClient(client);
    const logStreamId: string = getLogStreamId(client, logsPath);
    const logStream: ILogStream | undefined = logStreams.get(logStreamId);
    if (logStream && logStream.isConnected) {
        logStream.outputChannel.show();
        // tslint:disable-next-line:no-floating-promises
        ext.ui.showWarningMessage(localize('logStreamAlreadyActive', 'The log-streaming service for "{0}" is already active.', logStreamLabel));
        return logStream;
    } else {
        await verifyLoggingEnabled();

        const outputChannel: vscode.OutputChannel = logStream ? logStream.outputChannel : vscode.window.createOutputChannel(localize('logStreamLabel', '{0} - Log Stream', logStreamLabel));
        ext.context.subscriptions.push(outputChannel);
        outputChannel.show();
        outputChannel.appendLine(localize('connectingToLogStream', 'Connecting to log stream...'));
        const httpRequest: WebResource = new WebResource();
        await signRequest(httpRequest, kuduClient.credentials);

        const requestApi: request.RequestAPI = request.defaults(httpRequest);
        return await new Promise((onLogStreamCreated: (ls: ILogStream) => void): void => {
            // Intentionally setting up a separate telemetry event and not awaiting the result here since log stream is a long-running action
            // tslint:disable-next-line:no-floating-promises
            callWithTelemetryAndErrorHandling('appService.streamingLogs', async function (this: IActionContext): Promise {
                this.suppressErrorDisplay = true;
                let timerId: NodeJS.Timer | undefined;
                if (client.isFunctionApp) {
                    // For Function Apps, we have to ping "/admin/host/status" every minute for logging to work
                    // https://github.com/Microsoft/vscode-azurefunctions/issues/227
                    await pingFunctionApp(client);
                    timerId = setInterval(async () => await pingFunctionApp(client), 60 * 1000);
                }
github microsoft / vscode-azure-blockchain-ethereum / src / ARMBlockchain / AzureBlockchainServiceClient.ts View on Github external
public getHttpRequest(url: string, method: HttpMethods, body?: string): WebResource {
    const httpRequest = new WebResource();

    httpRequest.method = method;
    httpRequest.url = url;
    httpRequest.headers = {};

    httpRequest.headers['Content-Type'] = Constants.azureResourceExplorer.contentType;
    if (this.options && this.options.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = uuid.v4();
    }
    if (this.options && this.options.acceptLanguage) {
      httpRequest.headers['accept-language'] = this.options.acceptLanguage;
    }

    httpRequest.body = body;

    return httpRequest;
github Azure / oav / lib / wireFormatGenerator.ts View on Github external
}
    }

    if (options.headers) {
      if (options.headers["content-type"]) {
        const val = delete options.headers["content-type"]
        options.headers["Content-Type"] = val
      }
      if (!options.headers["Content-Type"]) {
        options.headers["Content-Type"] = utils.getJsonContentType(operation.consumes)
      }
    } else {
      options.headers = {}
      options.headers["Content-Type"] = utils.getJsonContentType(operation.consumes)
    }
    return new msRest.WebResource().prepare(options)
  }
github microsoft / vscode-azurelogicapps / src / utils / authorizationUtils.ts View on Github external
return new Promise((resolve, reject) => {
        const webResource = new WebResource();
        credentials.signRequest(webResource, (err: Error | undefined): void => {
            if (err) {
                reject(err);
            } else {
                resolve(webResource.headers.authorization);
            }
        });
    });
}