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

feat(guardian): support policies, selected-provider, message-types methods [MFA-310] #501

Merged
merged 3 commits into from
Jun 30, 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
174 changes: 174 additions & 0 deletions src/management/GuardianManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,48 @@ var GuardianManager = function(options) {
guardianFactorsProvidersAuth0RestClient,
options.retry
);

/**
* Provides an abstraction layer for retrieving Guardian policies.
*
* @type {external:RestClient}
*/
var guardianPoliciesAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/policies',
clientOptions,
options.tokenProvider
);
this.policies = new RetryRestClient(guardianPoliciesAuth0RestClient, options.retry);

/**
* Provides an abstraction layer for retrieving Guardian phone factor selected provider.
*
* @type {external:RestClient}
*/
var guardianFactorsPhoneSelectedProviderAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/sms/selected-provider',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed whether this should be /sms/selected-provider (the one that is already in production) or the new alias /phone/selected-provider (almost ready, but not available in PSaaS until July's release). To make the release smooth and ship this early, I opted to use the /sms/selected-provider. cc @joseluisdiaz

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, shall we create a task to change it in the future ?

clientOptions,
options.tokenProvider
);
this.factorsPhoneSelectedProvider = new RetryRestClient(
guardianFactorsPhoneSelectedProviderAuth0RestClient,
options.retry
);

/**
* Provides an abstraction layer for retrieving Guardian phone factor message types.
*
* @type {external:RestClient}
*/
var guardianFactorsPhoneMessageTypesAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/phone/message-types',
clientOptions,
options.tokenProvider
);
this.factorsPhoneMessageTypes = new RetryRestClient(
guardianFactorsPhoneMessageTypesAuth0RestClient,
options.retry
);
};

/**
Expand Down Expand Up @@ -280,4 +322,136 @@ utils.wrapPropertyMethod(GuardianManager, 'updateFactorTemplates', 'factorsTempl
*/
utils.wrapPropertyMethod(GuardianManager, 'updateFactor', 'factors.update');

/**
* Get enabled Guardian policies
*
* @method getPolicies
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPolicies(function (err, policies) {
* console.log(policies);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'getPolicies', 'policies.get');

/**
* Update enabled Guardian policies
*
* @method updatePolicies
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePolicies({}, [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first argument here is the generic "params", that we have no use for. But since this is a convention for all GET endpoints, it seems that it is preferable to keep it here.

See also other methods that have the same approach:

  • /**
    * Update the prompts settings.
    *
    * @method updateSettings
    * @memberOf module:management.PromptsManager.prototype
    *
    * @example
    * management.prompts.updateSettings(data, function (err, prompts) {
    * if (err) {
    * // Handle error.
    * }
    *
    * // Updated prompts
    * console.log(prompts);
    * });
    *
    * @param {Object} params Prompts parameters.
    * @param {Object} data Updated prompts data.
    * @param {Function} [cb] Callback function.
    *
    * @return {Promise|undefined}
    */
    utils.wrapPropertyMethod(PromptsManager, 'updateSettings', 'resource.patch');
  • /**
    * Update the branding settings.
    *
    * @method updateSettings
    * @memberOf module:management.BrandingManager.prototype
    *
    * @example
    * management.branding.updateSettings(data, function (err, branding) {
    * if (err) {
    * // Handle error.
    * }
    *
    * // Updated branding
    * console.log(branding);
    * });
    *
    * @param {Object} params Branding parameters.
    * @param {Object} data Updated branding data.
    * @param {Function} [cb] Callback function.
    *
    * @return {Promise|undefined}
    */
    utils.wrapPropertyMethod(BrandingManager, 'updateSettings', 'resource.patch');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One argument to keep the param argument is to allow extending the method with additional parameters/options in the future (ex. if the API endpoint starts accepting optional query params).

