Skip to content

Commit 67941ce

Browse files
committed
Update the readme; examples/docs for all two commands
1 parent 45ece1f commit 67941ce

File tree

1 file changed

+118
-34
lines changed

1 file changed

+118
-34
lines changed

readme.md

Lines changed: 118 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,156 @@
22
[![Build status](https://api.travis-ci.org/codedx/codedx-cli-client.svg?branch=master)](https://travis-ci.org/codedx/codedx-cli-client)
33

44

5-
This is a utility intended to make it easier to interact with
5+
This is a utility intended to make it easier to interact with
66
[Code Dx's REST API](https://codedx.com/Documentation/APIGuide.html) from the command line.
77

88
Currently only a couple API actions are supported, but more may come with demand (or with pull requests!)
99

10+
- [Usage](#Usage)
11+
- [`analyze`](#Command-analyze)
12+
- [`projects`](#Command-projects)
13+
1014
# Usage
1115

12-
The program runs as a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop).
13-
Start it by providing the connection information (Code Dx "base url", and username+password or API Key):
16+
This program has two modes of operation; "one-shot" and "[REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)".
17+
18+
With *one-shot mode*, you enter your Code Dx connection information followed by a command and its arguments, all a a single command in your terminal.
19+
The program will run the command, then exit.
20+
21+
With *REPL mode*, you enter your Code Dx connection information the same way as with one-shot mode, but omit the command.
22+
The program will enter a loop in which it prompts for commands.
23+
You only have to enter the connection information once, up front; each command will not require the information a second time.
24+
*REPL mode* is helpful if you want to explore the CLI's capabilities, or if you want to pipe in several commands from a file.
25+
26+
The required connection information includes the "base url" where you browse Code Dx,
27+
and the information you use to log in (username+password, or an API Key).
1428

1529
```text
16-
$> ./codedx-client -b https://localhost/codedx -u johndoe -p supersecret
30+
$> ./codedx-client https://localhost/codedx -u johndoe -p supersecret
31+
Welcome to the Code Dx CLI Client REPL.
1732
codedx>
1833
```
1934

2035
```text
21-
$> ./codedx-client -b https://localhost/codedx --api-key 8e218b38-fcdd-453d-8f78-185f7d1d9fa7
36+
$> ./codedx-client https://localhost/codedx --api-key 8e218b38-fcdd-453d-8f78-185f7d1d9fa7
37+
Welcome to the Code Dx CLI Client REPL.
38+
codedx>
39+
```
40+
41+
If you skip the password argument, the program will prompt for it afterwards.
42+
This way, you enter your password without it appearing in your terminal.
43+
44+
```text
45+
$> ./codedx-client https://localhost/codedx -u johndoe
46+
password:
47+
Welcome to the Code Dx CLI Client REPL.
2248
codedx>
2349
```
2450

25-
The program reads input from `STDIN`, so you can pipe the contents of a file to it, to run several commands in sequence.
26-
Each line of the file will be interpreted as a command.
27-
When using this mode, you may wish to provide the `--no-prompt` flag to prevent the program from writing stuff like "codedx>" to `STDOUT`.
51+
If you wish to run several commands at once, it's easiest to write a shell script or batch file,
52+
but you can also pipe the commands into the program's *REPL mode* from a file,
53+
where each line of the file is interpreted as a command.
54+
If you wish to do this, you may also want to use the `--no-prompt` flag to prevent the program from writing stuff like "codedx>" to `STDOUT`.
2855

2956
```text
3057
$> ./codedx-client -b https://localhost/codedx --api-key 8e218b38-fcdd-453d-8f78-185f7d1d9fa7 --no-prompt < ./my-commands.txt
3158
```
3259

33-
Once in the REPL, type `help` (and hit Enter) for a list of commands.
34-
You can exit the REPL by typing `exit` or `quit`, or with <kbd>Ctrl+C</kbd> or sending an EOF signal.
60+
## About REPL Mode
61+
62+
In *REPL mode*, type `help` (and hit Enter) for a list of commands.
63+
You can exit the program by typing `exit` or `quit`, or with <kbd>Ctrl+C</kbd> or sending an EOF signal.
3564
You can learn more about a command by typing `help <command name>` e.g. `help analyze`.
3665

3766
For any command that takes arguments, each argument should be space-separated.
3867
Arguments that contain spaces should be surrounded with quotes e.g. `'this is one argument'` or `"so is this"`.
39-
Arguments surrounded with quotes treat backslash (`\`) as an escape character.
68+
Arguments surrounded with quotes treat backslash (`\`) as an escape character.
4069
This means if you have a quoted argument that has a backslash or another quote, it needs a backslash in front of it, e.g. `"a \"quote\" inside"` or `"C:\\my data\\source\\files.zip"`.
4170

42-
Note that you can usually get around needing to escape anything by being clever:
71+
Note that you can usually get around needing to escape anything by being clever:
4372
- For file paths with backslashes, just use forward slashes (`/`) instead, e.g. `"C:/my data/source/files.zip"`.
4473
- For arguments with quotes in them, surround them with the other type of quote, e.g. `'a "quoted" string'`
4574

46-
If you see an error message like "The filename, directory name, or volume label syntax is incorrect.",
75+
If you see an error message like "The filename, directory name, or volume label syntax is incorrect.",
4776
you likely used backslashes (`\`) without escaping them (`\\`) inside a quoted argument.
4877

49-
# Example
78+
# Command: `analyze`
79+
80+
The `analyze` command sends one or more files to one of your Code Dx projects to be analyzed.
81+
This is the most common way of adding findings to Code Dx.
82+
83+
The `analyze` command takes care of several actions for you:
84+
85+
- Generate a request to upload the analysis input files
86+
- Get the `jobId` and `analysisId` from the response
87+
- Set the name of the analysis (optional)
88+
- Poll until the analysis "job" completes
89+
90+
## Arguments and Options
91+
92+
- `-p, --project-id <ID>` Specify which Code Dx project you want to upload files to, by its ID.
93+
(Note: you can find a project's ID using the [`projects`](#command-projects) command,
94+
or finding the number in the URL when you visit that project in a browser)
95+
- `-n, --name <NAME>` Optionally specify a name for the analysis.
96+
- `-f, --file <FILE(S)>` Specify the path to one or more files that you wish to upload.
97+
Each file is a separate argument, but you only need to give the `-f` flag once.
98+
99+
You *must* provide a project ID, and at least one file.
100+
101+
## Example
50102

51-
You're probably here because you're trying to configure your CI environment to send files to Code Dx for analysis.
52-
For this, you'll want the `analyze` command.
53-
You can find more details about the `analyze` command by entering `help analyze` in the REPL, but here's an example:
103+
Suppose I want analyze my "WebGoat" project, which happens to have an ID of `5`:
54104

55-
The `analyze` command has two required flags: a project ID and at least one file.
56-
These are given with the `--project-id` (`-p`) and `--file` (`-f`) flags respectively.
57-
Suppose I want analyze a file in my "WebGoat" project, which happens to have an ID of `5`:
105+
```text
106+
codedx> analyze -p 5 -f "/path/to/workspace/webgoat-source.zip" "/path/to/workspace/webgoat-classes.zip"
107+
# Started analysis 77 with job id f2f3b8c3-9a2c-4446-9765-e99a6d47e69e
108+
# Polling job completion, iteration 1: status = Running
109+
...omitted for brevity...
110+
# Polling job completion, iteration 13: status = Running
111+
# Polling done
112+
Completed
113+
```
114+
115+
# Command: `projects`
116+
117+
The `projects` command helps you get a list of all Code Dx projects, or search for specific projects.
118+
119+
## Arguments and Options
120+
121+
- *no arguments* - Prints a list of all Code Dx projects that you have at least read access to.
122+
- `-n, --name <PART OF NAME>` - If this flag is given, it adds search criteria such that matching
123+
projects include `<PART OF NAME>` in their name (case insensitive).
124+
- `-m, --metadata <FIELD> <VALUE>` - If this flag is given, it should be followed a key-value
125+
pair related to the project's metadata. If given, it adds search criteria such that
126+
matching projects must have entries for the given metadata fields matching the respective
127+
given metadata values. To specify another key-value pair, use the `-m` flag again.
128+
129+
## Examples
130+
131+
```text
132+
codedx> projects
133+
{"id":1,"name":"My First Project","parentId":null}
134+
{"id":2,"name":"Another Project","parentId":3}
135+
{"id":3,"name":"Project Group","parentId":null}
136+
{"id":4,"name":"Yet another","parentId":3}
137+
...
138+
```
139+
140+
```text
141+
codedx> projects -n another
142+
{"id":2,"name":"Another Project","parentId":3}
143+
{"id":4,"name":"Yet another","parentId":3}
144+
```
145+
146+
Here I search for projects with the metadata field `Owner` set to "johndoe" and the metadata field `Visibility` set to "high".
147+
```text
148+
codedx> projects -m Owner johndoe -m Visibility high
149+
{"id":4,"name":"Yet another","parentId":3}
150+
```
58151

152+
Note that for project metadata fields with the "Dropdown" type, you have to specify the full name of the dropdown option in order to get a match.
153+
For regular (plain text entry) fields, you can just give part of the value for it to match.
59154
```text
60-
codedx> analyze -p 5 -f "/path/to/workspace/webgoat-source.zip"
61-
# Started analysis 77 with job id f2f3b8c3-9a2c-4446-9765-e99a6d47e69e
62-
# Polling job completion, iteration 1: status = Running
63-
...omitted for brevity...
64-
# Polling job completion, iteration 13: status = Running
65-
# Polling done
66-
Completed
67-
codedx>
68-
```
69-
70-
You can optionally set the name of the analysis with the `--name` flag.
71-
The `analyze` command saves the effort of putting together a complex `curl` request for the initial file upload,
72-
setting up a separate request to set an analysis name,
73-
and setting up a polling loop to wait for the analysis "job" to complete.
155+
codedx> projects -m Owner jo -m Visibility high
156+
{"id":4,"name":"Yet another","parentId":3}
157+
```

0 commit comments

Comments
 (0)