| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 | |
| 6 --> | |
| 7 <!DOCTYPE html> | |
| 8 <html> | |
| 9 <head> | |
| 10 <title>bot-page Demo</title> | |
| 11 <meta charset="utf-8"> | |
| 12 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
| 13 <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-
scale=1, user-scalable=yes"> | |
| 14 <script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></scri
pt> | |
| 15 <script src="../../../node_modules/skia-common-js/common.js"></script> | |
| 16 <script src="../../../build/js/common-strings.js"></script> | |
| 17 <script src="/res/js/common.js"></script> | |
| 18 <script src="/res/js/alias.js"></script> | |
| 19 <script src="../../../node_modules/sinon/pkg/sinon-1.17.5.js"></script> | |
| 20 <!-- Makes a var called bots. It's an array of things that could be returned-
-> | |
| 21 <script type="text/javascript" src="bot-demo.json"></script> | |
| 22 <!-- Makes a var called events. It's an array of things that could be returne
d--> | |
| 23 <script type="text/javascript" src="bot-events-demo.json"></script> | |
| 24 <!-- Makes a var called tasks. It's an array of things that could be returned
--> | |
| 25 <script type="text/javascript" src="bot-tasks-demo.json"></script> | |
| 26 | |
| 27 <script type="text/javascript" charset="utf-8"> | |
| 28 sinon.format = function(object) {return JSON.stringify(object);} | |
| 29 sinon.log = function(message) {console.log(message);}; | |
| 30 var server = sinon.fakeServer.create(); | |
| 31 server.autoRespond = true; | |
| 32 server.autoRespondAfter = 1000; | |
| 33 sk.now = function(){ | |
| 34 // for stats, lock in "now" at Wed Sep 28 2016 16:23:04 GMT-0400 (EDT) | |
| 35 return 1475094184; | |
| 36 } | |
| 37 | |
| 38 var genResponse = function(arr) { | |
| 39 return function(request){ | |
| 40 if (!request.requestHeaders.authorization) { | |
| 41 sinon.log("You must be logged in (check your Oauth?)"); | |
| 42 request.respond(403, {}, "You must be logged in (check your Oauth?)"); | |
| 43 return; | |
| 44 } | |
| 45 sinon.log("User authenticated :) "+ request.requestHeaders.authorization
); | |
| 46 sinon.log("Bot Request: "+sinon.format(request)); | |
| 47 // If the user changes bot id, show them some of the other sample data. | |
| 48 var idx = request.url.indexOf("-00"); | |
| 49 var item = 0; | |
| 50 if (idx !=-1) { | |
| 51 var name = request.url.substring(idx+1, idx+4); | |
| 52 item = parseInt(name) || 0; | |
| 53 item = Math.max(item - 1, 0); | |
| 54 item = Math.min(item, arr.length-1); | |
| 55 } | |
| 56 | |
| 57 | |
| 58 request.respond(200, {"Content-Type":"application/json"}, JSON.stringify
(arr[item])); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 | |
| 63 server.respondWith("GET", /^\/_ah\/api\/swarming\/v1\/bot\/test-bot-\d+\/get
.*/, genResponse(bots)); | |
| 64 server.respondWith("GET", /^\/api\/swarming\/v1\/bot\/test-bot-\d+\/get.*/,
genResponse(bots)); | |
| 65 | |
| 66 server.respondWith("GET", /^\/_ah\/api\/swarming\/v1\/bot\/test-bot-\d+\/eve
nts.*/, genResponse(events)); | |
| 67 server.respondWith("GET", /^\/api\/swarming\/v1\/bot\/test-bot-\d+\/events.*
/, genResponse(events)); | |
| 68 | |
| 69 server.respondWith("GET", /^\/_ah\/api\/swarming\/v1\/bot\/test-bot-\d+\/tas
ks.*/, genResponse(tasks)); | |
| 70 server.respondWith("GET", /^\/api\/swarming\/v1\/bot\/test-bot-\d+\/tasks.*/
, genResponse(tasks)); | |
| 71 | |
| 72 var permissions = { | |
| 73 cancel_task: true, | |
| 74 delete_bot: true, | |
| 75 terminate_bot: true, | |
| 76 }; | |
| 77 server.respondWith("GET", /^\/_ah\/api\/swarming\/v1\/server\/permissions/,
JSON.stringify(permissions)); | |
| 78 server.respondWith("GET", /^\/api\/swarming\/v1\/server\/permissions/, JSON.
stringify(permissions)); | |
| 79 | |
| 80 var details = { | |
| 81 server_version: "1234-deadbeef", | |
| 82 bot_version: "abcdoeraymeyouandme", | |
| 83 machine_provider_template: "http://example.com#/leases/%s?foo=bar", | |
| 84 }; | |
| 85 server.respondWith("GET", /^\/_ah\/api\/swarming\/v1\/server\/details/, JSON
.stringify(details)); | |
| 86 server.respondWith("GET", /^\/api\/swarming\/v1\/server\/details/, JSON.stri
ngify(details)); | |
| 87 | |
| 88 var deleteRequest = function(request) { | |
| 89 console.log("Deleting", request); | |
| 90 if (!request.requestHeaders.authorization) { | |
| 91 sinon.log("You must be logged in (check your Oauth?)"); | |
| 92 request.respond(403, {}, "You must be logged in (check your Oauth?)"); | |
| 93 return; | |
| 94 } | |
| 95 request.respond(200, {}, "Bot has been deleted."); | |
| 96 } | |
| 97 | |
| 98 server.respondWith("POST", /^\/_ah\/api\/swarming\/v1\/bot\/.+\/delete/, del
eteRequest); | |
| 99 server.respondWith("POST", /^\/api\/swarming\/v1\/bot\/.+\/delete/, deleteRe
quest); | |
| 100 | |
| 101 var terminateRequest = function(request) { | |
| 102 console.log("Terminating", request); | |
| 103 if (!request.requestHeaders.authorization) { | |
| 104 sinon.log("You must be logged in (check your Oauth?)"); | |
| 105 request.respond(403, {}, "You must be logged in (check your Oauth?)"); | |
| 106 return; | |
| 107 } | |
| 108 request.respond(200, {}, "Bot has been terminated."); | |
| 109 } | |
| 110 | |
| 111 server.respondWith("POST", /^\/_ah\/api\/swarming\/v1\/bot\/.+\/terminate/,
terminateRequest); | |
| 112 server.respondWith("POST", /^\/api\/swarming\/v1\/bot\/.+\/terminate/, termi
nateRequest); | |
| 113 </script> | |
| 114 | |
| 115 <link rel="import" href="bot-page.html"> | |
| 116 </head> | |
| 117 <body> | |
| 118 | |
| 119 <bot-page | |
| 120 bot_id="test-bot-001" | |
| 121 client_id="20770472288-t5smpbpjptka4nd888fv0ctd23ftba2o.apps.googleusercontent
.com"> | |
| 122 </bot-page> | |
| 123 | |
| 124 </body> | |
| 125 </html> | |
| OLD | NEW |