Created
August 6, 2018 19:42
-
-
Save kclinden/101248d3f2afb997a0d51314e4e39eee to your computer and use it in GitHub Desktop.
SatelliteRESTRequestRetry
This file contains hidden or 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
| // Creator: Les Kimmel | |
| // Description: This function can be used in vRO to initate a retry on any REST request that fails due to an expired cookie from Satellite. | |
| // Inputs: N/A | |
| // Return Type: Any | |
| // How to use: For a vRO REST Request to Red Hat Satellite input the following line to invoke the rest request `var SatelliteRESTRequest = System.getModule("module.rhsat.rest").SatelliteRESTRequest();` | |
| var SatelliteRESTRequest = function (req) { | |
| System.debug("Request URL: " + req.fullUrl); | |
| var resp = req.execute(); | |
| // Check it unauthorized. If so retry once. This accounts | |
| // for an issue with the Foreman API cookie where it doesn't | |
| // expire but the Foreman idle timeout can cause an unathorized. | |
| if ( resp.statusCode == 401 ) { | |
| System.error("Retrying request due to authentication failure."); | |
| resp = req.execute(); | |
| // If still unathorized, fail. | |
| if ( resp.statusCode == 401 ) { throw "Failed to authenticate to Satellite!"; } | |
| } | |
| return resp; | |
| } | |
| return SatelliteRESTRequest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment