-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #15 - Add dynamic dialog methods for creating a dialog of LDAP …
…entries
- Loading branch information
CFME
committed
Aug 18, 2017
1 parent
89fc127
commit 50ac3ec
Showing
13 changed files
with
392 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...dHatConsulting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/get_ldap_entries.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Returns a dynamic drop down dialog with all of the given LDAP entries using the value of the given attribute names for the drop down values and descriptions. | ||
# | ||
# EXPECTED | ||
# EVM STATE || EVM CURRENT || EVM OBJECT || EVM ROOT | ||
# ldap_entries - LDAP entries to display in the dynamic drop down | ||
# dialog_value_ldap_entry_attribute_name - LDAP entry attribute to use as the value for the dynamic drop down | ||
# dialog_description_ldap_entry_attribute_name - LDAP entry attribute to use as the description for the dynamic drop down | ||
# Optional. Defaults to `dialog_value_ldap_entry_attribute_name` if not specifed. | ||
# | ||
@DEBUG = false | ||
|
||
require 'rubygems' | ||
require 'net/ldap' | ||
|
||
# Log an error and exit. | ||
# | ||
# @param msg Message to error with | ||
def error(msg) | ||
$evm.log(:error, msg) | ||
$evm.root['ae_result'] = 'error' | ||
$evm.root['ae_reason'] = msg.to_s | ||
exit MIQ_STOP | ||
end | ||
|
||
# There are many ways to attempt to pass parameters in Automate. | ||
# This function checks all of them in priorty order as well as checking for symbol or string. | ||
# | ||
# Order: | ||
# 1. Current | ||
# 2. Object | ||
# 3. Root | ||
# 4. State | ||
# | ||
# @return Value for the given parameter or nil if none is found | ||
def get_param(param) | ||
# else check if current has been set for given param | ||
param_value ||= $evm.current[param.to_sym] | ||
param_value ||= $evm.current[param.to_s] | ||
|
||
# else cehck if current has been set for given param | ||
param_value ||= $evm.object[param.to_sym] | ||
param_value ||= $evm.object[param.to_s] | ||
|
||
# else check if param on root has been set for given param | ||
param_value ||= $evm.root[param.to_sym] | ||
param_value ||= $evm.root[param.to_s] | ||
|
||
# check if state has been set for given param | ||
param_value ||= $evm.get_state_var(param.to_sym) | ||
param_value ||= $evm.get_state_var(param.to_s) | ||
|
||
$evm.log(:info, "get_param: { '#{param}' => '#{param_value}' }") if @DEBUG | ||
return param_value | ||
end | ||
|
||
begin | ||
# get the parameters | ||
ldap_entries = get_param(:ldap_entries) | ||
|
||
values = {} | ||
if ldap_entries | ||
dialog_value_ldap_entry_attribute_name = get_param(:dialog_value_ldap_entry_attribute_name) | ||
error("dialog_value_ldap_entry_attribute_name parameter not found") if dialog_value_ldap_entry_attribute_name.nil? | ||
|
||
dialog_description_ldap_entry_attribute_name = get_param(:dialog_description_ldap_entry_attribute_name) || dialog_value_ldap_entry_attribute_name | ||
|
||
values = {} | ||
ldap_entries.each do |entry| | ||
value = entry[dialog_value_ldap_entry_attribute_name][0] | ||
description = entry[dialog_description_ldap_entry_attribute_name][0] | ||
values[value] = description | ||
end | ||
$evm.log(:info, "values => #{values}") if @DEBUG | ||
values[nil] = '' | ||
end | ||
|
||
dialog_field = $evm.object | ||
dialog_field["sort_by"] = "value" | ||
dialog_field["sort_order"] = "ascending" | ||
dialog_field["data_type"] = "string" | ||
dialog_field["required"] = true | ||
dialog_field["values"] = values | ||
end |
12 changes: 12 additions & 0 deletions
12
...atConsulting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/get_ldap_entries.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: get_ldap_entries | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../RedHatConsulting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/skip_to_state.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Helper method used to skip to a given state. | ||
# Great for error or exception handling. | ||
# | ||
# EXPECTED | ||
# INPUT PARAMETERS | ||
# next_state - The next state to skip to | ||
# | ||
@DEBUG = false | ||
|
||
begin | ||
# set the tags and attributes for the LDAP sync failure | ||
next_state = $evm.inputs['next_state'] | ||
|
||
# depending on if this method was entered by on_error or on_exit | ||
# the new result needs to be updated correctly | ||
case $evm.root['ae_status_state'] | ||
when 'on_error' | ||
new_result = 'continue' | ||
when 'on_exit' | ||
new_result = 'skip' | ||
else | ||
new_result = 'skip' | ||
end | ||
$evm.log(:info, "{ $evm.root['ae_status_state'] => #{$evm.root['ae_status_state']}, $evm.root['ae_result'] => #{$evm.root['ae_result']}, new_result => #{new_result} }") if @DEBUG | ||
|
||
# Set attributes to skip to specified next state | ||
$evm.log(:info, "Skip to State: #{next_state}") | ||
$evm.root['ae_result'] = new_result | ||
$evm.root['ae_next_state'] = next_state | ||
end |
12 changes: 12 additions & 0 deletions
12
...edHatConsulting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/skip_to_state.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: skip_to_state | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
53 changes: 53 additions & 0 deletions
53
...ulting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/validate_ldap_attributes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Validates attributes before getting LDAP entries. | ||
# | ||
# NOTE: Intended to be overriden by implimenters. | ||
# | ||
@DEBUG = false | ||
|
||
require 'rubygems' | ||
require 'net/ldap' | ||
|
||
# Log an error and exit. | ||
# | ||
# @param msg Message to error with | ||
def error(msg) | ||
$evm.log(:error, msg) | ||
$evm.root['ae_result'] = 'error' | ||
$evm.root['ae_reason'] = msg.to_s | ||
end | ||
|
||
# There are many ways to attempt to pass parameters in Automate. | ||
# This function checks all of them in priorty order as well as checking for symbol or string. | ||
# | ||
# Order: | ||
# 1. Current | ||
# 2. Object | ||
# 3. Root | ||
# 4. State | ||
# | ||
# @return Value for the given parameter or nil if none is found | ||
def get_param(param) | ||
# else check if current has been set for given param | ||
param_value ||= $evm.current[param.to_sym] | ||
param_value ||= $evm.current[param.to_s] | ||
|
||
# else cehck if current has been set for given param | ||
param_value ||= $evm.object[param.to_sym] | ||
param_value ||= $evm.object[param.to_s] | ||
|
||
# else check if param on root has been set for given param | ||
param_value ||= $evm.root[param.to_sym] | ||
param_value ||= $evm.root[param.to_s] | ||
|
||
# check if state has been set for given param | ||
param_value ||= $evm.get_state_var(param.to_sym) | ||
param_value ||= $evm.get_state_var(param.to_s) | ||
|
||
$evm.log(:info, "get_param: { '#{param}' => '#{param_value}' }") if @DEBUG | ||
return param_value | ||
end | ||
|
||
begin | ||
# IMPLEMENTER TODO: | ||
# Any needed parameter validation. | ||
end |
12 changes: 12 additions & 0 deletions
12
...ting_LDAP/Integration/LDAP/DynamicDialogs.class/__methods__/validate_ldap_attributes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
object_type: method | ||
version: 1.0 | ||
object: | ||
attributes: | ||
name: validate_ldap_attributes | ||
display_name: | ||
description: | ||
scope: instance | ||
language: ruby | ||
location: inline | ||
inputs: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.