From 93c0e5bb4c7c9209c031460428a328f6d6658dd5 Mon Sep 17 00:00:00 2001 From: nhyatt Date: Sun, 22 Oct 2023 10:13:11 -0500 Subject: [PATCH] corrects syntax --- nordvpn-autoconfigure.jenkins | 144 +++++++++++++++++----------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/nordvpn-autoconfigure.jenkins b/nordvpn-autoconfigure.jenkins index ba711eb..552dea4 100644 --- a/nordvpn-autoconfigure.jenkins +++ b/nordvpn-autoconfigure.jenkins @@ -42,84 +42,84 @@ pipeline { stage ('Prepare Values') { steps { container ('alpine') { - retry(3) { - try { - // list of urls that return different nordVPN servers - def nordURLs = [ - // canada - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // costa-rica - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:52,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // denmark - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:58,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // france - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:74,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // gremany - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:81,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // japan - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:108,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // sweden - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:208,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // switzerland - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:209,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // netherlands - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:153,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - // united kingdom - "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", - ] - // randomly select one from the list - nordURL = nordURLs[Math.abs(new Random().nextInt() % [8])] + script { + retry(3) { + try { + // list of urls that return different nordVPN servers + def nordURLs = [ + // canada + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // costa-rica + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:52,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // denmark + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:58,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // france + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:74,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // gremany + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:81,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // japan + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:108,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // sweden + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:208,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // switzerland + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:209,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // netherlands + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:153,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + // united kingdom + "https://nordvpn.com/wp-admin/admin-ajax.php?action=servers_recommendations&filters=\\{%22country_id%22:38,%22servers_groups%22:\\[15\\],%22servers_technologies%22:\\[5\\]\\}", + ] + // randomly select one from the list + nordURL = nordURLs[Math.abs(new Random().nextInt() % [8])] - // install required components - script { - sh """ - if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then - apk add --no-cache curl - fi - if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then - apk add --no-cache jq - fi - if [ ! -f "/bin/sed" ] || [ ! -x "/bin/sed" ]; then - apk add --no-cache sed - fi - """ - } + // install required components + script { + sh """ + if [ ! -f "/usr/bin/curl" ] || [ ! -x "/usr/bin/curl" ]; then + apk add --no-cache curl + fi + if [ ! -f "/usr/bin/jq" ] || [ ! -x "/usr/bin/jq" ]; then + apk add --no-cache jq + fi + if [ ! -f "/bin/sed" ] || [ ! -x "/bin/sed" ]; then + apk add --no-cache sed + fi + """ + } - // get OpenVPN Configuration from NordVPN - openVPNConfig = sh( - returnStdout: true, - script: """# Get OpenVPN Config - curl \ - --silent \ - --location \ - --fail \ - "https://downloads.nordcdn.com/configs/files/ovpn_tcp/servers/\$( - curl \ - --silent \ - --location \ - --fail \ - '""" + nordURL + """' \ - | jq \ - --raw-output \ - '[.[] | select(.technologies[] | .identifier == "openvpn_tcp")][0] | .hostname' \ - ).tcp.ovpn" \ - | sed \ - --regexp-extended \ - --expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \ - | base64 -w 0 - """ - ) - } catch(e) { - if (openVPNConfig.length() == 0 || openVPNConfig == "") { - printf("Bad nordURL: %s", nordURL) - throw e + // get OpenVPN Configuration from NordVPN + openVPNConfig = sh( + returnStdout: true, + script: """# Get OpenVPN Config + curl \ + --silent \ + --location \ + --fail \ + "https://downloads.nordcdn.com/configs/files/ovpn_tcp/servers/\$( + curl \ + --silent \ + --location \ + --fail \ + '""" + nordURL + """' \ + | jq \ + --raw-output \ + '[.[] | select(.technologies[] | .identifier == "openvpn_tcp")][0] | .hostname' \ + ).tcp.ovpn" \ + | sed \ + --regexp-extended \ + --expression='s/auth-user-pass/auth-user-pass \\/etc\\/openvpn\\/client\\/openvpn-credentials.txt/' \ + | base64 -w 0 + """ + ) + } catch(e) { + if (openVPNConfig.length() == 0 || openVPNConfig == "") { + printf("Bad nordURL: %s", nordURL) + throw e + } } } } - } - // Create K8S Secret - script { + // Create K8S Secret withCredentials( [ string(