Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

[AutoPR graphrbac/data-plane] [GraphRBAC] Add delete owner #3832

Merged
merged 1 commit into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 217 additions & 0 deletions lib/services/graphManagement/lib/operations/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,135 @@ function _addOwner(applicationObjectId, parameters, options, callback) {
});
}

/**
* Remove a member from owners.
*
* @param {string} applicationObjectId The object ID of the application from
* which to remove the owner.
*
* @param {string} ownerObjectId Owner object id
*
* @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 _removeOwner(applicationObjectId, ownerObjectId, 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 (applicationObjectId === null || applicationObjectId === undefined || typeof applicationObjectId.valueOf() !== 'string') {
throw new Error('applicationObjectId cannot be null or undefined and it must be of type string.');
}
if (ownerObjectId === null || ownerObjectId === undefined || typeof ownerObjectId.valueOf() !== 'string') {
throw new Error('ownerObjectId 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}/applications/{applicationObjectId}/$links/owners/{ownerObjectId}';
requestUrl = requestUrl.replace('{applicationObjectId}', encodeURIComponent(applicationObjectId));
requestUrl = requestUrl.replace('{ownerObjectId}', encodeURIComponent(ownerObjectId));
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);
});
}

/**
* Get the keyCredentials associated with an application.
*
Expand Down Expand Up @@ -1925,6 +2054,7 @@ class Applications {
this._patch = _patch;
this._listOwners = _listOwners;
this._addOwner = _addOwner;
this._removeOwner = _removeOwner;
this._listKeyCredentials = _listKeyCredentials;
this._updateKeyCredentials = _updateKeyCredentials;
this._listPasswordCredentials = _listPasswordCredentials;
Expand Down Expand Up @@ -2663,6 +2793,93 @@ class Applications {
}
}

/**
* Remove a member from owners.
*
* @param {string} applicationObjectId The object ID of the application from
* which to remove the owner.
*
* @param {string} ownerObjectId Owner object id
*
* @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<null>} - The deserialized result object.
*
* @reject {Error} - The error object.
*/
removeOwnerWithHttpOperationResponse(applicationObjectId, ownerObjectId, options) {
let client = this.client;
let self = this;
return new Promise((resolve, reject) => {
self._removeOwner(applicationObjectId, ownerObjectId, options, (err, result, request, response) => {
let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
httpOperationResponse.body = result;
if (err) { reject(err); }
else { resolve(httpOperationResponse); }
return;
});
});
}

/**
* Remove a member from owners.
*
* @param {string} applicationObjectId The object ID of the application from
* which to remove the owner.
*
* @param {string} ownerObjectId Owner object id
*
* @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.
*/
removeOwner(applicationObjectId, ownerObjectId, 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._removeOwner(applicationObjectId, ownerObjectId, options, (err, result, request, response) => {
if (err) { reject(err); }
else { resolve(result); }
return;
});
});
} else {
return self._removeOwner(applicationObjectId, ownerObjectId, options, optionalCallback);
}
}

/**
* Get the keyCredentials associated with an application.
*
Expand Down
Loading