UNPKG

52.8 kBMarkdownView Raw
1| LINTING | UNIT | INTEGRATION | NPM SECURITY |
2|-------------------|-------------------|-------------------|-------------------|
3| [![Build1][1]][5] | [![Build2][2]][5] | [![Build3][3]][5] | [![Build4][4]][5] |
4
5[1]: https://travis-matrix-badges.herokuapp.com/repos/Kinvey/kinvey-cli/branches/master/1
6[2]: https://travis-matrix-badges.herokuapp.com/repos/Kinvey/kinvey-cli/branches/master/2
7[3]: https://travis-matrix-badges.herokuapp.com/repos/Kinvey/kinvey-cli/branches/master/3
8[4]: https://travis-matrix-badges.herokuapp.com/repos/Kinvey/kinvey-cli/branches/master/4
9[5]: https://travis-ci.org/Kinvey/kinvey-cli
10
11
12
13
14# Kinvey CLI
15
16Kinvey CLI is a utility for managing various aspects of your Kinvey account from the command line. Its features include:
17
18* Deploying and managing FlexServices running on the Kinvey FlexService Runtime
19* Deploying and managing websites
20* Creating, listing, and deleting applications
21* Creating, listing, and deleting app environments
22* Creating, listing, and deleting collections
23
24Contents:
25
26- [Installation](#installation)
27- [Usage](#usage)
28- [Commands](#commands)
29- [Global Options](#global-options)
30- [Environment Variables](#environment-variables)
31- [Getting Help](#getting-help)
32- [Getting Started](#getting-started)
33- [Managing Profiles](#managing-profiles)
34- [Authenticating One-time Commands](#authenticating-one-time-commands)
35- [Precedence of Configuration Options](#precedence-of-configuration-options)
36- [Output Format](#output-format)
37- [Flex Runtime Version Selection](#flex-runtime-version-selection)
38- [Proxy Settings](#proxy-settings)
39- [Troubleshooting](#troubleshooting)
40- [Changelog](#changelog)
41- [License](#license)
42
43
44
45## Installation
46
47Kinvey CLI is distributed as an NPM package. After you install NPM, run the following command to download and install Kinvey CLI.
48
49 npm install -g kinvey-cli
50
51## Usage
52
53 kinvey <command> [args] [options]
54
55## Commands
56
57* `init`
58
59 Prompts you to provide account credentials and instance ID and creates a new working profile for you based on the information you provided. Command-line options that specify the same data are ignored.
60
61* `profile create <name> [profile information]`
62
63 Creates a profile with the specified name. You can specify the profile information either at the command line as arguments or as environment variables. In the presence of command line argument, any values specified through environment variables are ignored.
64
65* `profile list`
66
67 Lists all existing profiles. Profiles are saved under the user home.
68
69* `profile login [name]`
70
71 Re-authenticates a specified profile. If you omit the profile name, the active profile is used. Prompts for password and for two-factor authentication token if needed.
72
73* `profile show [name]`
74
75 Shows detailed information about the specified profile. If you omit the profile name, information about the active profile is shown.
76
77* `profile use <name>`
78
79 Sets an active profile.
80
81* `profile delete [name]`
82
83 Deletes the specified profile or the active one if you don't specify a profile name.
84
85* `org apply`
86
87 Applies org configuration file to the specified org or to the active one.
88
89 * `--org <organization>`
90
91 Specifies a Kinvey organization by ID or name.
92
93 * `--file <file path>`
94
95 Specifies path to an organization configuration file. Required.
96
97* `org list`
98
99 Lists all existing organizations within your Kinvey account.
100
101* `org show`
102
103 Shows detailed information about the specified organization or about the active one if you don't specify an organization. You can specify an organization by ID or name.
104
105 * `--org <organization>`
106
107 Specifies a Kinvey organization by ID or name.
108
109* `org use <org>`
110
111 Sets the specified organization as active. You can specify an organization by ID or name.
112
113* `org export`
114
115 Exports to a file the specified org or the active one. The organization services and the organization apps along with their services are exported in separate configuration files in the respective 'applications' and 'services' directories.
116
117 * `--org <organization>`
118
119 Specifies a Kinvey organization by ID or name.
120
121 * `--file <file path>`
122
123 Specifies path to file. Required.
124
125* `app create <name>`
126
127 Creates an application. You can specify an organization ID or name if you want to create the app within the context of an organization.
128
129 * `--org <organization>`
130
131 Specifies a Kinvey organization by ID or name.
132
133 * `--file <file path>`
134
135 Specifies path to an application configuration file.
136
137* `app apply`
138
139 Applies app configuration file to the specified app or to the active one.
140
141 * `--app <application>`
142
143 Specifies a Kinvey app by ID or name.
144
145 * `--file <file path>`
146
147 Specifies path to an application configuration file. Required.
148
149* `app list`
150
151 Lists all existing applications within your Kinvey account.
152
153* `app show`
154
155 Shows detailed information about the specified application or about the active one if you don't specify an application.
156
157 * `--app <application>`
158
159 Specifies a Kinvey app by ID or name.
160
161* `app use <app>`
162
163 Sets the specified application as active. You can specify an application by ID or name.
164
165* `app export`
166
167 Exports to a file the specified app or the active one. Also exports the app environments and the app services in separate files in the corresponding 'environments' and 'services' directories
168
169 * `--app <application>`
170
171 Specifies a Kinvey app by ID or name.
172
173 * `--file <file path>`
174
175 Specifies path to file. Required.
176
177* `app delete`
178
179 Deletes the specified application or the active one if you don't specify an application. You will be prompted for confirmation unless you set the `--no-prompt` flag.
180
181 * `--app <application>`
182
183 Specifies a Kinvey app by ID or name.
184
185 * `--no-prompt`
186
187 Do not ask for confirmation.
188
189* `appenv create <name>`
190
191 Creates an environment within the active application. To use a different application, specify it using `--app`.
192
193 * `--app <application>`
194
195 Specifies a Kinvey app by ID or name.
196
197 * `--file <file path>`
198
199 Specifies path to an app environment configuration file.
200
201* `appenv apply`
202
203 Applies configuration (defined in file) to the specified environment or to the active one if you don't specify an environment. You can specify an environment by ID or name. By default, the command searches inside the active application but you can specify a different application using `--app`.
204
205 * `--app <application>`
206
207 Specifies a Kinvey app by ID or name.
208
209 * `--env <environment>`
210
211 Specifies a Kinvey app environment by ID or name.
212
213 * `--file <file path>`
214
215 Specifies path to an app environment configuration file. Required.
216
217* `appenv show`
218
219 Shows detailed information about the specified environment or about the active one if you don't specify an environment. By default, the command searches inside the active application but you can specify a different application using `--app`.
220
221 * `--env <environment>`
222
223 Specifies a Kinvey app environment by ID or name.
224
225 * `--app <application>`
226
227 Specifies a Kinvey app by ID or name.
228
229* `appenv use <env>`
230
231 Sets the specified environment as active. By default, the command searches inside the active application but you can specify a different application using `--app`.
232
233 * `--app <application>`
234
235 Specifies a Kinvey app by ID or name.
236
237* `appenv export`
238
239 Exports to a file the specified app environment or the active one.
240
241 * `--env <environment>`
242
243 Specifies a Kinvey app environment by ID or name.
244
245 * `--app <application>`
246
247 Specifies a Kinvey app by ID or name.
248
249 * `--file <file path>`
250
251 Specifies path to file. Required.
252
253* `appenv delete`
254
255 Deletes the specified environment or the active one if you don't specify an environment. By default, the command searches inside the active application but you can specify a different application using `--app`. You will be prompted for confirmation unless you set the `--no-prompt` flag.
256
257 * `--env <environment>`
258
259 Specifies a Kinvey app environment by ID or name.
260
261 * `--app <application>`
262
263 Specifies a Kinvey app by ID or name.
264
265 * `--no-prompt`
266
267 Do not ask for confirmation.
268
269* `coll create <name>`
270
271 Creates a collection within the active application and environment. You can specify another pair of application and environment using the `--app` and `--env` options.
272
273 * `--app <application>`
274
275 Specifies a Kinvey app by ID or name. Requires `--env`.
276
277 * `--env <environment>`
278
279 Specifies a Kinvey app environment by ID or name.
280
281* `coll list`
282
283 Lists all existing collections within the active application and environment. You can specify another pair of application and environment using the `--app` and `--env` options.
284
285 * `--app <application>`
286
287 Specifies a Kinvey app by ID or name. Requires `--env`.
288
289 * `--env <environment>`
290
291 Specifies a Kinvey app environment by ID or name.
292
293* `coll delete <coll>`
294
295 Deletes a collection by name within the active application and environment. You can specify another pair of application and environment using the `--app` and `--env` options. You will be prompted for confirmation unless you set the `--no-prompt` flag.
296
297 * `--app <application>`
298
299 Specifies a Kinvey app by ID or name. Requires `--env`.
300
301 * `--env <environment>`
302
303 Specifies a Kinvey app environment by ID or name.
304
305 * `--no-prompt`
306
307 Do not ask for confirmation.
308
309* `service create <name>`
310
311 Creates a service within an application or organization (either `--app` or `--org` must be specified).
312
313 * `--app <application>`
314
315 Specifies a Kinvey app by ID or name.
316
317 * `--org <organization>`
318
319 Specifies a Kinvey organization by ID or name.
320
321 * `--file <file path>`
322
323 Specifies path to a service configuration file. Required.
324
325* `service apply`
326
327 Applies a service configuration file to the specified service.
328
329 * `--service <service>`
330
331 Specifies service ID.
332
333 * `--file <file path>`
334
335 Specifies path to a service configuration file. Required.
336
337* `service export`
338
339 Exports the specified service to a file.
340
341 * `--service <service>`
342
343 Specifies service ID.
344
345 * `--file <file path>`
346
347 Specifies path to file. Required.
348
349* `flex init`
350
351 Configures Kinvey CLI to work with a specific Flex service and service environment combination through prompts. This command is designed to be executed in a Node.js project directory where it creates a `.kinvey` configuration file. Information within the file is saved per profile. Each successive execution in the same directory overwrites the respective profile section in the configuration file. This command requires that either an active profile is set or a profile is specified using the `--profile` option. Profile data options such as `--email`, `--password`, and `--instanceId` are ignored if specified.
352
353* `flex create <service_name>`
354
355 Creates an internal flex service with the specified name along with a service environment. You need to specify a domain (application or organization) using the `--app` or `--org` option.
356
357 * `--app <application>`
358
359 Specifies a Kinvey app by ID or name.
360
361 * `--org <organization>`
362
363 Specifies a Kinvey organization by ID or name.
364
365 * `--secret <secret>`
366
367 Specifies a shared secret of your choice (minimum 2 characters, no leading or trailing whitespaces). If you skip this option, a random shared secret is generated for you. In the latter case, Kinvey CLI will pass the secret automatically to the Flex Runtime and print it on the screen for your information.
368
369 * `--env <service environment name>`
370
371 Specifies a name for the default service environment that will be created with the service. The name will be set to Development if you omit this option.
372
373 * `--vars, --set-vars <environment variables>`
374
375 Specifies environment variables to set. Specify either as a comma-separated list of key-value pairs (key1=value1,key2=value2) or in stringified JSON format.
376
377 * `--runtime <node6|node8|node10|node12>`
378
379 Specifies major Node.js version to run the project on. The minor and patch versions will vary depending on the [latest Flex Runtime updates](#flex-runtime-version-selection). Defaults to the [Kinvey-recommended Node.js version](https://devcenter.kinvey.com/guides/flexservice-runtime#environment).
380
381* `flex deploy`
382
383 Deploys the current project to the Kinvey FlexService Runtime, using the current service and service environment combination, which is the one you initiated last on the current profile. To use a different service, specify its service ID.
384
385 * `--service <service>`
386
387 Specifies service ID.
388
389 * `--env <service environment>`
390
391 Specifies a service environment by ID or name.
392
393 * `--replace-vars <environment variables>`
394
395 Overwrite the full set of existing environment variables with a new set. Specify either as a comma-separated list of key-value pairs (key1=value1,key2=value2) or in stringified JSON format.
396
397 * `--set-vars <environment variables>`
398
399 Specifies environment variables to set. If any of the variables already exist on the server, they are overwritten without prompt. Specify either as a comma-separated list of key-value pairs (key1=value1,key2=value2) or in stringified JSON format.
400
401 * `--runtime <node6|node8|node10|node12>`
402
403 Specifies major Node.js version to run the project on. The minor and patch versions will vary depending on the [latest Flex Runtime updates](#flex-runtime-version-selection). Defaults to the [Kinvey-recommended Node.js version](https://devcenter.kinvey.com/guides/flexservice-runtime#environment).
404
405* `flex job [id]`
406
407 _Deprecated_ Shows the job status of a deploy/recycle command. If you don't specify an `id`, the command returns the status of the most recent `flex deploy` or `flex recycle` command. _Deprecation note: For backward compatibility, the server always returns COMPLETE when the command is executed for the most recent deploy/recycle. Use `flex status` to track the progress of deploy or recycle commands._
408
409* `flex status`
410
411 Displays the health of the current Flex service and service environment combination, which is the one you initiated last on the current profile, as well as version information, runtime information, deployment status, etc. To get the status of a different service, specify its service ID.
412
413 * `--service <service>`
414
415 Specifies service ID.
416
417 * `--env <service environment>`
418
419 Specifies a service environment by ID or name.
420
421* `flex show`
422
423 Shows info about a service environment.
424
425 * `--service <service>`
426
427 Specifies service ID.
428
429 * `--env <service environment>`
430
431 Specifies a service environment by ID or name.
432
433* `flex list`
434
435 Lists all Flex services for a domain (app or organization), excluding external Flex services. Specify domain using `--domain` and then an app or organization ID using `--id`. If you skip the domain and ID options, the command lists the services within the domain you've configured as part of running `flex init`. In addition to the global options, this command supports the following options:
436
437 * `--domain <app|org>`
438
439 Specifies the domain type as either `app` for application or `org` for organization.
440
441 * `--id <app or organization ID>`
442
443 App or organization ID for use with `--domain <app|org>`.
444
445* `flex logs`
446
447 Retrieves and displays logs for the current Flex service environment. Log calls return 100 entries by default and can return up to 2,000 entries. Logs are displayed in the following format: `<runtime id> <timestamp> - <message>`. Combine with the paging and limiting options to narrow down your search. Logs for external Flex Services are not returned. In addition to the global options, this command supports the following options:
448
449 * `--service <service>`
450
451 Specifies service ID.
452
453 * `--env <service environment>`
454
455 Specifies a service environment by ID or name.
456
457 * `--from`
458
459 Timestamp specifying the beginning of a period for which you want to fetch log entries, in ISO 8601 format.
460
461 * `--number`
462
463 Number of entries to fetch, i.e. page size. The default is 100, the maximum allowed is 2000.
464
465 * `--page`
466
467 Page number to fetch. The first page is indexed 1.
468
469 * `--to`
470
471 Timestamp specifying the end of a period for which you want to fetch log entries, in ISO 8601 format.
472
473* `flex update`
474
475 Updates environment variables and/or runtime environment of the current Flex service environment, which is the one you initiated last on the current profile. To specify a different service, use `--service`. The command causes restart/rebuild of the service.
476
477 * `--service <service>`
478
479 Specifies service ID.
480
481 * `--env <service environment>`
482
483 Specifies a service environment by ID or name.
484
485 * `--replace-vars <environment variables>`
486
487 Overwrite the full set of existing environment variables with a new set. Specify either as a comma-separated list of key-value pairs (key1=value1,key2=value2) or in stringified JSON format.
488
489 * `--set-vars <environment variables>`
490
491 Specifies environment variables to set. If any of the variables already exist on the server, they are overwritten without prompt. Specify either as a comma-separated list of key-value pairs (key1=value1,key2=value2) or in stringified JSON format.
492
493 * `--runtime <node6|node8|node10|node12>`
494
495 Specifies major Node.js version to run the project on. The minor and patch versions will vary depending on the [latest Flex Runtime updates](#flex-runtime-version-selection). Defaults to the [Kinvey-recommended Node.js version](https://devcenter.kinvey.com/guides/flexservice-runtime#environment).
496
497* `flex recycle`
498
499 Recycles the current Flex service environment, which is the one you initiated last on the current profile. To recycle a different service, specify its service ID.
500
501 * `--service <service>`
502
503 Specifies service ID.
504
505 * `--env <service environment>`
506
507 Specifies a service environment by ID or name.
508
509* `flex delete`
510
511 Deletes the current Flex service, including all service environments inside it. The current service is the one you initiated last on the current profile. To delete a different service, specify its service ID. You will be prompted for confirmation unless you set the `--no-prompt` flag.
512
513 * `--service <service>`
514
515 Specifies service ID.
516
517 * `--no-prompt`
518
519 Do not ask for confirmation.
520
521* `flex clear`
522
523 When executed in a Node.js project directory, this command removes the current Flex Service configuration from the project.
524
525* `website create <name>`
526
527 Create a website. You need to specify an organization or an application.
528
529 * `--app <application>`
530
531 Specifies a Kinvey app by ID or name.
532
533 * `--org <organization>`
534
535 Specifies a Kinvey organization by ID or name.
536
537 * `--historyApiRouting`
538
539 Enables server support for History API routing.
540
541 * `--indexPage <index-page>`
542
543 Specifies index page.
544
545 * `--errorPage <error-page>`
546
547 Specifies error page. Not allowed if `--historyApiRouting` is also specified.
548
549* `website list`
550
551 List websites.
552
553* `website show`
554
555 Shows info for the specified website.
556
557 * `--website <website>`
558
559 Website ID/name. Required.
560
561* `website deploy`
562
563 Deploy your website.
564
565 * `--website <website>`
566
567 Website ID/name. Required.
568
569 * `--path <path>`
570
571 Path to file or directory. Required.
572
573 * `--force`
574
575 Skip client-side validation - deploy even if there are no files for index page and/or error page.
576
577* `website publish`
578
579 Publish your website - enable public access or change domain name.
580
581 * `--website <website>`
582
583 Website ID/name. Required.
584
585 * `--domainName <domain-name>`
586
587 Domain name. Required.
588
589* `website status`
590
591 Status of the specified website.
592
593 * `--website <website>`
594
595 Website ID/name. Required.
596
597* `website unpublish`
598
599 Unpublish your website - disable public access.
600
601 * `--website <website>`
602
603 Website ID/name. Required.
604
605* `website delete`
606
607 Deletes the specified website.
608
609 * `--website <website>`
610
611 Website ID/name. Required.
612
613 * `--no-prompt`
614
615 Do not ask for confirmation.
616
617* `help`
618
619 Prints general usage instructions. For detailed command usage instruction, use the `--help` option with the command.
620
621## Global Options
622
623You can add a global option to every Kinvey CLI command to get the described behavior. The only exceptions are `--email`, `--password`, `--instance-id` and `--2fa` which get ignored when added to a command that is designed to prompt for this information.
624
625* `--2fa <2fa-token>`
626
627 Two-factor authentication token. Applicable when two-factor authentication is enabled.
628
629* `--email <e-mail>`
630
631 Email address of your Kinvey account.
632
633* `--help, -h`
634
635 When used after a `kinvey-cli` command, shows its usage instructions.
636
637* `--instance-id <instance ID>`
638
639 ID (e.g., `kvy-us2`) or full hostname (e.g., `https://kvy-us2-manage.kinvey.com/`) of a Kinvey instance. It has a default value of `kvy-us1` (or `https://manage.kinvey.com/`) which most customers should use. If you are a customer on a dedicated Kinvey instance, enter your dedicated instance ID.
640
641* `--no-color`
642
643 Disable colors.
644
645* `--output <format>`
646
647 Output format. Valid choices: json.
648
649* `--password <password>`
650
651 Password for your Kinvey account.
652
653* `--profile <profile>`
654
655 Profile to use.
656
657* `--version`
658
659 Prints the version number of `kinvey-cli`.
660
661* `--silent`
662
663 Suppresses any output. Useful for scripting.
664
665* `--suppress-version-check`
666
667 Prevents Kinvey CLI to check for new versions, which normally happens each execution.
668
669* `--verbose`
670
671 Prints additional debug messages.
672
673## Environment Variables
674
675Use environment variables to specify profile information for the `profile create` command when you don't want to specify it at the command line. Keep in mind that any values specified at the command line take precedence over the environment variable values.
676
677Command-specific options can also be specified as environment variables. You just need to prefix the name of the option with `KINVEY_CLI_`. For example, `--no-prompt` becomes `KINVEY_CLI_NO_PROMPT` as environment variable.
678
679* `KINVEY_CLI_EMAIL`
680
681 Email address of your Kinvey account.
682
683* `KINVEY_CLI_PASSWORD`
684
685 Password for your Kinvey account.
686
687* `KINVEY_CLI_INSTANCE_ID`
688
689 ID (e.g., `kvy-us2`) or full hostname (e.g., `https://kvy-us2-manage.kinvey.com/`) of a Kinvey instance. It has a default value of `kvy-us1` (or `https://manage.kinvey.com/`) which most customers should use. If you are a customer on a dedicated Kinvey instance, enter your dedicated instance ID.
690
691* `KINVEY_CLI_2FA`
692
693 Two-factor authentication token.
694
695* `KINVEY_CLI_PROFILE`
696
697 Profile to use.
698
699Kinvey CLI also supports these universal environment variables:
700
701* `HTTPS_PROXY`/`https_proxy`
702
703 Routes all Kinvey CLI requests through the specified proxy server.
704
705
706## Getting Help
707
708Kinvey CLI comes with a two-stage help system. You can either call the `help` command to see an overview of the available commands or request details about a command usage with the `-h` flag.
709
710 kinvey help
711
712 kinvey flex -h
713
714 kinvey flex logs -h
715
716
717## Getting Started
718
719Kinvey CLI requires you to authenticate. The fastest way to get started is to run the `kinvey init` command. It prompts for credentials and hostname and creates a working profile for you, which stores the provided settings for future executions.
720
721Note that you only need to specify an instance ID if you are on a dedicated Kinvey instance. Otherwise just press Enter to continue.
722
723When prompted for `Profile name`, enter a name for your new working profile that Kinvey CLI will create for you. Kinvey CLI will use this profile automatically for future executions as long as it is the only profile on the system. You can create new profiles and select an active profile if you need to.
724
725```
726$ kinvey init
727? E-mail john.doe@kinvey.com
728? Password ***********
729? Instance ID (optional) kvy-us1
730? Profile name dev
731```
732
733You can run `kinvey init` from any directory as it always writes your new profile in your home directory.
734
735Next, you need to configure Kinvey CLI to connect to a Flex Service that you've already created using the Kinvey Console or through `kinvey flex create <service-name>`.
736
737For the following commands, you need to switch to the Node.js project directory that you will be deploying as a Flex Service as the configuration they create and read is project-specific.
738
739```
740cd <node.js project dir>
741kinvey flex init
742```
743
744Through a series of prompts, this command will ask you for a domain in which to operate (app or organization) and a Flex Service to deploy to.
745
746Finally, you are ready to deploy your Node.js project as a Flex Service.
747
748 kinvey flex deploy
749
750Alongside the deploy you can set environment variables for your service. If both names and values are void of the equality sign (`=`) and comma (`,`), you can use the shorthand syntax:
751
752 kinvey flex deploy --set-vars "MY_APP_A=valueA,MY_APP_B=valueB"
753
754Otherwise you need to specify environment variables in stringified JSON format:
755
756 kinvey flex deploy --set-vars "{\"MY_APP_A\":[\"value 1\", \"value 2\"], \"MY_APP_B\":\"valueB\"}"
757
758**Note**: Kinvey CLI sends binary data (content type "multipart/form-data") during the deploy process. The deploy job will fail if traffic of this type is blocked within your network.
759
760## Managing Profiles
761
762Another way to create working profiles, besides running `kinvey init`, is invoking `kinvey profile create <name>`. You can choose between providing the credentials at the command line or as preset [environment variables](#environment-variables).
763
764 kinvey profile create dev --email john.doe@kinvey.com --password john'sPassword --instanceId kvy-us2
765
766You can create multiple profiles and specify which one to use at the command line.
767
768 kinvey flex init --profile dev
769
770If you don't want to specify a profile every time, you can set one as active and it will be used for future executions:
771
772 kinvey profile use dev
773
774
775**Note**: If you have a single profile, you can skip setting it as active as well as providing it as a command line option. It will be used if no other credentials are provided.
776
777### Authentication Token Expiration
778
779As part of creating a working profile, the authentication token provided by Kinvey is stored locally. This token will be used to authenticate future command executions until it expires. At that point, you need to reenter your password or recreate the profile to keep working with Kinvey CLI. Run `kinvey profile login` to reenter your password. You can recreate the profile by providing the profile name to `kinvey init` or `kinvey profile create`.
780
781## Authenticating One-time Commands
782
783Every command that requires authentication can take credentials and a hostname as command line options. If a hostname is not provided, its default value is used.
784
785 kinvey flex status --service <service-id> --email <email> --password <password>
786
787You can also provide the same information through environment variables before running the command.
788
789**Linux, macOS**
790```
791export KINVEY_CLI_EMAIL=<email>
792export KINVEY_CLI_PASSWORD=<password>
793export KINVEY_CLI_INSTANCE_ID=<instance ID>
794```
795
796**Windows**
797```
798set KINVEY_CLI_EMAIL=<email>
799set KINVEY_CLI_PASSWORD=<password>
800set KINVEY_CLI_INSTANCE_ID=<instance ID>
801```
802
803## Precedence of Configuration Options
804
805For the Kinvey CLI commands that require passing configuration values, the following precedence order applies.
806
807* Command line options&mdash;take precedence when specified
808* Environment variables&mdash;the first choice when command line arguments are missing
809* Profile data&mdash;values saved as part of the applicable working profile are used if neither command line arguments nor environment variables are set
810
811
812## Output Format
813
814Kinvey CLI supports two output formats: plain text and JSON. Both are printed on the screen unless you redirect the output using shell syntax.
815
816Plain text is printed by default. Depending on the command, it produces tabular data or a simple message stating that the action has completed successfully.
817
818The JSON output format is suitable for cases where the output must be handled programmatically. It could be further processed using a tool like jq (command-line JSON processor). You can run any command with `--output json`. The output will then have the following format:
819
820```
821{
822 "result": [result]
823}
824```
825
826## Flex Runtime Version Selection
827
828Flex projects that you deploy run server-side on the Flex Runtime which represents a preconfigured Node.js environment. When creating a project and later when running it, you can select a Node.js version for the project to run on using the `--runtime` option. To see the available runtime versions, run `kinvey flex deploy --help`.
829
830The runtime selection is limited to the major Node.js version. The minor and patch versions are always determined by the Flex Runtime.
831
832New Flex services deploy on the [Kinvey-recommended Node.js version](https://devcenter.kinvey.com/guides/flexservice-runtime#environment) unless otherwise specified.
833
834After you deploy a Flex project, it remains on the same Node.js version until you upgrade it to a new major version or Kinvey decides to upgrade the project's runtime to a more recent minor and patch version because of security or efficiency reasons.
835
836## Proxy Settings
837
838Kinvey CLI supports the universal environment variables `HTTPS_PROXY` and `https_proxy` for routing commands through a proxy server. Set it if you are using a proxy.
839
840
841 export HTTPS_PROXY=proxy.local
842
843
844## Configuration management
845
846Kinvey CLI supports the usage of configuration files (JSON format) to enable configuring certain aspects of the backend.
847
848**Organizations** can be modified by applying an organization configuration file. The file can contain applications and org-level services.
849
850**Applications** can be created and modified by applying an application configuration file. The file can contain app environments and app-level services.
851
852**Environments** can be created and modified by applying an environment configuration file. The file can contain: environment-related settings, collections, business logic, roles, push settings.
853
854**Services** can be created and modified by applying a service configuration file. Supported services: internal flex, external flex, REST, Sharepoint, Salesforce, MS SQL, ProgressData, DataDirect, Rapid health.
855
856### Environment configuration file
857
858The environment configuration file can be used to create a brand new environment or to modify an existing one. It is easiest to generate the file by 'exporting' an existent environment and making the necessary modifications. To export an environment run:
859
860 ```
861kinvey appenv export (--file <file-path>) [--env <env>] [--app <app>]
862```
863
864Alternatively, the environment template beneath can be used and modified as needed.
865
866To create an environment from a configuration file run:
867 ```
868kinvey appenv create <envName> (--file <file-path>) (--app <AppNameOrID>)
869```
870
871To apply a configuration file to an existent environment run:
872 ```
873kinvey appenv apply [--file <file-path>] (-env <env>) (--app <app>)
874```
875
876Before an environment config file gets applied a check will be executed to verify JSON is valid and parameter values are allowed. If the check passes successfully, Kinvey CLI will start applying the changes. In the case of a new environment it will simply try to create all the entities described in the file.
877
878When the file is being applied to an existent environment then existent entities could be updated and new ones can be created. The CLI won't delete any entities even if they are not included in the file. Hence, if you want to create new endpoints but don't want to modify any existent collections for example, then you can exclude them from the configuration to have the file being applied faster.
879
880If an error occurs, the CLI stops applying the file and outputs the error message.
881
882#### Environment sample config file
883
884```
885{
886 "schemaVersion": "1.0.0",
887 "configType": "environment",
888 "settings": {
889 "apiVersion": 3,
890 "emailVerification": {
891 "required": false
892 }
893 },
894 "collections": {
895 "myCollection": {
896 "type": "internal",
897 "permissions": "shared"
898 },
899 "anotherCollection": {
900 "type": "external",
901 "permissions": "shared",
902 "service": "awesomeService",
903 "serviceEnvironment": "development",
904 "serviceObject": "awesomeServiceObject"
905 }
906 },
907 "commonCode": {
908 "my-common-code": {
909 "code": "var commonLogic = {};\ncommonLogic.print = function print(msg) {\n console.log(msg);\n};"
910 },
911 "another-common-code": {
912 "codeFile": "./another-common-code.js"
913 }
914 },
915 "collectionHooks": {
916 "myCollection": {
917 "onPreSave": {
918 "type": "internal",
919 "code": "function onPreSave(request, response, modules) {\n response.continue();\n}"
920 },
921 "onPostSave": {
922 "type": "external",
923 "service": "awesomeService",
924 "serviceEnvironment": "development",
925 "handlerName": "awesomeHandler"
926 }
927 }
928 },
929 "customEndpoints": {
930 "myEndpoint": {
931 "type": "internal",
932 "codeFile": "./my-endpoint.js",
933 "schedule": {
934 "start": "2019-07-22T16:35:00Z",
935 "interval": "5-minutes"
936 }
937 },
938 "anotherEndpoint": {
939 "type": "external",
940 "service": "awesomeService",
941 "serviceEnvironment": "development",
942 "handlerName": "anotherHandler"
943 }
944 },
945 "roles": {
946 "Intern": { "description": "Interns" },
947 "Employee": { "description": "Employees" }
948 },
949 "groups": {
950 "myGroup": {
951 "description": "Description here",
952 "groups": [ "otherGroup" ]
953 },
954 "otherGroup": {
955 "description": "Part of 'myGroup'"
956 }
957 },
958 "push": {
959 "android": {
960 "senderId": "id123",
961 "apiKey": "key123"
962 },
963 "ios": {
964 "production": false,
965 "certificateFilePath": "./mycertdev.p12"
966 }
967 }
968}
969```
970
971#### Allowed fields:
972
973`schemaVersion` The schema version the CLI supports. Required. Current: 1.0.0
974
975`configType` *environment|service* The configuration type. Required.
976
977`settings` Environment settings. Optional.
978
979`settings.apiVersion` The default REST API version for this env.
980
981`settings.emailVerification` Options regarding email verification for users of this environment. Optional.
982
983`settings.emailVerification.required` *true|false* If true, users who have not verified their email will not be able to access the environment. Required.
984
985`settings.emailVerification.auto` *true|false* If true, automatically send a email verification request to all new users created within the environment. Optional.
986
987`settings.emailVerification.since` ISO-8601 date. If specified, any user created before this date will not need a verified email in order to access the environment. Optional.
988
989`collections` Environment collections. Optional. Object. Each first-level property is the name of a collection and contains an object describing this collection.
990
991`collections.[collectionName].type` *internal|external* If external, then the collection is backed by a flex service. Required.
992
993`collections.[collectionName].permissions` Collections permissions. Required. Could be a string or an object. Allowed string values: private, full, shared, read-only. To specify roles, use an object in the following format:
994```
995"permissions": {
996 [roleName]: {
997 [operation]: [accessType]
998 }
999}
1000```
1001where **operation** is one of: *create, read, update, delete*
1002
1003and **accessType** is one of: *never, always, grant, entity*
1004
1005To specify the built-in **All users** role, use *all-users*.
1006
1007 Example:
1008
1009```
1010"permissions": {
1011 "all-users": {
1012 "read": "always"
1013 },
1014 "Employee": {
1015 "create": "always",
1016 "read": "always",
1017 "update": "always",
1018 "delete": "grant"
1019 }
1020}
1021```
1022
1023`collections.[collectionName].service` Service to connect the collection to. Either service name or ID. Collection type must be set to 'external'.
1024
1025`collections.[collectionName].serviceEnvironment` Service environment to connect the collection to. Collection type must be set to 'external'.
1026
1027`collections.[collectionName].serviceObject` Service object. Collection type must be set to 'external'.
1028
1029`commonCode` Common code functions. Optional. An object where each first-level property is the name of the common code script.
1030
1031`commonCode.[commonCodeName].code` Code. Either `code` or `codeFile` must be set.
1032
1033`commonCode.[commonCodeName].codeFile` Path to code - relative or absolute. Either `code` or `codeFile` must be set.
1034
1035`collectionHooks` Collection hooks. Optional. An object where each first-level property is the name of a collection.
1036
1037`collectionHooks.[collectionName].[hookName]` *onPreSave|onPreFetch|onPreDelete|onPostSave|onPostFetch|onPostDelete* Hook type.
1038
1039`collectionHooks.[collectionName].[hookName].type` *internal|external* External if a service is involved. Required.
1040
1041`collectionHooks.[collectionName].[hookName].code` Code. Either `code` or `codeFile` can be set.
1042
1043`collectionHooks.[collectionName].[hookName].codeFile` Path to code - relative or absolute. Either `code` or `codeFile` can be set.
1044
1045`collectionHooks.[collectionName].[hookName].service` Service to use. Collection hook type must be set to 'external'.
1046
1047`collectionHooks.[collectionName].[hookName].serviceEnvironment` Service environment to use. Collection hook type must be set to 'external'.
1048
1049`collectionHooks.[collectionName].[hookName].handlerName` Handler name. Collection hook type must be set to 'external'.
1050
1051`customEndpoints` Custom endpoints. Optional. Object where each first-level property is the name of an endpoint.
1052
1053`customEndpoints.[endpointName].type` *internal|external* External if a service is involved. Required.
1054
1055`customEndpoints.[endpointName].code` Code. Either `code` or `codeFile` can be set.
1056
1057`customEndpoints.[endpointName].codeFile` Path to code - relative or absolute. Either `code` or `codeFile` can be set.
1058
1059`customEndpoints.[endpointName].service` Service to use. Endpoint type must be set to 'external'.
1060
1061`customEndpoints.[endpointName].serviceEnvironment` Service environment to use. Endpoint type must be set to 'external'.
1062
1063`customEndpoints.[endpointName].handlerName` Handler name. Endpoint type must be set to 'external'.
1064
1065`customEndpoints.[endpointName].schedule` Object describing how to schedule the endpoint. Optional.
1066
1067`customEndpoints.[endpointName].schedule.start` The code will be scheduled to start running at this date and time. ISO-8601 datetime. Required.
1068
1069`customEndpoints.[endpointName].schedule.interval` *weekly|daily|hourly|30-minutes|10-minutes|5-minutes|1-minute* At what intervals to execute the code. Optional.
1070
1071`roles` Roles. Optional. Object where each first-level property is the name of a role.
1072
1073`roles.[roleName].description` Role description. String. Optional.
1074
1075`groups` Groups. Optional. Object where each first-level property is the ID of a group. For example if the name is 'My group', then an appropriate ID could be 'myGroup' or 'my-group'.
1076
1077`groups.[groupId].name` Name. Optional.
1078
1079`groups.[groupId].description` Description. Optional.
1080
1081`groups.[groupId].groups` Nested groups. Optional. An array of other groups IDs.
1082
1083`push` Push notifications settings. Optional. Object.
1084
1085`push.android` Object describing Android settings. Optional.
1086
1087`push.android.senderId` Sender ID. Required.
1088
1089`push.android.apiKey` API Key. Required.
1090
1091`push.ios` Object describing iOS settings. Optional.
1092
1093`push.ios.production` *true|false* If false, then it is a development certificate. Required.
1094
1095`push.ios.certificateFilePath` Path to certificate - relative or absolute. Required.
1096
1097`push.ios.password` Certificate password. Optional.
1098
1099### Service configuration file
1100
1101The service configuration file can be used to create a brand new service or to modify an existing one (excluding Auth services).
1102
1103To create a service from a configuration file run:
1104 ```
1105kinvey service create <serviceName> <file-path> [--app AppNameOrId|--org OrgNameOrId]
1106```
1107
1108Either `--app` or `--org` option must be set. The service will be accessible only to the chosen application or organization respectively.
1109
1110To apply a configuration file to an existent service run:
1111 ```
1112kinvey service apply [--file <file-path>] [--service <service-ID>]
1113```
1114
1115When a new internal flex service is created the CLI will attempt a deploy if `sourcePath` is set to the project root directory.
1116
1117When an existent internal flex service is updated and `sourcePath` is set, the CLI will attempt to deploy only if the version defined in `package.json` is higher then the cloud version. Otherwise, deployment procedure will be skipped.
1118
1119The following service templates can be used and modified as needed:
1120
1121#### `flex-internal` service sample config file
1122
1123```
1124{
1125 "schemaVersion": "1.0.0",
1126 "configType": "service",
1127 "type": "flex-internal",
1128 "environments": {
1129 "dev": {
1130 "secret": "123",
1131 "description": "Some description here",
1132 "environmentVariables": {
1133 "MY_KEY": "my value"
1134 }
1135 }
1136 }
1137}
1138```
1139
1140#### `data-rest` service sample config file
1141
1142```
1143{
1144 "schemaVersion": "1.0.0",
1145 "configType": "service",
1146 "type": "data-rest",
1147 "environments": {
1148 "Default": {
1149 "host": "http://www.test.com",
1150 "authentication": {
1151 "type": "None",
1152 "credentials": {
1153 "mapTo": {
1154 "decode": false
1155 }
1156 },
1157 "loginOptions": {
1158 "type": "noLogin",
1159 "headers": {},
1160 "querystring": {},
1161 "body": {}
1162 }
1163 },
1164 "connectionOptions": {
1165 "strictSSL": false,
1166 "rejectUnauthorized": false,
1167 "headers": {},
1168 "querystring": {}
1169 },
1170 "mapping": {
1171 "users": {
1172 "sourceObject": {
1173 "primaryKey": {
1174 "type": "string",
1175 "name": "Id"
1176 },
1177 "endpoint": "/users",
1178 "httpMethod": "GET",
1179 "queryMapping": {
1180 "query": "header"
1181 },
1182 "querystring": {
1183 "query_param_name": "query_param_value"
1184 },
1185 "headers": {
1186 "header_name": "header_value"
1187 }
1188 },
1189 "fields": [
1190 {
1191 "kinveyFieldMapping": "username",
1192 "sourceFieldMapping": "username"
1193 },
1194 {
1195 "kinveyFieldMapping": "_id",
1196 "sourceFieldMapping": "userId"
1197 }
1198 ],
1199 "methods": {
1200 "getAll": {
1201 "isEnabled": true
1202 },
1203 "getById": {
1204 "isEnabled": false
1205 },
1206 "insert": {
1207 "isEnabled": true
1208 },
1209 "update": {
1210 "isEnabled": false
1211 },
1212 "deleteById": {
1213 "isEnabled": false
1214 },
1215 "deleteByQuery": {
1216 "isEnabled": false
1217 },
1218 "getCount": {
1219 "isEnabled": true
1220 },
1221 "getCountByQuery": {
1222 "isEnabled": false
1223 }
1224 }
1225 }
1226 }
1227 }
1228 }
1229}
1230```
1231
1232#### Allowed fields:
1233
1234`schemaVersion` The schema version the CLI supports. Required. Current: 1.0.0
1235
1236`configType` *environment|service* The configuration type. Required.
1237
1238`type` *flex-internal|flex-external|data-rest|data-sharepoint|data-salesforce|data-mssql|data-progress|data-direct|data-health* Service type. Required.
1239
1240`description` Service description. String. Optional.
1241
1242`environments` Service environments. Object where each first-level property is the name of a service environment. Optional.
1243
1244 `environments.[envName].secret` Shared secret to use when communicating with the service. Аpplicable and required for 'flex-internal' and 'flex-external'
1245
1246`environments.[envName].host` URI pointing to the service server's location. Required for all service types except 'flex-internal' and 'data-health'.
1247
1248`environments.[envName].sourcePath` Path to source code - relative or absolute. Optional. Applicable when `type` is 'flex-internal'.
1249
1250`environments.[envName].runtime` The nodejs version of the runtime. Optional. The value must be one of [node6, node8, node10, node12]. Applicable when `type` is 'flex-internal'.
1251
1252`environments.[envName].authentication` Authentication type and credentials. Object. Optional. Applicable for 'data-rest', 'data-sharepoint', 'data-salesforce', 'data-mssql', 'data-progress', 'data-direct' and 'data-health' service types
1253
1254`environments.[envName].connectionOptions` Connection options. Object. Optional. Applicable for 'data-rest', 'data-sharepoint', 'data-salesforce', 'data-mssql', 'data-progress', 'data-direct' and 'data-health' service types.
1255
1256`environments.[envName].mapping` Contains the source object, the source fields mapping and the supported operations. Object. Optional. Applicable for 'data-rest', 'data-sharepoint', 'data-salesforce', 'data-mssql', 'data-progress', 'data-direct' and 'data-health' service types.
1257
1258`environments.[envName].version` The version of the source server. Object. Optional. Applicable when `type` is 'data-sharepoint' or 'data-mssql'.
1259
1260`environments.[envName].environmentVariables` Environment variables. Object. Optional. Applicable when `type` is 'flex-internal'.
1261
1262## Troubleshooting
1263
1264Run any command with the `--verbose` flag to receive more detailed information about a command execution.
1265
1266### Caveats
1267
1268Kinvey CLI is a subject to the following caveats:
1269
1270- The CLI has a 10-second request timeout when communicating with the backend for initialization which may cause a connection error in some rare cases. Retrying the command remedies the problem in many cases.
1271- If you are using a profile that has been configured a while ago, you may stumble upon the `InvalidCredentials` error. It may mean that the session token has expired. See [Authentication Token Expiration](#authentication-token-expiration) for details.
1272- You cannot deploy the same service version to the FlexService Runtime more than once. You must increment the version in `package.json` before redeploying.
1273- Kinvey CLI sends binary data (content type "multipart/form-data") during the deploy process. The deploy job will fail if traffic of this type is blocked within your network.
1274- There is a limit of 100 MB to the size of the FlexService logs that are kept on the backend. When log entries exceed that size, the oldest ones are deleted.
1275- Running the CLI from Git Bash on Windows is known to cause issues ranging from failing commands to complete inability to start. Use Windows Command Prompt instead.
1276
1277If problems persist, contact [Kinvey](http://support.kinvey.com).
1278
1279### Support for Service Environments
1280
1281Kinvey CLI version 4.1.0 introduces support for environments inside Flex services coinciding with the release of this feature on the backend. When upgrading from a previous Kinvey CLI version, have the following caveats in mind:
1282
1283- The `flex init` interactive command prompts for service environment selection in version 4.1.0 and later if the service contains multiple environments.
1284- Node.js projects configured with `flex init` with a Kinvey CLI version predating 4.1.0 do not contain a service environment ID. Therefore:
1285 - We recommend rerunning the `flex init` command on these projects.
1286 - Flex commands targeting the current service will continue to work as long as the service has a single environment.
1287 - Flex commands targeting the current service will error out if you create additional environments inside the service and don't include `--env`.
1288- Flex commands specifying a particular service using `--service` must include `--env` if the service has multiple environments. You can omit `--env` if the service has a single environment.
1289
1290## Changelog
1291
1292See the [Changelog](./CHANGELOG.md) for a list of changes.
1293
1294## License
1295
1296 Copyright (c) 2018, Kinvey, Inc. All rights reserved.
1297
1298 This software is licensed to you under the Kinvey terms of service located at
1299 http://www.kinvey.com/terms-of-use. By downloading, accessing and/or using this
1300 software, you hereby accept such terms of service (and any agreement referenced
1301 therein) and agree that you have read, understand and agree to be bound by such
1302 terms of service and are of legal age to agree to such terms with Kinvey.
1303
1304 This software contains valuable confidential and proprietary information of
1305 KINVEY, INC and is subject to applicable licensing agreements.
1306 Unauthorized reproduction, transmission or distribution of this file and its
1307 contents is a violation of applicable laws.
1308
\No newline at end of file