From 0dc79e588654ffb0ef202cad5012d0966096e70a Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 30 Apr 2015 14:41:52 -0700 Subject: [PATCH] page to get token for workers --- drone.go | 6 ++++++ server/agent.go | 18 +++++++++++++++++ server/static/index.html | 2 ++ server/static/scripts/controllers/agents.js | 22 +++++++++++++++++++++ server/static/scripts/drone.js | 5 +++++ server/static/scripts/services/agents.js | 22 +++++++++++++++++++++ server/static/scripts/views/agents.html | 12 +++++++++++ server/static/scripts/views/repos.html | 3 ++- 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 server/agent.go create mode 100644 server/static/scripts/controllers/agents.js create mode 100644 server/static/scripts/services/agents.js create mode 100644 server/static/scripts/views/agents.html diff --git a/drone.go b/drone.go index f7e15baaf..c4f80c7f1 100644 --- a/drone.go +++ b/drone.go @@ -68,6 +68,12 @@ func main() { users.DELETE("/:name", server.DeleteUser) } + agents := api.Group("/agents") + { + agents.Use(server.MustAdmin()) + agents.GET("/token", server.GetAgentToken) + } + repos := api.Group("/repos/:owner/:name") { repos.POST("", server.PostRepo) diff --git a/server/agent.go b/server/agent.go new file mode 100644 index 000000000..702e32e80 --- /dev/null +++ b/server/agent.go @@ -0,0 +1,18 @@ +package server + +import ( + "github.com/drone/drone/common" + "github.com/gin-gonic/gin" +) + +// GET /api/agents/token +func GetAgentToken(c *gin.Context) { + sess := ToSession(c) + token := &common.Token{} + tokenstr, err := sess.GenerateToken(token) + if err != nil { + c.Fail(500, err) + } else { + c.JSON(200, tokenstr) + } +} diff --git a/server/static/index.html b/server/static/index.html index 4da4f2f68..53b226e54 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -22,10 +22,12 @@ + + diff --git a/server/static/scripts/controllers/agents.js b/server/static/scripts/controllers/agents.js new file mode 100644 index 000000000..e261bc33e --- /dev/null +++ b/server/static/scripts/controllers/agents.js @@ -0,0 +1,22 @@ +(function () { + + function AgentsCtrl($scope, $window, users, agents) { + + // this is the address that agents should connect with. + $scope.addr = $window.location.origin; + + // Gets the currently authenticated user + users.getCached().then(function(payload){ + $scope.user = payload.data; + }); + + // Generages a remote token. + agents.getToken().then(function(payload){ + $scope.token = payload.data; + }); + } + + angular + .module('drone') + .controller('AgentsCtrl', AgentsCtrl); +})(); diff --git a/server/static/scripts/drone.js b/server/static/scripts/drone.js index 16f51c077..054738ae8 100644 --- a/server/static/scripts/drone.js +++ b/server/static/scripts/drone.js @@ -62,6 +62,11 @@ controller: 'UserCtrl', resolve: resolveUser }) + .when('/agents', { + templateUrl: '/static/scripts/views/agents.html', + controller: 'AgentsCtrl', + resolve: resolveUser + }) .when('/users', { templateUrl: '/static/scripts/views/users.html', controller: 'UsersCtrl', diff --git a/server/static/scripts/services/agents.js b/server/static/scripts/services/agents.js new file mode 100644 index 000000000..44d0372b7 --- /dev/null +++ b/server/static/scripts/services/agents.js @@ -0,0 +1,22 @@ +'use strict'; + +(function () { + + /** + * The Agent provides access to build agent + * data and management using REST API calls. + */ + function AgentService($http) { + + /** + * Gets an agent token. + */ + this.getToken = function() { + return $http.get('/api/agents/token'); + }; + } + + angular + .module('drone') + .service('agents', AgentService); +})(); diff --git a/server/static/scripts/views/agents.html b/server/static/scripts/views/agents.html new file mode 100644 index 000000000..7bc572e88 --- /dev/null +++ b/server/static/scripts/views/agents.html @@ -0,0 +1,12 @@ +

{{ user.login }}

+ +Back + +
+
Token
+
{{ token }}
+
+ +
+docker run drone/drone-agent --addr={{ addr }} --token={{ token }}
+
diff --git a/server/static/scripts/views/repos.html b/server/static/scripts/views/repos.html index 701c26e43..e5d13a1cb 100644 --- a/server/static/scripts/views/repos.html +++ b/server/static/scripts/views/repos.html @@ -3,6 +3,7 @@ New Settings User Management +Agent Management @@ -27,4 +28,4 @@ -
{{ repo.last_build.head_commit.sha || repo.last_build.pull_request.source.ref }}
\ No newline at end of file +