![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
apigee-access
Advanced tools
Readme
This module allows Node.js applications running on the Apigee Edge platform a way to access Apigee-specific functionality. The following features may be accessed:
This module is intended to be used when deploying a Node.js program to the Apigee Edge product and access to Apigee-specific functionality is needed. It may be used to build an application that is optimized for Apigee Edge, or it may be used to build higher-level functionality.
In order to support local development and testing, this module works in a local mode with no dependencies on Apigee functionality. When deployed to Apigee Edge, this functionality is replaced with native Apigee functionality.
This module is intended for use by developers who intend to primarily deploy to Apigee. For a more comprehensive set of tools that may be used in a variety of environments both inside and outside Apigee, please see our suite of "Volos" modules:
https://www.npmjs.org/search?q=volos
When you are an Apigee Edge user who is combining the traditional policy-based configuration of an API proxy with Node.js code.
When you are an Apigee Edge user who wants to take advantage of the built-in distributed cache available on the platform.
If you are not deploying to Apigee Edge and not using the existing policy framework, then this module makes no sense.
If you don't know what we're talking about so far, then you don't need this module.
When creating an API proxy in Apigee, it is common to set variables that can be used to pass information from one policy to the next.
Imagine that an Edge policy running on the request path has set a variable called "AuthenticatedUserId". Using this module, you may access that variable as follows:
var http = require('http');
var apigee = require('apigee-access');
http.createServer(function (request, response) {
var userId = apigee.getVariable('AuthenticatedUserId');
console.log('Authenticated Apigee User ID is %s', userid);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
The module supports the following functions:
getVariable(request, name);
setVariable(request, name, value);
setIntVariable(request, name, value);
deleteVariable(request, name);
getCache(name);
getMode();
And the following constant properties:
APIGEE_MODE = 'apigee';
STANDALONE_MODE = 'standalone';
Variables are part of the flow of each message through the Apigee Edge product. Among other things, they represent the context between the different policies that may affect the message as it flows through Apigee. There are a few reasons to access this data from Node.js:
var apigee = require('apigee-access');
// "httpRequest" must be a request object that came from the http module
var val1 = apigee.getVariable(request, 'TestVariable');
var val2 = apigee.getVariable(request, 'request.client.ip');
The value may be a string or a number, depending on the type that was set using "setVariable," or if the variable is built in to Apigee, depending on the type of the built-in variable.
Some variables are read-only -- an exception will be thrown if you try to set one of them.
var apigee = require('apigee-access');
// "httpRequest" must be a request object that came from the http module
apigee.setVariable(request, 'TestVariable', 'bar');
// This will throw an exception
apigee.setVariable(request, 'client.ip', 'Invalid');
For each variable, the key must be a string. The value may be a number, String, boolean, null, or undefined.
var apigee = require('apigee-access');
// Convert "123" to an integer and set it
apigee.setIntVariable(request, 'TestVariable', '123');
// Use something that's already a number
apigee.setIntVariable(request, 'TestVariable2', 42);
"setIntVariable" is a convenience method that first coerces "value" to an integer, and then sets it. "value" must be a string or number.
It is an error to delete a read-only variable.
apigee.deleteVariable(request, 'TestVariable');
// This will throw an exception
apigee.deleteVariable(request, 'client.ip', 'Invalid');
You can find the link of supported variables at the following page. These are the variables that are available when you deploy a Node.js application to Apigee Edge.
You may of course add your own variables with your own names.
The list of variables may be found here:
http://apigee.com/docs/api-services/api/variables-reference
This module also works outside Apigee Edge, but not all the pre-defined variables are supported. This table shows which ones are available. These variables are supported here in order to support local development and testing of Node.js applications for Apigee Edge.
Again, inside Apigee Edge, a much larger set of pre-defined variables is supported -- please see here:
http://apigee.com/docs/api-services/api/variables-reference
Variable | Read-Only | Type | Notes |
client.received.start.time | Yes | String | Time at which the request was received |
client.received.end.time | Yes | String | Time at which the request was received |
client.received.start.timestamp | Yes | Integer | Time at which the request was received |
client.received.end.timestamp | Yes | Integer | Time at which the request was received |
This module works outside Apigee mainly for testing purposes. Missing a variable that you need for a test? Open a GitHub issue and we can add it, or send a pull request.
The cache may be used to store strings or data. Like most caches, it is a least-recently-used cache with a maximum size.
Inside Apigee Edge, the cache is distributed between all nodes where the Node.js application executes.
Configuration of the cache is managed via a "cache resource." You can use the Apigee Edge API to manually create cache resources, or you can use the default resource.
When this module is used outside Apigee Edge, the cache is stored in memory inside Node.js. This support is provided primarily for testing purposes.
var apigee = require('apigee-access');
// Look up the cache named "cache" and create it if necessary. The
// resulting cache uses a pre-defined set of configuration parameters
// that should be workable for most situations.
var cache = apigee.getCache('cache');
// Get access to a custom cache resource
var customCache = apigee.getCache('MyCustomCache',
{ resource: 'MyCustomrResource'} );
To use a cache, call "getCache". This takes a name, and an optional configuration object.
The configuration object may be empty, or it may contain the following optional parameters:
For information about how to create a cache resource, see the product documentation:
http://apigee.com/docs/gateway-services/content/manage-caches-environment
The following values are valid for the "scope" field:
var apigee = require('apigee-access');
var cache = apigee.getCache();
// Insert a string with a timeout of 120 seconds
cache.put('key2', 'Hello, World!', 120);
// Insert a string and get notified when insert is complete
cache.put('key4', 'Hello, World!', function(err) {
// "err" will be undefined unless there was an error on insert
});
"put" takes four parameters:
var apigee = require('apigee-access');
var cache = apigee.getCache();
cache.get('key', function(err, data) {
// If there was an error, then "err" will be set
// "data" is the item that was retrieved
// It will be a Buffer or a String depending on what was inserted..
});
"get" takes two parameters:
The callback must be a function that takes two parameters:
The first is an error -- if there is an error while retrieving from the cache, then an Error object will be set here. Otherwise this parameter will be set to "undefined".
The second is the data retrieved, if any. It will be one of four values:
var apigee = require('apigee-access');
var cache = apigee.getCache();
cache.remove('key');
This method invalidates the key. Like "put," it optionally takes a function as the second parameter, which will be called with an Error object as the first parameter if there is an error.
Once a key is invalidated, subsequent "get" requests will return "undefined" unless another value is inserted.
var apigee = require('apigee-access')
console.log('The deployment mode is ' + apigee.getMode());
"getMode()" returns a string that determines where the module has been deployed.
If it returns the string "apigee," then the application is running on Apigee Edge and all functionality is supported.
If it returns the string "standalone," then the application is running outside the Apigee Edge environment, and the default functionality described at the top of the document takes effect.
FAQs
Provides access to Apigee-specific functionality
The npm package apigee-access receives a total of 349 weekly downloads. As such, apigee-access popularity was classified as not popular.
We found that apigee-access demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.