How To Set Up hvrhubserver Using REST API
Question
How can I set up hvrhubserver
using the REST API?
Environment
HVR 6
Answer
Create a user/schema/database for HVR to use as the repository. In this example, the HVR repository is a PostgreSQL database, so a database called hvhub6
is created in PostgreSQL with OS user jigsaw
.
NOTE: The example below is using HTTP port
5540
on a hubserver calledmalta
.
Download and install HVR. Learn how in our Installing HVR documentation.
After installation, create
$HVR_CONFIG/etc/hvrhubserver.conf
on the hubserver, as shown below:{ "HTTP_Port": "5540" }
or
hvrhubserverconfig HTTP_Port=5540
to create the above file.Start
hvrhubserver
on Linux with the command:hvrhubserver -d
or on Windows with the command:
hvrhubserver -acs -P<password of logged-in OS account> or without -P to run as local system account
The above hvrhubserver commands will start the hvrhubserver in SETUP mode.
Get Authorization bearer code
You can either use REST or use the command line hvrlogin. If you use hvrlogin, the authentication code can be saved into a reusable environment variable called $HVR_LOGIN_ACCESS_TOKEN
.
The REST API to get the authorization token while HVR Hub Server is in setup mode:
curl -X POST "http://malta:5540/auth/v1/setup" -H "Content-Type: application/json"
Set the database details for the hvrhubserver
The below example sets the hub database to PostgreSQL with database name hvhub6
:
curl -X PATCH "http://malta:5540/api/v0/hubserver/props" \
-H "Authorization: Bearer <copy Authorization bearer from http://malta:5540/auth/v1/setup call>” \
-H 'Content-Type: application/json' \
--data '{"HTTP_Port":"5540","Database_Host":"localhost","Database_Port":5463,"Database_Name":"hvhub6","Database_User":"jigsaw","Database_Password":"passw","Repository_Class":"postgresql","Setup_Mode":true}'
or if using a bash script like below:
#!/bin/bash
R=http://malta:5540
eval $(hvrlogin -s -a -S -R$R)
curl -X PATCH $R/api/v0/hubserver/props \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN" \
-H 'Content-Type: application/json' \
--data '{"HTTP_Port":"5540","Database_Host":"localhost","Database_Port":5463,"Database_Name":"hvhub6","Database_User":"jigsaw","Database_Password":"passw","Repository_Class":"postgresql","Setup_Mode":true}'
Create HVR repository
The below command creates the repository tables in the database hvhub6
:
curl -X POST "http://malta:5540/api/v0/repos" \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“
Add license to hub
Create an input file with the following content:
{"license":"<license file name>","raw":"<stringified content of generated license>"}
To stringify the original license file, see https://onlinetexttools.com/json-stringify-text.
curl -X POST "http://malta:5540/api/v0/licenses" \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“ \
-H 'Content-Type: application/json' \
--data-binary @<input file>
Add user to access the HVR system
The below example creates a HVR user called hvradmin
(a HVR application user, not a real OS user, because authentication is local):
curl -X POST "http://malta:5540/api/v0/users"
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“
-H 'Content-Type: application/json'
--data '{"user":"hvradmin","authentication":"local"","password":"mypass"}'
Authentication can also be pam instead of local.
Give user SysAdmin privilege
curl -X PATCH "http://malta:5540/api/v0/repos/props" \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“ \
-H 'Content-Type: application/json' \
--data '{"Access_List":[{"user":"hvradmin","level":"SysAdmin"}]}'
Since 6.1.5/2, the following should be used:
curl -X PATCH "http://malta:5540/api/v0/repos/props" \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“ \
-H 'Content-Type: application/json' \
--data '{"User_Access":{"hvradmin":{"sysadmin":true}}}'
Create a hub
The below example creates a hub called hvrhub6
:
curl -X POST $R/api/v0/hubs \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“ \
-H 'Content-Type: application/json' \
--data '{"hub":"hvrhub6"}'
End hvrhubserver’s setup mode
The below example will end the hvrhubserver’s setup mode, so channels can be created on the hub:
curl -X PATCH "http://malta:5540/api/v0/hubserver/props" \
-H "Authorization: Bearer $HVR_LOGIN_ACCESS_TOKEN or <copy Authorization bearer from http://malta:5540/auth/v1/setup call>“ \
-H 'Content-Type: application/json' \
--data '{"Setup_Mode":null}'
You can now go to the browser to malta:5540
and log in with user hvradmin
to create other users or set up channels, etc.