/*
* 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 { Mediaservices } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { AzureMediaServices } from "../azureMediaServices";
import { PollerLike, PollOperationState, LroEngine } from "@azure/core-lro";
import { LroImpl } from "../lroImpl";
import {
MediaService,
MediaservicesListNextOptionalParams,
MediaservicesListOptionalParams,
MediaservicesListResponse,
MediaservicesListBySubscriptionNextOptionalParams,
MediaservicesListBySubscriptionOptionalParams,
MediaservicesListBySubscriptionResponse,
MediaservicesGetOptionalParams,
MediaservicesGetResponse,
MediaservicesCreateOrUpdateOptionalParams,
MediaservicesCreateOrUpdateResponse,
MediaservicesDeleteOptionalParams,
MediaServiceUpdate,
MediaservicesUpdateOptionalParams,
MediaservicesUpdateResponse,
SyncStorageKeysInput,
MediaservicesSyncStorageKeysOptionalParams,
ListEdgePoliciesInput,
MediaservicesListEdgePoliciesOptionalParams,
MediaservicesListEdgePoliciesResponse,
MediaservicesListNextResponse,
MediaservicesListBySubscriptionNextResponse
} from "../models";
///
/** Class containing Mediaservices operations. */
export class MediaservicesImpl implements Mediaservices {
private readonly client: AzureMediaServices;
/**
* Initialize a new instance of the class Mediaservices class.
* @param client Reference to the service client
*/
constructor(client: AzureMediaServices) {
this.client = client;
}
/**
* List Media Services accounts in the resource group
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param options The options parameters.
*/
public list(
resourceGroupName: string,
options?: MediaservicesListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(resourceGroupName, 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, options, settings);
}
};
}
private async *listPagingPage(
resourceGroupName: string,
options?: MediaservicesListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: MediaservicesListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(resourceGroupName, options);
let page = result.value || [];
continuationToken = result.odataNextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
resourceGroupName,
continuationToken,
options
);
continuationToken = result.odataNextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
resourceGroupName: string,
options?: MediaservicesListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(resourceGroupName, options)) {
yield* page;
}
}
/**
* List Media Services accounts in the subscription.
* @param options The options parameters.
*/
public listBySubscription(
options?: MediaservicesListBySubscriptionOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listBySubscriptionPagingAll(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.listBySubscriptionPagingPage(options, settings);
}
};
}
private async *listBySubscriptionPagingPage(
options?: MediaservicesListBySubscriptionOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: MediaservicesListBySubscriptionResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listBySubscription(options);
let page = result.value || [];
continuationToken = result.odataNextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listBySubscriptionNext(continuationToken, options);
continuationToken = result.odataNextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listBySubscriptionPagingAll(
options?: MediaservicesListBySubscriptionOptionalParams
): AsyncIterableIterator {
for await (const page of this.listBySubscriptionPagingPage(options)) {
yield* page;
}
}
/**
* List Media Services accounts in the resource group
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param options The options parameters.
*/
private _list(
resourceGroupName: string,
options?: MediaservicesListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, options },
listOperationSpec
);
}
/**
* Get the details of a Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param options The options parameters.
*/
get(
resourceGroupName: string,
accountName: string,
options?: MediaservicesGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, accountName, options },
getOperationSpec
);
}
/**
* Creates or updates a Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
async beginCreateOrUpdate(
resourceGroupName: string,
accountName: string,
parameters: MediaService,
options?: MediaservicesCreateOrUpdateOptionalParams
): Promise<
PollerLike<
PollOperationState,
MediaservicesCreateOrUpdateResponse
>
> {
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, accountName, parameters, options },
createOrUpdateOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Creates or updates a Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
async beginCreateOrUpdateAndWait(
resourceGroupName: string,
accountName: string,
parameters: MediaService,
options?: MediaservicesCreateOrUpdateOptionalParams
): Promise {
const poller = await this.beginCreateOrUpdate(
resourceGroupName,
accountName,
parameters,
options
);
return poller.pollUntilDone();
}
/**
* Deletes a Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param options The options parameters.
*/
delete(
resourceGroupName: string,
accountName: string,
options?: MediaservicesDeleteOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, accountName, options },
deleteOperationSpec
);
}
/**
* Updates an existing Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
async beginUpdate(
resourceGroupName: string,
accountName: string,
parameters: MediaServiceUpdate,
options?: MediaservicesUpdateOptionalParams
): Promise<
PollerLike<
PollOperationState,
MediaservicesUpdateResponse
>
> {
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, accountName, parameters, options },
updateOperationSpec
);
const poller = new LroEngine(lro, {
resumeFrom: options?.resumeFrom,
intervalInMs: options?.updateIntervalInMs
});
await poller.poll();
return poller;
}
/**
* Updates an existing Media Services account
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
async beginUpdateAndWait(
resourceGroupName: string,
accountName: string,
parameters: MediaServiceUpdate,
options?: MediaservicesUpdateOptionalParams
): Promise {
const poller = await this.beginUpdate(
resourceGroupName,
accountName,
parameters,
options
);
return poller.pollUntilDone();
}
/**
* Synchronizes storage account keys for a storage account associated with the Media Service account.
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
syncStorageKeys(
resourceGroupName: string,
accountName: string,
parameters: SyncStorageKeysInput,
options?: MediaservicesSyncStorageKeysOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, accountName, parameters, options },
syncStorageKeysOperationSpec
);
}
/**
* List all the media edge policies associated with the Media Services account.
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param accountName The Media Services account name.
* @param parameters The request parameters
* @param options The options parameters.
*/
listEdgePolicies(
resourceGroupName: string,
accountName: string,
parameters: ListEdgePoliciesInput,
options?: MediaservicesListEdgePoliciesOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, accountName, parameters, options },
listEdgePoliciesOperationSpec
);
}
/**
* List Media Services accounts in the subscription.
* @param options The options parameters.
*/
private _listBySubscription(
options?: MediaservicesListBySubscriptionOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ options },
listBySubscriptionOperationSpec
);
}
/**
* ListNext
* @param resourceGroupName The name of the resource group within the Azure subscription.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
resourceGroupName: string,
nextLink: string,
options?: MediaservicesListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ resourceGroupName, nextLink, options },
listNextOperationSpec
);
}
/**
* ListBySubscriptionNext
* @param nextLink The nextLink from the previous successful call to the ListBySubscription method.
* @param options The options parameters.
*/
private _listBySubscriptionNext(
nextLink: string,
options?: MediaservicesListBySubscriptionNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ nextLink, options },
listBySubscriptionNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.MediaServiceCollection
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.MediaService
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesCreateOrUpdateHeaders
},
201: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesCreateOrUpdateHeaders
},
202: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesCreateOrUpdateHeaders
},
204: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesCreateOrUpdateHeaders
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters1,
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}",
httpMethod: "DELETE",
responses: {
200: {},
204: {},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept],
serializer
};
const updateOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}",
httpMethod: "PATCH",
responses: {
200: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesUpdateHeaders
},
201: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesUpdateHeaders
},
202: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesUpdateHeaders
},
204: {
bodyMapper: Mappers.MediaService,
headersMapper: Mappers.MediaservicesUpdateHeaders
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters2,
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const syncStorageKeysOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/syncStorageKeys",
httpMethod: "POST",
responses: {
200: {},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters3,
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listEdgePoliciesOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/listEdgePolicies",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.EdgePolicies
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
requestBody: Parameters.parameters4,
queryParameters: [Parameters.apiVersion1],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.accountName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listBySubscriptionOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Media/mediaservices",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.MediaServiceCollection
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion1],
urlParameters: [Parameters.$host, Parameters.subscriptionId],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.MediaServiceCollection
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.resourceGroupName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};
const listBySubscriptionNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.MediaServiceCollection
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};