/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

// 
// Copyright (c) Microsoft and contributors.  All rights reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
// 

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

'use strict';

var util = require('util');
var uuid = require('node-uuid');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var DEFAULT_API_VERSION = '2015-06-01';
var API_VERSION_QUERY_PARAM = 'api-version=' + DEFAULT_API_VERSION;

var KeyVaultInternalClient = ( /** @lends KeyVaultInternalClient */ function() {
  /* (jsdoc off)
   * @class
   * Initializes a new instance of the KeyVaultInternalClient class.
   * @constructor
   * 
   * @param {KeyVaultCredential} credentials Gets or sets the credential
   * 
   * @param {string} [baseUri] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function KeyVaultInternalClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    KeyVaultInternalClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = null;
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = DEFAULT_API_VERSION;
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the [KeyOperations](-KeyOperations.html) object.
     * @type {object}
     */
    this.keys = new KeyOperations(this);
    /**
     * Provides an instance of the [SecretOperations](-SecretOperations.html)
     * object.
     * @type {object}
     */
    this.secrets = new SecretOperations(this);
  }
  
  util.inherits(KeyVaultInternalClient, Service);
  
  
  return KeyVaultInternalClient;
})();
exports.KeyVaultInternalClient = KeyVaultInternalClient;

var KeyOperations = ( /** @lends KeyOperations */ function() {
  /* (jsdoc off)
   * @class
   * Cryptographic and management operations for keys in a vault
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [KeyVaultInternalClient] {@link
   * KeyVaultInternalClient~KeyVaultInternalClient}.
   * See [keys] {@link KeyVaultInternalClient~KeyVaultInternalClient#keys}.
   * Initializes a new instance of the KeyOperations class.
   * @constructor
   * 
   * @param {KeyVaultInternalClient} client Reference to the service client.
   */
  function KeyOperations(client) {
    this.client = client;
  }
  
  /**
   * Requests that a backup of the specified key be downloaded to the client.
   * 
   * @param {string} keyIdentifier
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.backup = function(keyIdentifier, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/backup';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = '{}';
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.byteLength(requestContent, 'UTF8');
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Creates a new, named, key in the specified vault.
   * 
   * @param {string} vault
   * 
   * @param {string} keyName
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.create = function(vault, keyName, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    if (keyName === null || keyName === undefined) {
      return callback(new Error('keyName cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/keys/';
    url2 = url2 + encodeURIComponent(keyName);
    url2 = url2 + '/create';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Decrypts a single block of data.
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.decryptData = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/decrypt';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete the specified key
   * 
   * @param {string} vault
   * 
   * @param {string} keyName
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.deleteKey = function(vault, keyName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    if (keyName === null || keyName === undefined) {
      return callback(new Error('keyName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/keys/';
    url2 = url2 + encodeURIComponent(keyName);
    url2 = url2 + '/delete';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Encrypts a single block of data.
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.encryptData = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/encrypt';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Retrieves the public portion of a key plus its attributes
   * 
   * @param {string} keyIdentifier
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.get = function(keyIdentifier, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Imports a key into the specified vault
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.importMethod = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/import';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the keys in the vault
   * 
   * @param {string} vault
   * 
   * @param {Number} [top]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.list = function(vault, top, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/keys/';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (top !== null && top !== undefined) {
      queryParameters.push('maxresults=' + encodeURIComponent(top.toString()));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the next page of keys in the vault
   * 
   * @param {string} nextLink
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the versions of a key
   * 
   * @param {string} vault
   * 
   * @param {string} keyName
   * 
   * @param {Number} [top]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.listVersions = function(vault, keyName, top, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    if (keyName === null || keyName === undefined) {
      return callback(new Error('keyName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/keys/';
    url2 = url2 + encodeURIComponent(keyName);
    url2 = url2 + '/versions';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (top !== null && top !== undefined) {
      queryParameters.push('maxresults=' + encodeURIComponent(top.toString()));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the next page of versions of a key
   * 
   * @param {string} nextLink
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.listVersionsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Restores the backup key in to a vault
   * 
   * @param {string} vault
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.restore = function(vault, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/keys/restore';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Creates a signature from a digest using the specified key in the vault
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.sign = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/sign';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Unwraps a symmetric key using the specified key in the vault
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.unwrapKey = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/unwrapkey';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates the Key Attributes associated with the specified key
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.update = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/update';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Verifies a signature using the specified key
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.verify = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/verify';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Wraps a symmetric key using the specified key
   * 
   * @param {string} keyIdentifier
   * 
   * @param {KeyOpRequestMessageWithRawJsonContent} keyOpRequest
   * 
   * @param {string} [keyOpRequest.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  KeyOperations.prototype.wrapKey = function(keyIdentifier, keyOpRequest, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (keyIdentifier === null || keyIdentifier === undefined) {
      return callback(new Error('keyIdentifier cannot be null.'));
    }
    if (keyOpRequest === null || keyOpRequest === undefined) {
      return callback(new Error('keyOpRequest cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + keyIdentifier;
    url2 = url2 + '/wrapkey';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = keyOpRequest.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.keyOpResponse = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  return KeyOperations;
})();

var SecretOperations = ( /** @lends SecretOperations */ function() {
  /* (jsdoc off)
   * @class
   * Operations for secrets in a vault
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [KeyVaultInternalClient] {@link
   * KeyVaultInternalClient~KeyVaultInternalClient}.
   * See [secrets] {@link
   * KeyVaultInternalClient~KeyVaultInternalClient#secrets}.
   * Initializes a new instance of the SecretOperations class.
   * @constructor
   * 
   * @param {KeyVaultInternalClient} client Reference to the service client.
   */
  function SecretOperations(client) {
    this.client = client;
  }
  
  /**
   * Delete the specified secret
   * 
   * @param {string} secretIdentifier
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.deleteMethod = function(secretIdentifier, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (secretIdentifier === null || secretIdentifier === undefined) {
      return callback(new Error('secretIdentifier cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + secretIdentifier;
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a secret
   * 
   * @param {string} secretIdentifier
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.get = function(secretIdentifier, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (secretIdentifier === null || secretIdentifier === undefined) {
      return callback(new Error('secretIdentifier cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + secretIdentifier;
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the secrets in the specified vault
   * 
   * @param {string} vault
   * 
   * @param {Number} [top]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.list = function(vault, top, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/secrets/';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (top !== null && top !== undefined) {
      queryParameters.push('maxresults=' + encodeURIComponent(top.toString()));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the next page of secrets in the specified vault
   * 
   * @param {string} nextLink
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the versions of a secret in the specified vault
   * 
   * @param {string} vault
   * 
   * @param {string} secretName
   * 
   * @param {Number} [top]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.listVersions = function(vault, secretName, top, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (vault === null || vault === undefined) {
      return callback(new Error('vault cannot be null.'));
    }
    if (secretName === null || secretName === undefined) {
      return callback(new Error('secretName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + vault;
    url2 = url2 + '/secrets/';
    url2 = url2 + encodeURIComponent(secretName);
    url2 = url2 + '/versions';
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (top !== null && top !== undefined) {
      queryParameters.push('maxresults=' + encodeURIComponent(top.toString()));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * List the versions of a secret in the specified vault
   * 
   * @param {string} nextLink
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.listVersionsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Sets a secret in the specified vault.
   * 
   * @param {string} secretIdentifier
   * 
   * @param {SecretRequestMessageWithRawJsonContent} request
   * 
   * @param {string} [request.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.set = function(secretIdentifier, request, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (secretIdentifier === null || secretIdentifier === undefined) {
      return callback(new Error('secretIdentifier cannot be null.'));
    }
    if (request === null || request === undefined) {
      return callback(new Error('request cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + secretIdentifier;
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = request.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  /**
   * Update the specified secret
   * 
   * @param {string} secretIdentifier
   * 
   * @param {SecretRequestMessageWithRawJsonContent} request
   * 
   * @param {string} [request.rawJsonRequest]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SecretOperations.prototype.update = function(secretIdentifier, request, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (secretIdentifier === null || secretIdentifier === undefined) {
      return callback(new Error('secretIdentifier cannot be null.'));
    }
    if (request === null || request === undefined) {
      return callback(new Error('request cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + secretIdentifier;
    var queryParameters = [];
    queryParameters.push(API_VERSION_QUERY_PARAM);
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['client-request-id'] = uuid();
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = request.rawJsonRequest;
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      result.response = responseContent;
      
      result.statusCode = statusCode;
      
      return callback(null, result);
    });
  };
  
  return SecretOperations;
})();
