Rundeck offers the possibility to load values of an option from a remote url.
Furthermore, the cascading of option is also implemented.
We have the use case to load static values (like environments) from a remote host.
The URL looks like the following: https://username:password@api.local/get-environment
If the URL is entered directly into the Remote URL
field, everything works as expected.
But as seen in the example, the API is password protected, and we have to provide a username and password. So, it's maybe a good idea to not store the data inside the Remote URL
field directly.
As far as I know, the Remote URL
can only be modified through cascading of option.
My idea was to store username
and password
inside the Key Storage and load it to an option through providing the storage path
. The resulting URL would look like the following:
https://${option.username.value}:${option.password.value}@api.local/get-environment
But now the problem:
The value of the Storage Path
acts like a default value.
This means, that the value of the storage path is only inserted inside the option,
if no other value is provided. When opening the job, the option username
and password
were empty and therefore, the cascading of option
does not work to fill in the needed values for the API URL.
Has anyone another idea of how to handle username
and password
inside the Remote URL
?
As suggested by MegaDrive68k
, I created a custom option plugin (Script Plugin Type).
Unfortunately, the Rundeck Script Plugin Type documentation is not really helpful.
With the help of the following GitHub issue and the Rundeck Script Plugin Development, I managed to finally create one.
Actions performed:
Enable the use of custom plugins (rundeck.feature.option-values-plugin.enabled=true
) as described here.
Create the custom option plugin (Script Plugin Type)
custom-rundeck-option-plugin.zip
structure:
custom-rundeck-option-plugin
├── contents
│ └── get_option_value.py
└── plugin.yaml
Content of plugin.yaml
:
name: Custom Rundeck option plugin
version: 1
rundeckPluginVersion: 1.2
author: Patrick
date: 2022-07-27
providers:
- name: Username
service: OptionValues
plugin-type: script
script-interpreter: /usr/bin/python3
script-file: get_option_value.py
script-args: USERNAME
- name: Password
service: OptionValues
plugin-type: script
script-interpreter: /usr/bin/python3
script-file: get_option_value.py
script-args: PASSWORD
- name: Url
service: OptionValues
plugin-type: script
script-interpreter: /usr/bin/python3
script-file: get_option_value.py
script-args: URL
Content of get_option_value.py
:
#!/usr/bin/python3
import os
import sys
env_var_name = sys.argv[1]
env_var_value = os.getenv(env_var_name, f"Environment variable '{env_var_name}' not defined!")
print("==START_OPTIONS==")
print(f"{env_var_value}:{env_var_value}")
print("==END_OPTIONS==")
custom-rundeck-option-plugin.zip
to $RDECK_BASE/libext
Now I have the following three "options" inside the Allowed values
: