UNPKG

14.6 kBMarkdownView Raw
1# Kinvey CLI
2
3Kinvey CLI is a utility for deploying and managing FlexServices running on the Kinvey FlexService Runtime.
4
5## Installation
6
7Kinvey CLI is distributed as an NPM package. After you install NPM, run the following command to download and install Kinvey CLI.
8
9 npm install -g kinvey-cli
10
11## Usage
12
13 kinvey <command> [args] [options]
14
15## Commands
16
17* `init`
18
19 Prompts you to provide account credentials and host and creates a new working profile for you based on the information you provided. Command-line options that specify the same data are ignored.
20
21* `profile create <name> [profile information]`
22
23 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 in the environment variables are ignored.
24
25* `profile list`
26
27 Lists all existing profiles. Profiles are saved under the user home.
28
29* `profile show [name]`
30
31 Shows detailed information about the specified profile. If you omit the profile name, information about the active profile is shown.
32
33* `profile use <name>`
34
35 Sets an active profile.
36
37* `profile delete <name>`
38
39 Deletes the specified profile.
40
41* `flex init`
42
43 Configures Kinvey CLI to work with a specific Flex Service through prompts. This command is designed to be executed in a Node.js project directory where it creates a `.kinvey` configuration file. Information inside 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.
44
45* `flex deploy`
46
47 Deploys the current project to the Kinvey FlexService Runtime. To use a different service than the one initiated last, specify its service ID.
48
49 * `--serviceId <Flex Service ID>`
50
51 Specifies a Flex Service by its ID.
52
53* `flex job [id]`
54
55 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.
56
57* `flex status`
58
59 Displays the health of the current (the one you initiated last) Flex Service. To get the status of a different service, specify its service ID using the `--serviceId` option. In addition to the global options, this command supports the following options:
60
61 * `--serviceId <Flex Service ID>`
62
63 Specifies a Flex Service by its ID.
64
65* `flex list`
66
67 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 inside the domain you've configured as part of running `flex init`. In addition to the global options, this command supports the following options:
68
69 * `--domain <app|org>`
70
71 Specifies the domain type as either `app` for application or `org` for organization.
72
73 * `--id <app or organization ID>`
74
75 App or organization ID for use with `--domain <app|org>`.
76
77* `flex logs`
78
79 Retrieves and displays Flex Services logs. Logs 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. You can specify a Flex Service to read logs from using the `--serviceId` option. In addition to the global options, this command supports the following options:
80
81 * `--from`
82
83 Timestamp specifying the beginning of a period for which you want to fetch log entries, in ISO 8601 format.
84
85 * `--number`
86
87 Number of entries to fetch, i.e. page size. The default is 100, the maximum allowed is 2000.
88
89 * `--page`
90
91 Page number to fetch. The first page is indexed 1.
92
93 * `--serviceId <Flex Service ID>`
94
95 Specifies a Flex Service by its ID.
96
97 * `--to`
98
99 Timestamp specifying the end of a period for which you want to fetch log entries, in ISO 8601 format.
100
101* `flex recycle`
102
103 Recycles the current (the one you initiated last) Flex Service. To recycle a different service, specify its service ID using the `--serviceId` option. In addition to the global options, this command supports the following options:
104
105 * `--serviceId <Flex Service ID>`
106
107 Specifies a Flex Service by its ID.
108
109* `flex delete`
110
111 Deletes the current Flex Service configuration from the Node.js project directory that it has been executed in.
112
113* `help`
114
115 Prints general usage instructions. For detailed command usage instruction, use the `--help` option with the command.
116
117## Global Options
118
119You can add a global option to every Kinvey CLI command to get the described behavior. The only exceptions are `--email`, `--password`, and `--host` which get ignored when added to a command that is designed to prompt for this information.
120
121* `--email <e-mail>`
122
123 Email address of your Kinvey account.
124
125* `--help, -h`
126
127 When used after a `kinvey-cli` command, shows its usage instructions.
128
129* `--instanceId <instance ID>`
130
131 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.
132
133* `--no-color`
134
135 Disable colors.
136
137* `--output <format>`
138
139 Output format. Valid choices: json.
140
141* `--password <password>`
142
143 Password for your Kinvey account.
144
145* `--profile <profile>`
146
147 Profile to use.
148
149* `--version`
150
151 Prints the version number of `kinvey-cli`.
152
153* `--silent`
154
155 Suppresses any output. Useful for scripting.
156
157* `--suppress-version-check`
158
159 Prevents Kinvey CLI to check for new versions, which normally happens each execution.
160
161* `--verbose`
162
163 Prints additional debug messages.
164
165## Environment Variables
166
167Use these 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.
168
169* `KINVEY_CLI_EMAIL`
170
171 Email address of your Kinvey account.
172
173* `KINVEY_CLI_PASSWORD`
174
175 Password for your Kinvey account.
176
177* `KINVEY_CLI_INSTANCE_ID`
178
179 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.
180
181* `KINVEY_CLI_PROFILE`
182
183 Profile to use.
184
185Kinvey CLI also supports these universal environment variables:
186
187* `HTTPS_PROXY`/`https_proxy`
188
189 Routes all Kinvey CLI requests through the specified proxy server.
190
191
192## Getting Help
193
194Kinvey 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.
195
196 kinvey help
197
198 kinvey flex -h
199
200 kinvey flex logs -h
201
202
203## Getting Started
204
205Kinvey 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.
206
207Note that you only need to specify a host if you are on a dedicated Kinvey instance. Otherwise just press Enter to continue.
208
209When 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.
210
211```
212$ kinvey init
213? E-mail john.doe@kinvey.com
214? Password ***********
215? Instance ID (optional) kvy-us1
216? Profile name dev
217```
218
219You can run `kinvey init` from any directory as it always writes your new profile in your home directory.
220
221Next, you need to configure Kinvey CLI to connect to a Flex Service that you've already created using the Kinvey Console.
222
223For 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.
224
225```
226cd <node.js project dir>
227kinvey flex init
228```
229
230Through 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.
231
232Finally, you are ready to deploy you node.js project as a Flex Service.
233
234 kinvey flex deploy
235
236**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.
237
238## Managing Profiles
239
240Another 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).
241
242 kinvey profile create dev --email john.doe@kinvey.com --password john'sPassword --host kvy-us2
243
244You can create multiple profiles and specify which one to use at the command line.
245
246 kinvey flex init --profile dev
247
248If you don't want to specify a profile every time, you can set one as active and it will be used for future executions:
249
250 kinvey profile use dev
251
252
253**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.
254
255### Authentication Token Expiration
256
257As 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 recreate the profile to keep working with Kinvey CLI. You can do that by providing the profile name to `kinvey init` or `kinvey profile create`.
258
259## Authenticating One-time Commands
260
261Every 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.
262
263 kinvey flex status --serviceId <service-id> --email <email> --password <password>
264
265You can also provide the same information through environment variables before running the command.
266
267**Linux, macOS**
268```
269export KINVEY_CLI_EMAIL=<email>
270export KINVEY_CLI_PASSWORD=<password>
271export KINVEY_CLI_INSTANCE_ID=<instance ID>
272```
273
274**Windows**
275```
276set KINVEY_CLI_EMAIL=<email>
277set KINVEY_CLI_PASSWORD=<password>
278set KINVEY_CLI_INSTANCE_ID=<instance ID>
279```
280
281## Precedence of Configuration Options
282
283For the Kinvey CLI commands that require passing configuration values, the following precedence order applies.
284
285* Command line options&mdash;take precedence when specified
286* Environment variables&mdash;the first choice when command line arguments are missing
287* Profile data&mdash;values saved as part of the applicable working profile are used if neither command line arguments nor environment variables are set
288
289
290## Output Format
291
292Kinvey CLI supports two output formats: plain text and JSON. Both are printed on the screen unless you redirect the output using shell syntax.
293
294Plain text is printed by default. Depending on the command, it produces tabular data or a simple message stating that the action has completed successfully.
295
296The JSON output format is suitable for cases where the output must be handled programmatically. You can run any command with `--output json`. The output will then have the following format:
297
298```
299{
300 "result": [result]
301}
302```
303
304## Proxy Settings
305
306Kinvey 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.
307
308
309 export HTTPS_PROXY=proxy.local
310
311
312## Troubleshooting
313
314Run any command with the `--verbose` flag to receive more detailed information about a command execution.
315
316Kinvey CLI is a subject to the following caveats:
317
318- It 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.
319- 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.
320- You cannot deploy the same service version to the FlexService Runtime more than once. You must increment the version in `package.json` before redeploying.
321- 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.
322- 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.
323
324If problems persist, contact [Kinvey](http://support.kinvey.com).
325
326## Changelog
327
328See the [Changelog](./CHANGELOG.md) for a list of changes.
329
330## License
331
332 Copyright (c) 2017, Kinvey, Inc. All rights reserved.
333
334 This software is licensed to you under the Kinvey terms of service located at
335 http://www.kinvey.com/terms-of-use. By downloading, accessing and/or using this
336 software, you hereby accept such terms of service (and any agreement referenced
337 therein) and agree that you have read, understand and agree to be bound by such
338 terms of service and are of legal age to agree to such terms with Kinvey.
339
340 This software contains valuable confidential and proprietary information of
341 KINVEY, INC and is subject to applicable licensing agreements.
342 Unauthorized reproduction, transmission or distribution of this file and its
343 contents is a violation of applicable laws.