-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #17132: Call promote API in rudder-node-to-relay #2238
Fixes #17132: Call promote API in rudder-node-to-relay #2238
Conversation
RUDDER_JSON="${RUDDER_VAR}/cfengine-community/inputs/rudder.json" | ||
|
||
rudder_json_value() { | ||
grep "$1" "${RUDDER_JSON}" | sed 's/.*"'$1'" *: *"\(.*\)",.*/\1/' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you read a json with grep and sed here but you use jq a few lines later
8b9828e
to
b26b2de
Compare
Commit modified |
RUDDER_JSON="${RUDDER_VAR}/cfengine-community/inputs/rudder.json" | ||
|
||
rudder_json_value() { | ||
cat "${RUDDER_JSON}" | jq -r ".$1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"cat file |" is an anti pattern, use "jq .. < file", even "jq .. file" since it is supported
moreover using -r with jq seems uselss to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad i mixed it with -R
API_URL="https://127.0.0.1/rudder/api/latest/scaleoutrelay/promote/${RELAY_UUID}" | ||
TOKEN_SYSTEM=$(cat /var/rudder/run/api-token) | ||
curl_command="${DOWNLOAD_COMMAND} --header \"X-API-Token: ${TOKEN_SYSTEM}\" --request POST \"${API_URL}\"" | ||
response=$(eval ${curl_command} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try avoiding eval as much as possible, because it is a frequent source of bugs
Here you could use : response=$(${DOWNLOAD_COMMAND} --header "X-API-Token: ${TOKEN_SYSTEM}" --request POST "${API_URL}")
provided that you make a little change to DOWNLOAD_COMMAND
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also need to check $? after this line in case of an error in the http query itself
CERTIFICATE_OPTION="--insecure" | ||
fi | ||
|
||
DOWNLOAD_COMMAND="curl --silent --show-error ${CERTIFICATE_OPTION} --location --proxy '' --globoff" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use --proxy= insteal of --proxy '' to make it usable without eval
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand that part, we don't want to use the proxy, so we let the parameter empty ? If yes we can't use --noproxy ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--xx= is equivalent to --xx ''
but without '' which make it usable without eval
you can also use --noproxy in that case, but i guess this command was coy pasted from somewhere we didn't know the url hostname beforehand
## Directives | ||
####################################################################################################################### | ||
${ECHO} -n "INFO: Triggering promises generation..." | ||
curl --proxy '' -k "https://localhost/rudder/api/deploy/reload" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use DOWNLOAD_COMMAND here and why 127.0.0.1 at one place and localhost in the other one
I prefer localhost
# Rudder is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with Rudder. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
##################################################################################### | ||
|
||
ECHO=/bin/echo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we're at it: this is useless
Should be distributed with the plugin or with rudder-agent |
PR updated with a new commit |
Commit modified |
fc82cb4
to
0c9807d
Compare
LDAP_SERVER='localhost' | ||
LDAP_PORT='389' | ||
if [ ${code} -ne 0 ]; then | ||
echo "Failed to promote ${RELAY_UUID} to relay" 1>&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diaplay the code here, it is always usefull for debugging
0c9807d
to
47115fd
Compare
Commit modified |
47115fd
to
8f497f2
Compare
Commit modified |
Like @amousset said, we should distributed it with the plugin |
closing we will make another pr to remove this file |
https://issues.rudder.io/issues/17132