This article describes how to use HttPie for related operations.
Introduction to the Use of Httpie
Web Api
Rundeck provides a better exposed WebApi for easier integration without cli. curl, for example, is basically the standard of all linux. In addition, Api and rundeck APIs can also be used directly in programs. See below for information on APIs of rundeck.
XML and JSON support
The API supports XML and JSON approaches, although some export/import functions also support YAML or text/plain, the overall use of XML and JSON approaches at all API levels. In version 14, all support JSON format, with one exception (/ api/V/project/[PROJECT]/jobs/export).
- Usage mode
The JSON return result can be obtained by setting the Accept of HTTP Header as application/json.
When Accept is not specified, the return result is the same as that in the request of POST or PUT, or the default XML request is returned.
Authentication method
Rundeck's use of the api can be done by username and password or token.
User name password mode
First you need to post the username and password to the following URL
- $RUNDECK_SERVER_URL/j_security_check
- j_username: Username
- j_password: Password
Note: Actually, the login process is saved in session.
Using the token approach
This method first needs to generate token, using the generated token, which can be used in the following two ways.
- Mode 1: Set token to X-Rundeck-Auth-Token in HTTP Header
- Mode 2: Pass in the url through the parameter authtoken
Generate token
First, you need to set token, which can be generated by GUI first, and then added to the user profile in the upper right corner after login.
Create token based on the following information
You can see the following token information
Click show token to get the token content
Query list information for project
- Default: Returns the results of XML and Header-related information
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/projects?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc HTTP/1.1 200 OK Content-Security-Policy: default-src 'none' ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ; style-src 'self' 'unsafe-inline' ; img-src * ; font-src 'self' data: ; connect-src 'self' https://api.rundeck.com ; form-action 'self' ; Content-Type: application/xml;charset=utf-8 Date: Wed, 10 Apr 2019 01:19:00 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Set-Cookie: JSESSIONID=node0cfzthent4gpjy3yiivzutipf62.node0;Path=/;HttpOnly Transfer-Encoding: chunked X-Application-Context: application:production:4440 X-Content-Type-Options: nosniff X-Frame-Options: deny X-Rundeck-API-Version: 30 X-Rundeck-API-XML-Response-Wrapper: false X-XSS-Protection: 1 <projects count='3'> <project url='http://localhost:32044/api/30/project/rundeck-test-cli-project'> <name>rundeck-test-cli-project</name> <description></description> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-project'> <name>rundeck-test-project</name> <description>This project is to introduce Rundeck function</description> <label>Rundeck Test Project</label> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-webapi-project'> <name>rundeck-test-webapi-project</name> <description></description> </project> </projects> liumiaocn:~ liumiao$
- Return only the result content of the result XML
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/projects?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc -b <projects count='3'> <project url='http://localhost:32044/api/30/project/rundeck-test-cli-project'> <name>rundeck-test-cli-project</name> <description></description> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-project'> <name>rundeck-test-project</name> <description>This project is to introduce Rundeck function</description> <label>Rundeck Test Project</label> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-webapi-project'> <name>rundeck-test-webapi-project</name> <description></description> </project> </projects> liumiaocn:~ liumiao$
- Set Accept: Specify return json format
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/projects?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc Accept:application/json -b [ { "description": "", "label": "", "name": "rundeck-test-cli-project", "url": "http://localhost:32044/api/30/project/rundeck-test-cli-project" }, { "description": "This project is to introduce Rundeck function", "label": "Rundeck Test Project", "name": "rundeck-test-project", "url": "http://localhost:32044/api/30/project/rundeck-test-project" }, { "description": "", "label": "", "name": "rundeck-test-webapi-project", "url": "http://localhost:32044/api/30/project/rundeck-test-webapi-project" } ] liumiaocn:~ liumiao$
Create Project
Preparation
Prepare project creation information in the following Json format
liumiaocn:~ liumiao$ cat rundeck-httpie-project.json { "name": "rundeck-test-webapi-httpie-project", "config": { "project.lable":"Rundeck Test WebApi Httpie Project" } } liumiaocn:~ liumiao$
Create Project
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/projects?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc <rundeck-httpie-project.json HTTP/1.1 201 Created Content-Security-Policy: default-src 'none' ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ; style-src 'self' 'unsafe-inline' ; img-src * ; font-src 'self' data: ; connect-src 'self' https://api.rundeck.com ; form-action 'self' ; Content-Type: application/json;charset=utf-8 Date: Wed, 10 Apr 2019 01:25:04 GMT Expires: Thu, 01 Jan 1970 00:00:00 GMT Set-Cookie: JSESSIONID=node0gazfa6shom3jpxvuikk7v4d066.node0;Path=/;HttpOnly Transfer-Encoding: chunked X-Application-Context: application:production:4440 X-Content-Type-Options: nosniff X-Frame-Options: deny X-XSS-Protection: 1 { "config": { "project.lable": "Rundeck Test WebApi Httpie Project", "project.name": "rundeck-test-webapi-httpie-project", "project.ssh-authentication": "privateKey", "project.ssh-keypath": "/home/rundeck/.ssh/id_rsa", "resources.source.1.type": "local", "service.FileCopier.default.provider": "jsch-scp", "service.NodeExecutor.default.provider": "jsch-ssh" }, "description": "", "name": "rundeck-test-webapi-httpie-project", "url": "http://localhost:32044/api/30/project/rundeck-test-webapi-httpie-project" } liumiaocn:~ liumiao$
Create information validation
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/projects?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc -b <projects count='4'> <project url='http://localhost:32044/api/30/project/rundeck-test-cli-project'> <name>rundeck-test-cli-project</name> <description></description> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-project'> <name>rundeck-test-project</name> <description>This project is to introduce Rundeck function</description> <label>Rundeck Test Project</label> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-webapi-httpie-project'> <name>rundeck-test-webapi-httpie-project</name> <description></description> </project> <project url='http://localhost:32044/api/30/project/rundeck-test-webapi-project'> <name>rundeck-test-webapi-project</name> <description></description> </project> </projects> liumiaocn:~ liumiao$
Confirmation through Web GUI
Project details confirmation
Confirm the Project details created
liumiaocn:~ liumiao$ http http://localhost:32044/api/30/project/rundeck-test-webapi-httpie-project?authtoken=vcopxmhraTC9vlNw1p5VJTlxNhQcVNbc Accept:application/json -b { "config": { "project.lable": "Rundeck Test WebApi Httpie Project", "project.name": "rundeck-test-webapi-httpie-project", "project.ssh-authentication": "privateKey", "project.ssh-keypath": "/home/rundeck/.ssh/id_rsa", "resources.source.1.type": "local", "service.FileCopier.default.provider": "jsch-scp", "service.NodeExecutor.default.provider": "jsch-ssh" }, "description": "", "name": "rundeck-test-webapi-httpie-project", "url": "http://localhost:32044/api/30/project/rundeck-test-webapi-httpie-project" } liumiaocn:~ liumiao$