/* * 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 * as coreClient from "@azure/core-client"; import * as coreRestPipeline from "@azure/core-rest-pipeline"; import { PipelineRequest, PipelineResponse, SendRequest } from "@azure/core-rest-pipeline"; import * as coreAuth from "@azure/core-auth"; import { OperationsImpl, GrantsImpl, LabsImpl, JoinRequestsImpl, StudentsImpl, StudentLabsImpl } from "./operations"; import { Operations, Grants, Labs, JoinRequests, Students, StudentLabs } from "./operationsInterfaces"; import * as Parameters from "./models/parameters"; import * as Mappers from "./models/mappers"; import { EducationManagementClientOptionalParams, RedeemRequest, RedeemInvitationCodeOptionalParams } from "./models"; export class EducationManagementClient extends coreClient.ServiceClient { $host: string; apiVersion: string; /** * Initializes a new instance of the EducationManagementClient class. * @param credentials Subscription credentials which uniquely identify client subscription. * @param options The parameter options */ constructor( credentials: coreAuth.TokenCredential, options?: EducationManagementClientOptionalParams ) { if (credentials === undefined) { throw new Error("'credentials' cannot be null"); } // Initializing default values for options if (!options) { options = {}; } const defaults: EducationManagementClientOptionalParams = { requestContentType: "application/json; charset=utf-8", credential: credentials }; const packageDetails = `azsdk-js-arm-education/1.0.0-beta.3`; const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}` : `${packageDetails}`; const optionsWithDefaults = { ...defaults, ...options, userAgentOptions: { userAgentPrefix }, endpoint: options.endpoint ?? options.baseUri ?? "https://management.azure.com" }; super(optionsWithDefaults); let bearerTokenAuthenticationPolicyFound: boolean = false; if (options?.pipeline && options.pipeline.getOrderedPolicies().length > 0) { const pipelinePolicies: coreRestPipeline.PipelinePolicy[] = options.pipeline.getOrderedPolicies(); bearerTokenAuthenticationPolicyFound = pipelinePolicies.some( (pipelinePolicy) => pipelinePolicy.name === coreRestPipeline.bearerTokenAuthenticationPolicyName ); } if ( !options || !options.pipeline || options.pipeline.getOrderedPolicies().length == 0 || !bearerTokenAuthenticationPolicyFound ) { this.pipeline.removePolicy({ name: coreRestPipeline.bearerTokenAuthenticationPolicyName }); this.pipeline.addPolicy( coreRestPipeline.bearerTokenAuthenticationPolicy({ credential: credentials, scopes: optionsWithDefaults.credentialScopes ?? `${optionsWithDefaults.endpoint}/.default`, challengeCallbacks: { authorizeRequestOnChallenge: coreClient.authorizeRequestOnClaimChallenge } }) ); } // Assigning values to Constant parameters this.$host = options.$host || "https://management.azure.com"; this.apiVersion = options.apiVersion || "2021-12-01-preview"; this.operations = new OperationsImpl(this); this.grants = new GrantsImpl(this); this.labs = new LabsImpl(this); this.joinRequests = new JoinRequestsImpl(this); this.students = new StudentsImpl(this); this.studentLabs = new StudentLabsImpl(this); this.addCustomApiVersionPolicy(options.apiVersion); } /** A function that adds a policy that sets the api-version (or equivalent) to reflect the library version. */ private addCustomApiVersionPolicy(apiVersion?: string) { if (!apiVersion) { return; } const apiVersionPolicy = { name: "CustomApiVersionPolicy", async sendRequest( request: PipelineRequest, next: SendRequest ): Promise { const param = request.url.split("?"); if (param.length > 1) { const newParams = param[1].split("&").map((item) => { if (item.indexOf("api-version") > -1) { return "api-version=" + apiVersion; } else { return item; } }); request.url = param[0] + "?" + newParams.join("&"); } return next(request); } }; this.pipeline.addPolicy(apiVersionPolicy); } /** * Redeem invite code to join a redeemable lab * @param parameters Request parameters to provide redeem code. * @param options The options parameters. */ redeemInvitationCode( parameters: RedeemRequest, options?: RedeemInvitationCodeOptionalParams ): Promise { return this.sendOperationRequest( { parameters, options }, redeemInvitationCodeOperationSpec ); } operations: Operations; grants: Grants; labs: Labs; joinRequests: JoinRequests; students: Students; studentLabs: StudentLabs; } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const redeemInvitationCodeOperationSpec: coreClient.OperationSpec = { path: "/providers/Microsoft.Education/redeemInvitationCode", httpMethod: "POST", responses: { 200: {}, default: { bodyMapper: Mappers.ErrorResponseBody } }, requestBody: Parameters.parameters2, queryParameters: [Parameters.apiVersion], urlParameters: [Parameters.$host], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer };