Closed NassimBtk closed 1 month ago
For URL and Regex escaping, we can use native Java methods.
For Windows CMD, I think there is a problem in the table (2nd row), where we should see |
must be replaced with ^|
.
This will require some manual testing, to make sure the behavior is as intended, especially for Windows and Linux commands, before implementing unit tests.
Also, the source can be an actual source reference (${source::monitors.enclosure.discovery.source(1)_ESC_JSON}
).
Tested simple macros (Non-regression test) :
Tested the connector HPEGen9IloREST
(%{BASIC_AUTH_BASE64} macro). The HTTP request was executed without errors and the metrics collection worked as expected :white_check_mark:
Tested the connector CiscoUCSRest
(%{PASSWORD} and %{USERNAME} macros). The HTTP request was executed without errors and the metrics collection worked as expected :white_check_mark:
Tested the connector EMCuemcli
(%{HOSTNAME}, %{PASSWORD} and %{USERNAME} macros). The OsCommand command was executed without errors and the metrics collection worked as expected :white_check_mark:
Description:
We need to extend our macro replacement functionality to support various escape formats. The goal is to allow the engine to automatically replace macros with their corresponding inputs in different escaped formats.
Current Functionality: Currently, our code supports the replacement of macros with their corresponding inputs. For example, the macro
%{USERNAME}
is replaced with the actual username from the user's configuration.New Functionality: We want to introduce a new set of macros that apply different types of escaping to the input values. The new macros should follow the pattern
%{SOURCE_ESC_FORMAT}
.Supported Escape Formats:
%{SOURCE_ESC_REGEX}
%{SOURCE_ESC_URL}
%{SOURCE_ESC_JSON}
%{SOURCE_ESC_XML}
%{SOURCE_ESC_WINDOWS}
and%{SOURCE_ESC_CMD}
%{SOURCE_ESC_LINUX}
and%{SOURCE_ESC_BASH}
%{SOURCE_ESC_SQL}
Supported Input Sources (
SOURCE
)USERNAME
HOSTNAME
PASSWORD
AUTHENTICATIONTOKEN
BASIC_AUTH_BASE64
SHA256_AUTH
PASSWORD_BASE64
Example Usage:
ℹ️ We must ensure that all possible scenarios are accounted for in each escape format. These are just a few examples:
JSON Escape:
%{USERNAME_ESC_JSON}
:Na"ssim
→Na\"ssim
Explanation: In JSON, the double quote character
"
must be escaped with a backslash, soNa"ssim
becomesNa\"ssim
.URL Encoding:
%{USERNAME_ESC_URL}
:Na ssim
→Na%20ssim
Explanation: In URLs, spaces are encoded as
%20
, soNa ssim
becomesNa%20ssim
.Regex Escape:
%{USERNAME_ESC_REGEX}
:Na.ssim
→Na\.ssim
Explanation: In regular expressions, the dot
.
is a special character and must be escaped with a backslash, soNa.ssim
becomesNa\.ssim
.XML Escape:
%{USERNAME_ESC_XML}
:Na<ssim & "N"
→Na<ssim & "N"
Explanation: In XML,
<
,&
, and"
are special characters that must be escaped as<
,&
, and"
, respectively.Windows CMD Escape:
%{USERNAME_ESC_WINDOWS}
:Na&ssim
→Na^&ssim
Explanation: In Windows CMD, the ampersand
&
is a special character that must be escaped with a caret^
, soNa&ssim
becomesNa^&ssim
.Linux Bash Escape:
%{USERNAME_ESC_BASH}
:Na'ssim
→Na\'ssim
Explanation: In Linux Bash, single quotes inside a quoted string must be escaped with a backslash, so
Na'ssim
becomesNa\'ssim
.SQL Escape:
%{USERNAME_ESC_SQL}
:Na'ssim
→Na''ssim
Explanation: In SQL, single quotes are escaped by doubling them, so
Na'ssim
becomesNa''ssim
.Additional Notes:
%{USERNAME_JSON}
and%{PASSWORD_JSON}
and replace them with%{USERNAME_ESC_JSON}
and%{PASSWORD_ESC_JSON}
Specification
The possible escape characters for all the source formats are as follow: (@bertysentry Can you please review the escape sequences below ?)
%20
!
%21
"
%22
#
%23
$
%24
%
%25
&
%26
'
%27
(
%28
)
%29
*
%2A
+
%2B
,
%2C
/
%2F
:
%3A
;
%3B
=
%3D
?
%3F
@
%40
[
%5B
]
%5D
^
%5E
`
|%60
{
%7B
}
%7D
\|
%7C
~
%7E
.
\.
^
\^
$
\$
*
\*
+
\+
?
\?
{
\{
}
\}
[
\[
]
\]
(
\(
)
\)
\|
\\|
\
\\
/
\/
<
<
>
>
&
&
"
"
'
'
&
^&
&&
for "AND") in CMD\|
^\|
<
^<
>
^>
^
^^
%
^%
(
^(
)
^)
"
^"
'
\'
"
\"
\
\\
$
\$
!
\!
*
\*
?
\?
[
\[
]
\]
(
\(
)
\)
{
\{
}
\}
\|
\\|
&
\&
<
\<
>
\>
~
\~
'
''
"
\"
(if applicable)\
\\
(if applicable)%
%
LIKE
)_
_
LIKE
)\n
)\\n
\r
)\\r
\t
)\\t