UNPKG

21.1 kBMarkdownView Raw
1# apigeetool
2
3This is a tool for deploying API proxies and Node.js applications to the Apigee Edge platform. The tool also lets you list and undeploy API proxies.
4
5* [Installation](#installation)
6* [What you need to know about apigeetool](#whatyouneed)
7* [Command reference and examples](#reference)
8* [SDK reference and examples](#sdkreference)
9* [Original tool](#original)
10* [Contribution](#contrib)
11
12# <a name="installation"></a>Installation
13
14`apigeetool` is a Node.js module and you can install it using npm:
15
16`npm install -g apigeetool`
17
18*NOTE*: The `-g` option places the apigeetool command in your PATH. On "\*nix"-based machines, `sudo` may be required with the `-g` option. If you do not use `-g`, then you need to add the apigeetool command to your PATH manually. Typically, the `-g` option places modules in: `/usr/local/lib/node_modules/apigee-127` on *nix-based machines.
19
20# <a name="whatyouneed"></a>What you need to know about apigeetool
21
22You must have an account on Apigee Edge to perform any `apigeetool` functions. These functions include:
23
24* deploying an API proxy to Edge,
25* undeploying an API proxy from Edge,
26* deploying Node.js apps to Edge,
27* listing deployed API proxies on Edge,
28* retrieving deployed proxies and apps from Edge,
29* deleting proxy definitions from Edge, and
30* retreiving log messages from Node.js apps deployed to Edge.
31* create or delete an API product in Edge
32* create or delete a Developer in Edge
33* create or delete a Developer Application in Edge
34* create or delete a Cache resource in Edge
35
36You need to be familiar with basic concepts and features of Apigee Edge such as API proxies, organizations, and environments.
37
38For more information, refer to the [Apigee Edge docs](http://apigee.com/docs/).
39
40# <a name="commonargs"></a>Common Parameters
41
42The following parameters are available on all of the commands supported by
43this tool:
44
45`--baseuri -L`
46(optional) The base URI for you organization on Apigee Edge. The default is the base URI for Apigee cloud deployments is `api.enterprise.apigee.com`. For on-premise deployments, the base URL may be different.
47
48`--cafile -c`
49(optional) The names of one of more PEM files that represent trusted certificate authorities.
50Multiple file names may be comma-separated. Use this to communicate with an installation
51of Apigee Edge that uses a custom certificate for API calls.
52
53`--debug -D`
54(optional) Prints additional information about the deployment, including router and message processor IDs.
55
56`--help -h`
57(optional) Displays help on this command.
58
59`--insecure -k`
60(optional) Do not validate the TLS certificate of the HTTPS target for API calls.
61Use this to communicate with an installation of Apigee Edge that does not use a
62trusted TLS certificate.
63
64`--asynclimit -a`
65(optional) Limit for the maximum number of operations performed concurrently.
66Currently this only affects file uploads in the `deploynodeapp` command. Defaults to 4.
67
68`--json -j`
69(optional) Formats the command's response as a JSON object.
70
71`--organization -o`
72(required) The name of the organization to deploy to. May be set as an environment variable APIGEE_ORGANIZATION.
73
74`--password -p`
75(required) Your Apigee account password. May be set as an environment variable APIGEE_PASSWORD.
76
77`--username -u`
78(required) Your Apigee account username. May be set as an environment variable APIGEE_USERNAME.
79
80`--token -t`
81(optional) Your Apigee access token. Use this in lieu of -u / -p/
82
83`--netrc -n`
84(optional) Use this in lieu of -u / -p, to tell apigeetool to retrieve credentials from your .netrc file.
85
86`--verbose -V`
87(optional) Prints additional information as the deployment proceeds.
88
89# <a name="reference"></a>Command reference and examples
90
91* [deploynodeapp](#deploynodeapp)
92* [deployproxy](#deployproxy)
93* [undeploy](#undeploy)
94* [listdeployments](#listdeployments)
95* [fetchproxy](#fetchproxy)
96* [getlogs](#getlogs)
97* [delete](#delete)
98* [createdeveloper](#createdeveloper)
99* [deletedeveloper](#deletedeveloper)
100* [createproduct](#createproduct)
101* [deleteproduct](#deleteproduct)
102* [createapp](#createapp)
103* [deleteapp](#deleteapp)
104* [createcache](#createcache)
105* [deletecache](#deletecache)
106
107
108## <a name="deploynodeapp"></a>deploynodeapp
109
110Deploys a Node.js app to Apigee Edge as an API proxy. With your Node.js app deployed to Edge, you can take advantage of Edge features like security, quotas, caching, analytics, trace tool, and more.
111
112#### Examples
113
114Deploys a Node.js app to Apigee Edge.
115
116 apigeetool deploynodeapp -u sdoe@apigee.com -o sdoe -e test -n 'Test Node App 2' -d . -m app.js -b /node2
117
118Deploys a Node.js app to both the default (HTTP) and secure (HTTPS) virtual hosts.
119
120 apigeetool deploynodeapp -u sdoe@apigee.com -o sdoe -e test -n 'Test Node App 2' -d . -m app.js -b /node2 -v default,secure
121
122#### Required parameters
123
124The following parameters are required. However, if any are left unspecified
125on the command line, and if apigeetool is running in an interactive shell,
126then apigeetool will prompt for them.
127
128For example, if you do not specify a password using "-p", apigeetool will
129prompt for the password on the command line.
130
131See [Common Parameters](#commonargs) for a list of additional parameters, including
132the "-u" and "-p" parameters for username and password, and the "-o" parameter
133for organization name, all of which are required.
134
135`--environments -e`
136(required) The name(s) of the environment(s) to deploy to (comma-delimited).
137
138#### Optional parameters
139
140`--api -n`
141(optional) The name of the API proxy. The name of the API proxy must be unique within an organization. The characters you are allowed to use in the name are restricted to the following: `A-Z0-9._\-$ %`. If not specified, will attempt to use name from package.json.
142
143`--base-path -b`
144(optional) The base path of the API proxy. For example, for this API proxy, the base path is `/example-proxy`: `http://myorg-test.apigee.net/example-proxy/resource1`.
145
146`--directory -d`
147(optional) The path to the root directory of the API proxy on your local system. Will attempt to use current directory is none is specified.
148
149`--import-only -i`
150(optional) Imports the API proxy to Apigee Edge but does not deploy it.
151
152`--main -m`
153(optional) The Node.js file you want to be the main file. If not specified, will attempt to use main from package.json.
154
155`--preserve-policies -P`
156(optional) If specified, the highest revision of the existing proxy will be downloaded and the node code in your directory will be overlayed upon it to create a resulting proxy that contains both any existing policies and the node code in the directory. If there is no existing revision, this option will have no effect.
157
158`--resolve-modules -R`
159(optional) If the API proxy includes Node.js modules (e.g., in a `node_modules` directory), this option updates them on Apigee Edge without uploading them from your system. Basically, it's like running "npm install" on Apigee Edge in the root directory of the API proxy bundle.
160
161`--upload-modules -U`
162(optional) If specified, uploads Node.js modules from your system to Apigee Edge rather than resolving the modules directly on Apigee Edge (the default behavior).
163
164`--virtualhosts -v`
165(optional) A comma-separated list of virtual hosts that the deployed app will use. The two most common options are `default` and `secure`. The `default` option is always HTTP and `secure` is always HTTPS. By default, `apigeetool deploynodeapp` uses `default,secure`.
166
167## <a name="deployproxy"></a>deployproxy
168
169Deploys an API proxy to Apigee Edge. If the proxy is currently deployed, it will be undeployed first, and the newly deployed proxy's revision number is incremented.
170
171#### Example
172
173Deploys an API proxy called example-proxy to Apigee Edge. Per the `-d` flag, the command is executed in the root directory of the proxy bundle.
174
175 apigeetool deployproxy -u sdoe@example.com -o sdoe -e test -n example-proxy -d .
176
177#### Required parameters
178
179The following parameters are required. However, if any are left unspecified
180on the command line, and if apigeetool is running in an interactive shell,
181then apigeetool will prompt for them.
182
183See [Common Parameters](#commonargs) for a list of additional parameters, including
184the "-u" and "-p" parameters for username and password, and the "-o" parameter
185for organization name, all of which are required.
186
187`--api -n`
188(required) The name of the API proxy. Note: The name of the API proxy must be unique within an organization. The characters you are allowed to use in the name are restricted to the following: `A-Z0-9._\-$ %`.
189
190`--environments -e`
191(required) The name(s) of the environment(s) to deploy to (comma delimited).
192
193#### Optional parameters
194
195`--base-path -b`
196(optional) The base path of the API proxy. For example, for this API proxy, the base path is /example-proxy: http://myorg-test.apigee.net/example-proxy/resource1.
197
198`--directory -d`
199(optional) The path to the root directory of the API proxy on your local system. Will attempt to use current directory is none is specified.
200
201`--import-only -i`
202(optional) Imports the API proxy to Apigee Edge but does not deploy it.
203
204`--resolve-modules -R`
205(optional) If the API proxy includes Node.js modules (e.g., in a `node_modules` directory), this option updates them on Apigee Edge without uploading them from your system. Basically, it's like running npm on Apigee Edge in the root directory of the API proxy bundle.
206
207`--upload-modules -U`
208(optional) If specified, uploads Node.js modules from your system to Apigee Edge.
209
210## <a name="undeploy"></a>undeploy
211
212Undeploys a named API proxy or Node.js app deployed on Apigee Edge.
213
214#### Example
215
216Undeploy the proxy named "example-proxy".
217
218 apigeetool undeploy -u sdoe@example.com -o sdoe -n example-proxy -e test -D
219
220#### Required parameters
221
222The following parameters are required. However, if any are left unspecified
223on the command line, and if apigeetool is running in an interactive shell,
224then apigeetool will prompt for them.
225
226See [Common Parameters](#commonargs) for a list of additional parameters, including
227the "-u" and "-p" parameters for username and password, and the "-o" parameter
228for organization name, all of which are required.
229
230`--api -n`
231(required) The name of the API proxy or app to undeploy.
232
233`--environment -e`
234(required) The environment on Apigee Edge where the API proxy or app is currently deployed.
235
236#### Optional parameters
237
238`--revision -r`
239(optional) Specify the revision number of the API proxy to undeploy.
240
241## <a name="listdeployments"></a>listdeployments
242
243Lists the API proxies deployed on Apigee Edge for the specified organization. Lets you filter the result by API proxy name or environment.
244
245#### Examples
246
247List all API proxies in an organization:
248
249 $ apigeetool listdeployments -u sdoe@example.com -o sdoe -e test`
250
251List API proxies named "example-proxy":
252
253 $ apigeetool listdeployments -u sdoe@example.com -o sdoe -n example-proxy
254
255#### Required parameters
256
257See [Common Parameters](#commonargs) for a list of additional parameters, including
258the "-u" and "-p" parameters for username and password, and the "-o" parameter
259for organization name, all of which are required.
260
261#### Required, mutually exclusive parameters
262
263`--api -n`
264(You must specify either `api` or `environment` in this command) The name of the API proxy to list.
265
266`--environment -e`
267(You must specify either `api` or `environment` in this command) The environment for which you want to list deployments. When `-e` is specified, the command lists all deployed proxies in the environment.
268
269#### Optional parameters
270
271`--long -l`
272(optional) Returns additional information about the API proxy or Node.js app,
273including the URL to use as the base path for each one.
274
275`--revision -r`
276(optional) Filters the list by the specified revision number.
277
278## <a name="fetchproxy"></a>fetchproxy
279
280Fetches a deployed API proxy or Node.js application from Apigee Edge. The
281result will be a ZIP file that contains the contents of the entire
282proxy.
283
284Regardless of whether "deployproxy" or "deploynodeapp" is used to deploy the
285proxy or app, the result of "fetchproxy" will always be a ZIP file that
286represents an API proxy. The resulting proxy may be "unzipped" and
287re-deployed using "deployproxy."
288
289#### Example
290
291Fetch the deployed proxy named "example-proxy".
292
293 apigeetool fetchproxy -u sdoe@example.com -o sdoe -n example-proxy -r 1
294
295#### Required parameters
296
297The following parameters are required. However, if any are left unspecified
298on the command line, and if apigeetool is running in an interactive shell,
299then apigeetool will prompt for them.
300
301See [Common Parameters](#commonargs) for a list of additional parameters, including
302the "-u" and "-p" parameters for username and password, and the "-o" parameter
303for organization name, all of which are required.
304
305`--api -n`
306(required) The name of the API proxy or app to undeploy.
307
308`--revision -r`
309(optional) Specifies the revision to retrieve.
310
311#### Optional parameters
312
313`--file -f`
314(optional) The name of the file to write as the result. If not specified,
315then the file name will be the same as the name passed to the "name"
316parameter.
317
318## <a name="delete"></a>delete
319
320Delete all revisions of a proxy from Apigee Edge.
321
322It is an error to delete a proxy that still has deployed revisions. Revisions
323must be undeployed using "undeploy" before this command may be used.
324
325#### Example
326
327Delete the proxy named "example-proxy".
328
329 apigeetool delete -u sdoe@example.com -o sdoe -n example-proxy
330
331#### Required parameters
332
333The following parameters are required. However, if any are left unspecified
334on the command line, and if apigeetool is running in an interactive shell,
335then apigeetool will prompt for them.
336
337See [Common Parameters](#commonargs) for a list of additional parameters, including
338the "-u" and "-p" parameters for username and password, and the "-o" parameter
339for organization name, all of which are required.
340
341`--api -n`
342(required) The name of the API proxy or app to undeploy.
343
344## <a name="getlogs"></a>getlogs
345
346Retrieve the last set of log records from a Node.js application deployed to Apigee Edge.
347
348The resulting log files will be written directly to standard output. Each is prefixed with:
349
350* A timestamp, in UTC by default
351* An indication of whether the log record came from standard output or standard error
352* A unique identifier of the server where the log was generated.
353
354Since Apigee Edge, by default, deploys each Node.js application on at least two
355different servers, most applications will see at least two sets of logs. These are
356sorted in time stamp order.
357
358The log records from this command come from a cache inside Apigee Edge that retains
359the last 500 lines of log output from each server. The cache is a circular buffer,
360so older messages will be discarded when it fills up.
361
362By default, the last set of log records will be pulled and written to standard output. However, if the
363"-f" option is used, then "apigeetool" will poll Edge for new log records and append them to standard
364output, in the manner of "tail -f". (By default, the tool polls every
365five seconds).
366
367For example, a set of log records might look like this:
368
369<pre>
370[2014-11-05T01:30:01.530Z nodejs/stderr svr.362] *** Starting script
371[2014-11-05T01:30:09.182Z nodejs/stderr svr.362] 2014-11-05T01:30:09.181Z - debug: 1/4. this is a debug log
372[2014-11-05T01:30:09.186Z nodejs/stdout svr.362] 2014-11-05T01:30:09.186Z - info: 2/4. this is an info log
373[2014-11-05T01:30:09.187Z nodejs/stdout svr.362] 2014-11-05T01:30:09.187Z - warn: 3/4. this is a warning log
374[2014-11-05T01:30:09.188Z nodejs/stderr svr.362] 2014-11-05T01:30:09.188Z - error: 4/4. this is an error log
375[2014-11-05T01:48:21.419Z nodejs/stderr svr.828] *** Starting script
376[2014-11-05T01:48:28.637Z nodejs/stderr svr.828] js-bson: Failed to load c++ bson extension, using pure JS version
377[2014-11-05T01:48:29.801Z nodejs/stderr svr.828] 2014-11-05T01:48:29.800Z - debug: 1/4. this is a debug log
378[2014-11-05T01:48:29.804Z nodejs/stdout svr.828] 2014-11-05T01:48:29.804Z - info: 2/4. this is an info log
379[2014-11-05T01:48:29.805Z nodejs/stdout svr.828] 2014-11-05T01:48:29.805Z - warn: 3/4. this is a warning log
380[2014-11-05T01:48:29.806Z nodejs/stderr svr.828] 2014-11-05T01:48:29.806Z - error: 4/4. this is an error log
381</pre>
382
383#### Required Parameters
384
385The following parameters are required. However, if any are left unspecified
386on the command line, and if apigeetool is running in an interactive shell,
387then apigeetool will prompt for them.
388
389See [Common Parameters](#commonargs) for a list of additional parameters, including
390the "-u" and "-p" parameters for username and password, and the "-o" parameter
391for organization name, all of which are required.
392
393`--api -n`
394(required) The name of the deployed app to get logs from.
395
396`--environment -e`
397(required) The environment on Apigee Edge where the app is currently deployed.
398
399#### Optional Parameters
400
401`--streaming -f`
402(optional) If specified, do not exit, but instead poll Apigee Edge for new log
403records and write them to standard output in the manner of "tail -f."
404
405`--timezone -z`
406(optional) If specified, use the time zone to format the timestamps on the
407log records. If not specified, then the default is UTC. The timestamp name
408should be a name such as "PST."
409
410# <a name="sdkreference"></a>SDK Reference
411
412You could use apigeetool as an SDK to orchestrate tasks that you want to perform with Edge, for eg, deploying an api proxy or running tests etc.
413
414#### Usage Example
415
416 var apigeetool = require('apigeetool')
417 var sdk = apigeetool.getPromiseSDK()
418 var opts = {
419 organization: 'edge-org',
420 username: 'edge-user',
421 password: 'password',
422 environment: 'environment',
423 }
424 opts.api = APIGEE_PROXY_NAME;
425 opts.directory = path.join(__dirname);
426
427 sdk.deployProxy(opts)
428 .then(function(result){
429 //deploy success
430 },function(err){
431 //deploy failed
432 })
433
434## <a name="createdeveloper"></a>Create Developer
435
436Creates a new Developer in Edge
437
438#### Example
439
440Create a developer.
441
442 //see above for other required options
443 opts.email = DEVELOPER_EMAIL
444 opts.firstName = 'Test'
445 opts.lastName = 'Test1'
446 opts.userName = 'runningFromTest123'
447
448 sdk.createDeveloper(opts)
449 .then(function(result){
450 //developer created
451 },function(err){
452 //developer creation failed
453 }) ;
454
455
456## <a name="deletedeveloper"></a>Delete Developer
457
458Delete a Developer in Edge
459
460#### Example
461
462 //see above for other required options
463 opts.email = DEVELOPER_EMAIL
464
465 sdk.deleteDeveloper(opts)
466 .then(function(result){
467 //developer deleted
468 },function(err){
469 //developer delete failed
470 }) ;
471
472## <a name="createproduct"></a>Create Product
473
474Creates a new API Product in Edge
475
476#### Example
477
478 opts.productName = APIGEE_PRODUCT_NAME
479 opts.productDesc = 'description'
480 opts.proxies = APIGEE_PROXY_NAME
481 opts.environments = 'test' //apigee env
482 opts.quota = '1', //quota amount
483 opts.quotaInterval = '1' //interval
484 opts.quotaTimeUnit = 'minute' //timeunit
485
486 sdk.createProduct(opts)
487 .then(function(result){
488 //product created
489 },function(err){
490 //product creation failed
491 }) ;
492
493## <a name="deleteproduct"></a>Delete Product
494
495Delete API Product in Edge
496
497#### Example
498 opts.productName = APIGEE_PRODUCT_NAME
499
500 sdk.deleteProduct(opts)
501 .then(function(result){
502 //delete success
503 },function(err){
504 //delete failed
505 }) ;
506
507## <a name="createapp"></a>Create App
508
509Create App in Edge
510
511#### Example
512
513 opts.name = APP_NAME
514 opts.apiproducts = APIGEE_PRODUCT_NAME
515 opts.email = DEVELOPER_EMAIL
516
517 sdk.createApp(opts)
518 .then(function(result){
519 //create app done
520 },function(err){
521 //create app failed
522 }) ;
523
524## <a name="deleteapp"></a>Delete App
525
526Delete App in Edge
527
528#### Example
529
530 opts.email = DEVELOPER_EMAIL
531 opts.name = APP_NAME
532
533 sdk.deleteApp(opts)
534 .then(function(result){
535 //delete app success
536 },function(err){
537 //delete app failed
538 }) ;
539
540## <a name="createcache"></a>Create Cache
541
542Create Cache in Edge
543
544#### Example
545 opts.cache = CACHE_RESOURCE_NAME;
546 sdk.createcache(opts)
547 .then(function(result){
548 //cache create success
549 },function(err){
550 //cache create failed
551 }) ;
552
553## <a name="deletecache"></a>Delete Cache
554
555Delete Cache in Edge
556
557#### Example
558 opts.cache = CACHE_RESOURCE_NAME;
559 sdk.deletecache(opts)
560 .then(function(result){
561 //delete create success
562 },function(err){
563 //delete create failed
564 }) ;
565
566# <a name="original"></a>Original Tool
567
568This module replaces the original "apigeetool," which was written in Python.
569It is also called "apigeetool" and resides here:
570
571https://github.com/apigee/api-platform-tools
572
573# <a name="contrib"></a>Contribution
574
575To run remotetests, provide your edge creds, org, env details in `remotetest/testconfig.js` similar to 'remotetest/testconfig-sample.js'