diff --git a/lib/services/graphManagement/LICENSE.txt b/lib/services/graphManagement/LICENSE.txt index 5431ba98b9..8f3d856145 100644 --- a/lib/services/graphManagement/LICENSE.txt +++ b/lib/services/graphManagement/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Microsoft +Copyright (c) 2019 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/services/graphManagement/lib/models/index.d.ts b/lib/services/graphManagement/lib/models/index.d.ts index bf32a0bed7..749103186d 100644 --- a/lib/services/graphManagement/lib/models/index.d.ts +++ b/lib/services/graphManagement/lib/models/index.d.ts @@ -897,6 +897,10 @@ export interface Permissions { * The objectId of the Service Principal associated with the app */ clientId?: string; + /** + * The objectId of the permission grant + */ + objectId?: string; /** * Typically set to AllPrincipals */ @@ -1002,3 +1006,13 @@ export interface UserGetMemberGroupsResult extends Array { */ export interface DomainListResult extends Array { } + +/** + * Server response for get permissions grants +*/ +export interface PermissionsListResult extends Array { + /** + * the URL to get the next set of results. + */ + odatanextLink?: string; +} diff --git a/lib/services/graphManagement/lib/models/index.js b/lib/services/graphManagement/lib/models/index.js index f0927b9540..bf72df9a92 100644 --- a/lib/services/graphManagement/lib/models/index.js +++ b/lib/services/graphManagement/lib/models/index.js @@ -60,6 +60,7 @@ exports.ServicePrincipalListResult = require('./servicePrincipalListResult'); exports.UserListResult = require('./userListResult'); exports.UserGetMemberGroupsResult = require('./userGetMemberGroupsResult'); exports.DomainListResult = require('./domainListResult'); +exports.PermissionsListResult = require('./permissionsListResult'); exports.discriminators = { 'DirectoryObject' : exports.DirectoryObject, 'DirectoryObject.Application' : exports.Application, diff --git a/lib/services/graphManagement/lib/models/permissions.js b/lib/services/graphManagement/lib/models/permissions.js index 815cb2d112..7d35d353c3 100644 --- a/lib/services/graphManagement/lib/models/permissions.js +++ b/lib/services/graphManagement/lib/models/permissions.js @@ -20,6 +20,7 @@ class Permissions { * Microsoft.DirectoryServices.OAuth2PermissionGrant * @property {string} [clientId] The objectId of the Service Principal * associated with the app + * @property {string} [objectId] The objectId of the permission grant * @property {string} [consentType] Typically set to AllPrincipals * @property {object} [principalId] Set to null if AllPrincipals is set * @property {string} [resourceId] Service Principal Id of the resource you @@ -59,6 +60,13 @@ class Permissions { name: 'String' } }, + objectId: { + required: false, + serializedName: 'objectId', + type: { + name: 'String' + } + }, consentType: { required: false, serializedName: 'consentType', diff --git a/lib/services/graphManagement/lib/models/permissionsListResult.js b/lib/services/graphManagement/lib/models/permissionsListResult.js new file mode 100644 index 0000000000..321486b7c7 --- /dev/null +++ b/lib/services/graphManagement/lib/models/permissionsListResult.js @@ -0,0 +1,67 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * Server response for get permissions grants + */ +class PermissionsListResult extends Array { + /** + * Create a PermissionsListResult. + * @property {string} [odatanextLink] the URL to get the next set of results. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of PermissionsListResult + * + * @returns {object} metadata of PermissionsListResult + * + */ + mapper() { + return { + required: false, + serializedName: 'PermissionsListResult', + type: { + name: 'Composite', + className: 'PermissionsListResult', + modelProperties: { + value: { + required: false, + serializedName: '', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'PermissionsElementType', + type: { + name: 'Composite', + className: 'Permissions' + } + } + } + }, + odatanextLink: { + required: false, + serializedName: 'odata\\.nextLink', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = PermissionsListResult; diff --git a/lib/services/graphManagement/lib/operations/index.d.ts b/lib/services/graphManagement/lib/operations/index.d.ts index 89ac79ab51..d37d244c67 100644 --- a/lib/services/graphManagement/lib/operations/index.d.ts +++ b/lib/services/graphManagement/lib/operations/index.d.ts @@ -3988,7 +3988,7 @@ export interface OAuth2 { /** - * Queries OAuth2 permissions for the relevant SP ObjectId of an app. + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. * * @param {object} [options] Optional Parameters. * @@ -4000,14 +4000,14 @@ export interface OAuth2 { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getWithHttpOperationResponse(options?: { filter? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + getWithHttpOperationResponse(options?: { filter? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; /** - * Queries OAuth2 permissions for the relevant SP ObjectId of an app. + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. * * @param {object} [options] Optional Parameters. * @@ -4024,7 +4024,7 @@ export interface OAuth2 { * * {Promise} A promise is returned. * - * @resolve {Permissions} - The deserialized result object. + * @resolve {PermissionsListResult} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -4032,16 +4032,16 @@ export interface OAuth2 { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {Permissions} [result] - The deserialized result object if an error did not occur. - * See {@link Permissions} for more information. + * {PermissionsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. * * {WebResource} [request] - The HTTP Request object if an error did not occur. * * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. */ - get(options?: { filter? : string, customHeaders? : { [headerName: string]: string; } }): Promise; - get(callback: ServiceCallback): void; - get(options: { filter? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(options?: { filter? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + get(callback: ServiceCallback): void; + get(options: { filter? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -4058,6 +4058,8 @@ export interface OAuth2 { * @param {string} [options.body.clientId] The objectId of the Service * Principal associated with the app * + * @param {string} [options.body.objectId] The objectId of the permission grant + * * @param {string} [options.body.consentType] Typically set to AllPrincipals * * @param {object} [options.body.principalId] Set to null if AllPrincipals is @@ -4097,6 +4099,8 @@ export interface OAuth2 { * @param {string} [options.body.clientId] The objectId of the Service * Principal associated with the app * + * @param {string} [options.body.objectId] The objectId of the permission grant + * * @param {string} [options.body.consentType] Typically set to AllPrincipals * * @param {object} [options.body.principalId] Set to null if AllPrincipals is @@ -4139,4 +4143,115 @@ export interface OAuth2 { grant(options?: { body? : models.Permissions, customHeaders? : { [headerName: string]: string; } }): Promise; grant(callback: ServiceCallback): void; grant(options: { body? : models.Permissions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Delete a OAuth2 permission grant for the relevant resource Ids of an app. + * + * @param {string} objectId The object ID of a permission grant. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + deleteMethodWithHttpOperationResponse(objectId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Delete a OAuth2 permission grant for the relevant resource Ids of an app. + * + * @param {string} objectId The object ID of a permission grant. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + deleteMethod(objectId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + deleteMethod(objectId: string, callback: ServiceCallback): void; + deleteMethod(objectId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + getNextWithHttpOperationResponse(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {PermissionsListResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {PermissionsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + getNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getNext(nextPageLink: string, callback: ServiceCallback): void; + getNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } diff --git a/lib/services/graphManagement/lib/operations/oAuth2.js b/lib/services/graphManagement/lib/operations/oAuth2.js index c9d2fe0aeb..f575f193a8 100644 --- a/lib/services/graphManagement/lib/operations/oAuth2.js +++ b/lib/services/graphManagement/lib/operations/oAuth2.js @@ -15,7 +15,7 @@ const msRestAzure = require('ms-rest-azure'); const WebResource = msRest.WebResource; /** - * Queries OAuth2 permissions for the relevant SP ObjectId of an app. + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. * * @param {object} [options] Optional Parameters. * @@ -32,7 +32,7 @@ const WebResource = msRest.WebResource; * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. - * See {@link Permissions} for more information. + * See {@link PermissionsListResult} for more information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -142,7 +142,7 @@ function _get(options, callback) { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { - let resultMapper = new client.models['Permissions']().mapper(); + let resultMapper = new client.models['PermissionsListResult']().mapper(); result = client.deserialize(resultMapper, parsedResponse, 'result'); } } catch (error) { @@ -171,6 +171,8 @@ function _get(options, callback) { * @param {string} [options.body.clientId] The objectId of the Service * Principal associated with the app * + * @param {string} [options.body.objectId] The objectId of the permission grant + * * @param {string} [options.body.consentType] Typically set to AllPrincipals * * @param {object} [options.body.principalId] Set to null if AllPrincipals is @@ -328,6 +330,255 @@ function _grant(options, callback) { }); } +/** + * Delete a OAuth2 permission grant for the relevant resource Ids of an app. + * + * @param {string} objectId The object ID of a permission grant. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _deleteMethod(objectId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (objectId === null || objectId === undefined || typeof objectId.valueOf() !== 'string') { + throw new Error('objectId cannot be null or undefined and it must be of type string.'); + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (this.client.tenantID === null || this.client.tenantID === undefined || typeof this.client.tenantID.valueOf() !== 'string') { + throw new Error('this.client.tenantID cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{tenantID}/oauth2PermissionGrants/{objectId}'; + requestUrl = requestUrl.replace('{objectId}', encodeURIComponent(objectId)); + requestUrl = requestUrl.replace('{tenantID}', encodeURIComponent(this.client.tenantID)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'DELETE'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 204) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['GraphError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + + return callback(null, result, httpRequest, response); + }); +} + +/** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _getNext(nextPageLink, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['PermissionsListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + /** Class representing a OAuth2. */ class OAuth2 { /** @@ -338,10 +589,12 @@ class OAuth2 { this.client = client; this._get = _get; this._grant = _grant; + this._deleteMethod = _deleteMethod; + this._getNext = _getNext; } /** - * Queries OAuth2 permissions for the relevant SP ObjectId of an app. + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. * * @param {object} [options] Optional Parameters. * @@ -353,7 +606,7 @@ class OAuth2 { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ @@ -372,7 +625,7 @@ class OAuth2 { } /** - * Queries OAuth2 permissions for the relevant SP ObjectId of an app. + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. * * @param {object} [options] Optional Parameters. * @@ -389,7 +642,7 @@ class OAuth2 { * * {Promise} A promise is returned * - * @resolve {Permissions} - The deserialized result object. + * @resolve {PermissionsListResult} - The deserialized result object. * * @reject {Error} - The error object. * @@ -398,7 +651,7 @@ class OAuth2 { * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. - * See {@link Permissions} for more information. + * See {@link PermissionsListResult} for more information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -438,6 +691,8 @@ class OAuth2 { * @param {string} [options.body.clientId] The objectId of the Service * Principal associated with the app * + * @param {string} [options.body.objectId] The objectId of the permission grant + * * @param {string} [options.body.consentType] Typically set to AllPrincipals * * @param {object} [options.body.principalId] Set to null if AllPrincipals is @@ -489,6 +744,8 @@ class OAuth2 { * @param {string} [options.body.clientId] The objectId of the Service * Principal associated with the app * + * @param {string} [options.body.objectId] The objectId of the permission grant + * * @param {string} [options.body.consentType] Typically set to AllPrincipals * * @param {object} [options.body.principalId] Set to null if AllPrincipals is @@ -548,6 +805,171 @@ class OAuth2 { } } + /** + * Delete a OAuth2 permission grant for the relevant resource Ids of an app. + * + * @param {string} objectId The object ID of a permission grant. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + deleteMethodWithHttpOperationResponse(objectId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(objectId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Delete a OAuth2 permission grant for the relevant resource Ids of an app. + * + * @param {string} objectId The object ID of a permission grant. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {null} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + deleteMethod(objectId, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._deleteMethod(objectId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(objectId, options, optionalCallback); + } + } + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {PermissionsListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + getNext(nextPageLink, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._getNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getNext(nextPageLink, options, optionalCallback); + } + } + } module.exports = OAuth2; diff --git a/lib/services/graphManagement/lib/operations/permissionsGrants.js b/lib/services/graphManagement/lib/operations/permissionsGrants.js new file mode 100644 index 0000000000..fa6a12ead3 --- /dev/null +++ b/lib/services/graphManagement/lib/operations/permissionsGrants.js @@ -0,0 +1,241 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const msRest = require('ms-rest'); +const msRestAzure = require('ms-rest-azure'); +const WebResource = msRest.WebResource; + +/** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listNext(nextPageLink, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['PermissionsListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a PermissionsGrants. */ +class PermissionsGrants { + /** + * Create a PermissionsGrants. + * @param {GraphRbacManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._listNext = _listNext; + } + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Queries OAuth2 permissions grants for the relevant SP ObjectId of an app. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {PermissionsListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link PermissionsListResult} for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listNext(nextPageLink, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listNext(nextPageLink, options, optionalCallback); + } + } + +} + +module.exports = PermissionsGrants;