/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging";
import { setContinuationToken } from "../pagingHelper";
import { FileImports } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { SecurityInsights } from "../securityInsights";
import { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro";
import { LroImpl } from "../lroImpl";
import {
FileImport,
FileImportsListNextOptionalParams,
FileImportsListOptionalParams,
FileImportsListResponse,
FileImportsGetOptionalParams,
FileImportsGetResponse,
FileImportsCreateOptionalParams,
FileImportsCreateResponse,
FileImportsDeleteOptionalParams,
FileImportsDeleteResponse,
FileImportsListNextResponse
} from "../models";
///
/** Class containing FileImports operations. */
export class FileImportsImpl implements FileImports {
private readonly client: SecurityInsights;
/**
* Initialize a new instance of the class FileImports class.
* @param client Reference to the service client
*/
constructor(client: SecurityInsights) {
this.client = client;
}
/**
* Gets all file imports.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param options The options parameters.
*/
public list(
resourceGroupName: string,
workspaceName: string,
options?: FileImportsListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(resourceGroupName, workspaceName, options);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage: (settings?: PageSettings) => {
if (settings?.maxPageSize) {
throw new Error("maxPageSize is not supported by this operation.");
}
return this.listPagingPage(
resourceGroupName,
workspaceName,
options,
settings
);
}
};
}
private async *listPagingPage(
resourceGroupName: string,
workspaceName: string,
options?: FileImportsListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: FileImportsListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(resourceGroupName, workspaceName, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
resourceGroupName,
workspaceName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
resourceGroupName: string,
workspaceName: string,
options?: FileImportsListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(
resourceGroupName,
workspaceName,
options
)) {
yield* page;
}
}
/**
* Gets all file imports.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param options The options parameters.
*/
private _list(
resourceGroupName: string,
workspaceName: string,
options?: FileImportsListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, options },
listOperationSpec
);
}
/**
* Gets a file import.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param fileImportId File import ID
* @param options The options parameters.
*/
get(
resourceGroupName: string,
workspaceName: string,
fileImportId: string,
options?: FileImportsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, fileImportId, options },
getOperationSpec
);
}
/**
* Creates the file import.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param fileImportId File import ID
* @param fileImport The file import
* @param options The options parameters.
*/
create(
resourceGroupName: string,
workspaceName: string,
fileImportId: string,
fileImport: FileImport,
options?: FileImportsCreateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, fileImportId, fileImport, options },
createOperationSpec
);
}
/**
* Delete the file import.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param fileImportId File import ID
* @param options The options parameters.
*/
async beginDelete(
resourceGroupName: string,
workspaceName: string,
fileImportId: string,
options?: FileImportsDeleteOptionalParams
): Promise<
PollerLike<
PollOperationState,
FileImportsDeleteResponse
>
> {
const directSendOperation = async (
args: coreClient.OperationArguments,
spec: coreClient.OperationSpec
): Promise => {
return this.client.sendOperationRequest(args, spec);
};
const sendOperation = async (
args: coreClient.OperationArguments,
spec: coreClient.OperationSpec
) => {
let currentRawResponse:
| coreClient.FullOperationResponse
| undefined = undefined;
const providedCallback = args.options?.onResponse;
const callback: coreClient.RawResponseCallback = (
rawResponse: coreClient.FullOperationResponse,
flatResponse: unknown
) => {
currentRawResponse = rawResponse;
providedCallback?.(rawResponse, flatResponse);
};
const updatedArgs = {
...args,
options: {
...args.options,
onResponse: callback
}
};
const flatResponse = await directSendOperation(updatedArgs, spec);
return {
flatResponse,
rawResponse: {
statusCode: currentRawResponse!.status,
body: currentRawResponse!.parsedBody,
headers: currentRawResponse!.headers.toJSON()
}
};
};
const lro = new LroImpl(
sendOperation,
{ resourceGroupName, workspaceName, fileImportId, options },
deleteOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs,
lroResourceLocationConfig: "location"
});
await poller.poll();
return poller;
}
/**
* Delete the file import.
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param fileImportId File import ID
* @param options The options parameters.
*/
async beginDeleteAndWait(
resourceGroupName: string,
workspaceName: string,
fileImportId: string,
options?: FileImportsDeleteOptionalParams
): Promise {
const poller = await this.beginDelete(
resourceGroupName,
workspaceName,
fileImportId,
options
);
return poller.pollUntilDone();
}
/**
* ListNext
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param workspaceName The name of the workspace.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
resourceGroupName: string,
workspaceName: string,
nextLink: string,
options?: FileImportsListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, workspaceName, nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/fileImports",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.FileImportList
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.filter,
Parameters.orderby,
Parameters.top,
Parameters.skipToken
],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/fileImports/{fileImportId}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.FileImport
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.fileImportId
],
headerParameters: [Parameters.accept],
serializer
};
const createOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/fileImports/{fileImportId}",
httpMethod: "PUT",
responses: {
201: {
bodyMapper: Mappers.FileImport
},
default: {
bodyMapper: Mappers.CloudError
}
},
requestBody: Parameters.fileImport,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.fileImportId
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OperationalInsights/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/fileImports/{fileImportId}",
httpMethod: "DELETE",
responses: {
200: {
bodyMapper: Mappers.FileImport
},
201: {
bodyMapper: Mappers.FileImport
},
202: {
bodyMapper: Mappers.FileImport
},
204: {
bodyMapper: Mappers.FileImport
},
default: {
bodyMapper: Mappers.CloudError
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.fileImportId
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.FileImportList
},
default: {
bodyMapper: Mappers.CloudError
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.workspaceName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};