diff --git a/drone.go b/drone.go index f7e15baa..c4f80c7f 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 00000000..702e32e8 --- /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 4da4f2f6..53b226e5 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 00000000..e261bc33 --- /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 16f51c07..054738ae 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 00000000..44d0372b --- /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 00000000..7bc572e8 --- /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 701c26e4..e5d13a1c 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 +