This Bash CLI is automatically generated by the Swagger Codegen project:
swagger-codegen generate -i swagger.json -l bash -o generated/selectel-dns -c swagger-codegen.json
Thanks to https://github.com/mdsina/selectel-dns-api for swagger.json
.
The script uses cURL underneath for making all REST calls.
- bash 4.3
- curl
- jq (optional, for prettify json output)
Add to your terminal config:
export SELECTEL_API_KEY="your-key"
# Make sure the script has executable rights
$ chmod u+x selectel-dns
# Print the list of operations available on the service
$ selectel-dns -h
# Print the service description
$ selectel-dns --about
# Get domains json
$ selectel-dns getDomains
# Get domains list
$ selectel-dns getDomains | grep -oE 'name": "[a-z0-9\.-]+"' | awk '{print $2}' | tr -d '"'
# Get domains list using jq
$ selectel-dns getDomains | jq -r '.[] | "\(.id)\t\(.name)\t\(.tags)\t\(.create_date)\t\(.change_date)"'
# Add new domain from zone file
$ selectel-dns addDomain name=="example.com" bind_zone=="/var/lib/bind/example.com.hosts"
# Get domain records json
$ selectel-dns getResourceRecordsByDomainName domain_name=example.com
# Get domain records table
$ selectel-dns getResourceRecordsByDomainName domain_name=example.com | jq -r '.[] | "\(.id)\t\(.name)\t\(.type)\t\(.ttl)\t\(.content)\t\(.email)"'
# Print detailed information about specific operation
$ selectel-dns <operationId> -h
# Make GET request
selectel-dns <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>
# Make GET request using arbitrary curl options (must be passed before <operationId>) to an SSL service using username:password
selectel-dns -k -sS --tlsv1.2 -u <user>:<password> <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>
# Make POST request
$ echo '<body_content>' | selectel-dns --host <hostname> --content-type json <operationId> -
# Make POST request with simple JSON content, e.g.:
# {
# "key1": "value1",
# "key2": "value2",
# "key3": 23
# }
$ echo '<body_content>' | selectel-dns --host <hostname> --content-type json <operationId> key1==value1 key2=value2 key3:=23 -
# Preview the cURL command without actually executing it
$ selectel-dns --host http://<hostname>:<port> --dry-run <operationid>
You can easily create a Docker image containing a preconfigured environment for using the REST Bash client including working autocompletion and short welcome message with basic instructions, using the generated Dockerfile:
docker build -t my-rest-client .
docker run -it my-rest-client
By default you will be logged into a Zsh environment which has much more advanced auto completion, but you can switch to Bash, where basic autocompletion is also available.
I checked only antigen completion.
The generated bash-completion script can be either directly loaded to the current Bash session using:
source selectel-dns.bash-completion
Alternatively, the script can be copied to the /etc/bash-completion.d
(or on OSX with Homebrew to /usr/local/etc/bash-completion.d
):
sudo cp selectel-dns.bash-completion /etc/bash-completion.d/selectel-dns
On OSX you might need to install bash-completion using Homebrew:
brew install bash-completion
and add the following to the ~/.bashrc
:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
In Zsh, selectel-dns.plugin.zsh
completion file must be copied to one of the folders under $FPATH
variable.
antigen bundle viasite/selectel-dns-cli