The JetPatch server authorizes API requests to users with an API key. Since the API is sessionless, every HTTP request must be authenticated. Authorization is valid for 15 minutes, so the client's clock must match the server's.
The API authentication should be implemented by the REST client using standard HTTP digest authentication (as according to RFC 2617). The credentials should be the user's username and API key.
Java Authentication Example:
HttpClient client = new HttpClient();
List authPrefs = new ArrayList(2);
authPrefs.add(AuthPolicy.DIGEST);
client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
Power-Shell Example:
Here is also a Power-Shell Example that pulls Servers Compliance:
$resource = "https://<JetPatch URI>/vmanage-server/rest/experimental/patch-governance/servers-compliance?size=-1" $user = "<USERNAME>" $apiKey = "<API-KEY>" $pwd = ConvertTo-SecureString $apiKey -AsPlainText -Force $Credential = New-Object Management.Automation.PSCredential ($user, $pwd) # Ignore validation of self-signed certificates add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$resp = Invoke-WebRequest -UseBasicParsing -Uri $resource -Credential $Credential -TimeoutSec 30 -Method GET
$strResp = [string]$resp
echo $strResp
Curl Example:
Regular GET command:
curl -k --digest -D- -u username:apikey 'https://30.30.0.151/vmanage-server/rest/experimental/patch-governance/servers-compliance?size=-1'
Regular POST command (with Body as JSON and a separate file):
curl -k --digest -D- -u <USERNAME>:<AP_KEY> -H 'Content-Type: application/json' -d @<JSON_BODY> 'https://30.30.0.151/vmanage-server/rest/experimental/patch-governance/pg-computer/action/update-group'
Python Example:
This script will list all Jetpatch UI server accounts.
Pre-Requisites:
- Python3
- The API user needs to have administrator permissions in the Jetpatch UI.
- The location for .py files is in the directory /opt/intigua-python-client/ on JetPatch Core Server
Usage Samples:
Change to /opt/intigua-python-client/ directory:
cd /opt/intigua-python-client/
./intigua_display_credentials.py --apikey <APIKEY> --url https://<DNS>/vmanage-server/rest/rest-api --user <username>
Comments
0 comments
Please sign in to leave a comment.