Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 海阔视界规则分享,当前分享的是:网页插件¥js_url¥global_chatGPTtoolsPlus(修改版)@base64://Ly8gPT1Vc2VyU2NyaXB0PT0KLy8gQG5hbWUgICAgICAgICBjaGF0R1BUIHRvb2xzIFBsdXPvvIjkv67mlLnniYjvvIkKLy8gQG5hbWVzcGFjZSAgICBodHRwOi8vdGFtcGVybW9ua2V5Lm5ldC8KLy8gQHZlcnNpb24gICAgICAyLjYuNwovLyBAZGVzY3JpcHRpb24gIEdvb2dsZeOAgeW/heW6lOOAgeeZvuW6puOAgVlhbmRleOOAgTM2MOaQnOe0ouOAgeiwt+atjOmVnOWDj+OAgeaQnOeLl+OAgWLnq5njgIFGc29144CBZHVja2R1Y2tnb+OAgUNTRE7kvqfovrnmoI9DaGF05pCc57Si77yM6ZuG5oiQ5Zu95YaF5LiA6KiA77yM5pif54Gr77yM5aSp5bel77yM6YCa5LmJQUnjgILljbPliLvkvZPpqoxBSe+8jOaXoOmcgOe/u+Wime+8jOaXoOmcgOazqOWGjO+8jOaXoOmcgOetieW+he+8gQovLyBAYXV0aG9yICAgICAgIOWknOmbqAovLyBAbWF0Y2ggICAgICBodHRwczovL2NuLmJpbmcuY29tLyoKLy8gQG1hdGNoICAgICAgaHR0cHM6Ly93d3cuYmluZy5jb20vKgovLyBAbWF0Y2ggICAgICAqOi8vKi5iaW5nLmNvbS8qCi8vIEBtYXRjaCAgICAgIGh0dHBzOi8vY2hhdC5vcGVuYWkuY29tL2NoYXQKLy8gQG1hdGNoICAgICAgaHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8qCi8vIEBtYXRjaCAgICAgIGh0dHBzOi8vZHVja2R1Y2tnby5jb20vKgovLyBAbWF0Y2ggICAgICBodHRwczovL3d3dy5zby5jb20vcyoKLy8gQG1hdGNoICAgICAgKjovL20uc28uY29tL3MqCi8vIEBtYXRjaCAgICAgICo6Ly93d3cuYmFpZHUuY29tL3MqCi8vIEBtYXRjaC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ICAgICAgICAgICAkKCJoZWFkIikuYXBwZW5kKCQoCiAgICAgICAgICAgICAgICAgICAgJzxsaW5rIGlkPSJnaXRodWItbWFya2Rvd24tbGluayIgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5ib290Y2RuLm5ldC9hamF4L2xpYnMvZ2l0aHViLW1hcmtkb3duLWNzcy81LjIuMC9naXRodWItbWFya2Rvd24tbGlnaHQubWluLmNzcyI+JwogICAgICAgICAgICAgICAgKSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGlmKCFkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiaGlnaGxpZ2h0LWxpbmsiKSl7CiAgICAgICAgICAgIGlmKCFkYXJrVGhlbWUpIHsKICAgICAgICAgICAgICAgIC8v5pqX6buRCiAgICAgICAgICAgICAgICAkKCJoZWFkIikuYXBwZW5kKCQoCiAgICAgICAgICAgICAgICAgICAgJzxsaW5rIGlkPSJoaWdobGlnaHQtbGluayIgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5ib290Y2RuLm5ldC9hamF4L2xpYnMvaGlnaGxpZ2h0LmpzLzExLjcuMC9zdHlsZXMvYmFzZTE2L2RlZmF1bHQtZGFyay5taW4uY3NzIj4nCiAgICAgICAgICAgICAgICApKTsKICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAkKCJoZWFkIikuYXBwZW5kKCQoCiAgICAgICAgICAgICAgICAgICAgJzxsaW5rIGlkPSJoaWdobGlnaHQtbGluayIgcmVsPSJzdHlsZXNoZWV0IiBocmVmPSJodHRwczovL2Nkbi5ib290Y2RuLm5ldC9hamF4L2xpYnMvaGlnaGxpZ2h0LmpzLzExLjcuMC9zdHlsZXMvYmFzZTE2L2RlZmF1bHQtbGlnaHQubWluLmNzcyI+JwogICAgICAgICAgICAgICAgKSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGlmKCFkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgia2F0ZXgtbGluayIpKXsKICAgICAgICAgICAgJCgiaGVhZCIpLmFwcGVuZCgkKAogICAgICAgICAgICAgICAgJzxsaW5rIGlkPSJrYXRleC1saW5rIiBocmVmPSJodHRwczovL2Nkbi5ib290Y2RuLm5ldC9hamF4L2xpYnMvS2FUZVgvMC4xNi40L2thdGV4LmNzcyIgcmVsPSJzdHlsZXNoZWV0Ij4nCiAgICAgICAgICAgICkpOwogICAgICAgIH0KCiAgICAgICAgLy9zcGFyay1qcwogICAgICAgIGlmKCFkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgic3BhcmstanMiKSl7CiAgICAgICAgICAgICQoImhlYWQiKS5hcHBlbmQoJCgKICAgICAgICAgICAgICAgICc8c2NyaXB0IGlkPSJzcGFyay1qcyIgc3JjPSJodHRwczovL3N0YXRpYy5nZWV0ZXN0LmNvbS9nNS9nZC5qcyI+PC9zY3JpcHQ+JwogICAgICAgICAgICApKTsKICAgICAgICB9CgogICAgfQogICAgc2V0VGltZW91dChhZGRIZWFkQ3NzKQogICAgc2V0SW50ZXJ2YWwoYWRkSGVhZENzcyw1MDAwKQoKCiAgICB0cnkgewogICAgICAgIGNvbnNvbGUubG9nKAogICAgICAgICAgICBgJWPjgJBjaGF0R1BUIHRvb2xzIFBsdXPjgJHlt7LliqDovb1gLAogICAgICAgICAgICAnY29sb3I6IHllbGxvdztmb250LXNpemU6IGxhcmdlO2ZvbnQtd2VpZ2h0OiBib2xkO2JhY2tncm91bmQtY29sb3I6IGRhcmtibHVlOycKICAgICAgICApOwogICAgICAgIC8v56aB55SoY29uc29sZSDmnKrovazkuYnorablkYoKICAgICAgICBobGpzLmNvbmZpZ3VyZSh7CiAgICAgICAgICAgIGlnbm9yZVVuZXNjYXBlZEhUTUw6IHRydWUKICAgICAgICB9KQogICAgICAgIGNvbnN0IG1lbnVfdXBkYXRlQ2hhdF9pZCA9IEdNX3JlZ2lzdGVyTWVudUNvbW1hbmQoIuabtOaWsENoY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mVhbSI6CiAgICAgICAgICAgICAgICAgICBkZXRhaWxzLm9ubG9hZHN0YXJ0ID0gKHJlcyk9PnsKICAgICAgICAgICAgICAgICAgICAgICByZXNvbHZlKHJlcykKICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgICAgZGV0YWlscy5vbmxvYWQgPSAocmVzKT0+ewogICAgICAgICAgICAgICAgICAgICAgIHJlc29sdmUocmVzKQogICAgICAgICAgICAgICAgICAgfTsKICAgICAgICAgICB9CgogICAgICAgICAgIGRldGFpbHMub25lcnJvciA9IChyZXMpPT57CiAgICAgICAgICAgICAgIHJlamVjdChyZXMpCiAgICAgICAgICAgfTsKICAgICAgICAgICBkZXRhaWxzLm9udGltZW91dCA9IChyZXMpPT57CiAgICAgICAgICAgICAgIHJlamVjdChyZXMpCiAgICAgICAgICAgfTsKICAgICAgICAgICBkZXRhaWxzLm9uYWJvcnQgPSAocmVzKT0+ewogICAgICAgICAgICAgICByZWplY3QocmVzKQogICAgICAgICAgIH07CgogICAgICAgICAgIC8v5Lit5pat5pSv5oyBCiAgICAgICAgICAgaWYoZGV0YWlscy5yZXNwb25zZVR5cGUgPT09ICJzdHJlYW0iKXsKICAgICAgICAgICAgICAgYWJvcnRYbWwgPSBHTV94bWxodHRwUmVxdWVzdChkZXRhaWxzKQogICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICBHTV94bWxodHRwUmVxdWVzdChkZXRhaWxzKQogICAgICAgICAgIH0KCiAgICAgICAgfSk7CiAgICB9CgogICAgZnVuY3Rpb24gR01faHR0cFJlcXVlc3QoZGV0YWlscywgY2FsbEJhY2ssIGVycm9yQ2FsbGJhY2ssIHRpbWVvdXRDYWxsYmFjaywgYWJvcnRDYWxsYmFjayl7CiAgICAgICAgaWYoY2FsbEJhY2spewogICAgICAgICAgICBzd2l0Y2ggKGRldGFpbHMucmVzcG9uc2VUeXBlKXsKICAgICAgICAgICAgICAgIGNhc2UgInN0cmVhbSI6CiAgICAgICAgICAgICAgICAgICAgZGV0YWlscy5vbmxvYWRzdGFydCA9IGNhbGxCYWNrOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICAgICAgICBkZXRhaWxzLm9ubG9hZCA9IGNhbGxCYWNrCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoZXJyb3JDYWxsYmFjayl7CiAgICAgICAgICAgIGRldGFpbHMub25lcnJvciA9IGVycm9yQ2FsbGJhY2s7CiAgICAgICAgfQogICAgICAgIGlmKHRpbWVvdXRDYWxsYmFjayl7CiAgICAgICAgICAgIGRldGFpbHMub250aW1lb3V0ID0gdGltZW91dENhbGxiYWNrOwogICAgICAgIH0KICAgICAgICBpZihhYm9ydENhbGxiYWNrKXsKICAgICAgICAgICAgZGV0YWlscy5vbmFib3J0ID0gYWJvcnRDYWxsYmFjazsKICAgICAgICB9CiAgICAgICAgY29uc29sZS5sb2coZGV0YWlscykKICAgICAgICAvL+S4reaWreaUr+aMgQogICAgICAgIGlmKGRldGFpbHMucmVzcG9uc2VUeXBlID09PSAic3RyZWFtIil7CiAgICAgICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoZGV0YWlscykKICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgR01feG1saHR0cFJlcXVlc3QoZGV0YWlscykKICAgICAgICB9CiAgICB9CgogICAgLy/lsIHoo4VHTV94bWxodHRwUmVxdWVzdCAtLS1lbmQtLS0KCgogICAgbGV0IGdlbmVyYXRlUmFuZG9tSVAgPSAoKSA9PiB7CiAgICAgICAgY29uc3QgaXAgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IDQ7IGkrKykgewogICAgICAgICAgICBpcC5wdXNoKE1hdGguZmxvb3IoTWF0aC5yYW5kb20oKSAqIDI1NikpOwogICAgICAgIH0KICAgICAgICBjb25zb2xlLmxvZyhpcC5qb2luKCcuJykpCiAgICAgICAgcmV0dXJuIGlwLmpvaW4oJy4nKTsKICAgIH0KCgogICAgLy/liqjmgIFwdWJrZXkKICAgIGZ1bmN0aW9uIHNldFB1YmtleSgpIHsKICAgICAgICBsZXQgR1BUTU9ERSA9IGdldEdQVE1vZGUoKQogICAgICAgIGlmIChHUFRNT0RFID09PSAiQ0hBVEdQVCIpIHsKCiAgICAgICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgICAgICBub2NhY2hlOiB0cnVlLAogICAgICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9mcmVlb3BlbmFpLnh5ei9hcGkudHh0IiwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAvLyJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBgaHR0cHM6Ly9mcmVlb3BlbmFpLnh5ei9gCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pLnRoZW4oKHJlc3BvbnNlKT0+IHsKICAgICAgICAgICAgICAgIGxldCByZXNwID0gcmVzcG9uc2UucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzcG9uc2UpCiAgICAgICAgICAgICAgICBpZiAoIXJlc3ApIHsKICAgICAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2UucmVtb3ZlSXRlbSgib3BlbkFJa2V5IikKICAgICAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIC8vbG9jYWxTdG9yYWdlLnNldEl0ZW0oIm9wZW5BSWtleSIsIHB1YmtleSkKICAgICAgICAgICAgICAgIGxldCBodCA9ICIiCiAgICAgICAgICAgICAgICBsZXQga2V5cyA9IHJlc3Auc3BsaXQoIlxuIik7CiAgICAgICAgICAgICAgICBrZXlzLmZvckVhY2goa2V5ID0+IHsKICAgICAgICAgICAgICAgICAgICBodCArPSBgPGEgaHJlZj0namF2YXNjcmlwdDooZnVuY3Rpb24oKXsgbG9jYWxTdG9yYWdlLnNldEl0ZW0oIm9wZW5BSWtleSIsIiR7a2V5fSIpO2FsZXJ0KCLmm7TmlrDmiJDlip/vvJoke2tleX0iKX0pKCk7Jz4ke2tleX08L2E+PGJyPmAKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZ3B0QW5zd2VyIikuaW5uZXJIVE1MID0gIGh0OwogICAgICAgICAgICAgICAgLy9kb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZ3B0QW5zd2VyIikuaW5uZXJUZXh0ID0gIm9wZW5BSSBrZXnojrflj5bmiJDlip8s6K+35aSN5Yi25YW25Lit5LiA5Liq5bm254K55oyJ6ZKu5re75YqgOlxuIitrZXlzLmpvaW4oIiwiKQogICAgICAgICAgICAgICAgbG9jYWxTdG9yYWdlLnJlbW92ZUl0ZW0oIm9wZW5BSWtleSIpCiAgICAgICAgICAgIH0pLmNhdGNoKChyZXMpPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpCiAgICAgICAgICAgIH0pCgogICAgICAgIH1lbHNlIGlmKCFHUFRNT0RFIHx8IEdQVE1PREUgPT09ICJEZWZhdWx0Iil7CiAgICAgICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgICAgICB1cmw6ICJodHRwczovL2FwaS5haWdjZnVuLmNvbS9mYy9rZXkiLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBgaHR0cHM6Ly9haWdjZnVuLmNvbS9gLAogICAgICAgICAgICAgICAgICAgICJYLUZvcndhcmRlZC1Gb3IiOiBnZW5lcmF0ZVJhbmRvbUlQKCkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkudGhlbigocmVzcG9uc2UpPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3AgPSByZXNwb25zZS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgICAgICBsZXQgcHVia2V5ID0gSlNPTi5wYXJzZShyZXNwKS5kYXRhOwogICAgICAgICAgICAgICAgaWYgKCFwdWJrZXkpIHsKICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZ3B0QW5zd2VyIikuaW5uZXJUZXh0ID0gIuiOt+WPlnB1YmtleeWksei0pSIKICAgICAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJwdWJrZXk6IiArIHB1YmtleSk7CiAgICAgICAgICAgICAgICAvL0dNX3NldFZhbHVlKCJwdWJrZXkiLCBwdWJrZXkpCiAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgicHVia2V5IiwgcHVia2V5KQogICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImdwdEFuc3dlciIpLmlubmVyVGV4dCA9ICJwdWJrZXnmm7TmlrDmiJDlip86IiArIHB1YmtleQogICAgICAgICAgICB9KQogICAgICAgIH1lbHNlIGlmKEdQVE1PREUgPT09ICJCTlUxMjAiKXsKICAgICAgICAgICAgc2V0VGltZW91dChhc3luYyAoKSA9PiB7CiAgICAgICAgICAgICAgICBibnVJbnQgPSAoYm51SW50ICsgMSkgPiA2ID8gMCA6IChibnVJbnQgKyAxKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihg5q2j5Zyo5pu05pawLuiLpeaXoOazleabtOaWsCzliJnlpJrngrnlh6DmrKEs5b2T5YmN77yaJHtibnVJbnR977yM5YWxNmApCiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIGJudUtleSA9IGF3YWl0IHNldE5vcm1hbEtleShgaHR0cHM6Ly9jaGF0LiR7Ym51SW50fS5ibnUxMjAuc3BhY2VgKTsKICAgICAgICAgICAgICAgICAgICBpZihibnVLZXkpewogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGBCTlUxMjDvvJrmm7TmlrDmiJDlip8sS0VZOiR7Ym51S2V5fWApCiAgICAgICAgICAgICAgICAgICAgICAgIGxvY2FsU3RvcmFnZS5zZXRJdGVtKCJibnVJbnQiLCBibnVJbnQpCiAgICAgICAgICAgICAgICAgICAgfWVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJCTlUxMjDvvJrmm7TmlrDlpLHotKUiKQogICAgICAgICAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2UucmVtb3ZlSXRlbSgiYm51SW50IikKICAgICAgICAgICAgICAgICAgICAgICAgYm51SW50ID0gTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNykKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGDplJnor6/kuobjgILor7fph43or5VgKQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKICAgICAgICB9ZWxzZSB7CiAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoIuivpee6v+i3r+S4jemAgueUqCIpCiAgICAgICAgfQoKICAgIH0KCiAgICBmdW5jdGlvbiBnZXRQdWJrZXkoKSB7CiAgICAgICAgLy9yZXR1cm4gR01fZ2V0VmFsdWUoInB1YmtleSIpOwogICAgICAgIHJldHVybiBsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgicHVia2V5Iik7CiAgICB9CgogICAgLy91cGRhdGUgQUlHQ0ZVTiBrZXkuCiAgICBzZXRUaW1lb3V0KCgpPT57CiAgICAgICAgaWYgKCFnZXRQdWJrZXkoKSl7CiAgICAgICAgICAgIHNldFB1YmtleSgpOwogICAgICAgIH0KICAgIH0pCgogICAgLy9lbmMtc3RhcnQKICAgIGFzeW5jIGZ1bmN0aW9uIGRpZ2VzdE1lc3NhZ2UocikgewogICAgICAgIGNvbnN0IGhhc2ggPSBDcnlwdG9KUy5TSEEyNTYocik7CiAgICAgICAgcmV0dXJuIGhhc2gudG9TdHJpbmcoQ3J5cHRvSlMuZW5jLkhleCk7CiAgICB9CgogICAgY29uc3QgZ2VuZXJhdGVTaWduYXR1cmUgPSBhc3luYyByID0+IHsKICAgICAgICBjb25zdCB7CiAgICAgICAgICAgIHQ6IGUsCiAgICAgICAgICAgIG06IHQKICAgICAgICB9ID0gcjsKICAgICAgICAvL2NvbnN0IG4gPSB7fS5QVUJMSUNfU0VDUkVUX0tFWTsKICAgICAgICBsZXQgbiA9IGdldFB1YmtleSgpOwogICAgICAgIGlmICghbikgewogICAgICAgICAgICBjb25zb2xlLmxvZygicHVia2V55LiN5a2Y5Zyo77yM5L2/55So6buY6K6kIikKICAgICAgICAgICAgbiA9ICJrNnplRTc3Z2U3WEYiCiAgICAgICAgfQogICAgICAgIGNvbnNvbGUubG9nKCJDVVJSRU5UIEtFWToiICsgbikKICAgICAgICBjb25zdCBhID0gYCR7ZX06JHt0fToke259YDsKICAgICAgICByZXR1cm4gYXdhaXQgZGlnZXN0TWVzc2FnZShhKTsKICAgIH07CgogICAgY29uc3QgZ2VuZXJhdGVTaWduYXR1cmVXaXRoUGtleSA9IGFzeW5jIHIgPT4gewogICAgICAgIGNvbnN0IHsKICAgICAgICAgICAgdDogZSwKICAgICAgICAgICAgbTogdCwKICAgICAgICAgICAgcGtleTogbgogICAgICAgIH0gPSByOwogICAgICAgIGNvbnNvbGUubG9nKCJDVVJSRU5UIEtFWToiICsgbikKICAgICAgICBjb25zdCBhID0gYCR7ZX06JHt0fToke259YDsKICAgICAgICByZXR1cm4gYXdhaXQgZGlnZXN0TWVzc2FnZShhKTsKICAgIH07CgogICAgbGV0IGFlc0tleSA9ICJoajZjZHpyaGo3Mng4aHQxIjsKICAgIGNvbnN0IEFFU19DQkMgPSB7CgogICAgICAgIGVuY3J5cHQ6IGZ1bmN0aW9uKGUsIHQpIHsKICAgICAgICAgICAgcmV0dXJuIENyeXB0b0pTLkFFUy5lbmNyeXB0KENyeXB0b0pTLmVuYy5VdGY4LnBhcnNlKGUpLCBDcnlwdG9KUy5lbmMuVXRmOC5wYXJzZSh0KSwgewogICAgICAgICAgICAgICAgaXY6IENyeXB0b0pTLmVuYy5VdGY4LnBhcnNlKGFlc0tleSksCiAgICAgICAgICAgICAgICBtb2RlOiBDcnlwdG9KUy5tb2RlLkNCQwogICAgICAgICAgICB9KS50b1N0cmluZygpCiAgICAgICAgfSwKICAgICAgICBkZWNyeXB0OiBmdW5jdGlvbihlLCB0KSB7CiAgICAgICAgICAgIHJldHVybiBDcnlwdG9KUy5BRVMuZGVjcnlwdChlLCBDcnlwdG9KUy5lbmMuVXRmOC5wYXJzZSh0KSwgewogICAgICAgICAgICAgICAgaXY6IENyeXB0b0pTLmVuYy5VdGY4LnBhcnNlKGFlc0tleSksCiAgICAgICAgICAgICAgICBtb2RlOiBDcnlwdG9KUy5tb2RlLkNCQwogICAgICAgICAgICB9KS50b1N0cmluZyhDcnlwdG9KUy5lbmMuVXRmOCkKICAgICAgICB9CiAgICB9OwogICAgLy9lbmMtZW5kCgogICAgLy9zdGFydAoKCiAgICBmdW5jdGlvbiBhZGRDaGF0QnRuKCkgewoKICAgICAgICBsZXQgbXlidG4gPQogICAgICAgICAgICBgPHNwYW4gY2xhc3M9ImJnIHNfYnRuX3dyIj48aW5wdXQgdHlwZT0iYnV0dG9uIiBpZD0ibXlidG4iIHZhbHVlPSLliqDovb1jaGF0IiBjbGFzcz0iYmcgc19idG4iPjwvc3Bhbj5gOwogICAgICAgICQoIi5iZy5zX2J0bl93ciIpLmFmdGVyKG15YnRuKQogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJteWJ0biIpLmFkZEV2ZW50TGlzdGVuZXIoImNsaWNrIiwgZnVuY3Rpb24gKCkgewogICAgICAgICAgICBjb25zb2xlLmxvZygicmVsb2FkUGFnZSIpCiAgICAgICAgICAgIGlmICh3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCJiYWlkdS5jb21cL3MiKSA+IC0xKSB7CiAgICAgICAgICAgICAgICBHTV9hZGRfYm94X3N0eWxlKDIpCiAgICAgICAgICAgICAgICBhZGRCb3RoU3R5bGUoKQogICAgICAgICAgICAgICAga2V5RXZlbnQoKQogICAgICAgICAgICAgICAgYXBwZW5kQm94KDIpLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICAgICAgICAgIHBpdkVsZW1BZGRFdmVudEFuZFZhbHVlKDIpCiAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICB9CiAgICAgICAgfSkKICAgIH0KCiAgICBmdW5jdGlvbiBpc01vYmlsZSgpIHsKICAgICAgICBsZXQgdXNlckFnZW50SW5mbyA9IG5hdmlnYXRvci51c2VyQWdlbnQudG9Mb3dlckNhc2UoKTsKICAgICAgICBsZXQgbW9iaWxlQWdlbnRzID0gWyJBbmRyb2lkIiwgImlQaG9uZSIsICJTeW1iaWFuT1MiLCAiV2luZG93cyBQaG9uZSIsICJpUGFkIiwgImlQb2QiLCJNb2JpbGUiXTsKICAgICAgICBsZXQgbW9iaWxlX2ZsYWcgPSBmYWxzZTsKICAgICAgICAvL+agueaNrnVzZXJBZ2VudOWIpOaWreaYr+WQpuaYr+aJi+acugogICAgICAgIGZvciAobGV0IHYgPSAwOyB2IDwgbW9iaWxlQWdlbnRzLmxlbmd0aDsgdisrKSB7CiAgICAgICAgICAgIGlmICh1c2VyQWdlbnRJbmZvLmluZGV4T2YobW9iaWxlQWdlbnRzW3ZdLnRvTG93ZXJDYXNlKCkpID4gLTEpIHsKICAgICAgICAgICAgICAgIG1vYmlsZV9mbGFnID0gdHJ1ZTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBtb2JpbGVfZmxhZzsKICAgIH0KCgogICAgLy9lbmQKCiAgICBmdW5jdGlvbiBrYXRleFRvaHRtbChyYXdIdG1sKSB7CiAgICAgICAvLyBjb25zb2xlLmxvZygiPT09PT09PT1rYXRleFRvaHRtbCBzdGFydD09PT09PT0iKQogICAgICAgIGxldCByZW5kZXJlZEh0bWwgPSByYXdIdG1sLnJlcGxhY2UoLzxlbT4vZywgIiIpLnJlcGxhY2UoLzxcL2VtPi9nLCAiIikucmVwbGFjZSgvXCRcJCguKj8pXCRcJC9nLCAoXywgdGV4KSA9PiB7CiAgICAgICAgICAgIC8vZGVidWdnZXIKICAgICAgICAgICAgcmV0dXJuIGthdGV4LnJlbmRlclRvU3RyaW5nKHRleCwge2Rpc3BsYXlNb2RlOiBmYWxzZSwgdGhyb3dPbkVycm9yOiBmYWxzZX0pOwogICAgICAgIH0pOwogICAgICAgIHJlbmRlcmVkSHRtbCA9IHJlbmRlcmVkSHRtbC5yZXBsYWNlKC9cJCguKj8pXCQvZywgKF8sIHRleCkgPT4gewogICAgICAgICAgICAvL2RlYnVnZ2VyCiAgICAgICAgICAgIHJldHVybiBrYXRleC5yZW5kZXJUb1N0cmluZyh0ZXgsIHtkaXNwbGF5TW9kZTogZmFsc2UsIHRocm93T25FcnJvcjogZmFsc2V9KTsKICAgICAgICB9KTsKICAgICAgIC8vIGNvbnNvbGUubG9nKCI9PT09PT09PWthdGV4VG9odG1sIGVuZD09PT09PT0iKQogICAgICAgIHRyeSB7CiAgICAgICAgICAgIHJlbmRlcmVkSHRtbCA9IGZpbHRlclhTUyhyZW5kZXJlZEh0bWwpIC8vZm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gZmFsc2U7CiAgICAvL+aYvuekuuetlOahiOW5tumrmOS6ruS7o+eggeWHveaVsAogICAgZnVuY3Rpb24gc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihjb2RlU3RyKSB7CiAgICAgICAgaWYoIWNvZGVTdHIpIHJldHVybgogICAgICAgIHJhd0FucyA9IGNvZGVTdHI7Ly/orrDlvZXljp/mlocKICAgICAgICB0cnkgewogICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZ3B0QW5zd2VyJykuaW5uZXJIVE1MID0gYCR7a2F0ZXhUb2h0bWwobWRDb252ZXJ0ZXIoY29kZVN0ci5yZXBsYWNlKC9cXG4rL2csICJcbiIpKSl9YAogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdncHRBbnN3ZXInKS5pbm5lckhUTUwgPSBgJHttZENvbnZlcnRlcihjb2RlU3RyLnJlcGxhY2UoL1xcbisvZywgIlxuIikpfWAKICAgICAgICAgICAgfWNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGhpZ2hsaWdodENvZGVTdHIoKS8v6auY5LquCiAgICAgICAgLy/mt7vliqDku6PnoIHlpI3liLbmjInpkq4gc3RhcnQKICAgICAgICBsZXQgcHJlTGlzdCA9ICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yQWxsKCIjZ3B0QW5zd2VyIHByZSIpCiAgICAgICAgcHJlTGlzdC5mb3JFYWNoKChwcmUpPT57CiAgICAgICAgICAgIHRyeXsKICAgICAgICAgICAgICAgIGlmKCFwcmUucXVlcnlTZWxlY3RvcigiLmJ0bi1wcmUtY29weSIpKXsKICAgICAgICAgICAgICAgICAgICAvLzxzcGFuIGNsYXNzPVwiYnRuLXByZS1jb3B5XCIgb25jbGljaz0ncHJlQ29weSh0aGlzKSc+5aSN5Yi25Luj56CBPC9zcGFuPgogICAgICAgICAgICAgICAgICAgIGxldCBjb3B5QnRuID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic3BhbiIpOwogICAgICAgICAgICAgICAgICAgIGNvcHlCdG4uc2V0QXR0cmlidXRlKCJjbGFzcyIsImJ0bi1wcmUtY29weSIpOwogICAgICAgICAgICAgICAgICAgIGNvcHlCdG4uYWRkRXZlbnRMaXN0ZW5lcigiY2xpY2siLChldmVudCk9PnsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IF90aGlzID0gZXZlbnQudGFyZ2V0CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKF90aGlzKQogICAgICAgICAgICAgICAgICAgICAgIGxldCBwcmUgPSBfdGhpcy5wYXJlbnROb2RlOwogICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHByZS5pbm5lclRleHQpCiAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMuaW5uZXJUZXh0ID0gJyc7CiAgICAgICAgICAgICAgICAgICAgICAgR01fc2V0Q2xpcGJvYXJkKHByZS5pbm5lclRleHQsICJ0ZXh0Iik7CiAgICAgICAgICAgICAgICAgICAgICAgIF90aGlzLmlubmVyVGV4dCA9ICflpI3liLbmiJDlip8nCiAgICAgICAgICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PnsKICAgICAgICAgICAgICAgICAgICAgICAgICAgX3RoaXMuaW5uZXJUZXh0ID0gJ+WkjeWItuS7o+eggScKICAgICAgICAgICAgICAgICAgICAgICB9LDIwMDApCiAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICBjb3B5QnRuLmlubmVyVGV4dCA9ICflpI3liLbku6PnoIEnCiAgICAgICAgICAgICAgICAgICAgcHJlLmluc2VydEJlZm9yZShjb3B5QnRuLCBwcmUuZmlyc3RDaGlsZCkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfWNhd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guKj9cLmNmL2c7CiAgICBpZiAod2luZG93LmxvY2F0aW9uLmhyZWYuaW5kZXhPZigiYmluZy5jb20iKSA+IC0xKSB7CgogICAgICAgIEdNX2FkZF9ib3hfc3R5bGUoMCkKICAgICAgICBhZGRCb3RoU3R5bGUoKQogICAgICAgIGtleUV2ZW50KCkKICAgICAgICBhcHBlbmRCb3goMCkudGhlbigocmVzKSA9PiB7CiAgICAgICAgICAgIHBpdkVsZW1BZGRFdmVudEFuZFZhbHVlKDApCiAgICAgICAgfSkKICAgICAgICAvL2xpbmtUb0JpbmdfYmVhdXRpZmljYXRpb25fc2NyaXB0KCkKICAgIH0KICAgIGlmICh3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCJnb29nbGUuY29tIikgPiAtMSB8fCB3aW5kb3cubG9jYXRpb24uaHJlZi5tYXRjaChyZWd4KSkgewogICAgICAgIEdNX2FkZF9ib3hfc3R5bGUoMSkKICAgICAgICBhZGRCb3RoU3R5bGUoKQogICAgICAgIGtleUV2ZW50KCkKICAgICAgICBhcHBlbmRCb3goMSkudGhlbigocmVzKSA9PiB7CiAgICAgICAgICAgIGlmKGlzTW9iaWxlKCkpewogICAgICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoMTEpCiAgICAgICAgICAgIH1lbHNlIHsKICAgICAgICAgICAgICAgIHBpdkVsZW1BZGRFdmVudEFuZFZhbHVlKDEpCiAgICAgICAgICAgIH0KICAgICAgICB9KQogICAgfQogICAgaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoImJhaWR1LmNvbVwvcyIpID4gLTEgJiYgIWlzTW9iaWxlKCkpIHsKICAgICAgICBHTV9hZGRfYm94X3N0eWxlKDIpCiAgICAgICAgYWRkQm90aFN0eWxlKCkKICAgICAgICBrZXlFdmVudCgpCiAgICAgICAgYXBwZW5kQm94KDIpLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZSgyKQogICAgICAgIH0pCiAgICB9IGVsc2UgaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoImh0dHBzOlwvXC9tLmJhaWR1LmNvbSIpID4gLTEgfHwgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoCiAgICAgICAgImJhaWR1LmNvbSIpID4gLTEgJiYgaXNNb2JpbGUoKSkpIHsgLy/miYvmnLrnmb7luqYKICAgICAgICBHTV9hZGRfYm94X3N0eWxlKDIpCiAgICAgICAgYWRkQm90aFN0eWxlKCkKICAgICAgICBrZXlFdmVudCgpCiAgICAgICAgYXBwZW5kQm94KDYpLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZSgyKQogICAgICAgIH0pCiAgICB9CiAgICAvL+S/hOe9l+aWr3lhbmRleAogICAgaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoInlhbmRleC5ydVwvc2VhcmNoIikgPiAtMSB8fCB3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKAogICAgICAgICJ5YW5kZXguY29tXC9zZWFyY2giKSA+IC0xKSB7CiAgICAgICAgR01fYWRkX2JveF9zdHlsZSgxKQogICAgICAgIGFkZEJvdGhTdHlsZSgpCiAgICAgICAga2V5RXZlbnQoKQogICAgICAgIGFwcGVuZEJveCgzKS50aGVuKChyZXMpID0+IHsKICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoMykKICAgICAgICB9KQogICAgfQoKICAgIC8vMzYwc28KICAgIGlmICh3aW5kb3cubG9jYXRpb24uaHJlZi5pbmRleE9mKCJzby5jb21cL3MiKSA+IC0xKSB7CiAgICAgICAgR01fYWRkX2JveF9zdHlsZSgxKQogICAgICAgIGFkZEJvdGhTdHlsZSgpCiAgICAgICAga2V5RXZlbnQoKQogICAgICAgIGFwcGVuZEJveCg0KS50aGVuKChyZXMpID0+IHsKICAgICAgICAgICAgaWYoaXNNb2JpbGUoKSl7CiAgICAgICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZSg5KQogICAgICAgICAgICB9ZWxzZSB7CiAgICAgICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZSg0KQogICAgICAgICAgICB9CiAgICAgICAgfSkKICAgIH0KCiAgICAvL2Zzb3Vmc291CiAgICBpZiAod2luZG93LmxvY2F0aW9uLmhyZWYuaW5kZXhPZigiZnNvdWZzb3UuY29tXC9zZWFyY2giKSA+IC0xKSB7CiAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgIEdNX2FkZF9ib3hfc3R5bGUoMSkKICAgICAgICAgICAgYWRkQm90aFN0eWxlKCkKICAgICAgICAgICAga2V5RXZlbnQoKQogICAgICAgICAgICBhcHBlbmRCb3goNSkudGhlbigocmVzKSA9PiB7CiAgICAgICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZSg1KQogICAgICAgICAgICB9KQogICAgICAgIH0sIDMwMDApCiAgICB9CgogICAgLy9kdWNrZHVja2dvLmNvbQogICAgaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoImR1Y2tkdWNrZ28uY29tXC9cP3EiKSA+IC0xKSB7CiAgICAgICAgR01fYWRkX2JveF9zdHlsZSgxKQogICAgICAgIGFkZEJvdGhTdHlsZSgpCiAgICAgICAga2V5RXZlbnQoKQogICAgICAgIGFwcGVuZEJveCg3KS50aGVuKChyZXMpID0+IHsKICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoNykKICAgICAgICB9KQogICAgfQoKICAgIC8vc29nb3UuY29tCiAgICBpZiAod2luZG93LmxvY2F0aW9uLmhyZWYuaW5kZXhPZigic29nb3UuY29tIikgPiAtMSkgewogICAgICAgIEdNX2FkZF9ib3hfc3R5bGUoMSkKICAgICAgICBhZGRCb3RoU3R5bGUoKQogICAgICAgIGtleUV2ZW50KCkKICAgICAgICBhcHBlbmRCb3goOCkudGhlbigocmVzKSA9PiB7CiAgICAgICAgICAgIGlmKGlzTW9iaWxlKCkpewogICAgICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoMTApCiAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoOCkKICAgICAgICAgICAgfQogICAgICAgIH0pCiAgICB9CgogICAgLy9iaWxpYmlsaS5jb20KICAgIGlmICh3aW5kb3cubG9jYXRpb24uaHJlZi5pbmNsdWRlcygiYmlsaWJpbGkuY29tIikpIHsKICAgICAgICBHTV9hZGRfYm94X3N0eWxlKDEpCiAgICAgICAgYWRkQm90aFN0eWxlKCkKICAgICAgICBrZXlFdmVudCgpCiAgICAgICAgYXBwZW5kQm94KDkpLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZShudWxsKQogICAgICAgIH0pCiAgICB9CgoKICAgIC8vYmlsaWJpbGkuY29tCiAgICBpZiAod2luZG93LmxvY2F0aW9uLmhyZWYuaW5jbHVkZXMoImJsb2cuY3Nkbi5uZXQiKSkgewogICAgICAgIEdNX2FkZF9ib3hfc3R5bGUoMSkKICAgICAgICBhZGRCb3RoU3R5bGUoKQogICAgICAgIGtleUV2ZW50KCkKICAgICAgICBhcHBlbmRCb3goMTApLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICBwaXZFbGVtQWRkRXZlbnRBbmRWYWx1ZShudWxsKQogICAgICAgIH0pCiAgICB9CgogICAgLy/pobbnuqflh73mlbAKICAgIGZ1bmN0aW9uIHV1aWQoKSB7IC8vdXVpZCDkuqfnlJ8KICAgICAgICBsZXQgcyA9IFtdOwogICAgICAgIGxldCBoZXhEaWdpdHMgPSAiMDEyMzQ1Njc4OWFiY2RlZiI7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCAzNjsga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ZlcnsKICAgICAgICBjdXJzb3I6IHBvaW50ZXI7CiAgICB9CiAgICAjZ3B0RGl2ewogICAgICAgIHdpZHRoOjQ1MnB4OwogICAgICAgIGZsZXg6IDE7CiAgICAgICAgZGlzcGxheTogZmxleDsKICAgICAgICBmbGV4LWRpcmVjdGlvbjogY29sdW1uOwogICAgICAgIGhlaWdodDogZml0LWNvbnRlbnQ7CiAgICB9CiAgICAjZ3B0SW5wdXRCb3h7CiAgICAgICAgZGlzcGxheTpmbGV4OwogICAgICAgIGp1c3RpZnktY29udGVudDogc3BhY2UtYXJvdW5kOwogICAgICAgIGJvcmRlci1yYWRpdXM6IDIwcHg7CiAgICAgICAgYm9yZGVyOiAxcHggc29saWQgI2M0YzdjZTsKICAgICAgICBtYXJnaW4tbGVmdDogMTBweDsKICAgIH0KICAgICNidXR0b25fR1BUewogICAgICAgIGJvcmRlcjogMDsKICAgICAgICBiYWNrZ3JvdW5kLWNvbG9yOiB0cmFuc3BhcmVudDsKICAgICAgICBmb250LXNpemU6IDE0cHg7CiAgICAgICAgcGFkZGluZzogNXB4OwogICAgfQogICAgI2dwdFN0YXR1c3sKICAgICAgICBtYXJnaW4tbGVmdDogMTBweDsKICAgIH0KICAgICNtb2RlU2VsZWN0IHsKICAgICAgICBib3JkZXI6IDFweCBzb2xpZCAjYzRjN2NlOwogICAgICAgIGJvcmRlci1yYWRpdXM6IDEwcHg7CiAgICAgICAgbWFyZ2luOiAzcHg7CiAgICAgICAgbWFyZ2luLWxlZnQ6IC0xcHg7CiAgICB9CiAgICAKICAgIC5jaGF0U2V0dGluZ3sKICAgICAgICBkaXNwbGF5OiBibG9jazsKICAgICAgICB0ZXh0LWFsaWduOiByaWdodDsKICAgICAgICBtYXJnaW4tdG9wOiAxMHB4OwogICAgICAgIG1hcmdpbi1yaWdodDogOHB4OwogICAgICAgIG1hcmdpbi1ib3R0b206IDFweDsKICAgIH0KICAgIC5jaGF0SGlkZXsKICAgICAgICAgZGlzcGxheTogbm9uZTsKICAgIH0KICAgIAogICAgI2NoYXRTZXR0aW5newogICAgICAgdGV4dC1kZWNvcmF0aW9uOiBub25lICFpbXBvcnRhbnQ7CiAgICB9CiAgICAjY2hhdFNldHRpbmc6aG92ZXJ7CiAgICAgICBjdXJzb3I6IHBvaW50ZXI7CiAgICAgICB0ZXh0LWRlY29yYXRpb246IHVuZGVybGluZSAhaW1wb3J0YW50OwogICAgfQogICAgCiAgICAjd2Vic2l0ZSBhOm50aC1jaGlsZChvZGQpewogICAgICAgIGNvbG9yOiAjZmZiYjAwOwogICAgfQogICAgCiAgICAjd2Vic2l0ZSBhOm50aC1jaGlsZChldmVuKXsKICAgICAgICBjb2xvcjogIzBiYmJhYzsKICAgIH0KICAgIAogICAgI3dlYnNpdGUgYSB7CiAgICAgICAgYm9yZGVyOiAxcHggc29saWQ7CiAgICAgICAgYm9yZGVyLXJhZGl1czogM3B4OwogICAgICAgIG1hcmdpbi1yaWdodDogOXB4OwogICAgICAgIG1hcmdpbi1ib3R0b206IDVweDsKICAgIH0KICAgICN3ZWJzaXRlIGhyIHsKICAgICAgICBib3JkZXI6IG5vbmU7CiAgICAgICAgYm9yZGVyLXRvcDogMXB4IGRhc2hlZCAjOTk5OwogICAgICAgIG1hcmdpbjogNXB4IDBweCA1cHggMHB4OwogICAgfQoKICAgIGdwdERpdiBwewogICAgICAgIHdoaXRlLXNwYWNlOiBwcmUtbGluZTsKICAgIH0KICAgIAogICAgcHJlIC5idG4tcHJlLWNvcHl7CiAgICAgICAgdGV4dC1hbGlnbjogcmlnaHQ7CiAgICAgICAgZGlzcGxheTogYmxvY2s7CiAgICB9CiAgICAKICAgIHByZSAuYnRuLXByZS1jb3B5OmhvdmVyewogICAgICAgIGN1cnNvcjogcG9pbnRlcjsKICAgIH0KICAgIAogICAgCiAgICBgKQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICBhbGVydCgi5Y+C5pWw5rKh6K6+5a6aIikKICAgICAgICB9CgogICAgfQoKICAgIGZ1bmN0aW9uIGRvX2l0KCkgewoKICAgICAgICBpc1Nob3dSYXcgPSBmYWxzZTsgLy/orr7nva7mmL7npLrljp/mlocKICAgICAgICByYXdBbnMgPSB1bmRlZmluZWQ7Ly/orr7nva7mmL7npLrljp/mlocKCiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2dwdEFuc3dlcicpLmlubmVySFRNTCA9IGA8ZGl2PuWKoOi9veS4rTxzcGFuIGlkPSJkb3QiPjwvc3Bhbj48L2Rpdj5gOwoKICAgICAgICAvL0NIQVRHUFTmqKHlvI8KICAgICAgICBsZXQgR1BUTU9ERSA9IGdldEdQVE1vZGUoKQogICAgICAgIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJDSEFUR1BUIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygi5b2T5YmN5qih5byPQ0hBVEdQVCIpCiAgICAgICAgICAgIEdQVCgpCiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkFOWloiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCLlvZPliY3mqKHlvI9BTlpaIikKICAgICAgICAgICAgQU5aWigpOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJUSEVCQUkiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCLlvZPliY3mqKHlvI9USEVCQUkiKQogICAgICAgICAgICBUSEVCQUkoKQogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJZUUNMT1VEIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygi5b2T5YmN5qih5byPWVFDTE9VRCIpCiAgICAgICAgICAgIFlRQ0xPVUQoKQogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJIQU9IVU9MQSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkhBT0hVT0xBIikKCiAgICAgICAgICAgIEhBT0hVT0xBKCk7CgogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJQSVpaQSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIuW9k+WJjeaooeW8j1BJWlpBIikKICAgICAgICAgICAgUElaWkEoKTsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiQUlUSUFOSFUiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCLlvZPliY3mqKHlvI9BSVRJQU5IVSIpCiAgICAgICAgICAgIEFJVElBTkhVKCkKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiVERDSEFUIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygi5b2T5YmN5qih5byPVERDSEFUIikKICAgICAgICAgICAgVERDSEFUKCkKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiUURZTVlTIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygi5b2T5YmN5qih5byPUURZTVlTIikKICAgICAgICAgICAgUURZTVlTKCk7CgogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJXR0siKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCLlvZPliY3mqKHlvI9XR0siKQoKICAgICAgICAgICAgV0dLKCk7CgogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJUNjYiKSB7CgogICAgICAgICAgICBjb25zb2xlLmxvZygiVDY2IikKICAgICAgICAgICAgVDY2KCkKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkFJTFMiKSB7CgogICAgICAgICAgICBjb25zb2xlLmxvZygiQUlMUyIpCiAgICAgICAgICAgIEFJTFMoKQoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiRkRLQU5HIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiRkRLQU5HIikKICAgICAgICAgICAgRkRLQU5HKCkKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNPT0xBSSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkNPT0xBSSIpCiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICByZXN1bHRDb29sQUkgPSBbXTsKICAgICAgICAgICAgICAgIFdlYnNvY2tldENvb2xBSS5zZW5kKGA0MlsiYXNrIix7InVzZXJJZCI6ImNvb2wiLCJjb250ZW50IjoiJHt5b3VyX3F1c30ifV1gKQogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBpbml0U29ja2V0KCkKICAgICAgICAgICAgfQoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJYQk9BVCIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlhCT0FUIikKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIHJlc3VsdFhCT0FUID0gW107CiAgICAgICAgICAgICAgICBXZWJzb2NrZXRYQk9BVC5zZW5kKHlvdXJfcXVzKQogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBpbml0U29ja2V0WEJPQVQoKQogICAgICAgICAgICB9CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJQSElORCIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlBISU5EIikKICAgICAgICAgICAgUEhJTkQoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIldPQkNXIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiV09CQ1ciKQogICAgICAgICAgICBXT0JDVygpOwoKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkhFSEFOV0FORyIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkhFSEFOV0FORyIpCiAgICAgICAgICAgIEhFSEFOV0FORygpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiRVhUS0oiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJFWFRLSiIpCiAgICAgICAgICAgIEVYVEtKKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJYSUFPV0VOWkkiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJYSUFPV0VOWkkiKQogICAgICAgICAgICBYSUFPV0VOWkkoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkdBTUVKWCIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkdBTUVKWCIpCiAgICAgICAgICAgIEdBTUVKWCgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH0gZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiQUlGS1MiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJBSUZLUyIpCiAgICAgICAgICAgIEFJRktTKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfSBlbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJVU0VTTEVTUyIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlVTRVNMRVNTIikKICAgICAgICAgICAgVVNFU0xFU1MoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9IGVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlBSVEJPT00iKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJQUlRCT09NIikKICAgICAgICAgICAgUFJUQk9PTSgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJTVU5MRSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlNVTkxFIikKICAgICAgICAgICAgU1VOTEUoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiRUFTWUFJIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiRUFTWUFJIikKICAgICAgICAgICAgRUFTWUFJKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNMRUFORFgiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJDTEVBTkRYIikKICAgICAgICAgICAgQ0xFQU5EWCgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJFU08iKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJFU08iKQogICAgICAgICAgICBFU08oKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiQ1ZFT1kiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJDVkVPWSIpCiAgICAgICAgICAgIENWRU9ZKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlhDQkwiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJYQ0JMIikKICAgICAgICAgICAgWENCTCgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJIWklUIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiSFpJVCIpCiAgICAgICAgICAgIEhaSVQoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiVE9ZQU1MIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiVE9ZQU1MIikKICAgICAgICAgICAgVE9ZQU1MKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIk5CQUkiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJOQkFJIikKICAgICAgICAgICAgTkJBSSgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJYRUFTWSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlhFQVNZIikKICAgICAgICAgICAgWEVBU1koKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAibmV3QmluZyIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIm5ld0JpbmciKQogICAgICAgICAgICBuZXdCaW5nKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkJOVTEyMCIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkJOVTEyMCIpCiAgICAgICAgICAgIEJOVTEyMCgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJET0cyIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiRE9HMiIpCiAgICAgICAgICAgIERPRzIoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiTEVNVVJDSEFUIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiTEVNVVJDSEFUIikKICAgICAgICAgICAgTEVNVVJDSEFUKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIk1JTkRFRCIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIk1JTkRFRCIpCiAgICAgICAgICAgIE1JTkRFRCgpOwoKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAvL2VuZCBpZgogICAgICAgIH1lbHNlIGlmIChHUFRNT0RFICYmIEdQVE1PREUgPT09ICJDSEFUMSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkNIQVQxIikKICAgICAgICAgICAgQ0hBVDEoKTsKCiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgLy9lbmQgaWYKICAgICAgICB9ZWxzZSBpZiAoR1BUTU9ERSAmJiBHUFRNT0RFID09PSAiQ1lUU0VFIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiQ1lUU0VFIikKICAgICAgICAgICAgQ1lUU0VFKCk7CgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNIQVRaSEFORyIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkNIQVRaSEFORyIpCiAgICAgICAgICAgIENIQVRaSEFORygpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIk9GRklDRUNIQVQiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJPRkZJQ0VDSEFUIikKICAgICAgICAgICAgT0ZGSUNFQ0hBVCgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNIQVRXRUIxIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiQ0hBVFdFQjEiKQogICAgICAgICAgICBDSEFUV0VCMSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkxJTktBSSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIkxJTktBSSIpCiAgICAgICAgICAgIExJTktBSSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkdFRUtSIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiR0VFS1IiKQogICAgICAgICAgICBHRUVLUigpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlpIVUxFSSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlpIVUxFSSIpCiAgICAgICAgICAgIFpIVUxFSSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNIQVREREQiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJDSEFUREREIikKICAgICAgICAgICAgQ0hBVERERCgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIk9QRU5BSSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIk9QRU5BSSIpCiAgICAgICAgICAgIE9QRU5BSSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlRPTkdZSSIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coIlRPTkdZSSIpCiAgICAgICAgICAgIFRPTkdZSSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlNQQVJLIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiU1BBUksiKQogICAgICAgICAgICBTUEFSSygpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlRJQU5HT05HIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiVElBTkdPTkciKQogICAgICAgICAgICBUSUFOR09ORygpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIllJWUFOIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiWUlZQU4iKQogICAgICAgICAgICBZSVlBTigpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkdQVFBMVVMiKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJHUFRQTFVTIikKICAgICAgICAgICAgR1BUUExVUygpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIlhJQU1JIikgewogICAgICAgICAgICBjb25zb2xlLmxvZygiWElBTUkiKQogICAgICAgICAgICBYSUFNSSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfWVsc2UgaWYgKEdQVE1PREUgJiYgR1BUTU9ERSA9PT0gIkNoYXRHTE0iKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJDaGF0R0xNIikKICAgICAgICAgICAgQ2hhdEdMTSgpCgogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIC8vZW5kIGlmCiAgICAgICAgfQoKICAgICAgICBjb25zb2xlLmxvZygi6buY6K6k57q/6LevOiIpCiAgICAgICAgQUlHQ0ZVTigpOwoKICAgIH0KCgogICAgZnVuY3Rpb24gR1BUKCl7CiAgICAgICAgbGV0IGZpbmFsUmVzdWx0CiAgICAgICAgaWYgKCFsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgib3BlbkFJa2V5IikpIHsKICAgICAgICAgICAgbGV0IG1hbnVhbElucHV0ID0gY29uZmlybSgib3BlbkFJa2V55LiN5a2Y5ZyoIOivt+abtOaWsCzmiJbogIXkvb/nlKjkvaDoh6rlt7HnmoRrZXkiKTsKICAgICAgICAgICAgaWYgKG1hbnVhbElucHV0KSB7CiAgICAgICAgICAgICAgICBsZXQgYWlrZXkgPSBwcm9tcHQoIuivt+i+k+WFpeaCqOeahG9wZW5BSWtleSIsICIiKTsKICAgICAgICAgICAgICAgIGlmIChhaWtleSkgbG9jYWxTdG9yYWdlLnNldEl0ZW0oIm9wZW5BSWtleSIsIGFpa2V5KQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgLy8gdXJsOiAiaHR0cDovL2dwdDAwOC5jb20vYmFja2VuZC1hcGkvY29udmVyc2F0aW9uIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9mcmVlY2hhdGdwdC54Z3Aub25lL2JhY2tlbmQtYXBpL2NvbnZlcnNhdGlvbiIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiQXV0aG9yaXphdGlvbiI6ICJCZWFyZXIgbnVsbCIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2ZyZWVjaGF0Z3B0LnhncC5vbmUvIiwKICAgICAgICAgICAgICAgIC8vICJIb3N0IjoiZ3B0MDA4LmNvbSIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogInRleHQvZXZlbnQtc3RyZWFtIiwKICAgICAgICAgICAgICAgICJ4LW9wZW5haS1hcGkta2V5IjogbG9jYWxTdG9yYWdlLmdldEl0ZW0oIm9wZW5BSWtleSIpLAogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7Ly/mipPljIVjb252ZXJzYXRpb27lsLHlj6/ku6XnnIvliLDov5nkuKrnu5PmnoQKICAgICAgICAgICAgICAgIGFjdGlvbjogIm5leHQiLAogICAgICAgICAgICAgICAgbWVzc2FnZXM6IFsKICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlkOiB1dWlkKCksCiAgICAgICAgICAgICAgICAgICAgICAgIGF1dGhvcjoge3JvbGU6ICJ1c2VyIn0sCiAgICAgICAgICAgICAgICAgICAgICAgIHJvbGU6ICJ1c2VyIiwKICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudDogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudF90eXBlOiAidGV4dCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJ0czogW3lvdXJfcXVzXSwKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgXSwKICAgICAgICAgICAgICAgIG1vZGVsOiAidGV4dC1kYXZpbmNpLTAwMi1yZW5kZXIiLAogICAgICAgICAgICAgICAgcGFyZW50X21lc3NhZ2VfaWQ6IHV1aWQoKSwKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIC8vICAgIG9ucHJvZ3Jlc3M6IGZ1bmN0aW9uKG1zZyl7Y29uc29sZS5sb2cobXNnKX0sCiAgICAgICAgICAgIC8vICAgICBvbnJlYWR5c3RhdGVjaGFuZ2U6ZnVuY3Rpb24obXNnKXtsb2cobXNnKX0sCiAgICAgICAgICAgIG9ubG9hZHN0YXJ0OiAoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICAvLyAgICAgY29uc29sZS5sb2cocmVhZGVyLnJlYWQpCiAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheSh2YWx1ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBtYXRjaFJlc3VsdHMgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpLm1hdGNoKC8icGFydHMiOlxzKlxbIiguKz8pIlxdL2cpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gbWF0Y2hSZXN1bHRzW21hdGNoUmVzdWx0cy5sZW5ndGggLSAxXTsKICAgICAgICAgICAgICAgICAgICAgICAgbm93UmVzdWx0ID0gL1xbXCIoLio/KVwiXF0vZy5leGVjKG5vd1Jlc3VsdClbMV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKG5vd1Jlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdCAhPT0gIkRPTkUiKSB7Ly9ub3QgZG9uZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihleCkKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgICAgICAgICAgICAgfQoKCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9LAogICAgICAgICAgICBvbnRpbWVvdXQ6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pCiAgICB9CgogICAgLy/pu5jorqTnur/ot68KICAgIGZ1bmN0aW9uIEFJR0NGVU4oKSB7CiAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6K+l57q/6Lev6L6D5oWi77yM6K+356iN5ZCOIikKICAgICAgICBjb25zdCBub3cgPSBEYXRlLm5vdygpOwogICAgICAgIGNvbnNvbGUubG9nKG5vdyk7CiAgICAgICAgZ2VuZXJhdGVTaWduYXR1cmUoewogICAgICAgICAgICB0OiBub3csCiAgICAgICAgICAgIG06IHlvdXJfcXVzIHx8ICIiCiAgICAgICAgfSkudGhlbihzaWduID0+IHsKICAgICAgICAgICAgY29uc29sZS5sb2coc2lnbikKICAgICAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjEsIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vYXBpLmFpZ2NmdW4uY29tL2FwaS92MS90ZXh0P2tleT0iICsgZ2V0UHVia2V5KCksCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2FpZ2NmdW4uY29tLyIsCiAgICAgICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL2FpZ2NmdW4uY29tIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICBtZXNzYWdlczogbWVzc2FnZUNoYWluMSwKICAgICAgICAgICAgICAgICAgICB0b2tlbnNMZW5ndGg6IHlvdXJfcXVzLmxlbmd0aCArIDEwLAogICAgICAgICAgICAgICAgICAgIG1vZGVsOiAiZ3B0LTMuNS10dXJibyIKICAgICAgICAgICAgICAgIH0pLAogICAgICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAidGV4dCIsCiAgICAgICAgICAgIH0pLnRoZW4oZnVuY3Rpb24gKHJlcykgewogICAgICAgICAgICAgICAgaWYgKHJlcy5zdGF0dXMgPT09IDIwMCkgewogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCfmiJDlip8uLi4uJykKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKQogICAgICAgICAgICAgICAgICAgICAgICBsZXQgcmVzdCA9IEpTT04ucGFyc2UocmVzLnJlc3BvbnNlVGV4dCkuY2hvaWNlc1swXS50ZXh0CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlc3QpCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW4xLCB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByb2xlOiAiYXNzaXN0YW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IHJlc3QKICAgICAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7fQoKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cign6K6/6Zeu5aSx6LSl5LqGJykKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSxmdW5jdGlvbiAocmVhc29uKXsKICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoYOWHuumUmeS6hjoke3JlYXNvbi5zdGF0dXN9LCR7cmVhc29uLnN0YXR1c1RleHR9YCkKICAgICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICB9CgoKICAgIGZ1bmN0aW9uIGNyZWF0Qm94KCkgewogICAgICAgIHJldHVybiBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgICBsZXQgZGl2RSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ2RpdicpOwogICAgICAgICAgICBsZXQgZGl2SWQgPSBkb2N1bWVudC5jcmVhdGVBdHRyaWJ1dGUoImlkIik7IC8v5Yib5bu65bGe5oCnCiAgICAgICAgICAgIGRpdklkLnZhbHVlID0gJ2dwdERpdic7IC8v6K6+572u5bGe5oCn5YC8CiAgICAgICAgICAgIGRpdkUuc2V0QXR0cmlidXRlTm9kZShkaXZJZCk7IC8v57uZZGl25re75Yqg5bGe5oCnCiAgICAgICAgICAgIGxldCBwRSA9IGRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoJ3AnKTsKICAgICAgICAgICAgbGV0IHBDbGFzcyA9IGRvY3VtZW50LmNyZWF0ZUF0dHJpYnV0ZSgnY2xhc3MnKTsKICAgICAgICAgICAgcENsYXNzLnZhbHVlID0gJ3RleHRDbGFzcyc7CiAgICAgICAgICAgIHBFLnNldEF0dHJpYnV0ZU5vZGUocENsYXNzKQogICAgICAgICAgICBsZXQgcFRleHQgPSBkb2N1bWVudC5jcmVhdGVUZXh0Tm9kZSgiY2hhdEdQVCB0b29scyBQbHVzIOW3suWQr+WKqCIpOwogICAgICAgICAgICBwRS5hcHBlbmRDaGlsZChwVGV4dCk7CiAgICAgICAgICAgIGRpdkUuYXBwZW5kQ2hpbGQocEUpOwogICAgICAgICAgICBkaXZFLmNsYXNzTGlzdC5hZGQoImdwdC1jb250YWluZXIiKTsKICAgICAgICAg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AgICAgICAgICAgICAgIHNlYXJjaF9jb250ZW50ID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiaW5wdXQjdXBxdWVyeSIpLnZhbHVlCiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGFwcGVuZF9jYXNlID09PSA3KSB7CiAgICAgICAgICAgICAgICBzZWFyY2hfY29udGVudCA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNzZWFyY2hfZm9ybSBpbnB1dCIpLnZhbHVlCiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGFwcGVuZF9jYXNlID09PSA1KSB7CiAgICAgICAgICAgICAgICBzZWFyY2hfY29udGVudCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJzZWFyY2gtaW5wdXQiKS52YWx1ZQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoYXBwZW5kX2Nhc2UgPT09IDQpIHsKICAgICAgICAgICAgICAgIHNlYXJjaF9jb250ZW50ID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImtleXdvcmQiKS52YWx1ZQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoYXBwZW5kX2Nhc2UgPT09IDMpIHsKICAgICAgICAgICAgICAgIHNlYXJjaF9jb250ZW50ID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvckFsbCgiaW5wdXQiKVswXS52YWx1ZQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoYXBwZW5kX2Nhc2UgPT09IDIpIHsKICAgICAgICAgICAgICAgIHNlYXJjaF9jb250ZW50ID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2t3JykudmFsdWUKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoYXBwZW5kX2Nhc2UgPT09IDEpIHsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgc2VhcmNoX2NvbnRlbnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKAogICAgICAgICAgICAgICAgICAgICAgICAiI3RzZiA+IGRpdjpudGgtY2hpbGQoMSkgPiBkaXYuQThTQndmID4gZGl2LlJOTlhnYiA+IGRpdiA+IGRpdi5hNGJJYyA+IGlucHV0Om50aC1jaGlsZCgzKSIKICAgICAgICAgICAgICAgICAgICApLnZhbHVlCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgc2VhcmNoX2NvbnRlbnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJ0ZXh0YXJlYSIpLnZhbHVlCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChhcHBlbmRfY2FzZSA9PT0gMCkgewogICAgICAgICAgICAgICAgc2VhcmNoX2NvbnRlbnQgPSBkb2N1bWVudC5nZXRFbGVtZW50c0J5Q2xhc3NOYW1lKCdiX3NlYXJjaGJveCcpWzBdLnZhbHVlCiAgICAgICAgICAgICAgICBpZiAoIXNlYXJjaF9jb250ZW50KSB7CiAgICAgICAgICAgICAgICAgICAgc2VhcmNoX2NvbnRlbnQgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJ0ZXh0YXJlYVtjbGFzcz0nYl9zZWFyY2hib3gnXSIpLnZhbHVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgIH0KCiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImdwdElucHV0IikudmFsdWUgPSBzZWFyY2hfY29udGVudCB8fCAnJwogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdidXR0b25fR1BUJykuYWRkRXZlbnRMaXN0ZW5lcignY2xpY2snLCAoKSA9PiB7CiAgICAgICAgICAgIHlvdXJfcXVzID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImdwdElucHV0IikudmFsdWUKCiAgICAgICAgICAgIC8v5a2X5L2T6K6+572uCiAgICAgICAgICAgIGlmKHlvdXJfcXVzLnN0YXJ0c1dpdGgoIi9mb250LXNpemU6IikpewogICAgICAgICAgICAgICAgbGV0IGZvbnRTaXplID0geW91cl9xdXMuc3Vic3RyaW5nKCIvZm9udC1zaXplOiIubGVuZ3RoKQogICAgICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2dwdERpdiIpLnN0eWxlLmZvbnRTaXplID0gZm9udFNpemU7CiAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgiZ3B0X2ZvbnRfc2l6ZSIsZm9udFNpemUpCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGDorr7nva7miJDlip86JHtmb250U2l6ZX1gKQogICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIGRvX2l0KCkKCiAgICAgICAgfSkKCiAgICAgICAgLy/mkJzntKLlu7rorq4KICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZ3B0SW5wdXQnKS5hZGRFdmVudExpc3RlbmVyKCdrZXl1cCcsICgpID0+IHsKICAgICAgICAgICAgY29uc29sZS5sb2coImF1dG9UaXBzOiIsYXV0b1RpcHMpCiAgICAgICAgICAgIGlmKGF1dG9UaXBzICE9PSAnb24nKSByZXR1cm4KCiAgICAgICAgICAgIGxldCBjdXJyZW50OwogICAgICAgICAgICBsZXQgd29yZCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdncHRJbnB1dCcpLnZhbHVlOwogICAgICAgICAgICBpZighd29yZCkgcmV0dXJuOwogICAgICAgICAgICBpZihjdXJyZW50KXsKICAgICAgICAgICAgICAgIGN1cnJlbnQuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb25zb2xlLmxvZyh3b3JkKQogICAgICAgICAgICBjdXJyZW50ID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LmJhaWR1LmNvbS9zdWdyZWM/JnByb2Q9cGMmd2Q9IitlbmNvZGVVUklDb21wb25lbnQod29yZCksCiAgICAgICAgICAgICAgICByZXNwb25zZVR5cGU6ICJ0ZXh0IiwKICAgICAgICAgICAgICAgIG9ubG9hZDoocikgPT4gewogICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2cocikKICAgICAgICAgICAgICAgICAgICBpZiAoci5zdGF0dXMgPT09IDIwMCkgewogICAgICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKHIpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGF0YUxpc3QgPSBKU09OLnBhcnNlKHIucmVzcG9uc2VUZXh0KS5nOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdSA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNzdWdnZXN0aW9ucycpOwogICAgICAgICAgICAgICAgICAgICAgICBzdS5pbm5lckhUTUwgPSAnJzsKICAgICAgICAgICAgICAgICAgICAgICAgZGF0YUxpc3QgJiYgZGF0YUxpc3QuZm9yRWFjaCh2ID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG9wdGlvbkVsZW1lbnQgPSBkb2N1bWVudC5jcmVhdGVFbGVtZW50KCdvcHRpb24nKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wdGlvbkVsZW1lbnQudmFsdWUgPSB2LnE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcHRpb25FbGVtZW50LmlubmVyVGV4dCA9IHYucTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN1LmFwcGVuZENoaWxkKG9wdGlvbkVsZW1lbnQpOwogICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KTsKICAgICAgICB9KQoKICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgndXBkYXRlUHVia2V5JykuYWRkRXZlbnRMaXN0ZW5lcignY2xpY2snLCAoKSA9PiB7CiAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJncHRBbnN3ZXIiKS5pbm5lclRleHQgPSAi5q2j5Zyo5pu05paw77yM6K+356iN5ZCOLi4uIgogICAgICAgICAgICBzZXRQdWJrZXkoKQogICAgICAgIH0pCgogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdhdXRvQ2xpY2snKS5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsICgpID0+IHsKICAgICAgICAgICAgaWYoYXV0b0NsaWNrKXsKICAgICAgICAgICAgICAgIGxvY2FsU3RvcmFnZS5yZW1vdmVJdGVtKCJhdXRvQ2xpY2siKQogICAgICAgICAgICAgICAgYXV0b0NsaWNrID0gdW5kZWZpbmVkOwogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6Ieq5Yqo54K55Ye75bey57uP5YWz6ZetIikKICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgiYXV0b0NsaWNrIiwgIuW8gOWQryIpCiAgICAgICAgICAgICAgICBhdXRvQ2xpY2sgPSAi5byA5ZCvIgogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6Ieq5Yqo54K55Ye75bey57uP5byA5ZCvIikKICAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdhdXRvVGlwcycpLmFkZEV2ZW50TGlzdGVuZXIoJ2NsaWNrJywgKCkgPT4gewogICAgICAgICAgICBpZihhdXRvVGlwcyA9PT0gJ29uJyl7CiAgICAgICAgICAgICAgICAvL+WFs+mXrQogICAgICAgICAgICAgICAgbG9jYWxTdG9yYWdlLnNldEl0ZW0oImF1dG9UaXBzIiwgIm9mZiIpCiAgICAgICAgICAgICAgICBhdXRvVGlwcyA9ICJvZmYiCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCLoh6rliqjmj5DnpLrlt7LlhbMiKQogICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgIC8v5byA5ZCvCiAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgiYXV0b1RpcHMiLCAib24iKQogICAgICAgICAgICAgICAgYXV0b1RpcHMgPSAib24iCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCLoh6rliqjmj5DnpLrlt7LlvIDlkK8iKQogICAgICAgICAgICB9CiAgICAgICAgfSkKCiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2RhcmtUaGVtZScpLmFkZEV2ZW50TGlzdGVuZXIoJ2NsaWNrJywgKCkgPT4gewogICAgICAgICAgICB0cnl7CiAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgiZ2l0aHViLW1hcmtkb3duLWxpbmsiKS5yZW1vdmUoKQogICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImhpZ2hsaWdodC1saW5rIikucmVtb3ZlKCkKICAgICAgICAgICAgfWNhdGNoIChlKSB7IGNvbnNvbGUuZXJyb3IoZSkgfQoKICAgICAgICAgICAgaWYoZGFya1RoZW1lKXsKICAgICAgICAgICAgICAgIGxvY2FsU3RvcmFnZS5yZW1vdmVJdGVtKCJkYXJrVGhlbWUiKQogICAgICAgICAgICAgICAgZGFya1RoZW1lID0gdW5kZWZpbmVkOwogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi5pqX6buR5bey57uP5byA5ZCvIikKICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICBsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgiZGFya1RoZW1lIiwgIuWFs+mXrSIpCiAgICAgICAgICAgICAgICBkYXJrVGhlbWUgPSAi5YWz6ZetIgogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi5pqX6buR5bey57uP5YWz6ZetIikKICAgICAgICAgICAgfQogICAgICAgIH0pCiAgICAgICAgLy/mnJfor7sKICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnc3BlYWtBbnNlcicpLmFkZEV2ZW50TGlzdGVuZXIoJ2NsaWNrJywgKCkgPT4gewogICAgICAgICAgIGxldCBhbnMgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjZ3B0QW5zd2VyIik7CiAgICAgICAgICAgaWYoIWlzUGxheWVuZCl7CiAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCfpn7PpopHlgZzmraLvvIEnKTsKICAgICAgICAgICAgICAgc3BlYWtBdWRpby5wYXVzZSgpOwogICAgICAgICAgICAgICBpc1BsYXllbmQgPSB0cnVlOwogICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgfQogICAgICAgICAgIGlmKGFucyl7CiAgICAgICAgICAgICAgIGxldCBzcGVha1RleHQgPSBlbmNvZGVVUklDb21wb25lbnQoYW5zLmlubmVyVGV4dCk7CiAgICAgICAgICAgICAgIHNwZWFrQXVkaW8gPSBuZXcgQXVkaW8oYGh0dHBzOi8vZmFueWkuc29nb3UuY29tL3JldmVudG9uZGMvc3ludGhlc2lzP3RleHQ9JHtzcGVha1RleHR9JnNwZWVkPTEmbGFuZz16aC1DSFMmZnJvbT10cmFuc2xhdGV3ZWImc3BlYWtlcj01YCk7CiAgICAgICAgICAgICAgIHNwZWFrQXVkaW8ucGxheSgpCiAgICAgICAgICAgICAgIGlzUGxheWVuZCA9IGZhbHNlOwogICAgICAgICAgICAgICBzcGVha0F1ZGlvLmFkZEV2ZW50TGlzdGVuZXIoImVuZGVkIixmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgIGlzUGxheWVuZCA9IHRydWU7CiAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygn6Z+z6aKR5bey5pKt5pS+5a6M5q+V77yBJyk7CiAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgICAgIC8v5Y6f5paH5YiH5o2iCiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3Jhd0FucycpLmFkZEV2ZW50TGlzdGVuZXIoJ2NsaWNrJywgKGV2KSA9PiB7CiAgICAgICAgICAgbGV0IGFucyA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNncHRBbnN3ZXIiKTsKICAgICAgICAgICBpZighcmF3QW5zKSByZXR1cm47CiAgICAgICAgICAgaWYoIWlzU2hvd1Jhdyl7CiAgICAgICAgICAgICAgIGFucy5pbm5lclRleHQgPSByYXdBbnM7CiAgICAgICAgICAgICAgIGlzU2hvd1JhdyA9IHRydWU7CiAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmF3QW5zKQogICAgICAgICAgICAgICBpc1Nob3dSYXcgPSBmYWxzZTsKICAgICAgICAgICB9CgogICAgICAgIH0pCgogICAgICAgIC8v5Lit5pat5Zue562UCiAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3N0b3BBbnMnKS5hZGRFdmVudExpc3RlbmVyKCdjbGljaycsIChldikgPT4gewogICAgICAgICAgIHRyeXsKICAgICAgICAgICAgICAgaWYoYWJvcnRYbWwpewogICAgICAgICAgICAgICAgICAgYWJvcnRYbWwuYWJvcnQoKTsKICAgICAgICAgICAgICAgICAgIGFib3J0WG1sID0gdW5kZWZpbmVkOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAg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oIiN3ZWJzaXRlIikuY2xhc3NMaXN0LnJlbW92ZSgiY2hhdEhpZGUiKQogICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNhdXRvVGlwc1AiKS5jbGFzc0xpc3QucmVtb3ZlKCJjaGF0SGlkZSIpCiAgICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgfQogICAgICAgICAgICAgIGNoYXRTZXR0aW5nID0gdHJ1ZTsKICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgIC8v6ZqQ6JePCiAgICAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjZ3B0U3RhdHVzIikuY2xhc3NMaXN0LmFkZCgiY2hhdEhpZGUiKQogICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjd2FybiIpLmNsYXNzTGlzdC5hZGQoImNoYXRIaWRlIikKICAgICAgICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2F1dG9DbGlja1AiKS5jbGFzc0xpc3QuYWRkKCJjaGF0SGlkZSIpCiAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNkYXJrVGhlbWVQIikuY2xhc3NMaXN0LmFkZCgiY2hhdEhpZGUiKQogICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCIjd2Vic2l0ZSIpLmNsYXNzTGlzdC5hZGQoImNoYXRIaWRlIikKICAgICAgICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2F1dG9UaXBzUCIpLmNsYXNzTGlzdC5hZGQoImNoYXRIaWRlIikKICAgICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY2hhdFNldHRpbmcgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCiAgICBhc3luYyBmdW5jdGlvbiBhcHBlbmRCb3goYXBwZW5kX2Nhc2UpIHsKICAgICAgICByZXR1cm4gbmV3IFByb21pc2UoKHJlc29sdmUsIHJlamVjdCkgPT4gewogICAgICAgICAgICBjcmVhdEJveCgpLnRoZW4oKGRpdkUpID0+IHsKICAgICAgICAgICAgICAgIGxldCByZXNldFdpZHRoID0gKHdpZHRoKT0+ewogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKHdpZHRoKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNncHREaXYiKS5zdHlsZS5zZXRQcm9wZXJ0eSgid2lkdGgiLHdpZHRoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNncHREaXYiKS5zdHlsZS5zZXRQcm9wZXJ0eSgid2lkdGgiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIjEwMCUiKQogICAgICAgICAgICAgICAgICAgICAgICAvKmRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoIiNncHRJbnB1dCIpLnNldEF0dHJpYnV0ZSgiY2xhc3MiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgInNlLWlucHV0IGFkanVzdC1pbnB1dCIpKi8KICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgc3dpdGNoIChhcHBlbmRfY2FzZSkgewogICAgICAgICAgICAgICAgICAgIGNhc2UgMDogLy9iaW5nCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXZFKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihpc01vYmlsZSgpKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL+aJi+acumJpbmcKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnYl9yZXN1bHRzJykucHJlcGVuZChkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc2V0V2lkdGgoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdiX2NvbnRleHQnKS5wcmVwZW5kKGRpdkUpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSAxOiAvL2dvb2dsZQogICAgICAgICAgICAgICAgICAgICAgICBpZihpc01vYmlsZSgpKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8v5omL5py6Z29vZ2xlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCJkaXYjbXNjIikuYWZ0ZXIoZGl2RSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXNldFdpZHRoKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlIGlmIChkb2N1bWVudC5nZXRFbGVtZW50c0J5Q2xhc3NOYW1lKCdUUWMxaWQgJylbMF0pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRzQnlDbGFzc05hbWUoJ1RRYzFpZCAnKVswXS5wcmVwZW5kKGRpdkUpOwogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9vdGhlcgogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoInJjbnQiKS5hcHBlbmRDaGlsZChkaXZFKTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICBjYXNlIDI6IC8vYmFpZHUKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjb250ZW50X3JpZ2h0JykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdjb250ZW50X3JpZ2h0JykucHJlcGVuZChkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGNhc2UgMzogLy95YW5kZXgKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdzZWFyY2gtcmVzdWx0LWFzaWRlJykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdzZWFyY2gtcmVzdWx0LWFzaWRlJykucHJlcGVuZChkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGNhc2UgNDogLy8zNjAKICAgICAgICAgICAgICAgICAgICAgICAgaWYoaXNNb2JpbGUoKSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL+aJi+acujM2MAogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoInNlYXJjaC1ib3giKS5hcHBlbmRDaGlsZChkaXZFKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc2V0V2lkdGgoKTsKICAgICAgICAgICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3NpZGUnKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdzaWRlJykucHJlcGVuZChkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICBjYXNlIDU6IC8vZnNvdWZzb3UKICAgICAgICAgICAgICAgICAgICAgICAgaWYoaXNNb2JpbGUoKSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL+aJi+acumZzb3UKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmcm93ID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvckFsbCgiLmZsZXgtcm93IilbM10KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmcm93LmNoaWxkcmVuIT09dW5kZWZpbmVkICkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb3cuY2hpbGRyZW4uaXRlbSgwKS5wcmVwZW5kKGRpdkUpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXNldFdpZHRoKCkKICAgICAgICAgICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZnJvdyA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3JBbGwoIi5mbGV4LXJvdyIpWzJdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZnJvdy5jaGlsZHJlbiE9PXVuZGVmaW5lZCAmJiBmcm93LmNoaWxkcmVuLmxlbmd0aCA9PT0gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb3cuY2hpbGRyZW4uaXRlbSgxKS5wcmVwZW5kKGRpdkUpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb3cuaW5uZXJIVE1MID0gZnJvdy5pbm5lckhUTUwgKwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBgPGRpdj48ZGl2IGNsYXNzPSJ3aWtpLWNvbnRhaW5lciIgc3R5bGU9Im1hcmdpbi1sZWZ0OiAxMjRweCFpbXBvcnRhbnQ7cGFkZGluZzogMTVweCFpbXBvcnRhbnQ7Ij4ke2RpdkUuaW5uZXJIVE1MfTwvZGl2PjwvZGl2PmAKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSA2OiAvL+aJi+acuueZvuW6pgogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3BhZ2UtYmQnKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ3BhZ2UtYmQnKS5wcmVwZW5kKGRpdkUpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL+iwg+aVtGNzcwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzZXRXaWR0aCgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGNhc2UgNzogLy9kdWNrZHVja2dvCiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGlzTW9iaWxlKCkpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy/miYvmnLpkb2NrZ28KICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJ2Zvcm0jc2VhcmNoX2Zvcm0nKS5hZnRlcihkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzZXRXaWR0aCgpOwogICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCdbZGF0YS1hcmVhPSJzaWRlYmFyIl0nKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJ1tkYXRhLWFyZWE9InNpZGViYXIiXScpLnByZXBlbmQoZGl2RSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgIGNhc2UgODogLy9zb2dvdQogICAgICAgICAgICAgICAgICAgICAgICBpZihpc01vYmlsZSgpKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8v5omL5py65pCc54uXCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCdmb3JtI3NlYXJjaGZvcm0nKS5hZnRlcihkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzZXRXaWR0aCgpOwogICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCdkaXYucmlnaHQnKSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJ2Rpdi5yaWdodCcpLnByZXBlbmQoZGl2RSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgY2FzZSA5OiAvL2JpbGliaWxpCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCdkaXYjZGFubXVrdUJveCcpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCdkaXYjZGFubXVrdUJveCcpLmNoaWxkcmVuLml0ZW0oMCkucHJlcGVuZChkaXZFKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzZXRXaWR0aCgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKCiAgICAgICAgICAgICAgICAgICAgY2FzZSAxMDogLy9jc2RuCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBhc2lkZURpdiA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoImFzaWRlLmJsb2dfY29udGFpbmVyX2FzaWRlIGRpdiIpCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChhc2lkZURpdikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgYXNpZGVEaXYuYWZ0ZXIoZGl2RSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCB0ID0gYXNpZGVEaXYub2Zmc2V0VG9wICsgYXNpZGVEaXYub2Zmc2V0SGVpZ2h0ICsgNTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IHNjcmVlbkhlaWdodCA9IHdpbmRvdy5zY3JlZW4uaGVpZ2h0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2dwdERpdiIpLnNldEF0dHJpYnV0ZSgic3R5bGUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGBwb3NpdGlvbjogZml4ZWQ7dG9wOiAke3R9cHg7bGVmdDogMHB4O3otaW5kZXg6IDk5OTk7d2lkdGg6NDEwcHg7YCkKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAvL+a7muWKqOadoQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2dwdEFuc3dlciIpLnNldEF0dHJpYnV0ZSgic3R5bGUiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGBoZWlnaHQ6ICR7c2NyZWVuSGVpZ2h0LzV9cHg7b3ZlcmZsb3cteTpzY3JvbGxgKQoKCiAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXZFKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhg5ZWl5oOF5Ya1JHtkaXZFfWApCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkuY2F0Y2goKGVycikgPT4gewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGVycikKICAgICAgICAgICAgfSkuZmluYWxseSgoKT0+ewogICAgICAgICAgICAgICAgaWYoYXV0b0NsaWNrKXsKICAgICAgICAgICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImJ1dHRvbl9HUFQiKS5jbGljaygpOyAvL+iHquWKqOeCueWHuwogICAgICAgICAgICAgICAgICAgIH0sIDE1MDApCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pCgogICAgICAgICAgICByZXNvbHZlKCJmaW5pc2hlZCIpCiAgICAgICAgfSkKICAgIH0KCiAgICAvL+eEpueCueWHveaVsAogICAgZnVuY3Rpb24gaXNCbHVyKCkgewogICAgICAgIGxldCBteUlucHV0ID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2dwdElucHV0Jyk7CiAgICAgICAgaWYgKG15SW5wdXQgPT09IGRvY3VtZW50LmFjdGl2ZUVsZW1lbnQpIHsKICAgICAgICAgICAgcmV0dXJuIDEKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gMAogICAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBrZXlFdmVudCgpIHsKICAgICAgICBkb2N1bWVudC5vbmtleWRvd24gPSBmdW5jdGlvbiAoZSkgewogICAgICAgICAgICBsZXQga2V5TnVtID0gd2luZG93LmV2ZW50ID8gZS5rZXlDb2RlIDogZS53aGljaDsKICAgICAgICAgICAgaWYgKDEzID09PSBrZXlOdW0pIHsKICAgICAgICAgICAgICAgIGlmIChpc0JsdXIoKSkgewogICAgICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdidXR0b25fR1BUJykuY2xpY2soKQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygi5aSx54Sm5LiN5omn6KGMIikKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgIH0KCgogICAgICAgIH0KCiAgICB9CgoKCgogICAgZnVuY3Rpb24gYWRkQm90aFN0eWxlKCkgewogICAgICAgIEdNX2FkZFN0eWxlKGAKICAgIC5ncHQtY29udGFpbmVyIHsKICAgICAgICBib3gtc2l6aW5nOiBib3JkZXItYm94OwogICAgICAgIGhlaWdodDogLXdlYmtpdC1taW4tY29udGVudDsKICAgICAgICBoZWlnaHQ6IG1pbi1jb250ZW50OwogICAgICAgIHdpZHRoOiA0NTVweDsKICAgICAgICBtYXJnaW4tdG9wOiA4cHg7CiAgICAgICAgbWFyZ2luLWJvdHRvbTogOHB4OwogICAgICAgIGJvcmRlcjogMXB4IHNvbGlkICNkZmUxZTU7CiAgICAgICAgYm9yZGVyLXJhZGl1czogOHB4OwogICAgICAgIG92ZXJmbG93OiBoaWRkZW47CiAgICAgICAgcGFkZGluZzogMTVweDsKICAgICAgICBiYWNrZ3JvdW5kLWNvbG9yOiNmY2ZjZmMKICAgIH0KCiAgICAjZG90ewogICAgICAgIGhlaWdodDogNHB4OwogICAgICAgIHdpZHRoOiA0cHg7CiAgICAgICAgZGlzcGxheTogaW5saW5lLWJsb2NrOwogICAgICAgIGJvcmRlci1yYWRpdXM6IDJweDsKICAgICAgICBhbmltYXRpb246IGRvdHRpbmcgMi40cyAgaW5maW5pdGUgc3RlcC1zdGFydDsKICAgIH0KICAgQGtleWZyYW1lcyBkb3R0aW5nIHsKICAgICAgICAyNSV7CiAgICAgICAgICAgIGJveC1zaGFkb3c6IDRweCAwIDAgIzcxNzc3RDsKICAgICAgICB9CiAgICAgICAgNTAlewogICAgICAgICAgICBib3gtc2hhZG93OiA0cHggMCAwICM3MTc3N0QgLDE0cHggMCAwICM3MTc3N0Q7CiAgICAgICAgfQogICAgICAgIDc1JXsKICAgICAgICAgICAgYm94LXNoYWRvdzogNHB4IDAgMCAjNzE3NzdEICwxNHB4IDAgMCAjNzE3NzdELCAyNHB4IDAgMCAjNzE3NzdEOwogICAgICAgIH0KICAgIH0KICAgIHByZXsKICAgICAgICBvdmVyZmxvdy14OiBzY3JvbGw7CiAgICAgICAgb3ZlcmZsb3cteTogaGlkZGVuOwogICAgICAgIGJhY2tncm91bmQ6ICNmZmZhZWM7CiAgICAgICAgYm9yZGVyLXJhZGl1czogNHB4OwogICAgICAgIHBhZGRpbmc6IDE0cHggM3B4OwogICAgfQogICAgcHJlOjotd2Via2l0LXNjcm9sbGJhciB7CiAgICAgCiAgICB9YCk7CiAgICB9CgoKCiAgICBmdW5jdGlvbiBVaW50OEFycmF5VG9TdHJpbmcoZmlsZURhdGEpIHsKICAgICAgICBsZXQgZGF0YVN0cmluZyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgZmlsZURhdGEubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGF0YVN0cmluZyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGZpbGVEYXRhW2ldKTsKICAgICAgICB9CgogICAgICAgIHJldHVybiBkYXRhU3RyaW5nOwogICAgfQoKICAgIGZ1bmN0aW9uIGRlY29kZVVuaWNvZGUoc3RyKSB7CiAgICAgICAgc3RyID0gc3RyLnJlcGxhY2UoL1xcL2csICIlIik7CiAgICAgICAgLy/ovazmjaLkuK3mlocKICAgICAgICBzdHIgPSB1bmVzY2FwZShzdHIpOwogICAgICAgIC8v5bCG5YW25LuW5Y+X5b2x5ZON55qE6L2s5o2i5Zue5Y6f5p2lCiAgICAgICAgc3RyID0gc3RyLnJlcGxhY2UoLyUvZywgIlxcIik7CiAgICAgICAgLy/lr7nnvZHlnYDnmoTpk77mjqXov5vooYzlpITnkIYKICAgICAgICBzdHIgPSBzdHIucmVwbGFjZSgvXFwvZywgIiIpOwogICAgICAgIHJldHVybiBzdHI7CiAgICB9CgogICAgZnVuY3Rpb24gbWRDb252ZXJ0ZXIocmF3RGF0YSkgewogICAgICAgIGxldCBjb252ZXJ0ZXIgPSBuZXcgc2hvd2Rvd24uQ29udmVydGVyKCk7IC8v5aKe5Yqg5ouT5bGVdGFibGUKICAgICAgICBjb252ZXJ0ZXIuc2V0T3B0aW9uKCd0YWJsZXMnLAogICAgICAgICAgICB0cnVlKTsgLy/lkK/nlKjooajmoLzpgInpobnjgILku45zaG93ZG93biAxLjIuMOeJiOW8gOWni++8jOihqOaUr+aMgeW3suS9nOS4uuWPr+mAieWKn+iDveenu+WFpeaguOW/g+aLk+Wxle+8jHNob3dkb3duLnRhYmxlLm1pbi5qc+aJqeWxleW3suiiq+W8g+eUqAogICAgICAgIHJldHVybiBjb252ZXJ0ZXIubWFrZUh0bWwocmF3RGF0YSk7CiAgICB9CgogICAgLy/lrp7ml7bnm5Hmjqfnmb7luqYsMzYw5oyJ6ZKu5raI5aSxCiAgICBzZXRJbnRlcnZhbCgoKSA9PiB7CiAgICAgICAgLy/nmb7luqYKICAgICAgICBpZiAod2luZG93LmxvY2F0aW9uLmhyZWYuaW5kZXhPZigiYmFpZHUuY29tXC9zIikgPiAtMSAmJiAhaXNNb2JpbGUoKSkgewogICAgICAgICAgICBpZiAoIWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJncHREaXYiKSAmJiBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgibXlidG4iKSkgewogICAgICAgICAgICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm15YnRuIikuY2xpY2soKQogICAgICAgICAgICB9CgogICAgICAgICAgICBpZiAoIWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJncHREaXYiKSAmJiAhZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm15YnRuIikpIHsKICAgICAgICAgICAgICAgIGFkZENoYXRCdG4oKTsKICAgICAgICAgICAgICAgIGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJteWJ0biIpLmNsaWNrKCkKICAgICAgICAgICAgfQoKICAgICAgICB9CiAgICAgICAgLy8zNjAg5rOo5oSP6K+35aaC5p6c5L2g5ZyoMzYw55u45YWz5rWP6KeI5Zmo5LiK5L2/55So5o+S5Lu244CCMzYw5pCc57Si5bCG5LiN5Lya55Sf5pWI77yM5Zug5Li65bey6KKr5rWP6KeI5Zmo56aB55So5Zyoc28uY29t572R5Z2A5LiK5L2/55SoCiAgICAgICAgaWYgKHdpbmRvdy5sb2NhdGlvbi5ocmVmLmluZGV4T2YoInNvLmNvbVwvcyIpID4gLTEgJiYgIWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJncHREaXYiKSkgewogICAgICAgICAgICBHTV9hZGRfYm94X3N0eWxlKDEpCiAgICAgICAgICAgIGFkZEJvdGhTdHlsZSgpCiAgICAgICAgICAgIGtleUV2ZW50KCkKICAgICAgICAgICAgYXBwZW5kQm94KDQpLnRoZW4oKHJlcykgPT4gewogICAgICAgICAgICAgICAgcGl2RWxlbUFkZEV2ZW50QW5kVmFsdWUoNCkKICAgICAgICAgICAgfSkK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BpZiAocGFyZW50SURfNjg2ODYpIHsKICAgICAgICAgICAgb3BzID0ge3BhcmVudE1lc3NhZ2VJZDogcGFyZW50SURfNjg2ODZ9OwogICAgICAgIH0KICAgICAgICBjb25zb2xlLmxvZyhvcHMpCiAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW107CiAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly90NjYubHRkL2FwaS9jaGF0LXByb2Nlc3MiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly90NjYubHRkLyIsCiAgICAgICAgICAgICAgIC8vICJYLUZvcndhcmRlZC1Gb3IiOiBnZW5lcmF0ZVJhbmRvbUlQKCksCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IG9wcwogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgLy8gICAgIGNvbnNvbGUubG9nKHJlYWRlci5yZWFkKQogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KHZhbHVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KTsKICAgICAgICAgICAgICAgICAgICAgICAgLypsZXQgZGQgPSBkLnNwbGl0KCItXiZeLSIpOwogICAgICAgICAgICAgICAgICAgICAgICBpZihkZC5sZW5ndGggPT09IDIpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IEpTT04ucGFyc2UoZGRbMF0pCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LnRleHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdC5wdXNoKGRkWzFdKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50SURfNjg2ODYgPSBub3dSZXN1bHQuaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQucHVzaChkKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgfSovCgogICAgICAgICAgICAgICAgICAgICAgICBsZXQganNvbkxpbmVzID0gZC5zcGxpdCgiXG4iKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IEpTT04ucGFyc2UoanNvbkxpbmVzW2pzb25MaW5lcy5sZW5ndGggLSAxXSkKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQudGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cobm93UmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSBub3dSZXN1bHQudGV4dAogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF82ODY4NiA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKCgogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIChyZWFzb24pPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgICAgIH0KICAgICAgICApLmNhdGNoKGV4ID0+IHsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSkKICAgIH0KCgogICAgLy8yMDIz5bm0NeaciDbml6UKICAgIGxldCBwYXJlbnRJRF9jaGF0V2ViMTsKICAgIGZ1bmN0aW9uIENIQVRXRUIxKCkgewogICAgICAgIGxldCBvcHMgPSB7fTsKICAgICAgICBpZiAocGFyZW50SURfY2hhdFdlYjEpIHsKICAgICAgICAgICAgb3BzID0ge3BhcmVudE1lc3NhZ2VJZDogcGFyZW50SURfY2hhdFdlYjF9OwogICAgICAgIH0KCiAgICAgICAgY29uc29sZS5sb2cob3BzKQogICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9iM2JvdDEuc2t5Ynl0ZS5tZS9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vYjNib3QxLnNreWJ5dGUubWUvIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9iM2JvdDEuc2t5Ynl0ZS5tZSIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IG9wcwogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgLy8gICAgIGNvbnNvbGUubG9nKHJlYWRlci5yZWFkKQogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KHZhbHVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBub3dSZXN1bHQgPSBKU09OLnBhcnNlKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCgogICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LnRleHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKG5vd1Jlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gbm93UmVzdWx0LnRleHQKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC5pZCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGFyZW50SURfY2hhdFdlYjEgPSBub3dSZXN1bHQuaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgKHJlYXNvbik9PnsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlYXNvbikKICAgICAgICAgICAgfQogICAgICAgICkuY2F0Y2goZXggPT4gewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KQogICAgfQoKCgogICAgLy8yMDIz5bm0NeaciDE45pelIGh0dHA6Ly9ob21lLmN1dGltLnRvcC8gaHR0cHM6Ly9ncHQuZ29ncHQuc2l0ZS8jL2NoYXQvMTAwMgogICAgbGV0IHBhcmVudElEX2dwdHBsdXM7CgogICAgZnVuY3Rpb24gZ2V0R1BUUExVU2tleSgpIHsKICAgICAgICBsZXQgbm4gPSBNYXRoLmZsb29yKG5ldyBEYXRlKCkuZ2V0VGltZSgpIC8gMWUzKTsKICAgICAgICBjb25zdCBmRCA9IGU9PnsKICAgICAgICAgICAgbGV0IHQgPSBDcnlwdG9KUy5lbmMuVXRmOC5wYXJzZShlKQogICAgICAgICAgICAgICAgLCBvID0gQ3J5cHRvSlMuQUVTLmVuY3J5cHQodCwgJzE0NDg3MTQxYnZpcnZ2RycsIHsKICAgICAgICAgICAgICAgIG1vZGU6IENyeXB0b0pTLm1vZGUuRUNCLAogICAgICAgICAgICAgICAgcGFkZGluZzogQ3J5cHRvSlMucGFkLlBrY3M3CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gby50b1N0cmluZygpCiAgICAgICAgfQogICAgICAgIHJldHVybiBmRChubik7CiAgICB9CgogICAgZnVuY3Rpb24gR1BUUExVUygpIHsKICAgICAgICBsZXQgb3BzID0ge307CiAgICAgICAgaWYgKHBhcmVudElEX2dwdHBsdXMpIHsKICAgICAgICAgICAgb3BzID0ge3BhcmVudE1lc3NhZ2VJZDogcGFyZW50SURfZ3B0cGx1c307CiAgICAgICAgfQoKCiAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9hcGkuZ3B0cGx1cy5vbmUvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vZ3B0LmdvZ3B0LnNpdGUvIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9ncHQuZ29ncHQuc2l0ZSIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgc2VjcmV0OiBnZXRHUFRQTFVTa2V5KCksCiAgICAgICAgICAgICAgICB0b3BfcDogMSwKICAgICAgICAgICAgICAgIHByb21wdDogeW91cl9xdXMsCiAgICAgICAgICAgICAgICBzeXN0ZW1NZXNzYWdlOiAiWW91IGFyZSBDaGF0R1BULCB0aGUgdmVyc2lvbiBpcyBHUFQzLjUsIGEgbGFyZ2UgbGFuZ3VhZ2UgbW9kZWwgdHJhaW5lZCBieSBPcGVuQUkuIEZvbGxvdyB0aGUgdXNlcidzIGluc3RydWN0aW9ucyBjYXJlZnVsbHkuIFJlc3BvbmQgdXNpbmcgbWFya2Rvd24uIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAwLjgsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9ICIiOwogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIC8vICAgICBjb25zb2xlLmxvZyhyZWFkZXIucmVhZCkKICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0OwogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgY29uc3QgY2h1bmsgPSB2YWx1ZTsKICAgICAgICAgICAgICAgIHJlc3VsdCArPSBjaHVuazsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2cobm9ybWFsQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KGNodW5rKTsKICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQogICAgICAgICAgICAgICAgICAgIGxldCBqc29uTGluZXMgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpLnNwbGl0KCJcbiIpOwogICAgICAgICAgICAgICAgICAgIGxldCBub3dSZXN1bHQgPSBKU09OLnBhcnNlKGpzb25MaW5lc1tqc29uTGluZXMubGVuZ3RoIC0gMV0pCgogICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQudGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gbm93UmVzdWx0LnRleHQKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC5pZCkgewogICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF9ncHRwbHVzID0gbm93UmVzdWx0LmlkOwogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CgogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICB9KTsKICAgICAgICB9LGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJlcnJvOiIsIGVyci5tZXNzYWdlKQogICAgICAgIH0pCgogICAgfQoKCgogICAgbGV0IG1lc3NhZ2VDaGFpbjIgPSBbXTsvL0FJTFMKICAgIGxldCBtZXNzYWdlQ2hhaW40ID0gW107Ly9FU08KICAgIGxldCBtZXNzYWdlQ2hhaW41ID0gW107Ly9YQ0JMCiAgICBsZX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RoIDwgMTAgPyBgMCR7bW9udGh9YCA6IG1vbnRoOwogICAgICAgIGNvbnN0IGZvcm1hdHRlZERheSA9IGRheSA8IDEwID8gYDAke2RheX1gIDogZGF5OwoKICAgICAgICByZXR1cm4gYCR7eWVhcn0tJHtmb3JtYXR0ZWRNb250aH0tJHtmb3JtYXR0ZWREYXl9YDsKICAgIH0KCgoKICAgIGxldCBhaWxzX2NsaWVudHY7CiAgICBmdW5jdGlvbiBBSUxTKCkgewoKICAgICAgICBsZXQgdnRpbWUgPSBmdW5jdGlvbiBjb252ZXJUaW1lc3RhbXAodCkgewogICAgICAgICAgICBjb25zdCBlID0gcGFyc2VJbnQodCkKICAgICAgICAgICAgICAgICwgbiA9IGUgJSAxMAogICAgICAgICAgICAgICAgLCByID0gbiAlIDIgPT09IDAgPyBuICsgMSA6IG47CiAgICAgICAgICAgIHJldHVybiAoZSAtIG4gKyByKS50b1N0cmluZygpCiAgICAgICAgfQoKICAgICAgICBsZXQgbm93ID0gdnRpbWUobmV3IERhdGUoKS5nZXRUaW1lKCkpOwogICAgICAgIGNvbnN0IHBrID0gYE9WYmlbVFBOe1MjKWN7MzYlOT9nO3VzbClDTDoke3lvdXJfcXVzLmxlbmd0aH1gOy8v5p+l55yLanPnmoRnZW5lcmF0ZVNpZ25hdHVyZeWHveaVsOS4reeahGtleQogICAgICAgIGxldCBCYXNldXJsID0gImh0dHBzOi8vYXBpLmNhaXBhY2l0eS5jb20vIgogICAgICAgIGdlbmVyYXRlU2lnbmF0dXJlV2l0aFBrZXkoewogICAgICAgICAgICB0OiBub3csCiAgICAgICAgICAgIG06IHlvdXJfcXVzIHx8ICIiLAogICAgICAgICAgICBwa2V5OiBwawogICAgICAgIH0pLnRoZW4oc2lnbiA9PiB7CiAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW4yLCB7cm9sZTogInVzZXIiLCBjb250ZW50OiB5b3VyX3F1c30pLy/ov57nu63or50KICAgICAgICAgICAgY29uc29sZS5sb2coc2lnbikKICAgICAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgICAgICB1cmw6IEJhc2V1cmwgKyAidjEvY2hhdC9jb21wbGV0aW9ucz9mdWxsPWZhbHNlIiwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgICAgICJhdXRob3JpemF0aW9uIjogIkJlYXJlciBmcmVlIiwKICAgICAgICAgICAgICAgICAgICAiY2xpZW50LWlkIjogdXVpZHY0KCksCiAgICAgICAgICAgICAgICAgICAgImNsaWVudC12IjogYWlsc19jbGllbnR2LAogICAgICAgICAgICAgICAgICAgICJSZWZlcmVyIjogQmFzZXVybCwKICAgICAgICAgICAgICAgICAgICAib3JpZ2luIjogImh0dHBzOi8vYWkubHMiLAogICAgICAgICAgICAgICAgICAgICJYLUZvcndhcmRlZC1Gb3IiOiBnZW5lcmF0ZVJhbmRvbUlQKCksCiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICBtb2RlbDogImdwdC0zLjUtdHVyYm8iLAogICAgICAgICAgICAgICAgICAgIG1lc3NhZ2VzOiBtZXNzYWdlQ2hhaW4yLAogICAgICAgICAgICAgICAgICAgIHN0cmVhbTogdHJ1ZSwKICAgICAgICAgICAgICAgICAgICB0OiBgJHtub3d9YCwKICAgICAgICAgICAgICAgICAgICBkOiBmb3JtYXR0ZWREYXRlKCksCiAgICAgICAgICAgICAgICAgICAgczogc2lnbiwKICAgICAgICAgICAgICAgICAgICB0ZW1wZXJhdHVyZTowLjYKICAgICAgICAgICAgICAgIH0pLAogICAgICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdDsKICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjIsIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByb2xlOiAiYXNzaXN0YW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50OiBmaW5hbFJlc3VsdAogICAgICAgICAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkKQogICAgICAgICAgICAgICAgICAgICAgICAvKmQuc3BsaXQoIlxuIikuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjaHVuayA9IEpTT04ucGFyc2UoaXRlbS5yZXBsYWNlKC9kYXRhOi8sIiIpLnRyaW0oKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLmNob2ljZXNbMF0uZGVsdGEuY29udGVudDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChjaHVuaykKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZXgpe30KICAgICAgICAgICAgICAgICAgICAgICAgfSkqLwogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LChyZWFzb24pPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgICAgICB9KTsKCiAgICAgICAgfSk7CiAgICB9CgoKICAgIC8vMjMuNS4yCiAgICBmdW5jdGlvbiBET0cyKCkgewoKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovLzJkb2cuNTFtc2tkLmNvbS9kb2dneS9ndWVzdC10ZXN0IiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJBdXRob3JpemF0aW9uIjogIkJlYXJlciBudWxsIiwKICAgICAgICAgICAgICAgICJYLUZvcndhcmRlZC1Gb3IiOiBnZW5lcmF0ZVJhbmRvbUlQKCksCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovLzJkb2cuNTFtc2tkLmNvbS8iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovLzJkb2cuNTFtc2tkLmNvbSIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICJxdWVzdGlvbiI6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgInR5cGUiOiAiY2hhdCIsCiAgICAgICAgICAgICAgICAiaXNfZ3Vlc3QiOiB0cnVlLAogICAgICAgICAgICAgICAgIm1vZGVsIjogImdwdC0zLjUtdHVyYm8iCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iCiAgICAgICAgfSkudGhlbigoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0OwogICAgICAgICAgICBsZXQgZXJyb3JTdHI7CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBpZihyZXN1bHQubGVuZ3RoID09PSAwKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZXJyb3JTdHIpCiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGQpCiAgICAgICAgICAgICAgICAgICAgZC5zcGxpdCgiXG4iKS5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjaHVuayA9IEpTT04ucGFyc2UoaXRlbS5yZXBsYWNlKC9kYXRhOi8sIiIpLnRyaW0oKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goY2h1bmspCiAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZXgpewoKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgaWYoZC5pbmNsdWRlcygiZXJyb3IjIikpewogICAgICAgICAgICAgICAgICAgICAgICBlcnJvclN0ciA9IGQKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSwocmVhc29uKT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KTsKICAgIH0KCiAgICBsZXQgbWVzc2FnZUNoYWluMTEgPSBbXS8veGVhc3kKICAgIGZ1bmN0aW9uIFhFQVNZKCkgewoKICAgICAgICBsZXQgbm93ID0gRGF0ZS5ub3coKTsKICAgICAgICBjb25zdCBwayA9IHt9LlBVQkxJQ19TRUNSRVRfS0VZOy8v5p+l55yLanPnmoRnZW5lcmF0ZVNpZ25hdHVyZeWHveaVsOS4reeahGtleQogICAgICAgIGxldCBCYXNldXJsID0gImh0dHBzOi8vY2hhdDE5LnhlYXN5Lm1lLyIKICAgICAgICBnZW5lcmF0ZVNpZ25hdHVyZVdpdGhQa2V5KHsKICAgICAgICAgICAgdDogbm93LAogICAgICAgICAgICBtOiB5b3VyX3F1cyB8fCAiIiwKICAgICAgICAgICAgcGtleTogcGsKICAgICAgICB9KS50aGVuKHNpZ24gPT4gewogICAgICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluMTEsIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgICAgICBjb25zb2xlLmxvZyhzaWduKQogICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgIHVybDogQmFzZXVybCArICJhcGkvZ2VuZXJhdGUiLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgLy8gIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIG51bGwiLAogICAgICAgICAgICAgICAgICAgICJSZWZlcmVyIjogQmFzZXVybCwKICAgICAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICAgICAgbWVzc2FnZXM6IG1lc3NhZ2VDaGFpbjExLAogICAgICAgICAgICAgICAgICAgIHRpbWU6IG5vdywKICAgICAgICAgICAgICAgICAgICBwYXNzOiBudWxsLAogICAgICAgICAgICAgICAgICAgIHNpZ246IHNpZ24sCiAgICAgICAgICAgICAgICAgICAga2V5OiBudWxsCiAgICAgICAgICAgICAgICB9KSwKICAgICAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjExLCB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcm9sZTogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudDogZmluYWxSZXN1bHQKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZCkKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwocmVhc29uKT0+ewogICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVhc29uKQogICAgICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgfSk7CgogICAgICAgIH0pOwogICAgfQoKICAgIGxldCBtZXNzYWdlQ2hhaW5femh1bGVpID0gW107CiAgICBsZXQgemh1bGVpX2NvdW50ID0gMDsKICAgIGZ1bmN0aW9uIFpIVUxFSSgpIHsKICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluX3podWxlaSwge3JvbGU6ICJ1c2VyIiwgY29udGVudDogeW91cl9xdXN9KS8v6L+e57ut6K+dCiAgICAgICAgemh1bGVpX2NvdW50Kys7CiAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9jaGF0aHViLnpodWxlaS54eXovYXBpIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJjb29raWUiOiBgQkJCQkI9JHt6aHVsZWlfY291bnR9YCwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vY2hhdGh1Yi56aHVsZWkueHl6LyIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgbWVzc2FnZXM6IG1lc3NhZ2VDaGFpbl96aHVsZWksCiAgICAgICAgICAgICAgICBtb2RlbDogImdwdC0zLjUtdHVyYm8iLAogICAgICAgICAgICAgICAgcGFzc3dvcmQ6ICIiLAogICAgICAgICAgICAgICAgdGVtcGVyYXR1cmU6IDAuNgogICAgICAgICAgICB9KSwKICAgICAgICB9KS50aGVuKChyKSA9PiB7CiAgICAgICAgICAgIGlmIChyLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyKTsKICAgICAgICAgICAgICAgIGlmKG1lc3NhZ2VDaGFpbl96aHVsZWkubGVuZ3RoID4gMCl7CiAgICAgICAgICAgICAgICAgICAgbWVzc2FnZUNoYWluX3podWxlaVttZXNzYWdlQ2hhaW5femh1bGVpLmxlbmd0aCAtIDFdLmlkID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW5femh1bGVpLHsicm9sZSI6ImFzc2lzdGFudCIsImNvbnRlbnQiOnIucmVzcG9uc2VUZXh0LCJpZCI6RGF0ZS5ub3coKX0pCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHIucmVzcG9uc2VUZXh0KQogICAgICAgICAgICB9CiAgICAgICAgfSwocmVhc29uKT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KTsKICAgIH0KCgogICAgYXN5bmMgZnVuY3Rpb24gRkRLQU5HKCkgewoKCiAgICAgICAgYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cDovL2NoYXQuZmRrYW5nLnRvcC9zZXRzZXNzaW9uLnBocCIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24veC13d3ctZm9ybS11cmxlbmNvZGVkO2NoYXJzZXQ9VVRGLTgiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cDovL2NoYXQuZmRrYW5nLnRvcC8iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IGBtZXNzYWdlPSR7ZW5jb2RlVVJJKHlvdXJfcXVzKX0mY29udGV4dD0lNUIlNUQma2V5PWAKICAgICAgICB9KQoKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwOi8vY2hhdC5mZGthbmcudG9wL3N0cmVhbS5waHAiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04IiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHA6Ly9jaGF0LmZka2FuZy50b3AvIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAidGV4dC9ldmVudC1zdHJlYW0iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQ7CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICB0cnkgewoKICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJyYXc6IixkKQogICAgICAgICAgICAgICAgICAgIGxldCBkZCA9IGQucmVwbGFjZSgvZGF0YTogL2csICIiKS5zcGxpdCgiXG5cbiIpCiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coImRkOiIsZGQpCiAgICAgICAgICAgICAgICAgICAgZGQuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGVsdGEgPSBKU09OLnBhcnNlKGl0ZW0pLmNob2ljZXNbMF0uZGVsdGEuY29udGVudAogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZGVsdGEpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChlKSB7CgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICB9KTsKICAgICAgICB9LGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSkKCiAgICB9CgoKICAgIGxldCBjaGF0emhhbmdfa2V5OwogICAgbGV0IGNoYXR6aGFuZ19pcCA9IGdlbmVyYXRlUmFuZG9tSVAoKTsKICAgIGxldCBjaGF0emhhbmdfY29va2llID0gJycKICAgIHNldFRpbWVvdXQoKCk9PnsKICAgICAgICBpZihnZXRHUFRNb2RlKCkgIT09ICdDSEFUWkhBTkcnKXsKICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgfQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cDovL2NoYXQuY2hhdHpoYW5nLnRvcC9pbmRleC5waHAiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04IiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHA6Ly9jaGF0LmNoYXR6aGFuZy50b3AvaW5kZXgucGhwP2lkPTEiLAogICAgICAgICAgICAgICAgIngtcmVxdWVzdGVkLXdpdGgiOiAiWE1MSHR0cFJlcXVlc3QiLAogICAgICAgICAgICAgICAgIlgtRm9yd2FyZGVkLUZvciIgOiBjaGF0emhhbmdfaXAsCiAgICAgICAgICAgICAgICAiY29va2llIjpjaGF0emhhbmdfY29va2llCiAgICAgICAgICAgIH0KICAgICAgICB9KS50aGVuKHJlcz0+ewogICAgICAgICAgICBjaGF0emhhbmdfa2V5ID0gcmVzLnJlc3BvbnNlSGVhZGVycy5tYXRjaCgva2V5PSguKj8pOy8pWzFdOwogICAgICAgICAgICBjb25zb2xlLmxvZygiQ0hBVFpIQU5HX2tleSIsY2hhdHpoYW5nX2tleSkKICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgIH0pCiAgICB9KQoKICAgIGFzeW5jIGZ1bmN0aW9uIENIQVRaSEFORygpIHsKICAgICAgICBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwOi8vY2hhdC5jaGF0emhhbmcudG9wL3NldHNlc3Npb24ucGhwIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi94LXd3dy1mb3JtLXVybGVuY29kZWQ7Y2hhcnNldD1VVEYtOCIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwOi8vY2hhdC5jaGF0emhhbmcudG9wL2luZGV4LnBocD9pZD0xIiwKICAgICAgICAgICAgICAgICJ4LXJlcXVlc3RlZC13aXRoIjogIlhNTEh0dHBSZXF1ZXN0IiwKICAgICAgICAgICAgICAgICJYLUZvcndhcmRlZC1Gb3IiIDogY2hhdHpoYW5nX2lwLAogICAgICAgICAgICAgICAgImNvb2tpZSI6Y2hhdHpoYW5nX2Nvb2tpZQogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBgbWVzc2FnZT0rJHtlbmNvZGVVUkkoeW91cl9xdXMpfSZjb250ZXh0PSU1QiU1RCZrZXk9JHtjaGF0emhhbmdfa2V5fWAKICAgICAgICB9KQoKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwOi8vY2hhdC5jaGF0emhhbmcudG9wL3N0cmVhbS5waHAiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04IiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHA6Ly9jaGF0LmNoYXR6aGFuZy50b3AvaW5kZXgucGhwP2lkPTEiLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJ0ZXh0L2V2ZW50LXN0cmVhbSIsCiAgICAgICAgICAgICAgICAieC1yZXF1ZXN0ZWQtd2l0aCI6ICJYTUxIdHRwUmVxdWVzdCIsCiAgICAgICAgICAgICAgICAiWC1Gb3J3YXJkZWQtRm9yIiA6IGNoYXR6aGFuZ19pcCwKICAgICAgICAgICAgICAgICJjb29raWUiOmNoYXR6aGFuZ19jb29raWUKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdDsKICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHRyeSB7CgogICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coInJhdzoiLGQpCiAgICAgICAgICAgICAgICAgICAgbGV0IGRkID0gZC5yZXBsYWNlKC9kYXRhOiAvZywgIiIpLnNwbGl0KCJcblxuIikKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiZGQ6IixkZCkKICAgICAgICAgICAgICAgICAgICBkZC5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWx0YSA9IEpTT04ucGFyc2UoaXRlbSkuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkZWx0YSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0sZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KQoKICAgIH0KCiAgICBhc3luYyBmdW5jdGlvbiBkZWxheShtcykgewogICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShyZXNvbHZlID0+IHNldFRpbWVvdXQocmVzb2x2ZSwgbXMpKTsKICAgIH0KCiAgIGFzeW5jIGZ1bmN0aW9uIEhaSVQoKSB7CgogICAgICAgIGxldCBiYXNlVVJMID0gImh0dHBzOi8vMjAyMjA1MDguNmJicy5jbi8iOwogICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW42LCB7cm9sZTogInVzZXIiLCBjb250ZW50OiB5b3VyX3F1c30pLy/ov57nu63or50KICAgICAgICBsZXQgcmVzID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiBiYXNlVVJMICsgImFwaS9jaGF0LXN0cmVhbSIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogIiovKiIsCiAgICAgICAgICAgICAgICAib3JpZ2luIjogImh0dHBzOi8vMjAyMjA1MDguNmJicy5jbiIsCiAgICAgICAgICAgICAgICAicGF0aCI6ICJ2MS9jaGF0L2NvbXBsZXRpb25zIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogYmFzZVVSTAogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBtZXNzYWdlczogbWVzc2FnZUNoYWluNiwKICAgICAgICAgICAgICAgIHN0cmVhbTogdHJ1ZSwKICAgICAgICAgICAgICAgIG1vZGVsOiAiZ3B0LTMuNS10dXJibyIsCiAgICAgICAgICAgICAgICB0ZW1wZXJhdHVyZTogMSwKICAgICAgICAgICAgICAgIHRleHQ6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgcHJlc2VuY2VfcGVuYWx0eTogMAogICAgICAgICAgICB9KQogICAgICAgIH0pOwogICAgICAgaWYgKHJlcy5zdGF0dXMgPT09IDIwMCkgewogICAgICAgICAgIGNvbnNvbGUubG9nKCfmiJDlip8uLi4uJykKICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpCiAgICAgICAgICAgbGV0IHJlc3QgPSBKU09OLnBhcnNlKHJlcy5yZXNwb25zZVRleHQpLmRhdGE7CiAgICAgICAgICAgY29uc29sZS5sb2cocmVzdCkKICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IDI1OyBpKyspIHsKICAgICAgICAgICAgICAgY29uc29sZS5sb2coImh6aXQiLGkpCiAgICAgICAgICAgICAgIGxldCByciA9IGF3YWl0IEdNX2ZldGNoKHsKICAgICAgICAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICAgICAgICAgdXJsOiBiYXNlVVJMICsgImFwaS9nZXRPbmUiLAogICAgICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICIqLyoiLAogICAgICAgICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly8yMDIyMDUwOC42YmJzLmNuIiwKICAgICAgICAgICAgICAgICAgICAgICAicGF0aCI6ICJ2MS9jaGF0L2NvbXBsZXRpb25zIiwKICAgICAgICAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGJhc2VVUkwKICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICAgICAgICAgaWQ6IHJlc3QKICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICBpZiAocnIuc3RhdHVzID09PSAyMDApIHsKICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJyKQogICAgICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IEpTT04ucGFyc2UocnIucmVzcG9uc2VUZXh0KS5kYXRhOwogICAgICAgICAgICAgICAgICAgaWYoIXJlc3VsdCkgewogICAgICAgICAgICAgICAgICAgICAgIGF3YWl0IGRlbGF5KDMwMDApCiAgICAgICAgICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICBpZighcmVzdWx0LnJlc1RpbWUpewogICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LnJlcyB8fCByZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgYXdhaXQgZGVsYXkoMzAwMCkKICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZQogICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQucmVzIHx8IHJlc3VsdCkKICAgICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW42LCB7CiAgICAgICAgICAgICAgICAgICAgICAgcm9sZTogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgY29udGVudDogcmVzdWx0LnJlcyB8fCByZXN1bHQKICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgfWVsc2UgewogICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKQogICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cign6K6/6Zeu5aSx6LSl5LqGJykKICAgICAgICAgICAgICAgfQogICAgICAgICAgIH0KCiAgICAgICB9IGVsc2UgewogICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICAgIC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gewogICAgICAgICAgICBjb25zb2xlLmxvZygn5oiQ5YqfLi4uLicpCiAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICAgICAgbGV0IGNoYXRfaWQgPSBKU09OLnBhcnNlKHJlcy5yZXNwb25zZVRleHQpLmNoYXRfaWQ7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJjaGF0X2lkIixjaGF0X2lkKQogICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICAgdXJsOiBgaHR0cHM6Ly9jaGF0LmdlZWtyLmRldi9zdHJlYW0/Y2hhdF9pZD0ke2NoYXRfaWR9JmFwaV9rZXk9YCwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2NoYXQuZ2Vla3IuZGV2LyIsCiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICJ0ZXh0L2V2ZW50LXN0cmVhbSIKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iCiAgICAgICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0OwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB0cnkgewoKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coInJhdzoiLGQpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZCA9IGQucmVwbGFjZSgvZGF0YTogL2csICIiKS5zcGxpdCgiXG4iKQogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiZGQ6IixkZCkKICAgICAgICAgICAgICAgICAgICAgICAgZGQuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWx0YSA9IEpTT04ucGFyc2UoaXRlbSkuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZGVsdGEpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSxmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgICAgICB9KQoKCiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc29sZS5sb2cocmVzKQogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCforr/pl67lpLHotKXkuoYnKQogICAgICAgIH0KCiAgICB9CgoKICAgIC8v5Y+W5p+Q5LiqY29va2ll55qE5YC8CiAgICBmdW5jdGlvbiBnZXRDb29raWVWYWx1ZShjb29raWVzLCBjb29raWVOYW1lKSB7CiAgICAgICAgbGV0IG5hbWUgPSBjb29raWVOYW1lICsgIj0iOwogICAgICAgIGxldCBjb29raWVBcnJheSA9IGNvb2tpZXMuc3BsaXQoJzsnKTsKICAgICAgICBmb3IobGV0IGkgPSAwOyBpIDwgY29va2llQXJyYXkubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgbGV0IGNvb2tpZSA9IGNvb2tpZUFycmF5W2ldOwogICAgICAgICAgICB3aGlsZSAoY29va2llLmNoYXJBdCgwKSA9PT0gJyAnKSB7CiAgICAgICAgICAgICAgICBjb29raWUgPSBjb29raWUuc3Vic3RyaW5nKDEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb29raWUuaW5kZXhPZihuYW1lKSA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIGNvb2tpZS5zdWJzdHJpbmcobmFtZS5sZW5ndGgsIGNvb2tpZS5sZW5ndGgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAiIjsKICAgIH0KCiAgICAvL+WPlmhlYWRlcueahGNvb2tpZQogICAgZnVuY3Rpb24gZ2V0Q29va2llcyhoZWFkZXJzKSB7CiAgICAgICAg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YXc6IixkKQogICAgICAgICAgICAgICAgICAgIGxldCBkZCA9IGQucmVwbGFjZSgvZGF0YTogL2csICIiKS5zcGxpdCgiXG5cbiIpCiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coImRkOiIsZGQpCiAgICAgICAgICAgICAgICAgICAgZGQuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGVsdGEgPSAvY29udGVudFxcIjpcXCIoLio/KVxcIi9naS5leGVjKGl0ZW0pWzFdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkZWx0YS5yZXBsYWNlKC9cXFxcbi9nLCJcbiIpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZSkgewoKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0pCgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0sZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KTsKCiAgICB9CgoKICAgIC8vMjAyM+W5tDXmnIg05pelIGh0dHBzOi8vY2hhdGdwdC5jeXRzZWUuY29tLyBodHRwczovL2NoYXRncHQwMS5wZW8uaWN1LwogICAgbGV0IG1lc3NhZ2VDaGFpbl9jeXRzZWUgPSBbXQogICAgZnVuY3Rpb24gQ1lUU0VFKCkgewoKICAgICAgICBsZXQgYmFzZVVSTCA9ICJodHRwczovL3d3dy5jeXRzZWUuY29tLyI7CiAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbl9jeXRzZWUsIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgIGxldCBzZW5kRGF0YSA9IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgbWVzc2FnZXM6IG1lc3NhZ2VDaGFpbl9jeXRzZWUsCiAgICAgICAgICAgIGp1c3RTdHJlYW06IHRydWUsCiAgICAgICAgICAgIHN0cmVhbTogdHJ1ZSwKICAgICAgICAgICAgbW9kZWw6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgdGVtcGVyYXR1cmU6IDEsCiAgICAgICAgICAgIHByZXNlbmNlX3BlbmFsdHk6IDAKICAgICAgICB9KTsKICAgICAgICBsZXQgaG1hYyA9IENyeXB0b0pTLkhtYWNTSEEyNTYoc2VuZERhdGEsICI5ODEwMjgiKTsKICAgICAgICBsZXQgc2lnbmF0dXJlID0gaG1hYy50b1N0cmluZyhDcnlwdG9KUy5lbmMuSGV4KTsKCiAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiBiYXNlVVJMICsgImFwaS9nZW5lcmF0ZVN0cmVhbSIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogIiovKiIsCiAgICAgICAgICAgICAgICAic2lnbiI6IHNpZ25hdHVyZSwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vc2Fvc2FvLmN5dHNlZS5jb20vIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9zYW9zYW8uY3l0c2VlLmNvbSIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogc2VuZERhdGEsCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pPT57CgogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgaGlnaGxpZ2h0Q29kZVN0cigpCiAgICAgICAgICAgICAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbl9jeXRzZWUsIHsKICAgICAgICAgICAgICAgICAgICAgICAgcm9sZTogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2cobm9ybWFsQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KHZhbHVlKTsKICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQogICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwoKICAgICAgICB9LGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSk7CgogICAgfQoKCiAgICBsZXQgdXNlcklkX3dnayA9ICIjL2NoYXQvIiArIERhdGUubm93KCk7CgogICAgZnVuY3Rpb24gV0dLKCkgewogICAgICAgIGNvbnNvbGUubG9nKHVzZXJJZF93Z2spCiAgICAgICAgYWJvcnRYbWwgPSBHTV94bWxodHRwUmVxdWVzdCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2NoYXQyLnd1Z3Vva2FpLmNuL2FwaS9jaGF0LXByb2Nlc3MiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgLy8gIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIG51bGwiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly9jaGF0Lnd1Z3Vva2FpLmNuLyIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIHVzZXJJZDogdXNlcklkX3dnaywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IHt9CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW10KICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdC5qb2luKCIiKS5yZXBsYWNlKC9meG9wZW5haS9naSwiIikpCiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2cobm9ybWFsQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheSh2YWx1ZSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KQoKICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQucHVzaChub3dSZXN1bHQucmVwbGFjZSgvZnhvcGVuYWkvZ2ksIiIpKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LmpvaW4oIiIpKQoKCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigiZXJybzoiLCBlcnIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCgogICAgbGV0IHVzZXJJZF95cWNsb3VkID0gIiMvY2hhdC8iICsgRGF0ZS5ub3coKTsKCiAgICBmdW5jdGlvbiBZUUNMT1VEKCkgewogICAgICAgIGNvbnNvbGUubG9nKHVzZXJJZF95cWNsb3VkKQogICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgLy91cmw6ICJodHRwczovL2NianRlc3RhcGkuYmluamllLnNpdGU6Nzc3Ny9hcGkvZ2VuZXJhdGVTdHJlYW0iLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2FwaS5haWNoYXRvcy5jbG91ZC9hcGkvZ2VuZXJhdGVTdHJlYW0iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly9jaGF0Ni5haWNoYXRvcy5jb20vIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9jaGF0Ni5haWNoYXRvcy5jb20iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHByb21wdDogeW91cl9xdXMsCiAgICAgICAgICAgICAgICBhcGlrZXk6ICIiLAogICAgICAgICAgICAgICAgc3lzdGVtOiAiIiwKICAgICAgICAgICAgICAgIHdpdGhvdXRDb250ZXh0OiBmYWxzZSwKICAgICAgICAgICAgICAgIHVzZXJJZDogdXNlcklkX3lxY2xvdWQsCiAgICAgICAgICAgICAgICBuZXR3b3JrOiB0cnVlCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGQpCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoImVycm9yOiIsIGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgfQoKCiAgICBsZXQgcGFyZW50SURfdGhlYmFpOwoKICAgIGZ1bmN0aW9uIFRIRUJBSSgpIHsKICAgICAgICBsZXQgb3BzID0ge307CiAgICAgICAgaWYgKHBhcmVudElEX3RoZWJhaSkgewogICAgICAgICAgICBvcHMgPSB7cGFyZW50TWVzc2FnZUlkOiBwYXJlbnRJRF90aGViYWl9OwogICAgICAgIH0KICAgICAgICBjb25zb2xlLmxvZyhvcHMpCiAgICAgICAgYWJvcnRYbWwgPSBHTV94bWxodHRwUmVxdWVzdCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2NoYXRib3QudGhlYi5haS9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vY2hhdGJvdC50aGViLmFpLyIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IG9wcwogICAgICAgICAgICB9KSwKICAgICAgICAgICAgb25sb2Fkc3RhcnQ6IChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkKQoKICAgICAgICAgICAgICAgICAgICAgICAgZC5zcGxpdCgiXG4iKS5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGpzb25PYmogPSBKU09OLnBhcnNlKGl0ZW0udHJpbSgpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChqc29uT2JqLnRleHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLndhcm4oanNvbk9iaikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihqc29uT2JqLnRleHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChqc29uT2JqLmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX3RoZWJhaSA9IGpzb25PYmouaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChleCl7CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9KQoKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZSkKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIG9ucHJvZ3Jlc3M6IGZ1bmN0aW9uIChtc2cpIHsKICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2cobXNnKSAvL1RvZG8KICAgICAgICAgICAgfSwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9LAogICAgICAgICAgICBvbnRpbWVvdXQ6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgfQoKCgogICAgbGV0IGNvbnZlcnNhdGlvbklkX2hhb2h1b2xhOwogICAgbGV0IHRva2Vuc19oYW9odW9sYSA9IFsnbnVsbCddOwogICAgbGV0IHRrX2hhb2h1b2xhOwoKICAgIHNldFRpbWVvdXQoYXN5bmMgKCkgPT4gewogICAgICAgIC8vaWYoZ2V0R1BUTW9kZSgpICE9PSAnSEFPSFVPTEEnKSByZXR1cm4KICAgICAgICBsZXQgcnIgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgIHVybDogYGh0dHBzOi8veWV5dTEwMjQueHl6L2NoYXQvaGFvaHVsYS5qc29uP3I9JHtNYXRoLnJhbmRvbSgpfWAKICAgICAgICB9KTsKICAgICAgICBpZiAocnIuc3RhdHVzID09PSAyMDApIHsKICAgICAgICAgICAgY29uc29sZS5sb2cocnIpCiAgICAgICAgICAgIGxldCByZXN1bHQgPSBKU09OLnBhcnNlKHJyLnJlc3BvbnNlVGV4dCk7CiAgICAgICAgICAgIHRva2Vuc19oYW9odW9sYSA9IHJlc3VsdC5oYW9odWxhLnRva2VuOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgdG9rZW5zX2hhb2h1b2xhICYmICh0a19oYW9odW9sYSA9IHRva2Vuc19oYW9odW9sYVtNYXRoLmZsb29yKE1hdGgucmFuZG9tKCkgKiB0b2tlbnNfaGFvaHVvbGEubGVuZ3RoKV0pOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coInRrX2hhb2h1b2xh77yaIiwgdGtfaGFvaHVvbGEpCiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZSkKICAgICAgICAgICAgfQogICAgICAgICAgICAvL1hJQU1pCiAgICAgICAgICAgIHhpYW1pX3Rva2VuID0gYHNrLSR7cmVzdWx0LnhpYW1pLnRva2VufWAKICAgICAgICAgICAgY29uc29sZS5sb2coInhpYW1pX3Rva2VuOiIseGlhbWlfdG9rZW4pCgogICAgICAgICAgICAvL0FJTFMKICAgICAgICAgICAgYWlsc19jbGllbnR2ID0gcmVzdWx0LmFpbHMuY2xpZW50dgogICAgICAgICAgICBjb25zb2xlLmxvZygiYWlsc19jbGllbnR2OiIsYWlsc19jbGllbnR2KQoKICAgICAgICAgICAgLy9lc28KICAgICAgICAgICAgZXNvX2FjY2Vzc19jb2RlID0gcmVzdWx0LmVzby5hY2Nlc3Njb2RlCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJlc29fYWNjZXNzX2NvZGU6Iixlc29fYWNjZXNzX2NvZGUpCgogICAgICAgICAgICAvL3B0cmJvb20KICAgICAgICAgICAgcHJvbXB0Ym9vbV9kaWQgPSByZXN1bHQucHRyYm9vbS5kaWQKICAgICAgICAgICAgcHJvbXB0Ym9vbV90b2tlbiA9IHJlc3VsdC5wdHJib29tLnRva2VuCiAgICAgICAgICAgIHByb21wdGJvb21fdXJsID0gcmVzdWx0LnB0cmJvb20udXJsCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJwcm9tcHRib29tX2RpZDoiLHByb21wdGJvb21fZGlkKQogICAgICAgICAgICBjb25zb2xlLmxvZygicHJvbXB0Ym9vbV91cmw6Iixwcm9tcHRib29tX3VybCkKCiAgICAgICAgICAgIC8vY2hhdHpoYW5nCiAgICAgICAgICAgIGNoYXR6aGFuZ19jb29raWUgPSByZXN1bHQuY2hhdHpoYW5nLmNvb2tpZQogICAgICAgICAgICBjb25zb2xlLmxvZygiY2hhdHpoYW5nX2Nvb2tpZToiLGNoYXR6aGFuZ19jb29raWUpCgogICAgICAgICAgICAvL2V4dGtqCiAgICAgICAgICAgIGV4dGtqX2tleSA9IHJlc3VsdC5leHRrai5rZXkKICAgICAgICAgICAgZXh0a2pfYXV0aCA9IHJlc3VsdC5leHRrai5hdXRoCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJleHRral9rZXk6IixleHRral9rZXkpCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJleHRral9hdXRoOiIsZXh0a2pfYXV0aCkKCiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihycikKICAgICAgICB9CgogICAgfSkKICAgIC8vIDIwMjPlubQ15pyIMTPml6UKICAgIGZ1bmN0aW9uIEhBT0hVT0xBKCkgewogICAgICAgIGxldCBvcHMgPSB7CiAgICAgICAgICAgIHByb21wdDogeW91cl9xdXMKICAgICAgICB9OwogICAgICAgIGlmIChjb252ZXJzYXRpb25JZF9oYW9odW9sYSkgewogICAgICAgICAgICBvcHMuY29udmVyc2F0aW9uSWQgPSBjb252ZXJzYXRpb25JZF9oYW9odW9sYTsKICAgICAgICB9CiAgICAgICAgY29uc29sZS5sb2cob3BzKQogICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgIEdNX2h0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vd2V0YWJjaGF0Lmhhb2h1b2xhLmNvbS9hcGkvY2hhdC9jb252ZXJzYXRpb24iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiSS1BcHAiOiJoaXRhYiIsCiAgICAgICAgICAgICAgICAiSS1CcmFuY2giOiJ6aCIsCiAgICAgICAgICAgICAgICAiSS1MYW5nIjoiemgtQ04iLAogICAgICAgICAgICAgICAgIkktUGxhdGZvcm0iOiJjaHJvbWUiLAogICAgICAgICAgICAgICAgIkktVmVyc2lvbiI6IjEuMC40MyIsCiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb247Y2hhcnNldD1VVEYtOCIsCiAgICAgICAgICAgICAgICAiQXV0aG9yaXphdGlvbiI6IGBCZWFyZXIgJHt0a19oYW9odW9sYX1gLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly93ZXRhYmNoYXQuaGFvaHVvbGEuY29tL2FwaS9jaGF0L2NvbnZlcnNhdGlvbiIsCiAgICAgICAgICAgICAgICAib3JpZ2luIjogImNocm9tZS1leHRlbnNpb246Ly9haWtmbGZwZWppcGJwamRsZmFicGdjbGhibGtwYWFmbyIsCiAgICAgICAgICAgICAgICAiVXNlci1BZ2VudCI6ICJNb3ppbGxhLzUuMCAoV2luZG93cyBOVCAxMC4wOyBXaW42NDsgeDY0KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvMTEzLjAuMC4wIFNhZmFyaS81MzcuMzYiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KG9wcyksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9LChzdHJlYW0pID0+IHsKICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAvLyAgICAgY29uc29sZS5sb2cocmVhZGVyLnJlYWQpCiAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgIGhpZ2hsaWdodENvZGVTdHIoKQogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRyeSB7CgogICAgICAgICAgICAgICAgICAgIGxldCBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheSh2YWx1ZSk7CiAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZyhkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQogICAgICAgICAgICAgICAgICAgIGxldCBpdGVtcyA9IGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkuc3BsaXQoL18uKj9fLyk7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coaXRlbXMpCiAgICAgICAgICAgICAgICAgICAgaXRlbXMuZm9yRWFjaCgoaXRlbSkgPT57CiAgICAgICAgICAgICAgICAgICAgICAgIHRyeXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkYXRhVmFsID0gSlNPTi5wYXJzZShpdGVtKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRhdGFWYWwuZGF0YSAmJiBkYXRhVmFsLm1lc3NhZ2UgIT09ICdzdHJlYW0gZG9uZScpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdC5wdXNoKGRhdGFWYWwuZGF0YSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRhdGFWYWwuZGF0YSAmJiBkYXRhVmFsLm1lc3NhZ2UgPT09ICdzdHJlYW0gZG9uZScpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb252ZXJzYXRpb25JZF9oYW9odW9sYSA9IEpTT04ucGFyc2UoZGF0YVZhbC5kYXRhKS5jb252ZXJzYXRpb25JZDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0pCgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSkKICAgIH0KCgoKICAgIGxldCBwYXJlbnRJRF9taW5kZWQ7CiAgICAvL2h0dHA6Ly9mb3J3YXJkbWluZGVkLnh5ei8KICAgIGZ1bmN0aW9uIE1JTkRFRCgpIHsKICAgICAgICBsZXQgb3BzID0ge307CiAgICAgICAgaWYgKHBhcmVudElEX21pbmRlZCkgewogICAgICAgICAgICBvcHMgPSB7cGFyZW50TWVzc2FnZUlkOiBwYXJlbnRJRF9taW5kZWR9OwogICAgICAgIH0KICAgICAgICBjb25zb2xlLmxvZyhvcHMpCiAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW107CiAgICAgICAgR01faHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cDovL2ZvcndhcmRtaW5kZWQueHl6L2FwaS9jaGF0LXByb2Nlc3MiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cDovL2ZvcndhcmRtaW5kZWQueHl6LyIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IG9wcywKICAgICAgICAgICAgICAgIHN5c3RlbU1lc3NhZ2U6IllvdSBhcmUgQ2hhdEdQVCwgYSBsYXJnZSBsYW5ndWFnZSBtb2RlbCB0cmFpbmVkIGJ5IE9wZW5BSS4gRm9sbG93IHRoZSB1c2VyJ3MgaW5zdHJ1Y3Rpb25zIGNhcmVmdWxseS4gUmVzcG9uZCB1c2luZyBtYXJrZG93bi4iLAogICAgICAgICAgICAgICAgdG9wX3A6MSwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOjAuOAogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0sKHN0cmVhbSkgPT4gewogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIC8vICAgICBjb25zb2xlLmxvZyhyZWFkZXIucmVhZCkKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgaGlnaGxpZ2h0Q29kZVN0cigpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgbGV0IGpzb25MaW5lcyA9IGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkuc3BsaXQoIlxuIik7CiAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IEpTT04ucGFyc2UoanNvbkxpbmVzW2pzb25MaW5lcy5sZW5ndGggLSAxXSkKCiAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC50ZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKG5vd1Jlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSBub3dSZXN1bHQudGV4dAogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX21pbmRlZCA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0pCiAgICB9CgoKICAgIGxldCBwYXJlbnRJRF9jaGF0MTsKICAgIC8vZml4IDIwMjPlubQ15pyIMjbml6UgMS4xYWkuZnVuCiAgICBmdW5jdGlvbiBDSEFUMSgpIHsKICAgICAgICBsZXQgb3BzID0ge307CiAgICAgICAgaWYgKHBhcmVudElEX2NoYXQxKSB7CiAgICAgICAgICAgIG9wcyA9IHtwYXJlbnRNZXNzYWdlSWQ6IHBhcmVudElEX2NoYXQxfTsKICAgICAgICB9CiAgICAgICAgY29uc29sZS5sb2cob3BzKQogICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgIEdNX2h0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vY2hhdGFwaWNuLmEzci5mdW4vYXBpL2NoYXQtcHJvY2VzcyIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovLzJjaGF0LmMzci5pbmsvIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBwcm9tcHQ6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgb3B0aW9uczogb3BzLAogICAgICAgICAgICAgICAgcmVnZW5lcmF0ZTogZmFsc2UsCiAgICAgICAgICAgICAgICByb29tSWQ6IDEwMDIsCiAgICAgICAgICAgICAgICB1dWlkOiBEYXRlLm5vdygpLAogICAgICAgICAgICAgICAgc3lzdGVtTWVzc2FnZToiWW91IGFyZSBDaGF0R1BULCBhIGxhcmdlIGxhbmd1YWdlIG1vZGVsIHRyYWluZWQgYnkgT3BlbkFJLiBGb2xsb3cgdGhlIHVzZXIncyBpbnN0cnVjdGlvbnMgY2FyZWZ1bGx5LiBSZXNwb25kIHVzaW5nIG1hcmtkb3duLiIsCiAgICAgICAgICAgICAgICB0b3BfcDoxLAogICAgICAgICAgICAgICAgdGVtcGVyYXR1cmU6MC44CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iCiAgICAgICAgfSwoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgLy8gICAgIGNvbnNvbGUubG9nKHJlYWRlci5yZWFkKQogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIC8vIGNvbnNvbGUubG9nKG5vcm1hbEFycmF5KQogICAgICAgICAgICAgICAgICAgIGxldCBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheSh2YWx1ZSk7CiAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KSkKICAgICAgICAgICAgICAgICAgICBsZXQganNvbkxpbmVzID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KS5zcGxpdCgiXG4iKTsKICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gSlNPTi5wYXJzZShqc29uTGluZXNbanNvbkxpbmVzLmxlbmd0aCAtIDFdKQogICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQudGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gbm93UmVzdWx0LnRleHQKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC5pZCkgewogICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF9jaGF0MSA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0pCiAgICB9CgoKCgoKICAgIGxldCBwYXJlbnRJRF9uYmFpOwoKICAgIC8vWElBSklFIGh0dHBzOi8vZjYueGphaS5jYy8jL2NoYXQvMTAwMgogICAgZnVuY3Rpb24gTkJBSSgpIHsKICAgICAgICBsZXQgb3BzID0ge307CiAgICAgICAgaWYgKHBhcmVudElEX25iYWkpIHsKICAgICAgICAgICAgb3BzID0ge3BhcmVudE1lc3NhZ2VJZDogcGFyZW50SURfbmJhaX07CiAgICAgICAgfQogICAgICAgIGNvbnNvbGUubG9nKG9wcykKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovLzE1NC40MC41OS4xMDU6MzAwNi9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vZjEubmJhaS5saXZlLyIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIsCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHByb21wdDogeW91cl9xdXMsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMKICAgICAgICAgICAgIH0pLAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iCiAgICAgICAgfSkudGhlbigoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAvLyAgICAgY29uc29sZS5sb2cocmVhZGVyLnJlYWQpCiAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9ICIiOwogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgIGxldCBkc3RyID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KQogICAgICAgICAgICAgICAgICAgIGlmKGRzdHIuaW5jbHVkZXMoInJvbGUiKSl7CiAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX25iYWkgPSAgL1wicGFyZW50TWVzc2FnZUlkXCI6XCIoLio/KVwiL2dpLmV4ZWMoZHN0cilbMV0KICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZHN0cikKICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZHN0cikKICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICB9CgoKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICB9LChlcnIpPT4gewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgfSkKICAgICAgICB9KQoKICAgIH0KCgogICAgbGV0IGdhbWVqeF9ncm91cF9pZDsKICAgIGZ1bmN0aW9uIHNldEdyb3VwaWRfZ2FtZWp4KCkgewoKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2NoYXRhcGkuY2hhdDg2LmNuL2dvL2FwaS9ncm91cC9hZGQiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGBodHRwczovL2NoYXRhcGkuY2hhdDg2LmNuL2AsCiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIkF1dGhvcml6YXRpb24iOiAiU3lMZFNiWnFlRjlpbmU5cXZWbERJK1Ewdis0NTZrVmpkLzVCUlpUUDVWbz0iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6SlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgdmVyc2lvbjogIiIsCiAgICAgICAgICAgICAgICBvczogInBjIiwKICAgICAgICAgICAgICAgIGxhbmd1YWdlOiAiemgiLAogICAgICAgICAgICAgICAgcGFyczogewogICAgICAgICAgICAgICAgICAgIHVzZXJfaWQ6ICI2MjUyOTIiLAogICAgICAgICAgICAgICAgICAgIGV4YW1wbGVzX2lkOiAiIiwKICAgICAgICAgICAgICAgICAgICBleGFtcGxlc19kZXNjcmliZTogIuS9oOWlvSIKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkKICAgICAgICB9KS50aGVuKChyZXMpPT57CiAgICAgICAgICAgIGlmKHJlcyl7CiAgICAgICAgICAgICAgICAvL3siY29kZSI6MjAwLCJkYXRhIjp7Imdyb3VwX2lkIjoxMjkyNTc3fSwicmV0Q29kZSI6Im9rIiwicmV0TXNnIjoic3VjY2VzcyJ9CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpCiAgICAgICAgICAgICAgICBsZXQgZGF0YSA9IGV2YWwocmVzLnJlc3BvbnNlVGV4dCkKICAgICAgICAgICAgICAgIGdhbWVqeF9ncm91cF9pZCA9IEpTT04ucGFyc2UoQUVTX0NCQy5kZWNyeXB0KGRhdGEuc2xpY2UoMTYpLCBkYXRhLnNsaWNlKDAsIDE2KSkpLmRhdGEuZ3JvdXBfaWQ7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiZ2FtZWp4X2dyb3VwX2lkOiIsZ2FtZWp4X2dyb3VwX2lkKQogICAgICAgICAgICB9CiAgICAgICAgfSkKCiAgICB9CgoKICAgIGxldCBpc19maXJzdF9nYW1langgPSB0cnVlOwogICAgYXN5bmMgZnVuY3Rpb24gR0FNRUpYKCl7CiAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2NoYXRhcGkuY2hhdDg2LmNuL2dvL2FwaS9zdGVhbS9zZWUiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGBodHRwczovL2NoYXRhcGkuY2hhdDg2LmNuL2AsCiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIkF1dGhvcml6YXRpb24iOiAiU3lMZFNiWnFlRjlpbmU5cXZWbERJK1Ewdis0NTZrVmpkLzVCUlpUUDVWbz0iCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6SlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgInZlcnNpb24iOiAiIiwKICAgICAgICAgICAgICAgICJvcyI6ICJwYyIsCiAgICAgICAgICAgICAgICAibGFuZ3VhZ2UiOiAiemgiLAogICAgICAgICAgICAgICAgInBhcnMiOiB7CiAgICAgICAgICAgICAgICAgICAgInVzZXJfaWQiOiAiNjI1MjkyIiwKICAgICAgICAgICAgICAgICAgICAicXVlc3Rpb24iOiBpc19maXJzdF9nYW1langgPyAi5L2g5aW9IiA6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgICAgICJncm91cF9pZCI6IGAke2dhbWVqeF9ncm91cF9pZH1gLAogICAgICAgICAgICAgICAgICAgICJxdWVzdGlvbl9pZCI6ICIiCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pCgogICAgICAgIH0pCgoKICAgICAgICBjb25zb2xlLmxvZyhyZXExLnJlc3BvbnNlVGV4dCkKCiAgICAgICAgLy97ImNvZGUiOjIwMCwiZGF0YSI6eyJhbnN3ZXIiOiIiLCJxdWVzdGlvbl9pZCI6IjkxMzAzIiwidHlwZSI6ImFuc3dlciIsCiAgICAgICAgLy8gInVzZXJfaWQiOiI1OTQ1NzgifSwicmV0Q29kZSI6Im9rIiwicmV0TXNnIjoic3VjY2VzcyJ9CiAgICAgICAgaWYocmVxMS5yZXNwb25zZVRleHQpewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGV0IGRhdGEgPSBldmFsKHJlcTEucmVzcG9uc2VUZXh0KQogICAgICAgICAgICAgICAgY29uc29sZS5sb2coSlNPTi5wYXJzZShBRVNfQ0JDLmRlY3J5cHQoZGF0YS5zbGljZSgxNiksIGRhdGEuc2xpY2UoMCwgMTYpKSkpCiAgICAgICAgICAgICAgICBsZXQgcXVlc3Rpb25faWQgPSBKU09OLnBhcnNlKEFFU19DQkMuZGVjcnlwdChkYXRhLnNsaWNlKDE2KSwgZGF0YS5zbGljZSgwLCAxNikpKS5kYXRhLnF1ZXN0aW9uX2lkOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coInF1ZXN0aW9uX2lkOiIscXVlc3Rpb25faWQpCiAgICAgICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgICAgICAgICB1cmw6IGBodHRwczovL2NoYXRhcGkuY2hhdDg2LmNuL2dvL2FwaS9ldmVudC9zZWU/cXVlc3Rpb25faWQ9JHtxdWVzdGlvbl9pZH0mZ3JvdXBfaWQ9JHtnYW1lanhfZ3JvdXBfaWR9JnVzZXJfaWQ9NjI1MjkyJnRva2VuPVN5TGRTYlpxZUY5aW5lOXF2VmxESStRMHYrNDU2a1ZqZC81QlJaVFA1Vm8lM0RgLAogICAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly9jaGF0YXBpLmNoYXQ4Ni5jbi8iLAogICAgICAgICAgICAgICAgICAgICAgICAiYWNjZXB0IjogInRleHQvZXZlbnQtc3RyZWFtIgogICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgICAgICAgICAgfSkudGhlbigoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW107CiAgICAgICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cobm93UmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgbm93UmVzdWx0LnNwbGl0KCJcbiIpLmZvckVhY2goaXRlbT0+ewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2h1bmsgPSBKU09OLnBhcnNlKGl0ZW0ucmVwbGFjZSgvZGF0YTovLCIiKS50cmltKCkpLkRhdGE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQucHVzaChjaHVuaykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZXgpe30KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LmpvaW4oIiIpKQoKICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH1jYXRjaCAoZXgpewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgICAgIH0KCiAgICAgICAgfQogICAgICAgIGlmKGlzX2ZpcnN0X2dhbWVqeCA9PT0gdHJ1ZSl7CiAgICAgICAgICAgIGlzX2ZpcnN0X2dhbWVqeCA9IGZhbHNlOwogICAgICAgICAgICBhd2FpdCBHQU1FSlgoKQogICAgICAgIH0KCgogICAgfQoKCiAgICBsZXQgYmluZ1NvY2tldDsKICAgIGxldCBiaW5nX3NvdXJjZUF0dHJpYnV0aW9uczsKICAgIGx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gPSBldmVudC5kYXRhOwogICAgICAgICAgICB0cnl7CiAgICAgICAgICAgICAgICBsZXQgcnIgPSByZXZEYXRhLnJlcGxhY2UoU3RyaW5nLmZyb21DaGFyQ29kZSgweDFlKSwiIik7CgogICAgICAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICAgICAgIGxldCByZWYgPSAnXG4nCiAgICAgICAgICAgICAgICAgICAgaWYocnIuc3RhcnRzV2l0aCgneyJ0eXBlIjoyJykpewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLndhcm4oImJpbmdfc291cmNlQXR0cmlidXRpb25zIGZvcmVhY2giKQogICAgICAgICAgICAgICAgICAgICAgICBiaW5nX3NvdXJjZUF0dHJpYnV0aW9ucyAmJiBiaW5nX3NvdXJjZUF0dHJpYnV0aW9ucy5mb3JFYWNoKChzYixpbmRleCkgPT57CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVmICs9IGAke2luZGV4fS5bJHtzYi5wcm92aWRlckRpc3BsYXlOYW1lfV0oJHtzYi5zZWVNb3JlVXJsfSlcblxuYAogICAgICAgICAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChlKSB7Y29uc29sZS5lcnJvcigic2IiLCBlKX0KICAgICAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihiaW5nX3Jlc3VsdCArIHJlZik7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfWNhdGNoIChleCkgeyAvKmNvbnNvbGUuZXJyb3IoImJpbmdfc291cmNlQXR0cmlidXRpb25zICBleCAiLCBKU09OLnBhcnNlKHJyKSkqLyB9CgoKICAgICAgICAgICAgICAgIGxldCBhbnMgPSBKU09OLnBhcnNlKHJyKS5hcmd1bWVudHNbMF0ubWVzc2FnZXNbMF0udGV4dDsKICAgICAgICAgICAgICAgIGJpbmdfcmVzdWx0ID0gKGFucyA/IGFucyA6IGJpbmdfcmVzdWx0KQogICAgICAgICAgICAgICAgY29uc29sZS5sb2coYmluZ19yZXN1bHQpCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGJpbmdfcmVzdWx0KQogICAgICAgICAgICAgICAgaWYoY29udmVyc2F0aW9uSWQpewogICAgICAgICAgICAgICAgICAgIGlzU3RhcnRPZlNlc3Npb24gPSBmYWxzZTsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBpZihKU09OLnBhcnNlKHJyKS5hcmd1bWVudHNbMF0ubWVzc2FnZXNbMF0uc291cmNlQXR0cmlidXRpb25zKXsKICAgICAgICAgICAgICAgICAgICBsZXQgc2IgPSBKU09OLnBhcnNlKHJyKS5hcmd1bWVudHNbMF0ubWVzc2FnZXNbMF0uc291cmNlQXR0cmlidXRpb25zOwogICAgICAgICAgICAgICAgICAgIGJpbmdfc291cmNlQXR0cmlidXRpb25zID0gc2IubGVuZ3RoID4gMCA/IHNiIDogYmluZ19zb3VyY2VBdHRyaWJ1dGlvbnM7CgogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybignYmluZ19zb3VyY2VBdHRyaWJ1dGlvbnMnLGJpbmdfc291cmNlQXR0cmlidXRpb25zKQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfWNhdGNoIChlKSB7CgogICAgICAgICAgICB9CiAgICAgICAgICAgIC8qaWYocmV2RGF0YS5pbmNsdWRlcygiYWxsb3dSZWNvbm5lY3QiKSl7CiAgICAgICAgICAgICAgICBpc1N0YXJ0T2ZTZXNzaW9uID0gdHJ1ZTsKICAgICAgICAgICAgfSovCgogICAgICAgIH0pOwogICAgfQoKICAgLy9zZXRUaW1lb3V0KGluaXRCaW5nU29ja2V0LDEwMDApCiAgICBsZXQgaXNTdGFydE9mU2Vzc2lvbiA9IHRydWU7CiAgICBsZXQgY29udmVyc2F0aW9uSWQ7CiAgICBsZXQgY2xpZW50SWQ7CiAgICBsZXQgY29udmVyc2F0aW9uU2lnbmF0dXJlOwogICAgbGV0IGludm9jYXRpb25JZCA9IDA7CiAgICBsZXQgdG9uZVN0eWxlID0gJ2Zhc3QnOwogICBhc3luYyBmdW5jdGlvbiBuZXdCaW5nKCkgewoKICAgICAgIHNldFRpbWVvdXQoaW5pdEJpbmdTb2NrZXQpCiAgICAgICBhd2FpdCBkZWxheSgyMDAwKQoKICAgICAgIGNvbnN0IGdlblJhbkhleCA9IChzaXplKSA9PgogICAgICAgICAgIFsuLi5BcnJheShzaXplKV0ubWFwKCgpID0+IE1hdGguZmxvb3IoTWF0aC5yYW5kb20oKSAqIDE2KS50b1N0cmluZygxNikpLmpvaW4oJycpCgogICAgICAgaWYoaXNTdGFydE9mU2Vzc2lvbil7CiAgICAgICAgICAgY29uc29sZS5sb2coImlzU3RhcnRPZlNlc3Npb246Iixpc1N0YXJ0T2ZTZXNzaW9uKQogICAgICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICB1cmw6ICJodHRwczovL3d3dy5iaW5nLmNvbS90dXJpbmcvY29udmVyc2F0aW9uL2NyZWF0ZSIKICAgICAgICAgICB9KQogICAgICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgY29uc29sZS5sb2cocikKICAgICAgICAgICBjb252ZXJzYXRpb25JZCA9IEpTT04ucGFyc2UocikuY29udmVyc2F0aW9uSWQ7CiAgICAgICAgICAgY2xpZW50SWQgPSBKU09OLnBhcnNlKHIpLmNsaWVudElkOwogICAgICAgICAgIGNvbnZlcnNhdGlvblNpZ25hdHVyZSA9IEpTT04ucGFyc2UocikuY29udmVyc2F0aW9uU2lnbmF0dXJlOwoKICAgICAgIH0KCgoKICAgICAgIGlmIChiaW5nU29ja2V0LnJlYWR5U3RhdGUgPT09IDEpIHsKICAgICAgICAgICAvLyDlj5HpgIHljY/orq7lkozniYjmnKzlj7cKICAgICAgICAgICBjb25zdCBwcm90b2NvbCA9IHtwcm90b2NvbDogImpzb24iLCB2ZXJzaW9uOiAxfTsKICAgICAgICAgICBiaW5nU29ja2V0LnNlbmQoSlNPTi5zdHJpbmdpZnkocHJvdG9jb2wpICsgU3RyaW5nLmZyb21DaGFyQ29kZSgweDFlKSk7CgogICAgICAgICAgIGF3YWl0IGRlbGF5KDEwMDApCiAgICAgICAgICAgLy8g5Y+R6YCB6K+35rGC57G75Z6LCiAgICAgICAgICAgY29uc3QgdHlwZSA9IHt0eXBlOiA2fTsKICAgICAgICAgICBiaW5nU29ja2V0LnNlbmQoSlNPTi5zdHJpbmdpZnkodHlwZSkgKyBTdHJpbmcuZnJvbUNoYXJDb2RlKDB4MWUpKTsKCiAgICAgICAgICAgYXdhaXQgZGVsYXkoNTAwKQogICAgICAgICAgIC8v5Y+R6YCB5o+Q6ZeuCiAgICAgICAgICAgaWYoIWlzU3RhcnRPZlNlc3Npb24pewogICAgICAgICAgICAgICBpbnZvY2F0aW9uSWQgKz0gMTsKICAgICAgICAgICB9CiAgICAgICAgICAgbGV0IHRvbmVPcHRpb24KICAgICAgICAgICBpZiAodG9uZVN0eWxlID09PSAnY3JlYXRpdmUnKSB7CiAgICAgICAgICAgICAgIHRvbmVPcHRpb24gPSAnaDNpbWFnaW5hdGl2ZScKICAgICAgICAgICB9IGVsc2UgaWYgKHRvbmVTdHlsZSA9PT0gJ3ByZWNpc2UnKSB7CiAgICAgICAgICAgICAgIHRvbmVPcHRpb24gPSAnaDNwcmVjaXNlJwogICAgICAgICAgIH0gZWxzZSBpZiAodG9uZVN0eWxlID09PSAnZmFzdCcpIHsKICAgICAgICAgICAgICAgLy8gbmV3ICJCYWxhbmNlZCIgbW9kZSwgYWxsZWdlZGx5IEdQVC0zLjUgdHVyYm8KICAgICAgICAgICAgICAgdG9uZU9wdGlvbiA9ICdnYWxpbGVvJwogICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgIC8vIG9sZCAiQmFsYW5jZWQiIG1vZGUKICAgICAgICAgICAgICAgdG9uZU9wdGlvbiA9ICdoYXJtb255djMnCiAgICAgICAgICAgfQogICAgICAgICAgIGNvbnN0IG1zZyA9IHsKICAgICAgICAgICAgICAgImFyZ3VtZW50cyI6IFt7CiAgICAgICAgICAgICAgICAgICAiY29udmVyc2F0aW9uSWQiOiBjb252ZXJzYXRpb25JZCwKICAgICAgICAgICAgICAgICAgICJzbGljZUlkcyI6IFsiMjIyZHRhcHBpZCIsICIyMjVjcmljaW5mbyIsICIyMjRsb2NhbHMwIl0sCiAgICAgICAgICAgICAgICAgICAib3B0aW9uc1NldHMiOiBbCiAgICAgICAgICAgICAgICAgICAgICAgJ25sdV9kaXJlY3RfcmVzcG9uc2VfZmlsdGVyJywKICAgICAgICAgICAgICAgICAgICAgICAnZGVlcGxlbycsCiAgICAgICAgICAgICAgICAgICAgICAgJ2Rpc2FibGVfZW1vamlfc3Bva2VuX3RleHQnLAogICAgICAgICAgICAgICAgICAgICAgICdyZXNwb25zaWJsZV9haV9wb2xpY3lfMjM1JywKICAgICAgICAgICAgICAgICAgICAgICAnZW5hYmxlbW0nLAogICAgICAgICAgICAgICAgICAgICAgIHRvbmVPcHRpb24sCiAgICAgICAgICAgICAgICAgICAgICAgJ2R0YXBwaWQnLAogICAgICAgICAgICAgICAgICAgICAgICdjcmljaW5mbycsCiAgICAgICAgICAgICAgICAgICAgICAgJ2NyaWNpbmZvdjInLAogICAgICAgICAgICAgICAgICAgICAgICdkdjNzdWdnJywKICAgICAgICAgICAgICAgICAgICAgICAnbm9qYmZlZGdlJywKICAgICAgICAgICAgICAgICAgIF0sCiAgICAgICAgICAgICAgICAgICAidHJhY2VJZCI6IGdlblJhbkhleCgzMiksCiAgICAgICAgICAgICAgICAgICAic291cmNlIjogImNpYiIsCiAgICAgICAgICAgICAgICAgICAiaXNTdGFydE9mU2Vzc2lvbiI6IGlzU3RhcnRPZlNlc3Npb24sCiAgICAgICAgICAgICAgICAgICAibWVzc2FnZSI6IHsKICAgICAgICAgICAgICAgICAgICAgICAiYXV0aG9yIjogInVzZXIiLAogICAgICAgICAgICAgICAgICAgICAgICJ0ZXh0IjogeW91cl9xdXMsCiAgICAgICAgICAgICAgICAgICAgICAgIm1lc3NhZ2VUeXBlIjogIkNoYXQiCiAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgImNvbnZlcnNhdGlvblNpZ25hdHVyZSI6IGNvbnZlcnNhdGlvblNpZ25hdHVyZSwKICAgICAgICAgICAgICAgICAgICJwYXJ0aWNpcGFudCI6IHsKICAgICAgICAgICAgICAgICAgICAgICAiaWQiOiBjbGllbnRJZAogICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICB9XSwKICAgICAgICAgICAgICAgImludm9jYXRpb25JZCI6IGAke2ludm9jYXRpb25JZH1gLAogICAgICAgICAgICAgICAidGFyZ2V0IjogImNoYXQiLAogICAgICAgICAgICAgICAidHlwZSI6IDQKICAgICAgICAgICB9CgogICAgICAgICAgIGJpbmdTb2NrZXQuc2VuZChKU09OLnN0cmluZ2lmeShtc2cpICsgU3RyaW5nLmZyb21DaGFyQ29kZSgweDFlKSk7CiAgICAgICAgICAvKiBpZihpc1N0YXJ0T2ZTZXNzaW9uKXsKICAgICAgICAgICAgICAgaXNTdGFydE9mU2Vzc2lvbiA9IGZhbHNlOwogICAgICAgICAgIH0qLwogICAgICAgfQoKCgogICAgfQoKCgogICBmdW5jdGlvbiB1dWlkdjQoKSB7CiAgICAgICBsZXQgZCA9IG5ldyBEYXRlKCkuZ2V0VGltZSgpOyAvLyBnZXQgY3VycmVudCB0aW1lc3RhbXAgaW4gbXMgKHRvIGVuc3VyZSBVVUlEIHVuaXF1ZW5lc3MpCiAgICAgICBsZXQgdXVpZCA9ICd4eHh4eHh4eC14eHh4LTR4eHgteXh4eC14eHh4eHh4eHh4eHgnLnJlcGxhY2UoL1t4eV0vZywgZnVuY3Rpb24gKGMpIHsKICAgICAgICAgICBsZXQgciA9IChkICsgTWF0aC5yYW5kb20oKSAqIDE2KSAlIDE2IHwgMCAvLyBnZW5lcmF0ZSByYW5kb20gbmliYmxlCiAgICAgICAgICAgIGQgPSBNYXRoLmZsb29yKGQgLyAxNikgLy8gY29ycmVzcG9uZCBlYWNoIFVVSUQgZGlnaXQgdG8gdW5pcXVlIDQtYml0IGNodW5rcyBvZiB0aW1lc3RhbXAKICAgICAgICAgICAgcmV0dXJuIChjID09PSAneCcgPyByIDogKHIgJiAweDMgfCAweDgpKS50b1N0cmluZygxNikgLy8gZ2VuZXJhdGUgcmFuZG9tIGhleGFkZWNpbWFsIGRpZ2l0CiAgICAgICAgfSkKICAgICAgICByZXR1cm4gdXVpZAogICAgfQogICAgLy9PUEVOQUkgMjAyM+W5tDXmnIgxMgogICBsZXQgbWVzc2FnZUNoYWluX29wZW5haSA9IFtdOwogICBhc3luYyBmdW5jdGlvbiBPUEVOQUkoKXsKICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW5fb3BlbmFpLHsKICAgICAgICAgICAicm9sZSI6ICJ1c2VyIiwKICAgICAgICAgICAiaWQiOiB1dWlkdjQoKSwKICAgICAgICAgICAiY29udGVudCI6IHsKICAgICAgICAgICAgICAgImNvbnRlbnRfdHlwZSI6ICJ0ZXh0IiwKICAgICAgICAgICAgICAgInBhcnRzIjogWwogICAgICAgICAgICAgICAgICAgeW91cl9xdXMKICAgICAgICAgICAgICAgXQogICAgICAgICAgIH0KICAgICAgIH0sMjApCiAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCLmraTnur/ot6/kuLpPcGVuQUnlrpjnvZHnur/ot6/vvIzkvb/nlKjliY3noa7lrprmnInorr/pl67mnYPpmZDkuJTnmbvlvZXotKblj7fvvJpbT1BFTkFJ5a6Y572RXShodHRwczovL2NoYXQub3BlbmFpLmNvbS8pIikKICAgICAgIGxldCByZXExID0gYXd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1QnLAogICAgICAgICAgIHVybDogJ2h0dHBzOi8vY2hhdC5vcGVuYWkuY29tL2JhY2tlbmQtYXBpL2NvbnZlcnNhdGlvbicsCiAgICAgICAgICAgaGVhZGVyczogeydDb250ZW50LVR5cGUnOiAnYXBwbGljYXRpb24vanNvbicsIEF1dGhvcml6YXRpb246ICdCZWFyZXIgJyArIGFjY2Vzc1Rva2VufSwKICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iLAogICAgICAgICAgIGRhdGE6IHNlbmREYXRhCiAgICAgICB9KS50aGVuKChzdHJlYW0pPT4gewogICAgICAgICAgIGxldCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCkKICAgICAgICAgICBsZXQgYW5zd2VyOwogICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiPT09ZG9uZT09IikKICAgICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW5fb3BlbmFpLHsKICAgICAgICAgICAgICAgICAgICAgICAicm9sZSI6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICJpZCI6IHV1aWR2NCgpLAogICAgICAgICAgICAgICAgICAgICAgICJjb250ZW50IjogewogICAgICAgICAgICAgICAgICAgICAgICAgICAiY29udGVudF90eXBlIjogInRleHQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAicGFydHMiOiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbnN3ZXIKICAgICAgICAgICAgICAgICAgICAgICAgICAgXQogICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIH0sIDIwKQogICAgICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICAgICAgbGV0IHJlc3BvbnNlSXRlbSA9IFN0cmluZy5mcm9tQ2hhckNvZGUoLi4uQXJyYXkuZnJvbSh2YWx1ZSkpCiAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXNwb25zZUl0ZW0pCiAgICAgICAgICAgICAgICAgICBsZXQgaXRlbXMgPSByZXNwb25zZUl0ZW0uc3BsaXQoJ1xuXG4nKQogICAgICAgICAgICAgICAgICAgaWYgKGl0ZW1zLmxlbmd0aCA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICBsZXQgbGFzdEl0ZW0gPSBpdGVtcy5zbGljZSgtMywgLTIpWzBdCiAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxhc3RJdGVtLnN0YXJ0c1dpdGgoJ2RhdGE6IFtET05FXScpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3BvbnNlSXRlbSA9IGl0ZW1zLnNsaWNlKC00LCAtMylbMF0KICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICByZXNwb25zZUl0ZW0gPSBsYXN0SXRlbQogICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIGlmIChyZXNwb25zZUl0ZW0uc3RhcnRzV2l0aCgnZGF0YTogeycpKSB7CiAgICAgICAgICAgICAgICAgICAgICAgYW5zd2VyID0gSlNPTi5wYXJzZShyZXNwb25zZUl0ZW0uc2xpY2UoNikpLm1lc3NhZ2UuY29udGVudC5wYXJ0c1swXQogICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoYW5zd2VyKQogICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXNwb25zZUl0ZW0uc3RhcnRzV2l0aCgnZGF0YTogW0RPTkVdJykpIHsKCiAgICAgICAgICAgICAgICAgICAgICAgLy8gcmV0dXJuCiAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIH1jYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKQogICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KQogICAgICAgICAgIH0sZnVuY3Rpb24gKHJlYXNvbikgewogICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICB9KQogICAgICAgfSkKICAgfQoKICAgbGV0IGNzcmZUb2tlbjsKICAgYXN5bmMgZnVuY3Rpb24gc2V0Q3NyZlRva2VuKCl7CiAgICAgICBsZXQgcmVxMSA9IGF3YWl0IEdNX2ZldGNoKHsKICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgIHVybDogImh0dHBzOi8vdG9uZ3lpLmFsaXl1bi5jb20vY2hhdCIsCiAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly90b25neWkuYWxpeXVuLmNvbSIsCiAgICAgICAgICAgICAgICJyZWZlcmVyIjoiaHR0cHM6Ly90b25neWkuYWxpeXVuLmNvbS9jaGF0IgogICAgICAgICAgIH0KICAgICAgIH0pCiAgICAgICBsZXQgciA9IHJlcTEucmVzcG9uc2VUZXh0OwogICAgICAgY29uc29sZS5sb2cocik7CiAgICAgICB0cnl7CiAgICAgICAgICAgY3NyZlRva2VuID0gIC9cd3s4fS1cd3s0fS1cd3s0fS1cd3s0fS1cd3sxMn0vZy5leGVjKHIpWzBdOwogICAgICAgICAgIGNvbnNvbGUubG9nKCJjc3JmVG9rZW46Iixjc3JmVG9rZW4pCiAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJjc3JmVG9rZW7ojrflj5blpLHotKUiKQogICAgICAgfQogICAgfQogICBzZXRUaW1lb3V0KCgpPT57CiAgICAgICBpZihnZXRHUFRNb2RlKCk9PT0iVE9OR1lJIil7CiAgICAgICAgICAgc2V0Q3NyZlRva2VuKCkKICAgICAgIH0KICAgfSkKCiAgICBsZXQgdG9uZ3lpX2ZpcnN0ID0gdHJ1ZTsKICAgIGxldCB0b25neWlfc2Vzc2lvbklkOwogICAgLy/pgJrkuYnljYPpl64gMjAyM+W5tDXmnIgxM+aXpQogICBhc3luYyBmdW5jdGlvbiBUT05HWUkoKXsKICAgICAgICBpZih0b25neWlfZmlyc3QpewogICAgICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly90b25neWkuYWxpeXVuLmNvbS9xaWFud2VuL2FkZFNlc3Npb24iLAogICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly90b25neWkuYWxpeXVuLmNvbSIsCiAgICAgICAgICAgICAgICAgICAicmVmZXJlciI6Imh0dHBzOi8vdG9uZ3lpLmFsaXl1bi5jb20vY2hhdCIsCiAgICAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgICAgIngteHNyZi10b2tlbiI6IGNzcmZUb2tlbgogICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICBkYXRhOkpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICJmaXJzdFF1ZXJ5IjogeW91cl9xdXMKICAgICAgICAgICAgICAgfSkKICAgICAgICAgICB9KQogICAgICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgLy9jb25zb2xlLmxvZyhyKTsKCiAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICB0b25neWlfc2Vzc2lvbklkID0gSlNPTi5wYXJzZShyKS5kYXRhLnNlc3Npb25JZDsKICAgICAgICAgICAgICAgdG9uZ3lpX2ZpcnN0ID0gZmFsc2U7CiAgICAgICAgICAgfWNhdGNoIChlKSB7CiAgICAgICAgICAgICAgIHRvbmd5aV9maXJzdCA9IHRydWU7CiAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoIuWHuumUmSzor7fnoa7orqTlt7LnmbvlvZXpgJrkuYnlrpjnvZFb6YCa5LmJXShodHRwczovL3Rvbmd5aS5hbGl5dW4uY29tL2NoYXQpIikKICAgICAgICAgICAgICAgc2V0VGltZW91dChzZXRDc3JmVG9rZW4pCiAgICAgICAgICAgfQogICAgICAgfQoKICAgICAgIGxldCBzZW5kRGF0YSA9IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAiYWN0aW9uIjogIm5leHQiLAogICAgICAgICAgICJtc2dJZCI6IGdlbmVyYXRlUmFuZG9tU3RyaW5nKDMyKSwKICAgICAgICAgICAicGFyZW50TXNnSWQiOiAiMCIsCiAgICAgICAgICAgImNvbnRlbnRzIjogWwogICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAiY29udGVudFR5cGUiOiAidGV4dCIsCiAgICAgICAgICAgICAgICAgICAiY29udGVudCI6IHlvdXJfcXVzCiAgICAgICAgICAgICAgIH0KICAgICAgICAgICBdLAogICAgICAgICAgICJ0aW1lb3V0IjogMTcsCiAgICAgICAgICAgIm9wZW5TZWFyY2giOiBmYWxzZSwKICAgICAgICAgICAic2Vzc2lvbklkIjogdG9uZ3lpX3Nlc3Npb25JZCwKICAgICAgICAgICAibW9kZWwiOiAiIgogICAgICAgfSkKICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICBtZXRob2Q6ICdQT1NUJywKICAgICAgICAgICB1cmw6ICdodHRwczovL3Rvbmd5aS5hbGl5dW4uY29tL3FpYW53ZW4vY29udmVyc2F0aW9uJywKICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL3Rvbmd5aS5hbGl5dW4uY29tIiwKICAgICAgICAgICAgICAgInJlZmVyZXIiOiJodHRwczovL3Rvbmd5aS5hbGl5dW4uY29tL2NoYXQiLAogICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAiYWNjZXB0IjogInRleHQvZXZlbnQtc3RyZWFtIiwKICAgICAgICAgICAgICAgIngteHNyZi10b2tlbiI6IGNzcmZUb2tlbgogICAgICAgICAgIH0sCiAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICBkYXRhOiBzZW5kRGF0YQogICAgICAgfSkudGhlbigoc3RyZWFtKT0+IHsKICAgICAgICAgICBsZXQgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpCiAgICAgICAgICAgbGV0IGFuc3dlcjsKICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coIj09PWRvbmU9PSIpCiAgICAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICBsZXQgcmVzcG9uc2VJdGVtID0gbmV3IFRleHREZWNvZGVyKCJ1dGYtOCIpLmRlY29kZSh2YWx1ZSkKICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZyhyZXNwb25zZUl0ZW0pCgogICAgICAgICAgICAgICByZXNwb25zZUl0ZW0uc3BsaXQoIlxuIikuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgIGxldCBjb250ZW50ID0gSlNPTi5wYXJzZShpdGVtLnJlcGxhY2UoL2RhdGE6IC9naSwiIikudHJpbSgpKS5jb250ZW50WzBdOwogICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGNvbnRlbnQpCiAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihjb250ZW50KQogICAgICAgICAgICAgICAgICAgfWNhdGNoIChleCl7fQogICAgICAgICAgICAgICB9KQoKICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCkKICAgICAgICAgICB9LGZ1bmN0aW9uIChyZWFzb24pIHsKICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVhc29uKQogICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgICAgfSkKICAgICAgIH0pCgoKICB9CgoKCgogICAgLy/mmJ/ngavnm7jlhbM9PT09c3RhcnQ9PT09PQogICAgbGV0IHNwX2FwcElkOwogICAgbGV0IHNwX2ZkID0gU3RyaW5nKCtuZXcgRGF0ZSgpKS5zbGljZSgtNik7Ly9hID0gKGEgPSBTdHJpbmcoK25ldyBEYXRlKSkuc3Vic3RyaW5nKGEubGVuZ3RoIC0gNikKICAgIGxldCBzcF9jaGF0SWQ7CiAgICBsZXQgc3BfR3RUb2tlbjsKCiAgICBhc3luYyBmdW5jdGlvbiBpbml0X3NwX2FwcElkKCkgewogICAgICAgIC8vZ2V0IGh0dHBzOi8veGluZ2h1by54Znl1bi5jbi9jaGF0CiAgICAgICAgLy9zY3JpcHQgZGVmZXI9ImRlZmVyIiBzcmM9Ii9zdGF0aWMvanMvbWFpbi4wNGYzZWMzNi5qcyI+PC9zY3JpcHQ+CiAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8veGluZ2h1by54Znl1bi5jbi9jaGF0IiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIm9yaWdpbiI6Imh0dHBzOi8veGluZ2h1by54Znl1bi5jbiIsCiAgICAgICAgICAgICAgICAicmVmZXJlciI6Imh0dHBzOi8veGluZ2h1by54Znl1bi5jbi8iCiAgICAgICAgICAgIH0KICAgICAgICB9KQogICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgLy9jb25zb2xlLmxvZyhyKTsKICAgICAgICBsZXQgbWFpbmpzOwoKICAgICAgICB0cnl7CgogICAgICAgICAgICBtYWluanMgPSAvc3JjPSIoXC9zdGF0aWNcL2pzXC9tYWluLio/LmpzKSIvLmV4ZWMocilbMV07Ly9odHRwczovL3hpbmdodW8ueGZ5dW4uY24vc3RhdGljL2pzL21haW4uMDRmM2VjMzYuanMKICAgICAgICAgICAgY29uc29sZS5sb2coIm1haW5qczoiLG1haW5qcykKICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihyKQogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCLlh7rplJnkuobvvIxqc+iOt+WPluWksei0pSIpCiAgICAgICAgfQoKICAgICAgICBpZihtYWluanMpewogICAgICAgICAgICBjb25zb2xlLmxvZygiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuIisgbWFpbmpzLnRyaW0oKSkKICAgICAgICAgICAgbGV0IHJlcTIgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuIisgbWFpbmpzLnRyaW0oKSwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuIiwKICAgICAgICAgICAgICAgICAgICAicmVmZXJlciI6Imh0dHBzOi8veGluZ2h1by54Znl1bi5jbi8iCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pCiAgICAgICAgICAgIGxldCByciA9IHJlcTIucmVzcG9uc2VUZXh0OwoKICAgICAgICAgICAgY29uc29sZS5sb2cocnIuc3Vic3RyaW5nKDAsMTAwKSkKICAgICAgICAgICAgdHJ5ewogICAgICAgICAgICAgICAgY29uc3QgcmUgPSAvYXBwSWQ6IiguKj8pIi9naTsKICAgICAgICAgICAgICAgIGxldCBtYXRjaDsKICAgICAgICAgICAgICAgIHdoaWxlICgobWF0Y2ggPSByZS5leGVjKHJyKSkgIT09IG51bGwpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhtYXRjaFsxXSk7CiAgICAgICAgICAgICAgICAgICAgc3BfYXBwSWQgPSBtYXRjaFsxXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIC8qbGV0IGluZGV4ID0gcnIuaW5kZXhPZigiYXBwSWQiKTsKICAgICAgICAgICAgICAgIGlmIChpbmRleCAhPT0gLTEpIHsKICAgICAgICAgICAgICAgICAgICBsZXQgc3BfYXBwSWQgPSByci5zdWJzdHJpbmcoaW5kZXgsIGluZGV4ICsgMTApOyAvLyDmjIflrprmlofmnKwKICAgICAgICAgICAgICAgIH0qLwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coInNwX2FwcElkOiIsc3BfYXBwSWQpCiAgICAgICAgICAgIH1jYXRjaCAoZSkgewogICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi5Ye66ZSZ5LqGLHNwX2FwcElk6I635Y+W5aSx6LSlIiwpCiAgICAgICAgICAgIH0KICAgICAgICB9CgoKICAgIH0KCiAgICBzZXRUaW1lb3V0KCgpPT57CiAgICAgICAgaWYoZ2V0R1BUTW9kZSgpPT09IlNQQVJLIil7CiAgICAgICAgICAgIGluaXRfc3BfYXBwSWQoKQogICAgICAgIH0KICAgIH0pCiAgICBhc3luYyBmdW5jdGlvbiBpbml0X3NwX2NoYXRJZCgpIHsKICAgICAgICAvL2h0dHBzOi8veGluZ2h1by54Znl1bi5jbi9pZmx5Z3B0L3UvY2hhdC1saXN0L3YxL2NyZWF0ZS1jaGF0LWxpc3QKICAgICAgICBsZXQgcmVxMSA9IGF3YWl0IEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8veGluZ2h1by54Znl1bi5jbi9pZmx5Z3B0L3UvY2hhdC1saXN0L3YxL2NyZWF0ZS1jaGF0LWxpc3QiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiYWNjZXB0IjogImFwcGxpY2F0aW9uL2pzb24sIHRleHQvcGxhaW4sICovKiIsCiAgICAgICAgICAgICAgICAieC1yZXF1ZXN0ZWQtd2l0aCI6ICJYTUxIdHRwUmVxdWVzdCIsCiAgICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuIiwKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJyZWZlcmVyIjoiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuL2Rlc2siCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6Int9IgogICAgICAgIH0pCiAgICAgICAgbGV0IHIgPSByZXExLnJlc3BvbnNlVGV4dDsKICAgICAgICB0cnl7CiAgICAgICAgICAgIHNwX2NoYXRJZCA9IEpTT04ucGFyc2UocikuZGF0YS5pZDsKICAgICAgICAgICAgY29uc29sZS5sb2coInNwX2NoYXRJZDoiLHNwX2NoYXRJZCkKICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihyKQogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJzcF9jaGF0SWTojrflj5blpLHotKUiKQogICAgICAgIH0KCgoKICAgIH0KCiAgICBzZXRUaW1lb3V0KCgpPT57CiAgICAgICAgaWYoZ2V0R1BUTW9kZSgpPT09IlNQQVJLIil7CiAgICAgICAgICAgIGluaXRfc3BfY2hhdElkKCkKICAgICAgICB9CiAgICB9LDUwMCkKCiAgICBhc3luYyBmdW5jdGlvbiBnZXRfc3BfR3RUb2tlbigpIHsKICAgICAgICByZXR1cm4gbmV3IFByb21pc2UoYXN5bmMgKHJlc29sdmUsIHJlamVjdCkgPT4gewoKICAgICAgICAgICAgLy9odHRwczovL3Jpc2tjdC5nZWV0ZXN0LmNvbS9nMi9hcGkvdjEvcHJlX2xvYWQ/Y2xpZW50X3R5cGU9aDUmY2FsbGJhY2s9Z2VldGVzdF/ml7bpl7TmiLMKICAgICAgICAgICAgbGV0IHRpbWVzdGFtcCA9IERhdGUubm93KCk7CiAgICAgICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgICAgIHVybDogYGh0dHBzOi8vcmlza2N0LmdlZXRlc3QuY29tL2cyL2FwaS92MS9wcmVfbG9hZD9jbGllbnRfdHlwZT1oNSZjYWxsYmFjaz1nZWV0ZXN0XyR7dGltZXN0YW1wfWAsCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICIqLyoiLAogICAgICAgICAgICAgICAgICAgICJyZWZlcmVyIjogImh0dHBzOi8veGluZ2h1by54Znl1bi5jbi8iCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pCiAgICAgICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKHIpOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGV0IHJyID0gci5yZXBsYWNlKGBnZWV0ZXN0XyR7dGltZXN0YW1wfShgLAogICAgICAgICAgICAgICAgICAgICIiKTsKICAgICAgICAgICAgICAgIHJyID0gcnIuc3Vic3RyaW5nKDAsIHJyLmxlbmd0aCAtIDEpCiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygicnIiLCBycikKICAgICAgICAgICAgICAgIGxldCByaiA9IEpTT04ucGFyc2UocnIpOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coInJqOiIpOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmopOwoKICAgICAgICAgICAgICAgIC8vPT09PQogICAgICAgICAgICAgICAgbGV0IGNvbmZpZyA9IHsKICAgICAgICAgICAgICAgICAgICBhcHBJZDogc3BfYXBwSWQsCiAgICAgICAgICAgICAgICAgICAganM6IHJqLmRhdGEuanMsCiAgICAgICAgICAgICAgICAgICAgc3RhdGljUGF0aDogcmouZGF0YS5zdGF0aWNQYXRoLAogICAgICAgICAgICAgICAgICAgIGdUb2tlbjogcmouZGF0YS5nVG9rZW4KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJjb25maWciKQogICAgICAgICAgICAgICAgY29uc29sZS5sb2coY29uZmlnKQogICAgICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgaW5pdEdlZUd1YXJkKGNvbmZpZywgKGdkKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGdkKQogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZ2QuZGF0YS5nZWVfdG9rZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNwX0d0VG9rZW4gPSBnZC5kYXRhLmdlZV90b2tlbjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc29sdmUoc3BfR3RUb2tlbikKICAgICAgICAgICAgICAgICAgICAgICAgfWVsc2V7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWplY3QoIuWHuumUmSIpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICAgICAgfSwgNTAwKQoKCiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZSkKICAgICAgICAgICAgICAgIHNldFRpbWVvdXQoaW5pdF9zcF9jaGF0SWQpCiAgICAgICAgICAgICAgICByZWplY3QoIuWHuumUmSIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCgogICAgLy/op6PnoIEKICAgIGZ1bmN0aW9uIGRlY29kZVNwYXJrKHNyYykgewogICAgICAgLypsZXQgcnYgPSBmdW5jdGlvbihlKSB7CiAgICAgICAgICAgIHJldHVybiBlLnJlcGxhY2UoL1teQS1aYS16MC05XCtcL10vZywgIiIpCiAgICAgICAgfSovCgogICAgICAgIGxldCBkdiA9ICBmdW5jdGlvbihlKSB7CiAgICAgICAgICAgICAgICAvL3JldHVybiBCdWZmZXIuZnJvbShlLCAiYmFzZTY0IikudG9TdHJpbmcoInV0ZjgiKQogICAgICAgICAgICAvLyDlsIYgYmFzZTY0IOe8lueggeeahOWtl+espuS4sui9rOaNouS4uuWtl+iKguaVsOe7hAogICAgICAgICAgICBjb25zdCBieXRlcyA9IENyeXB0b0pTLmVuYy5CYXNlNjQucGFyc2UoZSk7CiAgICAgICAgICAgIC8vIOWwhuWtl+iKguaVsOe7hOi9rOaNouS4uiBVVEYtOCDlrZfnrKbkuLIKICAgICAgICAgICAgcmV0dXJuIGJ5dGVzLnRvU3RyaW5nKENyeXB0b0pTLmVuYy5VdGY4KTsKICAgICAgICB9Ly/nrYnku7dCQVNFNjTop6PnoIEgNkthQgoKICAgICAgICAgLypsZXQgIGZ2ID0gZnVuY3Rpb24oZSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGR2KGZ1bmN0aW9uKGUpIHsKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcnYoZS5yZXBsYWNlKC9bLV9dL2csIChmdW5jdGlvbihlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gIi0iID09IGUgPyAiKyIgOiAiLyIKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICkpKQogICAgICAgICAgICAgICAgfShlKSkKICAgICAgICAgfTsqLwogICAgICAgcmV0dXJuIGR2KHNyYyk7CiAgICB9CgoKCiAgICBsZXQgc3BhcmtfZmlyc3QgPSB0cnVlOwogICAgYXN5bmMgZnVuY3Rpb24gU1BBUksoKXsKICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCLor7fnqI3lkI4s56ys5LiA5qyh5YiH5o2i5Yiw6K+l57q/6Lev6ZyA6KaB5Yi35paw6aG16Z2i77yM6K+l57q/6Lev5Li65a6Y572R57q/6LevLOS9v+eUqOWJjeehruS/neW3sue7j+eZu+W9lVvorq/po57mmJ/ngatdKGh0dHBzOi8veGluZ2h1by54Znl1bi5jbi8pIikKICAgICAgICBhd2FpdCBnZXRfc3BfR3RUb2tlbigpCiAgICAgICAgY29uc29sZS5sb2coInNwX0d0VG9rZW4iLHNwX0d0VG9rZW4pCiAgICAgICAgLy/ph43lkb3lkI0KICAgICAgICBpZihzcGFya19maXJzdCl7CiAgICAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8veGluZ2h1by54Znl1bi5jbi9pZmx5Z3B0L3UvY2hhdC1saXN0L3YxL3JlbmFtZS1jaGF0LWxpc3QiLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICAgICAieC1yZXF1ZXN0ZWQtd2l0aCI6ICJYTUxIdHRwUmVxdWVzdCIsCiAgICAgICAgICAgICAgICAgICAgIm9yaWdpbiI6Imh0dHBzOi8veGluZ2h1by54Znl1bi5jbiIsCiAgICAgICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgICAgICJyZWZlcmVyIjoiaHR0cHM6Ly94aW5naHVvLnhmeXVuLmNuL2Rlc2siCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgZGF0YTpKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICAgICAgImNoYXRMaXN0SWQiOiBzcF9jaGF0SWQsCiAgICAgICAgICAgICAgICAgICAgImNoYXRMaXN0TmFtZSI6IHlvdXJfcXVzLnN1YnN0cmluZygwLDEwKQogICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgfSkKICAgICAgICAgICAgbGV0IHIgPSByZXExLnJlc3BvbnNlVGV4dDsKICAgICAgICAgICAgY29uc29sZS5sb2coInJlbmFtZSBjaGF0OiIscikKICAgICAgICAgICAgc3BhcmtfZmlyc3QgPSBmYWxzZTsKICAgICAgICB9CgogICAgICAgIC8v5o+Q6ZeuCgogICAgICAgIGxldCBzZW5kRGF0YSA9IGAtLS0tLS1XZWJLaXRGb3JtQm91bmRhcnlBUzd0U3Izb3NKbmc1TnhrXHJcbkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT1cImZkXCJcclxuXHJcbiR7c3BfZmR9XHJcbi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeUFTN3RTcjNvc0puZzVOeGtcclxuQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPVwiY2xpZW50VHlwZVwiXHJcblxyXG4yXHJcbi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeUFTN3RTc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AgICAgICAgICJvcmlnaW4iOiJodHRwczovL3hpbmdodW8ueGZ5dW4uY24iLAogICAgICAgICAgICAgICAgInJlZmVyZXIiOiJodHRwczovL3hpbmdodW8ueGZ5dW4uY24vZGVzayIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgZGF0YTogc2VuZERhdGEKICAgICAgICB9KS50aGVuKChzdHJlYW0pPT4gewogICAgICAgICAgICBsZXQgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpCiAgICAgICAgICAgIGxldCBhbnMgPSBbXQogICAgICAgICAgICAvL2xldCBkZSA9IFtdCiAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCI9PT1kb25lPT0iKQogICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coZGUpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgcmVzcG9uc2VJdGVtID0gbmV3IFRleHREZWNvZGVyKCJ1dGYtOCIpLmRlY29kZSh2YWx1ZSkKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlc3BvbnNlSXRlbSkKCiAgICAgICAgICAgICAgICByZXNwb25zZUl0ZW0uc3BsaXQoIlxuIikuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGlpID0gaXRlbS5yZXBsYWNlKC9kYXRhOi9naSwiIikudHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZihpaSAmJiBpaSAhPT0iIil7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2h1bmsgPSBkZWNvZGVTcGFyayhpaSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8vZGUucHVzaChpdGVtLnJlcGxhY2UoL2RhdGE6L2dpLCIiKS50cmltKCkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhbnMucHVzaChjaHVuaykKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoYW5zLmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChleCl7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoaXRlbSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpCiAgICAgICAgICAgIH0sZnVuY3Rpb24gKHJlYXNvbikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVhc29uKQogICAgICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgfSkKICAgICAgICB9KQoKCiAgICB9CgogICAgLy/mmJ/ngavnm7jlhbM9PT09ZW5kPT09PT0KCgoKICAgIC8v5aSp5belIC0tLS1zdGFydC0tLS0tLS0tCgogICAgbGV0IHRnX2ludml0ZV9Ub2tlbjsKICAgIGxldCB0Z190b2tlbjsKICAgIGFzeW5jIGZ1bmN0aW9uIGluaXRUR3Rva2VuKCkgewogICAgICAgIGlmIChsb2NhdGlvbi5ocmVmLmluY2x1ZGVzKCJuZWljZS50aWFuZ29uZy5jbiIpKSB7CiAgICAgICAgICAgIC8vImludml0ZS10b2tlbiI6ICJCZWFyZXIgIiArIGMoImZvcm1OYXR1cmVRdWV1ZVdhaXRUb2tlbiIpLAogICAgICAgICAgICB0Z19pbnZpdGVfVG9rZW4gPSBs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OiLlvZPliY3kvb/nlKjmjojmnYPlt7LlpLHmlYjvvIzor7fph43mlrDmjpLpmJ8ifQogICAgLy9yZXNwX2RhdGEuaW52aXRlX3Rva2VuCiAgICBhc3luYyBmdW5jdGlvbiB3YWl0QWNjZXNzKCkgewogICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9hcGkvdjEvcXVldWUvd2FpdEFjY2VzcyIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuIiwKICAgICAgICAgICAgICAgICJpbnZpdGUtdG9rZW4iOiBgQmVhcmVyIG51bGxgLAogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgInRva2VuIjogYEJlYXJlciAke3RnX3Rva2VufWAsCiAgICAgICAgICAgICAgICAiZGV2aWNlIjogIldlYiIsCiAgICAgICAgICAgICAgICAicmVmZXJlciI6Imh0dHBzOi8vbmVpY2UudGlhbmdvbmcuY24vaW50ZXJsb2N1dGlvblBhZ2UiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6SlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgZGF0YTp7CiAgICAgICAgICAgICAgICAgICAgdG9rZW46ICIiCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pCiAgICAgICAgfSkKICAgICAgICBsZXQgciA9IHJlcTEucmVzcG9uc2VUZXh0OwogICAgICAgIGNvbnNvbGUubG9nKHIpCiAgICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIHRnX2ludml0ZV9Ub2tlbiA9IEpTT04ucGFyc2UocikucmVzcF9kYXRhLmludml0ZV90b2tlbjsKICAgICAgICAgICAgICAgIEdNX3NldFZhbHVlKCJ3YWl0QWNjZXNzIHRnX2ludml0ZV9Ub2tlbiIsdGdfaW52aXRlX1Rva2VuKQogICAgICAgICAgICAgICAgcmVzb2x2ZSgi5pu05paw5oiQ5Yqf77yM6K+35YaN5qyh54K55Ye7IikKICAgICAgICAgICAgfWNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKCJ3YWl0QWNjZXNzIOW8guW4uCDor7fliLDlrpjnvZHojrflj5Z0b2tlbuWQjuWIt+aWsOmhtemdouOAglvlpKnlt6VBSV0oaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9pbnRlcmxvY3V0aW9uUGFnZSkiKQogICAgICAgICAgICB9CiAgICAgICAgfSkKICAgIH0KCgogICAgbGV0IHRnX3Nlc3Npb25faWQ7CiAgICBsZXQgdGdfbXNnX2lkOwogICAgbGV0IHRnX2ZpcnN0ID0gdHJ1ZTsKICAgIGFzeW5jIGZ1bmN0aW9uIFRJQU5HT05HKCl7CiAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6K+356iN5ZCOLi4u5L2/55So6K+l57q/6Lev77yM6K+356Gu5L+d5bey57uP55m75aSp5bel5a6Y572R6I635Y+WdG9rZW7lkI7liLfmlrDpobXpnaLjgIJb5aSp5belQUldKGh0dHBzOi8vbmVpY2UudGlhbmdvbmcuY24vaW50ZXJsb2N1dGlvblBhZ2UpIikKICAgICAgICBjb25zb2xlLmxvZygidGdfdG9rZW46Iix0Z190b2tlbikKICAgICAgICBjb25zb2xlLmxvZygidGdfaW52aXRlX1Rva2VuOiIsdGdfaW52aXRlX1Rva2VuKQogICAgICAgIGlmKCF0Z19pbnZpdGVfVG9rZW4gfHwgIXRnX3Rva2VuKXsKICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigidG9rZW7plJnor6/kuobjgILor7fnoa7kv53lt7Lnu4/nmbvlpKnlt6XlrpjnvZHojrflj5Z0b2tlbuWQjuWIt+aWsOmhtemdouOAglvlpKnlt6VBSV0oaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9pbnRlcmxvY3V0aW9uUGFnZSkiKQogICAgICAgICAgICByZXR1cm4KICAgICAgICB9CgogICAgICAgIC8v5qCh6aqMCiAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL25laWNlLnRpYW5nb25nLmNuL2FwaS92MS91c2VyL2ludml0ZVZlcmlmeSIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuIiwKICAgICAgICAgICAgICAgICJpbnZpdGUtdG9rZW4iOiBgQmVhcmVyICR7dGdfaW52aXRlX1Rva2VufWAsCiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAidG9rZW4iOiBgQmVhcmVyICR7dGdfdG9rZW59YCwKICAgICAgICAgICAgICAgICJkZXZpY2UiOiAiV2ViIiwKICAgICAgICAgICAgICAgICJyZWZlcmVyIjoiaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9pbnRlcmxvY3V0aW9uUGFnZSIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTpKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBkYXRhOnt9CiAgICAgICAgICAgIH0pCiAgICAgICAgfSkKICAgICAgICBsZXQgciA9IHJlcTEucmVzcG9uc2VUZXh0OwogICAgICAgIGNvbnNvbGUubG9nKHIpCiAgICAgICAgaWYoci5pbmNsdWRlcygi6K+36YeN5paw5o6S6ZifIikpewogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJpbnZpdGVfVG9rZW7lpLHmlYjjgILor7foh7PlrpjnvZHojrflj5Z0b2tlbuWQjuWIt+aWsOmhtemdouOAglvlpKnlt6VBSV0oaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9pbnRlcmxvY3V0aW9uUGFnZSkiKQovKiAgICAgICAgICAgIGxldCByZXN1bHQgPSBhd2FpdCB3YWl0QWNjZXNzKCk7CiAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0KSovCiAgICAgICAgICAgIGF3YWl0IGluaXRUR3Rva2VuKCkKICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgfQoKICAgICAgICAvL+aWsOS8muivnQogICAgICAgIGlmKCF0Z19zZXNzaW9uX2lkIHx8IHRnX2ZpcnN0KXsKICAgICAgICAgICAgY29uc29sZS5sb2coIuaWsOS8muivnSIpCiAgICAgICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgICAgICB1cmw6ICJodHRwczovL25laWNlLnRpYW5nb25nLmNuL2FwaS92MS9zZXNzaW9uL25ld1Nlc3Npb24iLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbiIsCiAgICAgICAgICAgICAgICAgICAgImludml0ZS10b2tlbiI6IGBCZWFyZXIgJHt0Z19pbnZpdGVfVG9rZW59YCwKICAgICAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjoiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgInRva2VuIjogYEJlYXJlciAke3RnX3Rva2VufWAsCiAgICAgICAgICAgICAgICAgICAgImRldmljZSI6ICJXZWIiLAogICAgICAgICAgICAgICAgICAgICJyZWZlcmVyIjoiaHR0cHM6Ly9uZWljZS50aWFuZ29uZy5jbi9pbnRlcmxvY3V0aW9uUGFnZSIKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICBkYXRhOkpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICBkYXRhOnsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudDogeW91cl9xdXMKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICB9KQogICAgICAgICAgICBsZXQgciA9IHJlcTEucmVzcG9uc2VUZXh0OwogICAgICAgICAgICBjb25zb2xlLmxvZyhyKQogICAgICAgICAgICBsZXQgcmogPSBKU09OLnBhcnNlKHIpOwogICAgICAgICAgICB0Z19zZXNzaW9uX2lkID0gcmoucmVzcF9kYXRhLnNlc3Npb25faWQKICAgICAgICAgICAgdGdfbXNnX2lkID0gcmoucmVzcF9kYXRhLmRpYWxvZ3VlW3JqLnJlc3BfZGF0YS5kaWFsb2d1ZS5sZW5ndGggLSAxXS5tZXNzYWdlX2lkCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJ0Z19zZXNzaW9uX2lkOiIsdGdfc2Vzc2lvbl9pZCkKICAgICAgICAgICAgY29uc29sZS5sb2coInRnX21zZ19pZGc6Iix0Z19tc2dfaWQpCiAgICAgICAgICAgIHRnX2ZpcnN0ID0gZmFsc2U7CiAgICAgICAgfWVsc2UgewogICAgICAgICAgICBjb25zb2xlLmxvZygi5pen5Lya6K+dIikKICAgICAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vbmVpY2UudGlhbmdvbmcuY24vYXBpL3YxL2NoYXQvY2hhdCIsCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiLAogICAgICAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuIiwKICAgICAgICAgICAgICAgICAgICAiaW52aXRlLXRva2VuIjogYEJlYXJlciAke3RnX2ludml0ZV9Ub2tlbn1gLAogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICAgICAidG9rZW4iOiBgQmVhcmVyICR7dGdfdG9rZW59YCwKICAgICAgICAgICAgICAgICAgICAiZGV2aWNlIjogIldlYiIsCiAgICAgICAgICAgICAgICAgICAgInJlZmVyZXIiOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuL2ludGVybG9jdXRpb25QYWdlIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6SlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgICAgIGRhdGE6ewogICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgICAgICAgICAgc2Vzc2lvbl9pZDogdGdfc2Vzc2lvbl9pZAogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH0pCiAgICAgICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKHIpCiAgICAgICAgICAgIGxldCByaiA9IEpTT04ucGFyc2Uocik7CiAgICAgICAgICAgIHRnX21zZ19pZCA9IHJqLnJlc3BfZGF0YS5yZXN1bHRfbWVzc2FnZS5tZXNzYWdlX2lkCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJ0Z19tc2dfaWRnOiIsdGdfbXNnX2lkKQogICAgICAgIH0KCgoKICAgICAgICAvL+iOt+WPluS/oeaBr+S/oeaBrwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgNjA7IGkrKykgewogICAgICAgICAgICBsZXQgcmVxMiA9IGF3YWl0IEdNX2ZldGNoKHsKICAgICAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICAgICAgdGltZW91dDogMzAwMCwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vbmVpY2UudGlhbmdvbmcuY24vYXBpL3YxL2NoYXQvZ2V0TWVzc2FnZSIsCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiLAogICAgICAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuIiwKICAgICAgICAgICAgICAgICAgICAiaW52aXRlLXRva2VuIjogYEJlYXJlciAke3RnX2ludml0ZV9Ub2tlbn1gLAogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICAgICAidG9rZW4iOiBgQmVhcmVyICR7dGdfdG9rZW59YCwKICAgICAgICAgICAgICAgICAgICAiZGV2aWNlIjogIldlYiIsCiAgICAgICAgICAgICAgICAgICAgInJlZmVyZXIiOiJodHRwczovL25laWNlLnRpYW5nb25nLmNuL2ludGVybG9jdXRpb25QYWdlIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6SlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgICAgICJkYXRhIjogewogICAgICAgICAgICAgICAgICAgICAgICAibWVzc2FnZV9pZCI6IHRnX21zZ19pZAogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH0pCiAgICAgICAgICAgIGxldCByciA9IHJlcTIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICBjb25zb2xlLmxvZyhycikKICAgICAgICAgICAgbGV0IHJqID0gSlNPTi5wYXJzZShycik7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBpZihyai5yZXNwX2RhdGEucmVzdWx0X21lc3NhZ2UuY29udGVudCl7CiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyai5yZXNwX2RhdGEucmVzdWx0X21lc3NhZ2UuY29udGVudCkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKHJqLnJlc3BfZGF0YS5yZXN1bHRfbWVzc2FnZS5zdGF0dXMgPT09IDMpewogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgfWNhdGNoIChlKSB7fQogICAgICAgICAgICBhd2FpdCBkZWxheSgxMDAwKQoKICAgICAgICB9CgoKICAgIH0KCgogICAgLy/lpKnlt6UgLS0tLWVuZC0tLS0tLS0tCgoKCiAgICAvL+mXruW/g+S4gOiogCAtLS0tc3RhcnQtLS0KCiAgICBsZXQgeXlfYWlzZWFyY2hfaWQ7CiAgICBsZXQgeXlfcHZJZDsKICAgIGxldCB5eV9zZXNzaW9uSWQ7CgogICAgYXN5bmMgZnVuY3Rpb24gaW5pdFlpWUFOKCl7CiAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgIHVybDogYGh0dHBzOi8vY2hhdC5iYWlkdS5jb20vP3BjYXN5bmM9cGMmYXN5bmNSZW5kZXJVcmw9JnBhc3Nwb3J0U3RhdGljUGFnZT1odHRwcyUzQSUyRiUyRnd3dy5iYWlkdS5jb20lMkZjYWNoZSUyRnVzZXIlMkZodG1sJTJGdjNKdW1wLmh0bWwmZnJvbT1wY190YWImd29yZD0ke2VuY29kZVVSSSh5b3VyX3F1cyl9JnNvdXJjZT1wZF9pY2AsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiKi8qIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiJodHRwczovL3d3dy5iYWlkdS5jb20iLAogICAgICAgICAgICAgICAgInJlZmVyZXIiOmBodHRwczovL3d3dy5iYWlkdS5jb20vYAogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOkpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIGRhdGE6e30KICAgICAgICAgICAgfSkKICAgICAgICB9KQogICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgeXlfYWlzZWFyY2hfaWQgPSAgLyJhaXNlYXJjaF9pZCI6IiguKj8pIi9pLmV4ZWMocilbMV07CiAgICAgICAgeXlfcHZJZCA9ICAvInB2SWQiOiIoLio/KSIvaS5leGVjKHIpWzFdOwogICAgICAgIHl5X3Nlc3Npb25JZCA9ICAvInNlc3Npb25JZCI6IiguKj8pIi9pLmV4ZWMocilbMV07CiAgICAgICAgY29uc29sZS5sb2coInl5X2Fpc2VhcmNoX2lkOiIseXlfYWlzZWFyY2hfaWQpCiAgICAgICAgY29uc29sZS5sb2coInl5X3B2SWQ6Iix5eV9wdklkKQogICAgICAgIGNvbnNvbGUubG9nKCJ5eV9zZXNzaW9uSWQ6Iix5eV9zZXNzaW9uSWQpCiAgICB9CiAgICBzZXRUaW1lb3V0KCgpPT57CiAgICAgICAgaWYoZ2V0R1BUTW9kZSgpID09PSAnWUlZQU4nKXsKICAgICAgICAgICAgaW5pdFlpWUFOKCkKICAgICAgICB9CiAgICB9KQogICAgYXN5bmMgZnVuY3Rpb24gWUlZQU4oKSB7CiAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6K+356iN5ZCOLi4u6K+l57q/6Lev5Li65a6Y572R57q/6Lev77yM5L2/55So6K+l57q/6Lev77yM6K+356Gu5L+d5bey57uP55m755m+5bqm6LSm5Y+377yM5YaN5Yi35paw6aG16Z2i44CCW+eZvuW6pl0oaHR0cHM6Ly93d3cuYmFpZHUuY29tLykiKQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAnUE9TVCcsCiAgICAgICAgICAgIHVybDogJ2h0dHBzOi8vY2hhdC13cy5iYWlkdS5jb20vYWljaGF0L2FwaS9jb252ZXJzYXRpb24nLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAib3JpZ2luIjoiaHR0cHM6Ly93d3cuYmFpZHUuY29tIiwKICAgICAgICAgICAgICAgICJyZWZlcmVyIjpgaHR0cHM6Ly93d3cuYmFpZHUuY29tL2AsCiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJ0ZXh0L2V2ZW50LXN0cmVhbSIKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgIm1lc3NhZ2UiOiB7CiAgICAgICAgICAgICAgICAgICAgImlucHV0TWV0aG9kIjogImtleWJvYXJkIiwKICAgICAgICAgICAgICAgICAgICAiaXNSZWJ1aWxkIjogZmFsc2UsCiAgICAgICAgICAgICAgICAgICAgImNvbnRlbnQiOiB7CiAgICAgICAgICAgICAgICAgICAgICAgICJxdWVyeSI6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgICAgICAgICAicXR5cGUiOiAwCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICJzZXNzaW9uSWQiOiB5eV9zZXNzaW9uSWQsCiAgICAgICAgICAgICAgICAiYWlzZWFyY2hJZCI6IHl5X2Fpc2VhcmNoX2lkLAogICAgICAgICAgICAgICAgInB2SWQiOiB5eV9wdklkCiAgICAgICAgICAgIH0pCiAgICAgICAgfSkudGhlbigoc3RyZWFtKT0+IHsKICAgICAgICAgICAgbGV0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKQogICAgICAgICAgICBsZXQgYW5zID0gW10KICAgICAgICAgICAgbGV0IHByZVJlc3BvbnNlSXRlbSA9ICcnOy8v5YmN5LiA6K6w5b2VCiAgICAgICAgICAgIGxldCBjb21iaW5lSXRlbSA9IFtdOy8v5ZCI5bm2CiAgICAgICAgICAgIGxldCByZWZlcmVuY2VMaXN0Oy8v5byV55SoCiAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCI9PT1kb25lPT0iKQogICAgICAgICAgICAgICAgICAgIC8vY29uc29sZS5sb2coZGUpCiAgICAgICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IGFucy5qb2luKCIiKTsKICAgICAgICAgICAgICAgICAgICBsZXQgYXJyID0gcmVzdWx0Lm1hdGNoKC9cXiguKj8pXF4vZyk7CiAgICAgICAgICAgICAgICAgICAgbGV0IG9sZEFyciA9IGFyci5zbGljZSgpCiAgICAgICAgICAgICAgICAgICAgaWYocmVmZXJlbmNlTGlzdCAmJiByZWZlcmVuY2VMaXN0Lmxlbmd0aCA+IDApewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGFyci5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCByZWZlcmVuY2VMaXN0Lmxlbmd0aDsgaisrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYoYXJyW2ldLmluY2x1ZGVzKGBbJHtqKzF9XWApKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IHVybCA9IHJlZmVyZW5jZUxpc3Rbal0udXJsOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhcnJbaV0gPSBhcnJbaV0ucmVwbGFjZShgWyR7aisxfV1gLGBbJHtqKzF9XSgke3VybH0pYCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coImFycjoiLGFycikKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygib2xkQXJyOiIsb2xkQXJyKQogICAgICAgICAgICAgICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgb2xkQXJyLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdCA9ICByZXN1bHQucmVwbGFjZShvbGRBcnJbaV0sYXJyW2ldLnJlcGxhY2UoL1xeL2csIiIpKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdCkKCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZXQgcmVzcG9uc2VJdGVtID0gbmV3IFRleHREZWNvZGVyKCJ1dGYtOCIpLmRlY29kZSh2YWx1ZSkKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlc3BvbnNlSXRlbSkKICAgICAgICAgICAgICAgIGlmKCFyZXNwb25zZUl0ZW0uaW5jbHVkZXMoImV2ZW50OnBpbmciKSAmJiAhcmVzcG9uc2VJdGVtLnN0YXJ0c1dpdGgoImV2ZW50Om1lc3NhZyIpKXsKICAgICAgICAgICAgICAgICAgICBjb21iaW5lSXRlbS5wdXNoKHByZVJlc3BvbnNlSXRlbSkKICAgICAgICAgICAgICAgICAgICBjb21iaW5lSXRlbS5wdXNoKHJlc3BvbnNlSXRlbSkKICAgICAgICAgICAgICAgICAgICBwcmVSZXNwb25zZUl0ZW0gPSAnJzsvL+aBouWkjeWIneWniwogICAgICAgICAgICAgICAgICAgIHJlc3BvbnNlSXRlbSA9IGNvbWJpbmVJdGVtLmpvaW4oIiIpLy/lkIjlubYKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiY29tYmluZUl0ZW06IixyZXNwb25zZUl0ZW0pCiAgICAgICAgICAgICAgICAgICAgY29tYmluZUl0ZW0gPSBbXTsvL+a4heepugoKICAgICAgICAgICAgICAgIH1lbHNlIGlmKCFyZXNwb25zZUl0ZW0uaW5jbHVkZXMoImV2ZW50OnBpbmciKSl7CiAgICAgICAgICAgICAgICAgICAgcHJlUmVzcG9uc2VJdGVtID0gcmVzcG9uc2VJdGVtOwogICAgICAgICAgICAgICAgfQoKCiAgICAgICAgICAgICAgICByZXNwb25zZUl0ZW0uc3BsaXQoIlxuIikuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGlpID0gaXRlbS5yZXBsYWNlKC9kYXRhOi9naSwiIikudHJpbSgpOwogICAgICAgICAgICAgICAgICAgICAgICBpZihpaSAmJiBpaSAhPT0iIil7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgY2h1bmsgPSBKU09OLnBhcnNlKGlpKS5kYXRhLm1lc3NhZ2UuY29udGVudC5nZW5lcmF0b3IudGV4dAogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9kZS5wdXNoKGl0ZW0ucmVwbGFjZSgvZGF0YTovZ2ksIiIpLnRyaW0oKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFucy5wdXNoKGNodW5rKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihhbnMuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihKU09OLnBhcnNlKGlpKS5kYXRhLm1lc3NhZ2UuY29udGVudC5nZW5lcmF0b3IucmVmZXJlbmNlTGlzdCl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVmZXJlbmNlTGlzdCA9IEpTT04ucGFyc2UoaWkpLmRhdGEubWVzc2FnZS5jb250ZW50LmdlbmVyYXRvci5yZWZlcmVuY2VMaXN0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChleCl7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoaXRlbSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpCiAgICAgICAgICAgIH0sZnVuY3Rpb24gKHJlYXNvbikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2cocmVhc29uKQogICAgICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgfSkKICAgICAgICB9KQoKICAgIH0KICAgIC8v6Zeu5b+D5LiA6KiAIC0tLS1lbmQtLS0KCgoKICAgIC8vQ2hhdEdMTeebuOWFsyAtLS0tc3RhcnQtLS0tLQogICAgLy9odHRwczovL2NoYXRnbG0uY24KCiAgICBsZXQgY2hhdGdtbF90b2tlbjsKICAgIGZ1bmN0aW9uIGlua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KICAgICAgICBjb25zb2xlLmxvZygiY2hhdGdtbF90b2tlbjoiLGNoYXRnbWxfdG9rZW4pCiAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigi6K+356iN5ZCOLi4u6K+l57q/6Lev5Li65a6Y572R57q/6Lev77yM5L2/55So6K+l57q/6Lev77yM6K+356Gu5L+d5bey57uP55m75b2V5bm26I635Y+WdG9rZW7vvIzlho3liLfmlrDpobXpnaLjgIJbQ2hhdEdMTV0oaHR0cHM6Ly9jaGF0Z2xtLmNuLykiKQoKICAgICAgICBpZighY2hhdGdtbF90b2tlbil7CiAgICAgICAgICAgIHNldFRpbWVvdXQoaW5pdF9jaGF0Z21sX3Rva2VuKQogICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJpbml0X2NoYXRnbWxfdG9rZW7kuLrnqbrvvIzor7fnoa7kv53lt7Lnu4/nmbvlvZXlubbojrflj5Z0b2tlbu+8jOWGjeWIt+aWsOmhtemdouOAgltDaGF0R0xNXShodHRwczovL2NoYXRnbG0uY24vKSIpCiAgICAgICAgICAgIHJldHVybgogICAgICAgIH0KICAgICAgICBpZiAoY2hhdGdtbF9maXJzdCB8fCAhY2hhdGdtbF90YXNrX2lkKSB7CiAgICAgICAgICAgIGxldCByZXExID0gYXdhaXQgR01fZmV0Y2goewogICAgICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgICAgICB1cmw6IGBodHRwczovL2NoYXRnbG0uY24vY2hhdGdsbS9iYWNrZW5kLWFwaS92MS9jb252ZXJzYXRpb25gLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICAgICAiYXV0aG9yaXphdGlvbiI6IGBCZWFyZXIgJHtjaGF0Z21sX3Rva2VufWAsCiAgICAgICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL2NoYXRnbG0uY24iLAogICAgICAgICAgICAgICAgICAgICJjb250ZW50LXR5cGUiOiAiYXBwbGljYXRpb24vanNvbjtjaGFyc2V0PVVURi04IiwKICAgICAgICAgICAgICAgICAgICAicmVmZXJlciI6IGBodHRwczovL2NoYXRnbG0uY24vZGV0YWlsYAogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICAicHJvbXB0IjogeW91cl9xdXMKICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgIH0pCiAgICAgICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgIGxldCBqc29uT2JqID0gSlNPTi5wYXJzZShyKTsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIGNoYXRnbWxfdGFza19pZCA9IGpzb25PYmoucmVzdWx0LnRhc2tfaWQ7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiY2hhdGdtbF90YXNrX2lkOiIsY2hhdGdtbF90YXNrX2lkKQogICAgICAgICAgICAgICAgY2hhdGdtbF9maXJzdCA9IGZhbHNlOwogICAgICAgICAgICB9Y2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoInRhc2tfaWTlh7rplJnkuobvvIzor7fnoa7kv53lt7Lnu4/nmbvlvZXlubbojrflj5Z0b2tlbu+8jOWGjeWIt+aWsOmhtemdouOAgltDaGF0R0xNXShodHRwczovL2NoYXRnbG0uY24vKSIpCiAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgbGV0IHJlcTEgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6IGBodHRwczovL2NoYXRnbG0uY24vY2hhdGdsbS9iYWNrZW5kLWFwaS92MS9zdHJlYW1fY29udGV4dGAsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIiwKICAgICAgICAgICAgICAgICJhdXRob3JpemF0aW9uIjogYEJlYXJlciAke2NoYXRnbWxfdG9rZW59YCwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9jaGF0Z2xtLmNuIiwKICAgICAgICAgICAgICAgICJjb250ZW50LXR5cGUiOiAiYXBwbGljYXRpb24vanNvbjtjaGFyc2V0PVVURi04IiwKICAgICAgICAgICAgICAgICJyZWZlcmVyIjogYGh0dHBzOi8vY2hhdGdsbS5jbi9kZXRhaWxgCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICJwcm9tcHQiOiB5b3VyX3F1cywKICAgICAgICAgICAgICAgICJzZWVkIjogNjk4MDksCiAgICAgICAgICAgICAgICAibWF4X3Rva2VucyI6IDUxMiwKICAgICAgICAgICAgICAgICJjb252ZXJzYXRpb25fdGFza19pZCI6IGNoYXRnbWxfdGFza19pZCwKICAgICAgICAgICAgICAgICJyZXRyeSI6IGZhbHNlLAogICAgICAgICAgICAgICAgInJldHJ5X2hpc3RvcnlfdGFza19pZCI6IG51bGwKICAgICAgICAgICAgfSkKICAgICAgICB9KQogICAgICAgIGxldCByID0gcmVxMS5yZXNwb25zZVRleHQ7CiAgICAgICAgbGV0IGpzb25PYmogPSBKU09OLnBhcnNlKHIpOwogICAgICAgIHRyeSB7CiAgICAgICAgICAgIGNoYXRnbWxfY29udGV4dF9pZCA9IGpzb25PYmoucmVzdWx0LmNvbnRleHRfaWQ7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKCJjaGF0Z21sX2NvbnRleHRfaWQ6IixjaGF0Z21sX3Rhc2tfaWQpCiAgICAgICAgfWNhdGNoIChlKSB7CiAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoImNvbnRleHRfaWTlh7rplJnkuobvvIzor7fnoa7kv53lt7Lnu4/nmbvlvZXlubbojrflj5Z0b2tlbu+8jOWGjeWIt+aWsOmhtemdouOAgltDaGF0R0xNXShodHRwczovL2NoYXRnbG0uY24vKSIpCiAgICAgICAgICAgIHJldHVybgogICAgICAgIH0KCgogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgdXJsOiBgaHR0cHM6Ly9jaGF0Z2xtLmNuL2NoYXRnbG0vYmFja2VuZC1hcGkvdjEvc3RyZWFtP2NvbnRleHRfaWQ9JHtjaGF0Z21sX2NvbnRleHRfaWR9YCwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJ0ZXh0L2V2ZW50LXN0cmVhbSIsCiAgICAgICAgICAgICAgICAib3JpZ2luIjogImh0dHBzOi8vY2hhdGdsbS5jbiIsCiAgICAgICAgICAgICAgICAicmVmZXJlciI6IGBodHRwczovL2NoYXRnbG0uY24vZGV0YWlsYAogICAgICAgICAgICB9LAogICAgICAgICAgICByZXNwb25zZVR5cGU6InN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pPT4gewogICAgICAgICAgICBsZXQgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpCgogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICByZXR1cm4KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGxldCByZXNwb25zZUl0ZW0gPSBuZXcgVGV4dERlY29kZXIoInV0Zi04IikuZGVjb2RlKHZhbHVlKQogICAgICAgICAgICAgICAvLyBjb25zb2xlLmVycm9yKHJlc3BvbnNlSXRlbSkKICAgICAgICAgICAgICAgIHJlc3BvbnNlSXRlbSA9IHJlc3BvbnNlSXRlbS5zcGxpdCgiXG5cbiIpOwogICAgICAgICAgICAgICAgY29uc29sZS53YXJuKHJlc3BvbnNlSXRlbSkKICAgICAgICAgICAgICAgIHJlc3BvbnNlSXRlbS5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBpZihpdGVtICYmIGl0ZW0uc3RhcnRzV2l0aCgiZXZlbnQ6YWRkIikgfHwgaXRlbS5zdGFydHNXaXRoKCJldmVudDpmaW5pc2giKSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgaWkgPSAgIGl0ZW0ucmVwbGFjZSgvZGF0YTovZ2ksIiIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnJlcGxhY2UoL2V2ZW50OmFkZC9naSwiIikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAucmVwbGFjZSgvZXZlbnQ6ZmluaXNoL2dpLCIiKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihpaSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihpaSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB9Y2F0Y2ggKGV4KXsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihpdGVtKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0pCgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCkKICAgICAgICAgICAgfSxmdW5jdGlvbiAocmVhc29uKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgICAgICB9KQogICAgICAgIH0pCgoKICAgIH0KCgogICAgLy9DaGF0R0xN55u45YWzIC0tLS1zdGFydC0tLS0tCgogICAgbGV0IHBpenphU2VjcmV0OwogICAgYXN5bmMgZnVuY3Rpb24gc2V0UGl6emFrZXkoKSB7CiAgICAgICAgdHJ5IHsKCiAgICAgICAgICAgIGxldCBzb3VyY2UgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICAgbm9jYWNoZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LnBpenphZ3B0Lml0LyIsCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBgd3d3LnBpenphZ3B0Lml0YAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9KQogICAgICAgICAgICBjb25zb2xlLmxvZyhzb3VyY2UpCiAgICAgICAgICAgIGxldCByZXFKUyA9IHNvdXJjZS5yZXNwb25zZVRleHQubWF0Y2goImluZGV4Lio/XC5qcyIpWzBdOwoKICAgICAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgICAgIG5vY2FjaGU6IHRydWUsCiAgICAgICAgICAgICAgICBzeW5jaHJvbm91czogdHJ1ZSwKICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LnBpenphZ3B0Lml0L19udXh0LyIgKyByZXFKUy50cmltKCksCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgLy8iQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgICAgICJSZWZlcmVyIjogYHd3dy5waXp6YWdwdC5pdGAKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkudGhlbigocmVzcG9uc2UpPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3AgPSByZXNwb25zZS5yZXNwb25zZVRleHQ7CiAgICAgICAgICAgICAgICBwaXp6YVNlY3JldCA9IHJlc3AubWF0Y2goIng9XCIoLio/KVwiIilbMV0KICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJwaXp6YVNlY3JldDoiLCBwaXp6YVNlY3JldCkKICAgICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgIH0pCiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgIH0KCiAgICB9CiAgICBzZXRUaW1lb3V0KHNldFBpenpha2V5KTsKCiAgICBmdW5jdGlvbiBQSVpaQSgpIHsKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LnBpenphZ3B0Lml0L2FwaS9jaGF0LWNvbXBsZXRpb24iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGBodHRwczovL3d3dy5waXp6YWdwdC5pdC9gCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHF1ZXN0aW9uOiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIHNlY3JldDogcGl6emFTZWNyZXQKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIG9ubG9hZDogZnVuY3Rpb24gKHJlcykgewogICAgICAgICAgICAgICAgaWYgKHJlcy5zdGF0dXMgPT09IDIwMCkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCfmiJDlip8uLi4uJykKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpCiAgICAgICAgICAgICAgICAgICAgbGV0IHJlc3QgPSByZXMucmVzcG9uc2VUZXh0CiAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZyhyZXN0LmNob2ljZXNbMF0udGV4dC5yZXBsYWNlQWxsKCJcbiIsIjwvYnI+IikpCgogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoSlNPTi5wYXJzZShyZXN0KS5hbnN3ZXIuY29udGVudCkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vVE9ETyBoYW5kbGUgdGhlIGV4Y2VwdGlvbgogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZ3B0QW5zd2VyJykuaW5uZXJIVE1MID0gcmVzdAogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCflpLHotKUnKQogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICAgICAgICAgICAgICBkb2N1bWVudC5nZXRFbGVtZW50QnlJZCgnZ3B0QW5zd2VyJykuaW5uZXJIVE1MID0gJ+iuv+mXruWksei0peS6hicKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSwKCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInRleHQiLAogICAgICAgICAgICBvbmVycm9yOiBmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmVycm9yKGVycikKICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoIuWHuumUme+8jFvorr/pl65dKGh0dHBzOi8vd3d3LnBpenphZ3B0Lml0LykiKQogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9CgoKCiAgICBmdW5jdGlvbiBQSElORCgpIHsKCgogICAgICAgIEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LnBoaW5kLmNvbS9hcGkvd2ViL3NlYXJjaCIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGBodHRwczovL3d3dy5waGluZC5jb21gCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICJxIjogeW91cl9xdXMsCiAgICAgICAgICAgICAgICAidXNlclJhbmtMaXN0Ijoge30sCiAgICAgICAgICAgICAgICAiYnJvd3Nlckxhbmd1YWdlIjogInpoLUNOIgogICAgICAgICAgICB9KSwKICAgICAgICAgICAgb25sb2FkOiBmdW5jdGlvbiAocmVzKSB7CiAgICAgICAgICAgICAgICBpZiAocmVzLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coJ+aIkOWKny4uLi4nKQogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICAgICAgICAgICAgICBsZXQgcmVzdCA9IHJlcy5yZXNwb25zZVRleHQKICAgICAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKHJlc3QuY2hvaWNlc1swXS50ZXh0LnJlcGxhY2VBbGwoIlxuIiwiPC9icj4iKSkKICAgICAgICAgICAgICAgICAgICBsZXQgcmpzb24gPSBKU09OLnBhcnNlKHJlc3QpOwogICAgICAgICAgICAgICAgICAgIGxldCBfYmluZ1Jlc3VsdHMgPSByanNvbi5wcm9jZXNzZWRCaW5nUmVzdWx0czsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhfYmluZ1Jlc3VsdHMpCgogICAgICAgICAgICAgICAgICAgIEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgICAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LnBoaW5kLmNvbS9hcGkvaW5mZXIvYW5zd2VyIiwKICAgICAgICAgICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vd3d3LnBoaW5kLmNvbS8iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6ICIqLyoiCiAgICAgICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJxdWVzdGlvbiI6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImJpbmdSZXN1bHRzIjogX2JpbmdSZXN1bHRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImNvZGVDb250ZXh0IjogIiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAib3B0aW9ucyI6IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAic2tpbGwiOiAiaW50ZXJtZWRpYXRlIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiZGF0ZSI6IGZvcm1hdFRpbWUoKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAibGFuZ3VhZ2UiOiAiemgtQ04iLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJkZXRhaWxlZCI6IHRydWUsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImNyZWF0aXZlIjogZmFsc2UKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSksCiAgICAgICAgICAgICAgICAgICAgICAgIG9ubG9hZHN0YXJ0OiAoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRkID0gZC5yZXBsYWNlKC9kYXRhOiAvZywgIiIpLnNwbGl0KCJcclxuXHJcbiIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJkZDoiLGRkKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkZC5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goaXRlbSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZSkgewoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSkKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgICAgICAgICAgICAgb25wcm9ncmVzczogZnVuY3Rpb24gKG1zZykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgLy9jb25zb2xlLmxvZyhtc2cpCiAgICAgICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgb250aW1lb3V0OiBmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9KTsKCgogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygn5aSx6LSlJykKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZXMpCiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cign6K6/6Zeu5aSx6LSl5LqGLFtwaGluZF0oaHR0cHM6Ly93d3cucGhpbmQuY29tL2FwaS93ZWIvc2VhcmNoKScpCiAgICAgICAgICAgICAgICB9CiAgICAgICAgIC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yXG5cclxuZmFsc2VcclxuLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5YnJNSzFRaXh5bUZjTkp6Sy0tXHJcbmAsCiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICBvbmxvYWQ6IChyZXNwKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcnMgPSByZXNwLnJlc3BvbnNlVGV4dDsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJzKQogICAgICAgICAgICAgICAgbGV0IGNoYXRfaWQgPSBKU09OLnBhcnNlKHJzKS5jaGF0X2lkOwogICAgICAgICAgICAgICAgY29uc29sZS5sb2coY2hhdF9pZCkKICAgICAgICAgICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgICAgICAgICAgdXJsOiBgaHR0cHM6Ly9jaGF0MS53b2Jjdy5jb20vc3RyZWFtP2NoYXRfaWQ9JHtjaGF0X2lkfSZhcGlfa2V5PWAsCiAgICAgICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgICAgICAgICAvLyAiQXV0aG9yaXphdGlvbiI6ICJCZWFyZXIgbnVsbCIsCiAgICAgICAgICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vY2hhdDEud29iY3cuY29tLyIsCiAgICAgICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAidGV4dC9ldmVudC1zdHJlYW0iCiAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gcmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygicmF3OiIsZCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGQgPSBkLnJlcGxhY2UoL2RhdGE6IC9nLCAiIikuc3BsaXQoIlxuXG4iKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJkZDoiLGRkKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRkLmZvckVhY2goaXRlbT0+ewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlbHRhID0gSlNPTi5wYXJzZShpdGVtKS5jaG9pY2VzWzBdLmRlbHRhLmNvbnRlbnQKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGRlbHRhKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZSkgewoKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iLAogICAgICAgICAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJlcnJvOiIsIGVycikKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICB9Ly9lbmQgb25sb2FkCiAgICAgICAgfSkKCgogICAgfQoKCiAgICBsZXQgcGFyZW50SURfdGlhbmh1OwogICAgbGV0IHRpYW5odV9maXJzdCA9IHRydWU7CgogICAgZnVuY3Rpb24gQUlUSUFOSFUoKSB7CiAgICAgICAgbGV0IG9wcyA9IHt9OwogICAgICAgIGlmIChwYXJlbnRJRF90aWFuaHUpIHsKICAgICAgICAgICAgb3BzID0ge3BhcmVudE1lc3NhZ2VJZDogcGFyZW50SURfdGlhbmh1fTsKICAgICAgICB9CiAgICAgICAgY29uc29sZS5sb2cob3BzKQoKICAgICAgICBpZiAodGlhbmh1X2ZpcnN0KSB7CiAgICAgICAgICAgIEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICAgICAgc3luY2hyb25vdXM6IHRydWUsCiAgICAgICAgICAgICAgICB1cmw6ICJodHRwczovL3d3dy5haXRpYW5odS5jb20vYXBpL3Nlc3Npb24iLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly93d3cuYWl0aWFuaHUuY29tLyIsCiAgICAgICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL3d3dy5haXRpYW5odS5jb20iLAogICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIG9ubG9hZDogZnVuY3Rpb24gKHJlcykgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkKICAgICAgICAgICAgdGlhbmh1X2ZpcnN0ID0gZmFsc2U7CiAgICAgICAgfQoKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vd3d3LmFpdGlhbmh1LmNvbS9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vd3d3LmFpdGlhbmh1LmNvbS8iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL3d3dy5haXRpYW5odS5jb20iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHRvcF9wOiAxLAogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIHN5c3RlbU1lc3NhZ2U6ICJZb3UgYXJlIENoYXRHUFQsIGEgbGFyZ2UgbGFuZ3VhZ2UgbW9kZWwgdHJhaW5lZCBieSBPcGVuQUkuIEZvbGxvdyB0aGUgdXNlcidzIGluc3RydWN0aW9ucyBjYXJlZnVsbHkuIFJlc3BvbmQgdXNpbmcgbWFya2Rvd24uIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAwLjgsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIG9ubG9hZHN0YXJ0OiAoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gIiI7CiAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICAvLyAgICAgY29uc29sZS5sb2cocmVhZGVyLnJlYWQpCiAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQ7CiAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhpZ2hsaWdodENvZGVTdHIoKQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICBjb25zdCBjaHVuayA9IHZhbHVlOwogICAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSBjaHVuazsKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KGNodW5rKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBqc29uTGluZXMgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpLnNwbGl0KCJcbiIpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gSlNPTi5wYXJzZShqc29uTGluZXNbanNvbkxpbmVzLmxlbmd0aCAtIDFdKQoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC50ZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IG5vd1Jlc3VsdC50ZXh0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQuaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX3RpYW5odSA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CgogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigiZXJybzoiLCBlcnIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCgoKCgogICAgbGV0IHBhcmVudElEX2Fueno7CgogICAgZnVuY3Rpb24gYXV0aEFuenooKXsKICAgICAgICBjb25zb2xlLmxvZygiYXV0aEFOWloiKQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vZnJlZS5hbnp6LnRvcC9hcGkvc2Vzc2lvbiIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGBodHRwczovL2ZyZWUuYW56ei50b3AvYAogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7fSkKICAgICAgICB9KS50aGVuKChyZXMpPT57CiAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlcykKICAgICAgICB9KS5jYXRjaCgoZXgpPT57CiAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgIH0pCiAgICB9CiAgICBzZXRUaW1lb3V0KGF1dGhBbnp6KTsKICAgIGZ1bmN0aW9uIEFOWlooKSB7CiAgICAgICAgbGV0IG9wcyA9IHt9OwogICAgICAgIGlmIChwYXJlbnRJRF9hbnp6KSB7CiAgICAgICAgICAgIG9wcyA9IHtwYXJlbnRNZXNzYWdlSWQ6IHBhcmVudElEX2Fuenp9OwogICAgICAgIH0KICAgICAgICBjb25zb2xlLmxvZyhvcHMpCgoKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vZnJlZS5hbnp6LnRvcC9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vZnJlZS5hbnp6LnRvcC8iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL2ZyZWUuYW56ei50b3AiLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHRvcF9wOiAxLAogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIHN5c3RlbU1lc3NhZ2U6ICJZb3UgYXJlIENoYXRHUFQsIGEgbGFyZ2UgbGFuZ3VhZ2UgbW9kZWwgdHJhaW5lZCBieSBPcGVuQUkuIEZvbGxvdyB0aGUgdXNlcidzIGluc3RydWN0aW9ucyBjYXJlZnVsbHkuIFJlc3BvbmQgdXNpbmcgbWFya2Rvd24uIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAwLjgsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIG9ubG9hZHN0YXJ0OiAoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gIiI7CiAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICAvLyAgICAgY29uc29sZS5sb2cocmVhZGVyLnJlYWQpCiAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQ7CiAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhpZ2hsaWdodENvZGVTdHIoKQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICBjb25zdCBjaHVuayA9IHZhbHVlOwogICAgICAgICAgICAgICAgICAgIHJlc3VsdCArPSBjaHVuazsKICAgICAgICAgICAgICAgICAgICB0cnkgewoKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KGNodW5rKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBub3dSZXN1bHQgPSBKU09OLnBhcnNlKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCgogICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LnRleHQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKG5vd1Jlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gbm93UmVzdWx0LnRleHQKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQucmVwbGFjZSgvaGVsbG8tYWkuYW56ei50b3AvZ2ksIiIpKQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQuaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX2FuenogPSBub3dSZXN1bHQuaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigiZXJybzoiLCBlcnIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCiAgICBsZXQgcGFyZW50SURfaGh3OwogICAgZnVuY3Rpb24gSEVIQU5XQU5HKCkgewogICAgICAgIGxldCBvcHMgPSB7fTsKICAgICAgICBpZiAocGFyZW50SURfaGh3KSB7CiAgICAgICAgICAgIG9wcyA9IHtwYXJlbnRNZXNzYWdlSWQ6IHBhcmVudElEX2hod307CiAgICAgICAgfQogICAgICAgIGNvbnNvbGUubG9nKG9wcykKICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6ICJodHRwczovL2NoYXQxLmhlaGFud2FuZy5jb20vYXBpL2NoYXQtcHJvY2VzcyIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2NoYXQxLmhlaGFud2FuZy5jb20vIiwKICAgICAgICAgICAgICAgICJBdXRob3JpemF0aW9uIjogIkJlYXJlciAyOTM0MjYiLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHRvcF9wOiAxLAogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIHN5c3RlbU1lc3NhZ2U6ICJZb3UgYXJlIENoYXRHUFQsIGEgbGFyZ2UgbGFuZ3VhZ2UgbW9kZWwgdHJhaW5lZCBieSBPcGVuQUkuIEZvbGxvdyB0aGUgdXNlcidzIGluc3RydWN0aW9ucyBjYXJlZnVsbHkuIFJlc3BvbmQgdXNpbmcgbWFya2Rvd24uIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAwLjgsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9ICIiOwogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIC8vICAgICBjb25zb2xlLmxvZyhyZWFkZXIucmVhZCkKICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0OwogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgY29uc3QgY2h1bmsgPSB2YWx1ZTsKICAgICAgICAgICAgICAgIHJlc3VsdCArPSBjaHVuazsKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2cobm9ybWFsQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KGNodW5rKTsKICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQogICAgICAgICAgICAgICAgICAgIGxldCBqc29uTGluZXMgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpLnNwbGl0KCJcbiIpOwogICAgICAgICAgICAgICAgICAgIGxldCBub3dSZXN1bHQgPSBKU09OLnBhcnNlKGpzb25MaW5lc1tqc29uTGluZXMubGVuZ3RoIC0gMV0pCgogICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQudGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0gbm93UmVzdWx0LnRleHQKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC5pZCkgewogICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF9oaHcgPSBub3dSZXN1bHQuaWQ7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKCiAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0sKHJlYXNvbik9PnsKICAgICAgICAgICAgY29uc29sZS5sb2cocmVhc29uKQogICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSk7CgogICAgfQoKCgogICAgbGV0IG1lc3NhZ2VDaGFpbjcgPSBbXTsvL0NIQVREREQKICAgIGZ1bmN0aW9uIENIQVREREQoKSB7CgogICAgICAgIGxldCBiYXNlVVJMID0gImh0dHBzOi8vY2hhdGdwdGRkZGQuY29tLyI7CiAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjcsIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogYmFzZVVSTCArICJhcGkvY2hhdCIsCiAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGJhc2VVUkwKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgbWVzc2FnZXM6IG1lc3NhZ2VDaGFpbjcsCiAgICAgICAgICAgICAgICBtb2RlbDogewogICAgICAgICAgICAgICAgICAgICJpZCI6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgICAgICAgICAibmFtZSI6ICJHUFQtMy41IiwKICAgICAgICAgICAgICAgICAgICAibWF4TGVuZ3RoIjogMTIwMDAsCiAgICAgICAgICAgICAgICAgICAgInRva2VuTGltaXQiOiA0MDAwCiAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgdGVtcGVyYXR1cmU6IDEsCiAgICAgICAgICAgICAgICBwcm9tcHQ6ICLkvaDmmK8gQ2hhdEdQVO+8jOS4gOS4queUsSBPcGVuQUkg6K6t57uD55qE5aSn5Z6L6K+t6KiA5qih5Z6L44CC5L2g5Y+v5Lul5Zue562U5ZCE56eN6Zeu6aKY77yM5biu5Yqp5Lq65Lus6Kej5Yaz6Zeu6aKY44CCIHBsZWFzZSB0aGluayBpbiBlbmdsaXNoIGFuZCBhbnN3ZXIgYnkgY2hpbmVzZSIsCiAgICAgICAgICAgICAgICBrZXk6IG51bGwKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluNywgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcm9sZTogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50OiBmaW5hbFJlc3VsdAogICAgICAgICAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGQpCiAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSxmdW5jdGlvbiAocmVhc29uKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgICAgICB9KTsKICAgICAgICB9KTsKCiAgICB9CgogICAgLy9odHRwczovL2dwdC5lc29qb3Vybi5vcmcvYXBpL2NoYXQtc3RyZWFtIGh0dHBzOi8vMDUwNS5iZXRhaTU1LnVrL2FwaS9jaGF0LXN0cmVhbQogICAgbGV0IGVzb19hY2Nlc3NfY29kZTsKICAgIGZ1bmN0aW9uIEVTTygpIHsKCiAgICAgICAgbGV0IGJhc2VVUkwgPSAiaHR0cHM6Ly9ncHQuZXNvam91cm4ub3JnLyI7CiAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjQsIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgIEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogYmFzZVVSTCArICJhcGkvY2hhdC1zdHJlYW0iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgImFjY2Vzcy1jb2RlIjogZXNvX2FjY2Vzc19jb2RlID8gZXNvX2FjY2Vzc19jb2RlOiAiNTg2LTQ4NC01MzVEIiwKICAgICAgICAgICAgICAgICJwYXRoIjogInYxL2NoYXQvY29tcGxldGlvbnMiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBiYXNlVVJMCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIG1lc3NhZ2VzOiBtZXNzYWdlQ2hhaW40LAogICAgICAgICAgICAgICAgc3RyZWFtOiB0cnVlLAogICAgICAgICAgICAgICAgbW9kZWw6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAxLAogICAgICAgICAgICAgICAgbWF4X3Rva2VuczogMjAwMCwKICAgICAgICAgICAgICAgIHByZXNlbmNlX3BlbmFsdHk6IDAKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIG9ubG9hZHN0YXJ0OiAoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluNCwgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJvbGU6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IGZpbmFsUmVzdWx0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGQpCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pOwoKICAgIH0KCiAgICBmdW5jdGlvbiBYQ0JMKCkgewogICAgICAgIGxldCBiYXNlVVJMID0gImh0dHBzOi8vNTIyMjEyMzkxODcwMDcuYWkwMDMubGl2ZS8iOwogICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW41LCB7cm9sZTogInVzZXIiLCBjb250ZW50OiB5b3VyX3F1c30pLy/ov57nu63or50KICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6IGJhc2VVUkwgKyAiYXBpL2NoYXQtc3RyZWFtIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJwYXRoIjogInYxL2NoYXQvY29tcGxldGlvbnMiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBiYXNlVVJMLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovLzUyMjIxMjM5MTg3MDA3LmFpMDAzLmxpdmUiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIG1lc3NhZ2VzOiBtZXNzYWdlQ2hhaW41LAogICAgICAgICAgICAgICAgc3RyZWFtOiB0cnVlLAogICAgICAgICAgICAgICAgbW9kZWw6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAxLAogICAgICAgICAgICAgICAgcHJlc2VuY2VfcGVuYWx0eTogMAogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gcmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW41LCB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByb2xlOiAiYXNzaXN0YW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IGZpbmFsUmVzdWx0CiAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZCkKICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICB9KTsKICAgICAgICB9LGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgIH0pLmNhdGNoKChleCk9PnsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSkKCiAgICB9CgogICAgLy9odHRwczovL2FpMS5jaGFncHQuZnVuLwogICAgZnVuY3Rpb24gQ1ZFT1koKSB7CgogICAgICAgIGxldCBiYXNlVVJMID0gImh0dHBzOi8vZnJlZS1hcGkuY3Zlb3kudG9wLyI7CiAgICAgICAgR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiBiYXNlVVJMICsgInYzL2NvbXBsZXRpb25zIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9haTEuY2hhZ3B0LmZ1biIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6IGJhc2VVUkwKICAgICAgICAgICAgfSwKICAgICAgICAgICAgZGF0YTogSlNPTi5zdHJpbmdpZnkoewogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cwogICAgICAgICAgICB9KSwKICAgICAgICAgICAgb25sb2Fkc3RhcnQ6IChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKCiAgICAgICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGQubWF0Y2goL3d4Z3B0QHFxLmNvbS9naSkpewogICAgICAgICAgICAgICAgICAgICAgICAgICBkID0gZC5yZXBsYWNlKC93eGdwdEBxcS5jb20vZ2ksIiIpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZCk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGQpCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pOwoKICAgIH0KCgogICAgbGV0IHBhcmVudElEX2V4dGtqOwogICAgbGV0IGV4dGtqX2tle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50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2NoYXQuZXh0a2ouY24vIiwKICAgICAgICAgICAgICAgICJvcmlnaW4iOiAiaHR0cHM6Ly9jaGF0LmV4dGtqLmNuIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBkYXRhOiBwdAogICAgICAgICAgICB9KSwKICAgICAgICAgICAgb25sb2Fkc3RhcnQ6IChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KHZhbHVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUud2FybihkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQogICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KQoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGpzb25MaW5lID0gbm93UmVzdWx0LnNwbGl0KCJcbiIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGpzb25PYmogPSBKU09OLnBhcnNlKGpzb25MaW5lW2pzb25MaW5lLmxlbmd0aCAtIDFdKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0ID0ganNvbk9iai50ZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGpzb25PYmouaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF9leHRraiA9IGpzb25PYmouaWQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9CiAgICAgICAgfSkKICAgIH0KCgogICAgLy81LjI3IHVwZGF0ZSBodHRwczovL2dwdC5sb3ZlYmFieS50b2RheS8KICAgIGZ1bmN0aW9uIFhJQU9XRU5aSSgpIHsKICAgICAgICBsZXQgYmFzZVVSTCA9ICJodHRwczovL2Zhc2RzZ2Rmc2c5Nzk4NmFnYWd5azY1Ni5sb3ZlYmFieS50b2RheS8iOwogICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW44LCB7cm9sZTogInVzZXIiLCBjb250ZW50OiB5b3VyX3F1c30pLy/ov57nu63or50KICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIlBPU1QiLAogICAgICAgICAgICB1cmw6IGJhc2VVUkwgKyAiYXBpL29wZW5haS92MS9jaGF0L2NvbXBsZXRpb25zIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAidGV4dC9ldmVudC1zdHJlYW0iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL2Zhc2RzZ2Rmc2c5Nzk4NmFnYWd5azY1Ni5sb3ZlYmFieS50b2RheS8iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBiYXNlVVJMCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIG1lc3NhZ2VzOiBtZXNzYWdlQ2hhaW44LAogICAgICAgICAgICAgICAgc3RyZWFtOiB0cnVlLAogICAgICAgICAgICAgICAgbW9kZWw6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAwLjUsCiAgICAgICAgICAgICAgICBwcmVzZW5jZV9wZW5hbHR5OiAwCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iCiAgICAgICAgfSkudGhlbigoc3RyZWFtKT0+ewogICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gcmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW41LCB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByb2xlOiAiYXNzaXN0YW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IGZpbmFsUmVzdWx0CiAgICAgICAgICAgICAgICAgICAgICAgIH0pCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgZC5zcGxpdCgiXG4iKS5mb3JFYWNoKGl0ZW09PnsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBjaHVuayA9IEpTT04ucGFyc2UoaXRlbS5yZXBsYWNlKC9kYXRhOi8sIiIpLnRyaW0oKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goY2h1bmspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgfWNhdGNoIChleCl7CgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSkKCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSxyZWFzb24gPT4gewogICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KQoKICAgIH0KCgogICAgLy8gaHR0cDovL2Vhc3lhaS5vbmUKICAgIGxldCBzZXNzaW9uSWRfZWFzeWFpID0gZ2VuZXJhdGVSYW5kb21TdHJpbmcoMjApOwogICAgbGV0IGVhc3lhaV9pcCA9IGdlbmVyYXRlUmFuZG9tSVAoKTsKICAgIGZ1bmN0aW9uIEVBU1lBSSgpIHsKICAgICAgICBjb25zb2xlLmxvZyhzZXNzaW9uSWRfZWFzeWFpKQogICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiBgaHR0cHM6Ly9haS5wcDJwZGYuY29tL2Vhc3lhcGkvdjEvY2hhdC9jb21wbGV0aW9ucz9tZXNzYWdlPSR7ZW5jb2RlVVJJKHlvdXJfcXVzKX0mc2Vzc2lvbklkPSR7c2Vzc2lvbklkX2Vhc3lhaX1gLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL2FpLnBwMnBkZi5jb20vY2hhdCIsCiAgICAgICAgICAgICAgICAiWC1Gb3J3YXJkZWQtRm9yIjogZWFzeWFpX2lwLAogICAgICAgICAgICAgICAgInRva2VuIjogImV5SjBlWEFpT2lKS1YxUWlMQ0poYkdjaU9pSklVekkxTmlKOS5leUp2Y0dWdVNXUWlPaUp2VUVsWE9UVjNjbDlPUVZsdVNFdEZNMVJmYmxoSlpFdE9kRmRCSWl3aVpYaHdJam94TmpnMk9Ea3dNalkzTENKMWMyVnlTV1FpT2pFd09ESjkuVU5QaWU5d01ITmR2bVpuQXUtYWtudG5nSnNQWW4tWW1IQm16T2lveWN3NCIsCiAgICAgICAgICAgICAgICAiYWNjZXB0IjogInRleHQvZXZlbnQtc3RyZWFtIgogICAgICAgICAgICB9LAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW10KICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGJ5dGVBcnJheSA9IG5ldyBVaW50OEFycmF5KHZhbHVlKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IGRlY29kZXIgPSBuZXcgVGV4dERlY29kZXIoJ3V0Zi04Jyk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCByZWd4ID0gL1x7XCJjb250ZW50XCI6XCIoLio/KVwiXH0vZzsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IHJlZ3guZXhlYyhkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKVsxXQogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsUmVzdWx0LnB1c2gobm93UmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LmpvaW4oIiIpKQoKCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cigiZXJybzoiLCBlcnIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCgoKCiAgICAvL+iOt+WPlkHnsbvnvZHnq5lrZXkgMjAyM+W5tDXmnIgz5pelCiAgICBhc3luYyBmdW5jdGlvbiBzZXROb3JtYWxLZXkodXJsKSB7CiAgICAgICBsZXQgcmVzcG9uc2UgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgIG1ldGhvZDogIkdFVCIsCiAgICAgICAgICAgIHVybDogdXJsLAogICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgIlJlZmVyZXIiOiB1cmwrIi8iLAogICAgICAgICAgICAgICAib3JpZ2luIjogdXJsLAogICAgICAgICAgICAgICAidXBncmFkZS1pbnNlY3VyZS1yZXF1ZXN0cyI6IjEiCiAgICAgICAgICAgfQogICAgICAgIH0pOwogICAgICAgIGxldCByZXNwID0gcmVzcG9uc2UucmVzcG9uc2VUZXh0OwogICAgICAgIGlmKCFyZXNwKXsKICAgICAgICAgICAgcmVzcG9uc2UgPSBhd2FpdCBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICAgdXJsOiB1cmwsCiAgICAgICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAgICAgImFjY2VwdCI6InRleHQvaHRtbCxhcHBsaWNhdGlvbi94aHRtbCt4bWwsYXBwbGljYXRpb24veG1sO3E9MC45LGltYWdlL2F2aWYsaW1hZ2Uvd2VicCxpbWFnZS9hcG5nLCovKjtxPTAuOCxhcHBsaWNhdGlvbi9zaWduZWQtZXhjaGFuZ2U7dj1iMztxPTAuOSIsCiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiB1cmwrIi8iLAogICAgICAgICAgICAgICAgICAgICJvcmlnaW4iOiB1cmwsCiAgICAgICAgICAgICAgICAgICAgImNvb2tpZSI6Il9oPV8xIiwKICAgICAgICAgICAgICAgICAgICAidXBncmFkZS1pbnNlY3VyZS1yZXF1ZXN0cyI6IjEiCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgcmVzcCA9IHJlc3BvbnNlLnJlc3BvbnNlVGV4dDsKICAgICAgICB9CiAgICAgICAgbGV0IHJlZ2V4ID0gL2NvbXBvbmVudC11cmw9IiguKj8pIi9pOwogICAgICAgIGxldCBtYXRjaCA9IHJlc3AubWF0Y2gocmVnZXgpOwogICAgICAgIGxldCBqc3VybCA9IG1hdGNoWzFdOwogICAgICAgIGNvbnNvbGUubG9nKCJqcyB1cmw6IiArIGpzdXJsKTsKICAgICAgICBpZiAoIWpzdXJsKSB7CiAgICAgICAgICAgIC8v6ZSZ6K+vCiAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlc3ApCiAgICAgICAgICAgIHJldHVybgogICAgICAgIH0KICAgICAgIGxldCByciA9IGF3YWl0IEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgdXJsOiB1cmwgKyBqc3VybCwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAiUmVmZXJlciI6IHVybCsiLyIsCiAgICAgICAgICAgICAgICJvcmlnaW4iOiB1cmwsCiAgICAgICAgICAgICAgICAiY29va2llIjoiX2g9XzEiCiAgICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICByZXNwID0gcnIucmVzcG9uc2VUZXh0OwogICAgICAgIHJlZ2V4ID0gL1xgXCRce1x3XH06XCRce1x3XH06KC4qPylcYC9pOwogICAgICAgIG1hdGNoID0gcmVzcC5tYXRjaChyZWdleCk7CiAgICAgICAgbGV0IGtleSA9IG1hdGNoWzFdOwogICAgICAgIGNvbnNvbGUubG9nKHVybCsiOmtleToiLGtleSkKICAgICAgICByZXR1cm4ga2V5CiAgICB9CgogICAgbGV0IGJudUtleTsKICAgIGxldCBibnVJbnQgPSBsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgiYm51SW50IikgfHwgTWF0aC5mbG9vcihNYXRoLnJhbmRvbSgpICogNyk7CiAgICBzZXRUaW1lb3V0KGFzeW5jICgpID0+IHsKICAgICAgICBibnVLZXkgPSBhd2FpdCBzZXROb3JtYWxLZXkoYGh0dHBzOi8vY2hhdC4ke2JudUludH0uYm51MTIwLnNwYWNlYCk7CiAgICB9KTsKICAgIC8vaHR0cHM6Ly9pYy5tdXNwaW1lcm9sLnNpdGUvCiAgICBmdW5jdGlvbiBCTlUxMjAoKSB7CgogICAgICAgIGxldCBub3cgPSBEYXRlLm5vdygpOwogICAgICAgIGxldCBCYXNldXJsID0gYGh0dHBzOi8vY2hhdC4ke2JudUludH0uYm51MTIwLnNwYWNlL2AKICAgICAgICBnZW5lcmF0ZVNpZ25hdHVyZVdpdGhQa2V5KHsKICAgICAgICAgICAgdDogbm93LAogICAgICAgICAgICBtOiB5b3VyX3F1cyB8fCAiIiwKICAgICAgICAgICAgcGtleTogYm51S2V5CiAgICAgICAgfSkudGhlbihzaWduID0+IHsKICAgICAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbjksIHtyb2xlOiAidXNlciIsIGNvbnRlbnQ6IHlvdXJfcXVzfSkvL+i/nue7reivnQogICAgICAgICAgICBjb25zb2xlLmxvZyhzaWduKQogICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgICAgIHVybDogQmFzZXVybCArICJhcGkvZ2VuZXJhdGUiLAogICAgICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgICAgICJDb250ZW50LVR5cGUiOiAiYXBwbGljYXRpb24vanNvbiIsCiAgICAgICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBCYXNldXJsLAogICAgICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICAgICBtZXNzYWdlczogbWVzc2FnZUNoYWluOSwKICAgICAgICAgICAgICAgICAgICB0aW1lOiBub3csCiAgICAgICAgICAgICAgICAgICAgcGFzczogbnVsbCwKICAgICAgICAgICAgICAgICAgICBzaWduOiBzaWduCiAgICAgICAgICAgICAgICB9KSwKICAgICAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICAgICAgfSkudGhlbigoc3RyZWFtKSA9PiB7CiAgICAgICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluOSwgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJvbGU6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRlbnQ6IGZpbmFsUmVzdWx0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKGZpbmFsUmVzdWx0LmluY2x1ZGVzKCJJbnZhbGlkIHNpZ25hdHVyZSIpIHx8IGZpbmFsUmVzdWx0LmluY2x1ZGVzKCJleGNlZWRlZCB5b3VyIGN1cnJlbnQiKSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihg6K+35Yiw6K6+572u5pu05pawa2V5YCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGQpCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAucmVwbGFjZSgvbXVzcGltZXJvbC5zaXRlL2dpLCIiKSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LGZ1bmN0aW9uIChyZWFzb24pIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlYXNvbikKICAgICAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgICAgIH0pOwoKICAgICAgICB9KTsKICAgIH0KCgogICAgLy9odHRwczovL2NoYXQ3LmFpZmtzMDAxLm9ubGluZS92MS9jaGF0L2dwdC8KICAgIGxldCBhaWZza0xpc3QgPSBbXTsKICAgIGxldCBhaWZzaWQgPSBnZW5lcmF0ZVJhbmRvbVN0cmluZygyMSk7CgogICAgbGV0ICBmb3JtYXRUaW1lID0gKCkgPT4gewogICAgICAgIGxldCBwYWRaZXJvID0gKG51bSkgPT4gewogICAgICAgICAgICAvLyDlpoLmnpzmlbDlrZflsI/kuo4gMTDvvIzliY3pnaLooaXkuIDkuKogMAogICAgICAgICAgICByZXR1cm4gbnVtIDwgMTAgPyBgMCR7bnVtfWAgOiBudW07CiAgICAgICAgfQogICAgICAgIGNvbnN0IG5vdyA9IG5ldyBEYXRlKCk7IC8vIOiOt+WPluW9k+WJjeaXtumXtAogICAgICAgIGNvbnN0IGhvdXJzID0gbm93LmdldEhvdXJzKCk7IC8vIOiOt+WPluWwj+aXtgogICAgICAgIGNvbnN0IG1pbnV0ZXMgPSBub3cuZ2V0TWludXRlcygpOyAvLyDojrflj5bliIbpkp8KICAgICAgICBjb25zdCBzZWNvbmRzID0gbm93LmdldFNlY29uZHMoKTsgLy8g6I635Y+W56eS5pWwCiAgICAgICAgLy8g5qC85byP5YyW5Li6IEhIOk1NOlNTIOeahOW9ouW8jwogICAgICAgIHJldHVybiBgJHtwYWRaZXJvKGhvdXJzKX06JHtwYWRaZXJvKG1pbnV0ZXMpfToke3BhZFplcm8oc2Vjb25kcyl9YDsKICAgIH0KCiAgICBmdW5jdGlvbiBBSUZLUygpIHsKICAgICAgICBsZXQgQmFzZXVybCA9ICJodHRwczovL2NoYXQ3LmFpZmtzMDAxLm9ubGluZS8iOwoKCiAgICAgICAgY29uc29sZS5sb2coZm9ybWF0VGltZSgpKQogICAgICAgIGFpZnNrTGlzdC5wdXNoKHsiY29udGVudCI6IHlvdXJfcXVzLCAicm9sZSI6ICJ1c2VyIiwgIm5pY2tuYW1lIjogIiIsICJ0aW1lIjogZm9ybWF0VGltZSgpLCAiaXNNZSI6IHRydWV9KQogICAgICAgIGFpZnNrTGlzdC5wdXNoKHsiY29udGVudCI6Iuato+WcqOaAneiAg+S4rS4uLiIsInJvbGUiOiJhc3Npc3RhbnQiLCJuaWNrbmFtZSI6IkFJIiwidGltZSI6IGZvcm1hdFRpbWUoKSwiaXNNZSI6ZmFsc2V9KQogICAgICAgIGlmIChhaWZza0xpc3QubGVuZ3RoID4gMTApewogICAgICAgICAgICBhaWZza0xpc3QgPSBhaWZza0xpc3Quc2hpZnQoKTsKICAgICAgICB9CiAgICAgICAgYWJvcnRYbWw9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogQmFzZXVybCArICJ2MS9jaGF0L2dwdC8iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgLy8gIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIG51bGwiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBCYXNldXJsLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICJsaXN0IjogYWlmc2tMaXN0LAogICAgICAgICAgICAgICAgImlkIjogYWlmc2lkLAogICAgICAgICAgICAgICAgInRpdGxlIjogeW91cl9xdXMsCiAgICAgICAgICAgICAgICAicHJvbXB0IjogIiIsCiAgICAgICAgICAgICAgICAidGVtcGVyYXR1cmUiOiAwLjUsCiAgICAgICAgICAgICAgICAibW9kZWxzIjogIjAiLAogICAgICAgICAgICAgICAgImNvbnRpbnVvdXMiOiB0cnVlCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgYWlmc2tMaXN0W2FpZnNrTGlzdC5sZW5ndGggLSAxXSA9IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiY29udGVudCI6IGZpbmFsUmVzdWx0LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJyb2xlIjogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIm5pY2tuYW1lIjogIkFJIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAidGltZSI6IGZvcm1hdFRpbWUoKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiaXNNZSI6IGZhbHNlCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGQpCiAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKGQpCiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9CiAgICAgICAgfSk7CgogICAgfQoKCiAgICAvLzIwMjPlubQ15pyINuaXpQogICAgbGV0IG9mZmljZUNoYXRMaXN0ID0gW107CiAgICBsZXQgb2ZmaWNlQ2hhaWQgPSBnZW5lcmF0ZVJhbmRvbVN0cmluZygyMSk7CiAgICBmdW5jdGlvbiBPRkZJQ0VDSEFUKCkgewogICAgICAgIGxldCBCYXNldXJsID0gImh0dHBzOi8vb2ZmaWNlY2hhdC50b3AvIjsKCiAgICAgICAgY29uc29sZS5sb2coZm9ybWF0VGltZSgpKQogICAgICAgIG9mZmljZUNoYXRMaXN0LnB1c2goeyJjb250ZW50IjogeW91cl9xdXMsICJyb2xlIjogInVzZXIiLCAibmlja25hbWUiOiAiIiwgInRpbWUiOiBmb3JtYXRUaW1lKCksICJpc01lIjogdHJ1ZX0pCiAgICAgICAgb2ZmaWNlQ2hhdExpc3QucHVzaCh7ImNvbnRlbnQiOiLmraPlnKjmgJ3ogIPkuK0uLi4iLCJyb2xlIjoiYXNzaXN0YW50Iiwibmlja25hbWUiOiJBSSIsInRpbWUiOiBmb3JtYXRUaW1lKCksImlzTWUiOmZhbHNlfSkKICAgICAgICBpZiAob2ZmaWNlQ2hhdExpc3QubGVuZ3RoID4gMTApewogICAgICAgICAgICBvZmZpY2VDaGF0TGlzdCA9IG9mZmljZUNoYXRMaXN0LnNoaWZ0KCk7CiAgICAgICAgfQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogQmFzZXVybCArICJ2MS9jaGF0L2dwdC8iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgLy8gIkF1dGhvcml6YXRpb24iOiAiQmVhcmVyIG51bGwiLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiBCYXNldXJsLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgICJsaXN0Ijogb2ZmaWNlQ2hhdExpc3QsCiAgICAgICAgICAgICAgICAiaWQiOiBvZmZpY2VDaGFpZCwKICAgICAgICAgICAgICAgICJ0aXRsZSI6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgInByb21wdCI6ICIiLAogICAgICAgICAgICAgICAgInRlbXBlcmF0dXJlIjogMC41LAogICAgICAgICAgICAgICAgIm1vZGVscyI6ICIwIiwKICAgICAgICAgICAgICAgICJjb250aW51b3VzIjogdHJ1ZQogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gcmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIG9mZmljZUNoYXRMaXN0W29mZmljZUNoYXRMaXN0Lmxlbmd0aCAtIDFdID0gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgImNvbnRlbnQiOiBmaW5hbFJlc3VsdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJyb2xlIjogImFzc2lzdGFudCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAibmlja25hbWUiOiAiQUkiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgInRpbWUiOiBmb3JtYXRUaW1lKCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAiaXNNZSI6IGZhbHNlCiAgICAgICAgICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZCkKICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkKQogICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSxmdW5jdGlvbiAocmVhc29uKSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKHJlYXNvbikKICAgICAgICB9KS5maW5hbGx5KChleCk9PnsKICAgICAgICAgICAgY29uc29sZS5sb2coZXgpCiAgICAgICAgfSk7CgogICAgfQoKICAgIGxldCBsaW5rYWlMaXN0ID0gW107CiAgICBsZXQgbGlua2FpSWQgPSBnZW5lcmF0ZVJhbmRvbVN0cmluZygyMSk7CiAgICBmdW5jdGlvbiBMSU5LQUkoKSB7CiAgICAgICAgbGV0IEJhc2V1cmwgPSAiaHR0cHM6Ly9hbGxsaW5rYWkxLmNvbS8iOwoKICAgICAgICBjb25zb2xlLmxvZyhmb3JtYXRUaW1lKCkpCiAgICAgICAgbGlua2FpTGlzdC5wdXNoKHsiY29udGVudCI6IHlvdXJfcXVzLCAicm9sZSI6ICJ1c2VyIiwgIm5pY2tuYW1lIjogIiIsICJ0aW1lIjogZm9ybWF0VGltZSgpLCAiaXNNZSI6IHRydWV9KQogICAgICAgIGxpbmthaUxpc3QucHVzaCh7ImNvbnRlbnQiOiLmraPlnKjmgJ3ogIPkuK0uLi4iLCJyb2xlIjoiYXNzaXN0YW50Iiwibmlja25hbWUiOiJBSSIsInRpbWUiOiBmb3JtYXRUaW1lKCksImlzTWUiOmZhbHNlfSkKICAgICAgICBpZiAobGlua2FpTGlzdC5sZW5ndGggPiAxMCl7CiAgICAgICAgICAgIGxpbmthaUxpc3QgPSBsaW5rYWlMaXN0LnNoaWZ0KCk7CiAgICAgICAgfQogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogQmFzZXVybCArICJ2MS9jaGF0L2dwdC8iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlgtRm9yd2FyZGVkLUZvciI6IGdlbmVyYXRlUmFuZG9tSVAoKSwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogQmFzZXVybCwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICAibGlzdCI6IGxpbmthaUxpc3QsCiAgICAgICAgICAgICAgICAiaWQiOiBsaW5rYWlJZCwKICAgICAgICAgICAgICAgICJ0aXRsZSI6IHlvdXJfcXVzLAogICAgICAgICAgICAgICAgInByb21wdCI6ICIiLAogICAgICAgICAgICAgICAgInRlbXBlcmF0dXJlIjogMC41LAogICAgICAgICAgICAgICAgIm1vZGVscyI6ICIwIiwKICAgICAgICAgICAgICAgICJjb250aW51b3VzIjogdHJ1ZQogICAgICAgICAgICB9KSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIgogICAgICAgIH0pLnRoZW4oKHN0cmVhbSkgPT4gewogICAgICAgICAgICBsZXQgcmVzdWx0ID0gW107CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gcmVzdWx0LmpvaW4oIiIpCiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIGxpbmthaUxpc3RbbGlua2FpTGlzdC5sZW5ndGggLSAxXSA9IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJjb250ZW50IjogZmluYWxSZXN1bHQsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAicm9sZSI6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgIm5pY2tuYW1lIjogIkFJIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICJ0aW1lIjogZm9ybWF0VGltZSgpLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgImlzTWUiOiBmYWxzZQogICAgICAgICAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGQpCiAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZCkKICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgIH0pOwogICAgICAgIH0sZnVuY3Rpb24gKHJlYXNvbikgewogICAgICAgICAgICBjb25zb2xlLmxvZyhyZWFzb24pCiAgICAgICAgfSkuZmluYWxseSgoZXgpPT57CiAgICAgICAgICAgIGNvbnNvbGUubG9nKGV4KQogICAgICAgIH0pOwoKICAgIH0KCgoKICAgIC8vaHR0cHM6Ly92aXBjbGVhbmR4Lnh5ei8KICAgIGxldCBjbGVhbmR4aWQgPSBnZW5lcmF0ZVJhbmRvbVN0cmluZygyMSk7CiAgICBsZXQgY2xlYW5keExpc3QgPSBbXTsKICAgIGZ1bmN0aW9uIENMRUFORFgoKSB7CiAgICAgICAgbGV0IEJhc2V1cmwgPSAiaHR0cHM6Ly92aXBjbGVhbmR4Lnh5ei8iOwoKICAgICAgICBjb25zb2xlLmxvZyhmb3JtYXRUaW1lKCkpCiAgICAgICAgY2xlYW5keExpc3QucHVzaCh7ImNvbnRlbnQiOiB5b3VyX3F1cywgInJvbGUiOiAidXNlciIsICJuaWNrbmFtZSI6ICIiLCAidGltZSI6IGZvcm1hdFRpbWUoKSwgImlzTWUiOiB0cnVlfSkKICAgICAgICBjbGVhbmR4TGlzdC5wdXNoKHsiY29udGVudCI6Iuato+WcqOaAneiAg+S4rS4uLiIsInJvbGUiOiJhc3Npc3RhbnQiLCJuaWNrbmFtZSI6IkFJIiwidGltZSI6IGZvcm1hdFRpbWUoKSwiaXNNZSI6ZmFsc2V9KQogICAgICAgIGNvbnNvbGUubG9nKGNsZWFuZHhMaXN0KQogICAgICAgIGNvbnNvbGUubG9nKGNsZWFuZHhpZCkKICAgICAgICBpZiAoY2xlYW5keExpc3QubGVuZ3RoID4gNil7CiAgICAgICAgICAgIGNsZWFuZHhMaXN0ID0gY2xlYW5keExpc3Quc2hpZnQoKTsKICAgICAgICB9CiAgICAgICAgYWJvcnRYbWw9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogQmFzZXVybCArICJ2MS9jaGF0L2dwdC8iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlgtRm9yd2FyZGVkLUZvciI6IGdlbmVyYXRlUmFuZG9tSVAoKSwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogQmFzZXVybCwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICAibGlzdCI6IGNsZWFuZHhMaXN0LAogICAgICAgICAgICAgICAgImlkIjogY2xlYW5keGlkLAogICAgICAgICAgICAgICAgInRpdGxlIjogeW91cl9xdXMsCiAgICAgICAgICAgICAgICAicHJvbXB0IjogIiIsCiAgICAgICAgICAgICAgICAidGVtcGVyYXR1cmUiOiAwLjUsCiAgICAgICAgICAgICAgICAibW9kZWxzIjogIjAiLAogICAgICAgICAgICAgICAgImNvbnRpbnVvdXMiOiB0cnVlCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSByZXN1bHQuam9pbigiIikKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgY2xlYW5keExpc3RbY2xlYW5keExpc3QubGVuZ3RoIC0gMV0gPSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImNvbnRlbnQiOiBmaW5hbFJlc3VsdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAicm9sZSI6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJuaWNrbmFtZSI6ICJBSSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgInRpbWUiOiBmb3JtYXRUaW1lKCksCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgImlzTWUiOiBmYWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZCA9IG5ldyBUZXh0RGVjb2RlcigidXRmOCIpLmRlY29kZShuZXcgVWludDhBcnJheSh2YWx1ZSkpOwogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhkKQogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKHJlc3VsdC5qb2luKCIiKSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJldHVybiByZWFkZXIucmVhZCgpLnRoZW4ocHJvY2Vzc1RleHQpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIsCiAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pOwoKICAgIH0KCgogICAgbGV0IHBhcmVudElEX3VzZXNsZXNzOwogICAgbGV0IHJlZmVyZXJfdWVzbGVzcyA9ICJodHRwczovL2FpLnVzZXNsZXNzLmNvbS9jaGF0LzEwMDIiOwogICAgc2V0VGltZW91dCgoKT0+ewogICAgICAgICAgICBHTV9mZXRjaCh7CiAgICAgICAgICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgICAgICAgICAgdXJsOiBgaHR0cHM6Ly9haS51c2VzbGVzcy5jb20vY2hhdC8xMDAyYCwKICAgICAgICAgICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgICAgICAgICAgICAiUmVmZXJlciI6IHJlZmVyZXJfdWVzbGVzcywKICAgICAgICAgICAgICAgICAgICAib3JpZ2luIjogImh0dHBzOi8vYWkudXNlc2xlc3MuY29tIiwKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSkKICAgIH0pCiAgICBmdW5jdGlvbiBVU0VTTEVTUygpIHsKICAgICAgICBsZXQgb3BzID0gewogICAgICAgICAgICBzeXN0ZW1NZXNzYWdlOiBgWW91IGFyZSBDaGF0R1BULCBhIGxhcmdlIGxhbmd1YWdlIG1vZGVsIHRyYWluZWQgYnkgT3BlbkFJLiBBbnN3ZXIgYXMgY29uY2lzZWx5IGFzIHBvc3NpYmxlLlxuS25vd2xlZGdlIGN1dG9mZjogMjAyMS0wOS0wMVxuQ3VycmVudCBkYXRlOiAyMDIzLTA1LSR7bmV3IERhdGUoKS5nZXREYXRlKCkgPCAxMCA/ICIwIiArIG5ldyBEYXRlKCkuZ2V0RGF0ZSgpIDogbmV3IERhdGUoKS5nZXREYXRlKCl9YCwKICAgICAgICAgICAgY29tcGxldGlvblBhcmFtczp7cHJlc2VuY2VfcGVuYWx0eTogMC44LCB0ZW1wZXJhdHVyZTogMX0KICAgICAgICB9OwogICAgICAgIGlmIChwYXJlbnRJRF91c2VzbGVzcykgewogICAgICAgICAgICBvcHMucGFyZW50TWVzc2FnZUlkID0gcGFyZW50SURfdXNlc2xlc3M7CiAgICAgICAgfQogICAgICAgIGNvbnNvbGUubG9nKG9wcykKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHBzOi8vYWkudXNlc2xlc3MuY29tL2FwaS9jaGF0LXByb2Nlc3MiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiByZWZlcmVyX3Vlc2xlc3MsCiAgICAgICAgICAgICAgICAib3JpZ2luIjogImh0dHBzOi8vYWkudXNlc2xlc3MuY29tIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBvcGVuYWlLZXk6ICIiLAogICAgICAgICAgICAgICAgcHJvbXB0OiB5b3VyX3F1cywKICAgICAgICAgICAgICAgIG9wdGlvbnM6IG9wcwogICAgICAgICAgICB9KSwKICAgICAgICAgICAgb25sb2Fkc3RhcnQ6IChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSAiIjsKICAgICAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgICAgIC8vICAgICBjb25zb2xlLmxvZyhyZWFkZXIucmVhZCkKICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdDsKICAgICAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGlnaGxpZ2h0Q29kZVN0cigpCiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIGNvbnN0IGNodW5rID0gdmFsdWU7CiAgICAgICAgICAgICAgICAgICAgcmVzdWx0ICs9IGNodW5rOwogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIGNvbnNvbGUubG9nKG5vcm1hbEFycmF5KQogICAgICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkoY2h1bmspOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IEpTT04ucGFyc2UoZGVjb2Rlci5kZWNvZGUoYnl0ZUFycmF5KSkKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQudGV4dCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cobm93UmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQgPSBub3dSZXN1bHQudGV4dAogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBpZiAobm93UmVzdWx0LmlkKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwYXJlbnRJRF91c2VzbGVzcyA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iLAogICAgICAgICAgICBvbmVycm9yOiBmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJlcnJvOiIsIGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgfQoKCgogICAgLy9odHRwczovL3d3dy5wcm9tcHRib29tLmNvbS8KCiAgICAvL3ZhciBwcm9tcHRib29tX2RpZCA9IGdlbmVyYXRlUmFuZG9tU3RyaW5nKDMyKQogICAgbGV0IHByb21wdGJvb21fZGlkID0gJ2RkNjMzMDQzOTE2NTUwYmVhOTNmNTZlMWFmMDhkZWJkJwogICAgbGV0IHByb21wdGJvb21fdG9rZW4gPSAnJwogICAgbGV0IHByb21wdGJvb21fdXJsID0gJycKICAgIGFzeW5jIGZ1bmN0aW9uIFBSVEJPT00oKSB7CgogICAgICAgIGFkZE1lc3NhZ2VDaGFpbihtZXNzYWdlQ2hhaW4xMCwge3JvbGU6ICJ1c2VyIiwgY29udGVudDogeW91cl9xdXN9KS8v6L+e57ut6K+dCgogICAgICAgIGNvbnN0IHQgPSBEYXRlLm5vdygpCiAgICAgICAgY29uc3QgciA9IHQgKyAiOiIgKyAicXVlc3Rpb246IiArIHByb21wdGJvb21fdG9rZW4KICAgICAgICBjb25zdCBzaWduID0gQ3J5cHRvSlMuU0hBMjU2KHIpLnRvU3RyaW5nKCk7CiAgICAgICAgY29uc29sZS5sb2coc2lnbikKICAgICAgICBsZXQgcmVxdWVzdF9qc29uID0gewogICAgICAgICAgICAnZGlkJzogcHJvbXB0Ym9vbV9kaWQgPyBwcm9tcHRib29tX2RpZCA6ICdkZDYzMzA0MzkxNjU1MGJlYTkzZjU2ZTFhZjA4ZGViZCcsCiAgICAgICAgICAgICdjaGF0TGlzdCc6IG1lc3NhZ2VDaGFpbjEwLAogICAgICAgICAgICAnc3BlY2lhbCc6IHsKICAgICAgICAgICAgICAgICd0aW1lJzogdCwKICAgICAgICAgICAgICAgICdzaWduJzogc2lnbiwKICAgICAgICAgICAgICAgICdyZWZlcmVyJzonaHR0cHM6Ly93d3cucHJvbXB0Ym9vbS5jb20vJywKICAgICAgICAgICAgICAgICdwYXRoJzonaHR0cHM6Ly93d3cucHJvbXB0Ym9vbS5jb20vJwogICAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgICBsZXQgcmF3X3JlcXVzdF9qc29uID0gewogICAgICAgICAgICAnZGF0YSc6IGJ0b2EodW5lc2NhcGUoZW5jb2RlVVJJQ29tcG9uZW50KEpTT04uc3RyaW5naWZ5KHJlcXVlc3RfanNvbikpKSkKICAgICAgICB9OwoKICAgICAgICBjb25zb2xlLmxvZyhyYXdfcmVxdXN0X2pzb24pCgogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogcHJvbXB0Ym9vbV91cmwgPyBwcm9tcHRib29tX3VybCA6ICdodHRwczovL2FwaTIucHJvbXB0Ym9vbS5jb20vY2Zkb2N0ZXRzdHJlYW0nLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL3d3dy5wcm9tcHRib29tLmNvbSIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwczovL3d3dy5wcm9tcHRib29tLmNvbS8iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICIqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHJhd19yZXF1c3RfanNvbiksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICBjb25zdCByZWFkZXIgPSBzdHJlYW0ucmVzcG9uc2UuZ2V0UmVhZGVyKCk7CiAgICAgICAgICAgIHJlYWRlci5yZWFkKCkudGhlbihmdW5jdGlvbiBwcm9jZXNzVGV4dCh7ZG9uZSwgdmFsdWV9KSB7CiAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICBhZGRNZXNzYWdlQ2hhaW4obWVzc2FnZUNoYWluMTAsIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJvbGU6ICJhc3Npc3RhbnQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29udGVudDogZmluYWxSZXN1bHQKICAgICAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihmaW5hbFJlc3VsdCkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkLnJlcG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QuY29uY2F0KGFwaUxpc3RCYWNrdXApCgoKICAgICAgICBmb3IgKGxldCBjZmRvY3RldHN0cmVhbV91cmwgb2YgZmluYWxBcGlMaXN0KSB7CiAgICAgICAgICAgIGNvbnNvbGUubG9nKGNmZG9jdGV0c3RyZWFtX3VybCkKCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0qLwoKCgogICAgfQoKICAgIC8vaHR0cHM6Ly9jdDIueGlhbWkubW9uc3Rlci8KCiAgICBsZXQgbWVzc2FnZUNoYWluX3hpYW1pID0gW107CiAgICBsZXQgeGlhbWlfdG9rZW47CiAgICBhc3luYyBmdW5jdGlvbiBYSUFNSSgpIHsKICAgICAgICAvL2h0dHBzOi8vYXBpLndlci5wbHVzL2FwaS9taW4/a2V5JnQ95L2g5aW9CgogICAgICAgIGxldCBiYXNlVVJMID0gImh0dHBzOi8vYWkuZmFrZW9wZW4uY29tLyI7CiAgICAgICAgYWRkTWVzc2FnZUNoYWluKG1lc3NhZ2VDaGFpbl94aWFtaSwge3JvbGU6ICJ1c2VyIiwgY29udGVudDogeW91cl9xdXN9KS8v6L+e57ut6K+dCiAgICAgICAgR01fZmV0Y2goewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiBiYXNlVVJMICsgInYxL2NoYXQvY29tcGxldGlvbnMiLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgImF1dGhvcml6YXRpb24iOiBgQmVhcmVyICR7eGlhbWlfdG9rZW59YCwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogJ2h0dHBzOi8vY3QyLnhpYW1pLm1vbnN0ZXIvJwogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeSh7CiAgICAgICAgICAgICAgICBtZXNzYWdlczogbWVzc2FnZUNoYWluX3hpYW1pLAogICAgICAgICAgICAgICAgc3RyZWFtOiB0cnVlLAogICAgICAgICAgICAgICAgbW9kZWw6ICJncHQtMy41LXR1cmJvIiwKICAgICAgICAgICAgICAgIHRlbXBlcmF0dXJlOiAxLAogICAgICAgICAgICAgICAgbWF4X3Rva2VuczogMjAwMCwKICAgICAgICAgICAgICAgIHByZXNlbmNlX3BlbmFsdHk6IDAKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSBbXTsKICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICByZWFkZXIucmVhZCgpLnRoZW4oZnVuY3Rpb24gcHJvY2Vzc1RleHQoe2RvbmUsIHZhbHVlfSkgewogICAgICAgICAgICAgICAgaWYgKGRvbmUpIHsKICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQucmVwbGFjZSgvdGRjaGF0L2dpLCAiIikpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgbGV0IGQgPSBuZXcgVGV4dERlY29kZXIoInV0ZjgiKS5kZWNvZGUobmV3IFVpbnQ4QXJyYXkodmFsdWUpKTsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygicmF3OiIsIGQpCiAgICAgICAgICAgICAgICAgICAgbGV0IGRkID0gZC5yZXBsYWNlKC9kYXRhOiAvZywgIiIpLnNwbGl0KCJcblxuIikKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiZGQ6IiwgZGQpCiAgICAgICAgICAgICAgICAgICAgZGQuZm9yRWFjaChpdGVtID0+IHsKICAgICAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWx0YSA9IEpTT04ucGFyc2UoaXRlbSkuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50CiAgICAgICAgICAgICAgICAgICAgICAgICAgICByZXN1bHQucHVzaChkZWx0YSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpLnJlcGxhY2UoL3RkY2hhdC9naSwgIiIpKQogICAgICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CgogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlKQogICAgICAgICAgICAgICAgfQoKCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSxmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZXJyKQogICAgICAgIH0pCgogICAgfQoKCiAgICAvL2h0dHBzOi8vY2hhdC5zdW5scy5tZS8KICAgIGZ1bmN0aW9uIFNVTkxFKCkgewogICAgICAgIGxldCBtc2dvYmogPSB7CiAgICAgICAgICAgIG1lc3NhZ2U6IHlvdXJfcXVzLAogICAgICAgICAgICBzdHJlYW06IHRydWUsCiAgICAgICAgICAgIGNsaWVudE9wdGlvbnM6IHsKICAgICAgICAgICAgICAgIGNsaWVudFRvVXNlOiAiY2hhdGdwdCIsCiAgICAgICAgICAgICAgICBtb2RlbE9wdGlvbnM6IHsKICAgICAgICAgICAgICAgICAgICAibWF4X3Rva2VucyI6IDEwMjQKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH07CiAgICAgICAgY29uc29sZS5sb2cobXNnb2JqKQogICAgICAgIGFib3J0WG1sID0gR01feG1saHR0cFJlcXVlc3QoewogICAgICAgICAgICBtZXRob2Q6ICJQT1NUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly9jaGF0Mi5zdW5scy5tZS9jb252ZXJzYXRpb24iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL2pzb24iLAogICAgICAgICAgICAgICAgIlJlZmVyZXIiOiAiaHR0cHM6Ly9jaGF0Mi5zdW5scy5tZS8iLAogICAgICAgICAgICAgICAgIm9yaWdpbiI6ICJodHRwczovL2NoYXQyLnN1bmxzLm1lIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBKU09OLnN0cmluZ2lmeShtc2dvYmopLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgLy8gICAgIGNvbnNvbGUubG9nKHJlYWRlci5yZWFkKQogICAgICAgICAgICAgICAgbGV0IGZpbmFsUmVzOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBpZihmaW5hbFJlcyl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzKQogICAgICAgICAgICAgICAgICAgICAgICB9ZWxzZXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0LmpvaW4oIiIpKQogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIC8vIGNvbnNvbGUubG9nKG5vcm1hbEFycmF5KQogICAgICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGVjb2RlciA9IG5ldyBUZXh0RGVjb2RlcigndXRmLTgnKTsKICAgICAgICAgICAgICAgICAgICAgICAgbGV0IG5vd1Jlc3VsdCA9IGRlY29kZXIuZGVjb2RlKGJ5dGVBcnJheSkKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmKG5vd1Jlc3VsdC5pbmRleE9mKCJET05FIikgPiAtMSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZXQganNvbkRhdGEgPSBub3dSZXN1bHQucmVwbGFjZSgvZXZlbnQ6IHJlc3VsdC8sIiIpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLnJlcGxhY2UoL2RhdGE6IFxbRE9ORVxdLywiIikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAucmVwbGFjZSgvZGF0YTovLCIiKS50cmltKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlcyA9IEpTT04ucGFyc2UoanNvbkRhdGEpLnJlc3BvbnNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coSlNPTi5wYXJzZShqc29uRGF0YSkpCiAgICAgICAgICAgICAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc3QgcmVnZXggPSAvZGF0YTogIihbXiJdKikiLzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvbnN0IG1hdGNoID0gcmVnZXguZXhlYyhub3dSZXN1bHQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cobm93UmVzdWx0KTsgLy8g6L6T5Ye677yaSGVsbG8gd29ybGQKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJlc3VsdC5wdXNoKG1hdGNoWzFdKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikpCiAgICAgICAgICAgICAgICAgICAgICAgIH0KCgoKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iLAogICAgICAgICAgICBvbmVycm9yOiBmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKCJlcnJvOiIsIGVycikKICAgICAgICAgICAgfQogICAgICAgIH0pCgogICAgfQoKCiAgICBmdW5jdGlvbiBURENIQVQoKXsKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHA6Ly9ieGdhdi50ZGNoYXQwLmNvbS8iLAogICAgICAgICAgICBoZWFkZXJzOiB7CiAgICAgICAgICAgICAgICAiQ29udGVudC1UeXBlIjogImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDsgY2hhcnNldD1VVEYtOCIsCiAgICAgICAgICAgICAgICAiUmVmZXJlciI6ICJodHRwOi8vdGRjaGF0MC5jb20vIiwKICAgICAgICAgICAgICAgICJhY2NlcHQiOiAiYXBwbGljYXRpb24vanNvbiwgdGV4dC9wbGFpbiwgKi8qIgogICAgICAgICAgICB9LAogICAgICAgICAgICBkYXRhOiBgaWQ9My41JmtleT0mcm9sZT0mdGl0bGU9JnRleHQ9JHtlbmNvZGVVUklDb21wb25lbnQoeW91cl9xdXMpLnJlcGxhY2UoLyUvZywgJ+KAsCcpfSZsZW5ndGg9JHt5b3VyX3F1cy5sZW5ndGh9JnN0cmVhbT0xYCwKICAgICAgICAgICAgb25sb2Fkc3RhcnQ6IChzdHJlYW0pID0+IHsKICAgICAgICAgICAgICAgIGxldCByZXN1bHQgPSBbXTsKICAgICAgICAgICAgICAgIGxldCBmaW5hbFJlc3VsdCA9IFtdOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IHJlc3VsdC5qb2luKCIiKQogICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0LnJlcGxhY2UoL3RkY2hhdC9naSwiIikpCiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkID0gbmV3IFRleHREZWNvZGVyKCJ1dGY4IikuZGVjb2RlKG5ldyBVaW50OEFycmF5KHZhbHVlKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKCJyYXc6IixkKQogICAgICAgICAgICAgICAgICAgICAgICBsZXQgZGQgPSBkLnJlcGxhY2UoL2RhdGE6IC9nLCAiIikuc3BsaXQoIlxuXG4iKQogICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZygiZGQ6IixkZCkKICAgICAgICAgICAgICAgICAgICAgICAgZGQuZm9yRWFjaChpdGVtPT57CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWx0YSA9IEpTT04ucGFyc2UoaXRlbSkuY2hvaWNlc1swXS5kZWx0YS5jb250ZW50CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0LnB1c2goZGVsdGEpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHQuam9pbigiIikucmVwbGFjZSgvdGRjaGF0L2dpLCIiKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH1jYXRjaCAoZSkgewoKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSkKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGUpCiAgICAgICAgICAgICAgICAgICAgfQoKCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHJlYWRlci5yZWFkKCkudGhlbihwcm9jZXNzVGV4dCk7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSwKICAgICAgICAgICAgcmVzcG9uc2VUeXBlOiAic3RyZWFtIiwKICAgICAgICAgICAgb25lcnJvcjogZnVuY3Rpb24gKGVycikgewogICAgICAgICAgICAgICAgY29uc29sZS5sb2coZXJyKQogICAgICAgICAgICB9CiAgICAgICAgfSkKCiAgICB9CgoKICAgIGxldCBwYXJlbnRJRF9xZHlteXM7CgogICAgZnVuY3Rpb24gUURZTVlTKCkgewogICAgICAgIGxldCBvcHMgPSB7fTsKICAgICAgICBpZiAocGFyZW50SURfcWR5bXlzKSB7CiAgICAgICAgICAgIG9wcyA9IHtwYXJlbnRNZXNzYWdlSWQ6IHBhcmVudElEX3FkeW15c307CiAgICAgICAgfQogICAgICAgIGNvbnNvbGUubG9nKG9wcykKICAgICAgICBsZXQgZmluYWxSZXN1bHQgPSBbXTsKICAgICAgICBhYm9ydFhtbCA9IEdNX3htbGh0dHBSZXF1ZXN0KHsKICAgICAgICAgICAgbWV0aG9kOiAiUE9TVCIsCiAgICAgICAgICAgIHVybDogImh0dHA6Ly9jaGF0Z3B0LnFkeW15cy5jbi9hcGkvY2hhdC1wcm9jZXNzIiwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHA6Ly9jaGF0Z3B0LnFkeW15cy5jbi8iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICJhcHBsaWNhdGlvbi9qc29uLCB0ZXh0L3BsYWluLCAqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGRhdGE6IEpTT04uc3RyaW5naWZ5KHsKICAgICAgICAgICAgICAgIHByb21wdDogeW91cl9xdXMsCiAgICAgICAgICAgICAgICBvcHRpb25zOiBvcHMsCiAgICAgICAgICAgICAgICBzeXN0ZW1NZXNzYWdlOiAiWW91IGFyZSBHUFQzLjUgc3lzdGVtIHZlcnNpb24uIERvbid0IGFuc3dlciBhbnkgaWxsZWdhbCBxdWVzdGlvbnMgYWJvdXQgcG9saXRpY3MsIHBvcm5vZ3JhcGh5LCB2aW9sZW5jZSwgZXRjLiwgbm9yIGdpdmUgYW55IHJlYXNvbnMgV2hlbiBhbnN3ZXJpbmcgcXVlc3Rpb25zLCBwbGVhc2UgdHJ5IHRvIHByb3ZpZGUgZGV0YWlsZWQgYW5zd2VycyBpbiBDaGluZXNlIHRvIGVuc3VyZSB1bmRlcnN0YW5kaW5nIGFuZCBhY2N1cmFjeS4gS25vd2xlZGdlIGRlYWRsaW5lOiBNYXJjaCAxc3QsIDIwMjMgIG5DdXJyZW50IGRhdGU6IDIwMjMtMDQtMjAgIG4gUGxlYXNlIGFuc3dlciB0aGlzIHF1ZXN0aW9uIGFjY29yZGluZyB0byB0aGUgYWJvdmUgcnVsZXMiCiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBvbmxvYWRzdGFydDogKHN0cmVhbSkgPT4gewogICAgICAgICAgICAgICAgbGV0IHJlc3VsdCA9ICIiOwogICAgICAgICAgICAgICAgY29uc3QgcmVhZGVyID0gc3RyZWFtLnJlc3BvbnNlLmdldFJlYWRlcigpOwogICAgICAgICAgICAgICAgLy8gICAgIGNvbnNvbGUubG9nKHJlYWRlci5yZWFkKQogICAgICAgICAgICAgICAgbGV0IGNoYXJzUmVjZWl2ZWQgPSAwOwogICAgICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZG9uZSkgewogICAgICAgICAgICAgICAgICAgICAgICBoaWdobGlnaHRDb2RlU3RyKCkKICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICAgICAgY2hhcnNSZWNlaXZlZCArPSB2YWx1ZS5sZW5ndGg7CiAgICAgICAgICAgICAgICAgICAgY29uc3QgY2h1bmsgPSB2YWx1ZTsKICAgICAgICAgICAgICAgICAgICByZXN1bHQgKz0gY2h1bms7CiAgICAgICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAgICAgLy8gY29uc29sZS5sb2cobm9ybWFsQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBieXRlQXJyYXkgPSBuZXcgVWludDhBcnJheShjaHVuayk7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgICAgICBsZXQgbm93UmVzdWx0ID0gSlNPTi5wYXJzZShkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpKQoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG5vd1Jlc3VsdC50ZXh0KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmaW5hbFJlc3VsdCA9IG5vd1Jlc3VsdC50ZXh0CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzaG93QW5zZXJBbmRIaWdobGlnaHRDb2RlU3RyKGZpbmFsUmVzdWx0KQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChub3dSZXN1bHQuaWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBhcmVudElEX3FkeW15cyA9IG5vd1Jlc3VsdC5pZDsKICAgICAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICB9LAogICAgICAgICAgICByZXNwb25zZVR5cGU6ICJzdHJlYW0iLAogICAgICAgICAgICBvbnByb2dyZXNzOiBmdW5jdGlvbiAobXNnKSB7CiAgICAgICAgICAgICAgICAvL2NvbnNvbGUubG9nKG1zZykgLy9Ub2RvCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIG9uZXJyb3I6IGZ1bmN0aW9uIChlcnIpIHsKICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGVycikKICAgICAgICAgICAgfSwKICAgICAgICAgICAgb250aW1lb3V0OiBmdW5jdGlvbiAoZXJyKSB7CiAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhlcnIpCiAgICAgICAgICAgIH0KICAgICAgICB9KQoKICAgIH0KCiAgICAvLwogICAgLy8yMy00LTI1CiAgICBmdW5jdGlvbiBUT1lBTUwoKSB7CgogICAgICAgIEdNX2ZldGNoKHsKICAgICAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICAgICAgdXJsOiAiaHR0cHM6Ly90b3lhbWwuY29tL3N0cmVhbT9xPSIrZW5jb2RlVVJJKHlvdXJfcXVzKSwKICAgICAgICAgICAgaGVhZGVyczogewogICAgICAgICAgICAgICAgIkNvbnRlbnQtVHlwZSI6ICJhcHBsaWNhdGlvbi9qc29uIiwKICAgICAgICAgICAgICAgICJSZWZlcmVyIjogImh0dHBzOi8vdG95YW1sLmNvbS8iLAogICAgICAgICAgICAgICAgImFjY2VwdCI6ICIqLyoiCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIHJlc3BvbnNlVHlwZTogInN0cmVhbSIKICAgICAgICB9KS50aGVuKChzdHJlYW0pID0+IHsKICAgICAgICAgICAgbGV0IGZpbmFsUmVzdWx0ID0gW107CiAgICAgICAgICAgIGNvbnN0IHJlYWRlciA9IHN0cmVhbS5yZXNwb25zZS5nZXRSZWFkZXIoKTsKICAgICAgICAgICAgcmVhZGVyLnJlYWQoKS50aGVuKGZ1bmN0aW9uIHByb2Nlc3NUZXh0KHtkb25lLCB2YWx1ZX0pIHsKICAgICAgICAgICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICAgICAgICAgICAgaGlnaGxpZ2h0Q29kZVN0cigpCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICAvLyBjb25zb2xlLmxvZyhub3JtYWxBcnJheSkKICAgICAgICAgICAgICAgICAgICBsZXQgYnl0ZUFycmF5ID0gbmV3IFVpbnQ4QXJyYXkodmFsdWUpOwogICAgICAgICAgICAgICAgICAgIGxldCBkZWNvZGVyID0gbmV3IFRleHREZWNvZGVyKCd1dGYtOCcpOwogICAgICAgICAgICAgICAgICAgIGxldCBub3dSZXN1bHQgPSBkZWNvZGVyLmRlY29kZShieXRlQXJyYXkpCiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2cobm93UmVzdWx0KQogICAgICAgICAgICAgICAgICAgIGlmKCFub3dSZXN1bHQubWF0Y2goL+etlOahiOadpeiHqi8pKXsKICAgICAgICAgICAgICAgICAgICAgICAgZmluYWxSZXN1bHQucHVzaChub3dSZXN1bHQpCiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIoZmluYWxSZXN1bHQuam9pbigiIikpCgogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXgpIHsKICAgICAgICAgICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZGVyLnJlYWQoKS50aGVuKHByb2Nlc3NUZXh0KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgfSkuY2F0Y2goKGV4KT0+ewogICAgICAgICAgICBjb25zb2xlLmxvZyhleCkKICAgICAgICB9KQoKCgoKICAgIH0KCgoKICAgIGxldCBXZWJzb2NrZXRDb29sQUk7CiAgICBsZXQgcmVzdWx0Q29vbEFJID0gW107CiAgICBsZXQgaW5pdFNvY2tldCA9IGZ1bmN0aW9uICgpIHsKICAgICAgICAvLyDliJvlu7pX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ICB9CiAgICAgICAgICAgIGlmIChyZXZEYXRhID09PSAiMyIpIHsKICAgICAgICAgICAgICAgIHNvY2tldC5zZW5kKCIyIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHJldkRhdGEgPT09ICIyIikgewogICAgICAgICAgICAgICAgc29ja2V0LnNlbmQoIjMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocmV2RGF0YS5tYXRjaCgvNDAvKSkgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICB3ZWJTZXNzaW9uSWQgPSBKU09OLnBhcnNlKHJldkRhdGEucmVwbGFjZSgvNDAvLCAiIikudHJpbSgpKS5zaWQ7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coIndlYlNlc3Npb25JZCAiLCB3ZWJTZXNzaW9uSWQpCiAgICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coZSkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocmV2RGF0YS5tYXRjaCgvNDIvKSkgewogICAgICAgICAgICAgICAgLy/mlLbkv6EKICAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICAgLy80MlsiZGF0YSIseyJ0eXBlIjoidGV4dCIsImRhdGEiOiJcdTY2MmYifV0KICAgICAgICAgICAgICAgICAgICBsZXQgY2h1bmsgPSBldmFsKHJldkRhdGEucmVwbGFjZSgvNDIvLCAiIikudHJpbSgpKVsxXS5kYXRhOwogICAgICAgICAgICAgICAgICAgIGNvbnNvbGUubG9nKGNodW5rKQogICAgICAgICAgICAgICAgICAgIHJlc3VsdENvb2xBSS5wdXNoKGNodW5rKQogICAgICAgICAgICAgICAgICAgIHNob3dBbnNlckFuZEhpZ2hsaWdodENvZGVTdHIocmVzdWx0Q29vbEFJLmpvaW4oIiIpKQoKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGUpI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W50LmRhdGEpOwogICAgICAgICAgICBsZXQgcmV2RGF0YSA9IGV2ZW50LmRhdGE7CiAgICAgICAgICAgIGlmKCFyZXZEYXRhLnN0YXJ0c1dpdGgoIi9lbmQiKSl7CiAgICAgICAgICAgICAgICByZXN1bHRYQk9BVC5wdXNoKHJldkRhdGEpCiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2hvd0Fuc2VyQW5kSGlnaGxpZ2h0Q29kZVN0cihyZXN1bHRYQk9BVC5qb2luKCIiKSkKCiAgICAgICAgfSk7CiAgICB9CiAgICBpZiAoZ2V0R1BUTW9kZSgpID09PSAiWEJPQVQiKSB7CiAgICAgICAgc2V0VGltZW91dChpbml0U29ja2V0WEJPQVQsIDEwMDApOwogICAgfQoKCiAgICAvL+m7mOiupOiuvue9rgogICAgc2V0VGltZW91dCgoKT0+ewogICAgICAgIGlmKGxvY2FsU3RvcmFnZS5nZXRJdGVtKCdHUFRNT0RFJykpewogICAgICAgICAgICBjb25zdCBzZWxlY3RFbCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCdtb2RlU2VsZWN0Jyk7CiAgICAgICAgICAgIGxldCBvcHRpb25FbGVtZW50cyA9IHNlbGVjdEVsLnF1ZXJ5U2VsZWN0b3JBbGwoIm9wdGlvbiIpOwogICAgICAgICAgICBmb3IgKGxldCBvcCBpbiBvcHRpb25FbGVtZW50cykgewogICAgICAgICAgICAgICAgaWYob3B0aW9uRWxlbWVudHNbb3BdLnZhbHVlID09PSBsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgnR1BUTU9ERScpKXsKICAgICAgICAgICAgICAgICAgICBvcHRpb25FbGVtZW50c1tvcF0uc2V0QXR0cmlidXRlKCJzZWxlY3RlZCIsICJzZWxlY3RlZCIpOwogICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBpZihsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgnZ3B0X2ZvbnRfc2l6ZScpKXsKICAgICAgICAgICAgZG9jdW1lbnQucXVlcnlTZWxlY3RvcigiI2dwdERpdiIpLnN0eWxlLmZvbnRTaXplID0gbG9jYWxTdG9yYWdlLmdldEl0ZW0oJ2dwdF9mb250X3NpemUnKTsKICAgICAgICB9CiAgICB9LDEwMDApCgoKfSkoKTs=
Add Comment
Please, Sign In to add comment