* 'all-applications'
* ], function (err, policies) {
* console.log(policies);
* });
*
* @param {Object} params Parameters.
* @param {String[]} data Policies to enable. Empty array disables all policies.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'updatePolicies', 'policies.update');

/**
* Get the Guardian phone factor's selected provider
*
* @method getPhoneFactorSelectedProvider
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPhoneFactorSelectedProvider(function (err, selectedProvider) {
* console.log(selectedProvider);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'getPhoneFactorSelectedProvider',
'factorsPhoneSelectedProvider.get'
);

/**
* Update the Guardian phone factor's selected provider
*
* @method updatePhoneFactorSelectedProvider
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePhoneFactorSelectedProvider({}, {
* provider: 'twilio'
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String} data.provider Name of the selected provider
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'updatePhoneFactorSelectedProvider',
'factorsPhoneSelectedProvider.update'
);

/**
* Get the Guardian phone factor's message types
*
* @method getPhoneFactorMessageTypes
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPhoneFactorMessageTypes(function (err, messageTypes) {
* console.log(messageTypes);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'getPhoneFactorMessageTypes',
'factorsPhoneMessageTypes.get'
);

/**
* Update the Guardian phone factor's message types
*
* @method updatePhoneFactorMessageTypes
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePhoneFactorMessageTypes({}, {
* message_types: ['sms', 'voice']
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String[]} data.message_types Message types (only `"sms"` and `"voice"` are supported).
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'updatePhoneFactorMessageTypes',
'factorsPhoneMessageTypes.update'
);

module.exports = GuardianManager;
132 changes: 132 additions & 0 deletions src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,138 @@ utils.wrapPropertyMethod(
*/
utils.wrapPropertyMethod(ManagementClient, 'updateGuardianFactor', 'guardian.updateFactor');

/**
* Get enabled Guardian policies
*
* @method getGuardianPolicies
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getGuardianPolicies(function (err, policies) {
* console.log(policies);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'getGuardianPolicies', 'guardian.getPolicies');

/**
* Update enabled Guardian policies
*
* @method updateGuardianPolicies
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.updateGuardianPolicies({}, [
* 'all-applications'
* ], function (err, policies) {
* console.log(policies);
* });
*
* @param {Object} params Parameters.
* @param {String[]} data Policies to enable. Empty array disables all policies.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'updateGuardianPolicies', 'guardian.updatePolicies');

/**
* Get the Guardian phone factor's selected provider
*
* @method getGuardianPhoneFactorSelectedProvider
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getGuardianPhoneFactorSelectedProvider(function (err, selectedProvider) {
* console.log(selectedProvider);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
ManagementClient,
'getGuardianPhoneFactorSelectedProvider',
'guardian.getPhoneFactorSelectedProvider'
);

/**
* Update the Guardian phone factor's selected provider
*
* @method updateGuardianPhoneFactorSelectedProvider
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.updateGuardianPhoneFactorSelectedProvider({}, {
* provider: 'twilio'
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String} data.provider Name of the selected provider
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
ManagementClient,
'updateGuardianPhoneFactorSelectedProvider',
'guardian.updatePhoneFactorSelectedProvider'
);

/**
* Get the Guardian phone factor's message types
*
* @method getGuardianPhoneFactorMessageTypes
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getGuardianPhoneFactorMessageTypes(function (err, messageTypes) {
* console.log(messageTypes);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
ManagementClient,
'getGuardianPhoneFactorMessageTypes',
'guardian.getPhoneFactorMessageTypes'
);

/**
* Update the Guardian phone factor's message types
*
* @method updateGuardianPhoneFactorMessageTypes
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.updateGuardianPhoneFactorMessageTypes({}, {
* message_types: ['sms', 'voice']
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String[]} data.message_types Message types (only `"sms"` and `"voice"` are supported).
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
ManagementClient,
'updateGuardianPhoneFactorMessageTypes',
'guardian.updatePhoneFactorMessageTypes'
);

/**
* Get all roles.
*
Expand Down
Loading