- Install postgres
- Add user
tenable
with passwordinsecure
- Create database
restapi
- Install the server (this will install binary in your $GOPATH/bin directory)
go get -u github.com/warrenharper/restapi
- Run the sql script located in github.com/warrenharper/restapi/env/create_db.sql
psql -U tenable -d restapi -a -f env/create_db.sql -h localhost
Assuming $GOPATH/bin is in your path you can just run restapi
. This will start the server on port 8080.
The tests assume that you have a database with the name testapi
the has an identical schema to that of the database rest api
If you are familiar with vagrant you can cd into the root directory and run vagrant up
and all of the enviroment will be setup. You will need to cross compile the binary if you are not running vagrant on a linux machine.
GOOS=linux GOARCH=amd64 go build
#API
POST /login
Input
parameter | Description |
---|---|
"username" | Required: The username as a string |
"password" | Required: The password as a string |
Example
{
"name": "john_doe",
"password": "password"
}
Response
Status | Body |
---|---|
200 | "Authorized" |
401 | "Unauthorized" |
POST /logout
Input This requires no input
Response
Status | Body |
---|---|
200 | "Success" |
Note: If you are not authenticated you will receive a status code of 403 when you try to access any thing
GET /configurations/
NOTE: Note the url ends in a forward slash ("/")
Input This requires no input.
Response
Status |
---|
200 |
{
"configurations": [
{
"id": 1,
"name": "Config2",
"hostname": "add.here",
"port": 3384,
"username": "warren"
},
{
"id": 2,
"name": "A",
"hostname": "b.good",
"port": 3,
"username": "abernathy"
}
]
}
Get the configuration with the matching name
GET /configurations/:name
Input This requires no input.
Response
Status | Body | Description |
---|---|---|
200 | See example | Found the configuration |
404 | Could not find the configuration |
Example
GET /configurations/Config2
{
"configurations": [
{
"id": 6,
"name": "Config2",
"hostname": "add.here",
"port": 3384,
"username": "warren"
},
]
}
Add a configuration to the list of configurations
POST /configurations/
Input
parameter | Description | Type |
---|---|---|
"name" | Required: The name of the configuation | string |
"hostname" | Required: The hostname | string |
"port" | Required: The port | int |
"username" | Required: The username for the configuration | string |
Example
{
"name": "Config2",
"hostname": "add.here",
"port": 3384,
"username": "warren"
}
Response
Status | Body | Description |
---|---|---|
200 | See example | Configuration was added |
409 | List of configurations that collide with the name of the addee | Name collision |
Example
{
"configurations": [
{
"id": 6,
"name": "Config2",
"hostname": "add.here",
"port": 3384,
"username": "warren"
},
]
}
Delete the configuration with the matching name
DELETE /configurations/:name
Input This requires no input.
Response
Status | Body | Description |
---|---|---|
209 | Found the configuration | |
404 | Could not find the configuration |
Example
DELETE /configurations/Config2
PATCH /configurations/:name
Input
parameter | Description | Type |
---|---|---|
"name" | The name of the configuation | string |
"hostname" | The hostname | string |
"port" | The port | int |
"username" | The username for the configuration | string |
Note: Any of the input fields that are ommited will remain the same
Response
Status | Body | Description |
---|---|---|
200 | See example | Configuration was added |
409 | List of configurations that collide with the name of the modified | Name collision |
Example
PATCH /configurations/Config2
{
"name": "Config65"
}
Response
{
"configurations": [
{
"id": 6,
"name": "Config65",
"hostname": "add.here",
"port": 3384,
"username": "warren"
},
]
}
Sort your configurations and retrieve them by page
Add the sort
parameter to the GET /configurations/
request with one of the following values:
Value | Description |
---|---|
name | Sort configurations by name |
hostname | Sort configurations by hostname |
port | Sort configurations by port |
username | Sort configurations by username |
Example
GET /configurations/?sort=name
To paginate you must have both parameters page
and per_page
.
page
is 0 based.
per_page
cannot be greater than 100.
Example
GET /configurations/?page=0&per_page=50