Skip to content

micro-service-center/policy-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

   __                   __                           __    _                                   __                      
  / /_  ____   ____    / /           ____   ____    / /   (_)  _____   __  __          _____  / /_  ____    _____  ___
 / __/ / __ \ / __ \  / /  ______   / __ \ / __ \  / /   / /  / ___/  / / / / ______  / ___/ / __/ / __ \  / ___/ / _ \
/ /_  / /_/ // /_/ / / /  /_____/  / /_/ // /_/ / / /   / /  / /__   / /_/ / /_____/ (__  ) / /_  / /_/ / / /    /  __/
\__/  \____/ \____/ /_/           / .___/ \____/ /_/   /_/   \___/   \__, /         /____/  \__/  \____/ /_/     \___/
                                 /_/                                /____/                                             

Policy Store

This is the Policy Storage for the Tool Project. All Policies should be stored in this repo.

Rules

  • The name of the file must be <policy_name>_policy.
  • Names should not duplicate with other policies.
  • Upon creating a new policy, corresponding error configuration should be added to error.json.

The Policy File

const BasePolicy = require('policy').Policy // <- Always Extends Base Policy Class

/** Class for User Policy */
class PathPolicy extends BasePolicy {

	/**
	 * Checks if the Request Contains a Valid Path
	 * @param {Object} Request Validator
	 * @return {Boolean}
	 */
	static _approve(requestValidator) { // <- Always rewrite the _approve method, or an Unimplemented Error will be Triggered
		return requestValidator.paths.indexOf(requestValidator.pathRoot) > -1 // <- Always return true or false
	}

}

module.exports = PathPolicy

The Error Config

{
	"errors":{
		"path_policy_error": {  								// error name should always be <name>_policy_error
			"policy": "path_policy", 							// policy name
			"log_path":"validator",								// place to log the error
			"log_root":"",										// place of the root of the log
			"http_status": 401,									// http_status if needed
			"code": "0001",										// error code
			"msg": "request path did not match any services",	// error message for backend debugger
			"emitter": "request"								// source of the error
		},
		"header_policy_error": {
			"policy": "header_policy",
			"log_path":"validator",
			"log_root":"",
			"http_status": 401,
			"code": "0002",
			"msg": "request header did not contain credential",
			"emitter": "request"
		}
	}
}

Releases

No releases published

Packages

No packages published