#!groovy // repository configuration def repository = "registry.c.test-chamber-13.lan" // jenkins secrets def nordCreds = "nordvpn-login-creds" // kubernetes configuration def kubeNamespace = "dl-automation" def kubeSecret = "openvpn" // 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\\]\\}", // 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 def nordURL = nordURLs[Math.abs(new Random().nextInt() % [8])] // script used to retrieve a nordVPN OpenVPN configuration from NordVPN def openVPNConfigScript = """# 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 """ def label = "kubernetes-${UUID.randomUUID().toString()}" def templateName = "pipeline-worker" podTemplate( label: label, name: templateName, yaml: functions.podYaml( repo: repository, templateName: templateName, alpine: true ) ) { node (label) { def workspace = pwd() stage ("Prepare Container") { container ("alpine") { sh """ apk add --no-cache curl jq sed """ } } def openVPNConfig stage ("Get Remote OpenVPN Config") { container ("alpine") { openVPNConfig = sh( returnStdout: true, script: openVPNConfigScript ) } } def k8sSecret stage ("Compile Secret") { withCredentials([string( credentialsId: nordCreds, variable: "NORD_CREDS", )]) { k8sSecret = """apiVersion: v1 kind: Secret metadata: name: """ + kubeSecret + """ namespace: """ + kubeNamespace + """ data: openvpn-credentials.txt: """ + NORD_CREDS + """ nordvpn.com.tcp.ovpn: """ + openVPNConfig + """ """ } } functions.createSecret( kubeAuth: "k8s-dl-automation-access", kubeURL: "https://kubernetes.test-chamber-13.lan:6443", namespace: "dl-automation", secret: k8sSecret ) functions.deletePod( kubeAuth: "k8s-dl-automation-access", kubeURL: "https://kubernetes.test-chamber-13.lan:6443", namespace: "dl-automation", selector: "app=deluge" ) } }