Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Log Streams #518

Merged
merged 2 commits into from
Aug 24, 2020
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
179 changes: 179 additions & 0 deletions src/management/LogStreamsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');
var Auth0RestClient = require('../Auth0RestClient');
var RetryRestClient = require('../RetryRestClient');

/**
* @class LogStreamsManager
* The logStreams class provides a simple abstraction for performing CRUD operations
* on Auth0 Log Streams.
* @constructor
* @memberOf module:management
*
* @param {Object} options The client options.
* @param {String} options.baseUrl The URL of the API.
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
var LogStreamsManager = function(options) {
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide client options');
}

if (options.baseUrl === null || options.baseUrl === undefined) {
throw new ArgumentError('Must provide a base URL for the API');
}

if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
throw new ArgumentError('The provided base URL is invalid');
}

/**
* Options object for the Rest Client instance.
*
* @type {Object}
*/
var clientOptions = {
headers: options.headers,
query: { repeatParams: false }
};

/**
* Provides an abstraction layer for performing CRUD operations on
* {@link https://auth0.com/docs/api/management/v2#!/Log_Streams Auth0
* Log Streams}.
*
* @type {external:RestClient}
*/
var auth0RestClient = new Auth0RestClient(
options.baseUrl + '/log-streams/:id ',
clientOptions,
options.tokenProvider
);
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};

/**
* Get all Log Streams.
*
* @method getAll
* @memberOf module:management.LogStreamsManager.prototype
*
* @example
*
* management.logStreams.getAll(function (err, logStreams) {
* console.log(logStreams.length);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(LogStreamsManager, 'getAll', 'resource.getAll');

/**
* Get an Auth0 Log Streams.
*
* @method get
* @memberOf module:management.LogStreamsManager.prototype
*
* @example
* management.logStreams.get({ id: LOG_STREAM_ID }, function (err, logStream) {
* if (err) {
* // Handle error.
* }
*
* console.log(logStream);
* });
*
* @param {Object} params Log Stream parameters.
* @param {String} params.id Log Stream ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(LogStreamsManager, 'get', 'resource.get');

/**
* Create an Auth0 Log Stream.
*
* @method create
* @memberOf module:management.LogStreamsManager.prototype
*
* @example
* management.logStreams.create(data, function (err, log) {
* if (err) {
* // Handle error.
* }
*
* console.log(log);
* });
*
* @param {Object} data Log Stream data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(LogStreamsManager, 'create', 'resource.create');

/**
* Update an Auth0 Log Streams.
*
* @method update
* @memberOf module:management.LogStreamsManager.prototype
*
* @example
* var data = { name: 'New name' };
* var params = { id: LOG_STREAM_ID };
*
* // Using auth0 instance.
* management.updateLogStream(params, data, function (err, logStream) {
* if (err) {
* // Handle error.
* }
*
* console.log(logStream.name); // 'New name'
* });
*
* // Using the logStreams manager directly.
* management.logStreams.update(params, data, function (err, logStream) {
* if (err) {
* // Handle error.
* }
*
* console.log(logStream.name);
* });
*
* @param {Object} params Log Stream parameters.
* @param {String} params.id Log Stream ID.
* @param {Object} data Updated Log Stream data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(LogStreamsManager, 'update', 'resource.patch');

/**
* Delete an Auth0 Log Streams.
*
* @method delete
* @memberOf module:management.LogStreamsManager.prototype
*
* @example
* management.logStreams.delete({ id: LOG_STREAM_ID }, function (err, log) {
* if (err) {
* // Handle error.
* }
*
* console.log(log);
* });
*
* @param {Object} params Log Stream parameters.
* @param {String} params.id Log Stream ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(LogStreamsManager, 'delete', 'resource.delete');

module.exports = LogStreamsManager;
120 changes: 120 additions & 0 deletions src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var TenantManager = require('./TenantManager');
var JobsManager = require('./JobsManager');
var TicketsManager = require('./TicketsManager');
var LogsManager = require('./LogsManager');
var LogStreamsManager = require('./LogStreamsManager');
var ResourceServersManager = require('./ResourceServersManager');
var ManagementTokenProvider = require('./ManagementTokenProvider');
var RulesConfigsManager = require('./RulesConfigsManager');
Expand Down Expand Up @@ -282,6 +283,13 @@ var ManagementClient = function(options) {
*/
this.logs = new LogsManager(managerOptions);

/**
* Log Streams manager.
*
* @type {LogStreamsManager}
*/
this.logStreams = new LogStreamsManager(managerOptions);

/**
* Simple abstraction for performing CRUD operations on the
* resource servers endpoint.
Expand Down Expand Up @@ -2246,6 +2254,118 @@ utils.wrapPropertyMethod(ManagementClient, 'getLog', 'logs.get');
*/
utils.wrapPropertyMethod(ManagementClient, 'getLogs', 'logs.getAll');

/**
* Get all Log Streams.
*
* @method getLogStreams
* @memberOf module:management.ManagementClient.prototype
*
*
*
* management.getLogStreams( function (err, logStreams) {
* console.log(logStreams.length);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'getLogStreams', 'logStreams.getAll');

/**
* Create a new Log Stream.
*
* @method createLogStream
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.createLogStream(data, function (err) {
* if (err) {
* // Handle error.
* }
*
* // Log Stream created.
* });
*
* @param {Object} data Log Stream data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'createLogStream', 'logStreams.create');

/**
* Get an Auth0 Log Stream.
*
* @method getLogStream
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getLogStream({ id: LOG_STREAM_ID }, function (err, logStream) {
* if (err) {
* // Handle error.
* }
*
* console.log(logStream);
* });
*
* @param {Object} params Log Stream parameters.
* @param {String} params.id Log Stream ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'getLogStream', 'logStreams.get');

/**
* Delete an existing Log Stream.
*
* @method deleteLogStream
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.deleteLogStream({ id: LOG_STREAM_ID }, function (err) {
* if (err) {
* // Handle error.
* }
*
* // Log Stream deleted.
* });
*
* @param {Object} params Log Stream parameters.
* @param {String} params.id Log Stream ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'deleteLogStream', 'logStreams.delete');

/**
* Update an existing Log Stream.
*
* @method updateLogStream
* @memberOf module:management.ManagementClient.prototype
*
* @example
* var params = { id: LOG_STREAM_ID };
* var data = { name: 'my-log-stream'};
* management.updateLogStream(params, data, function (err, logStream) {
* if (err) {
* // Handle error.
* }
*
* console.log(logStream.name); // 'my-log-stream'.
* });
*
* @param {Object} params Rule parameters.
* @param {String} params.id Rule ID.
* @param {Object} data Updated rule data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'updateLogStream', 'logStreams.update');

/**
* Create a new resource server.
*
Expand Down
Loading