page to get token for workers

This commit is contained in:
Brad Rydzewski 2015-04-30 14:41:52 -07:00
parent 6fcae7d80a
commit 0dc79e5886
8 changed files with 89 additions and 1 deletions

View file

@ -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)

18
server/agent.go Normal file
View file

@ -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)
}
}

View file

@ -22,10 +22,12 @@
<!-- main javascript application -->
<script src="/static/scripts/term.js"></script>
<script src="/static/scripts/drone.js"></script>
<script src="/static/scripts/controllers/agents.js"></script>
<script src="/static/scripts/controllers/repos.js"></script>
<script src="/static/scripts/controllers/builds.js"></script>
<script src="/static/scripts/controllers/users.js"></script>
<script src="/static/scripts/services/agents.js"></script>
<script src="/static/scripts/services/repos.js"></script>
<script src="/static/scripts/services/builds.js"></script>
<script src="/static/scripts/services/users.js"></script>

View file

@ -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);
})();

View file

@ -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',

View file

@ -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);
})();

View file

@ -0,0 +1,12 @@
<h1>{{ user.login }}</h1>
<a href="/">Back</a>
<dl>
<dt>Token</dt>
<dd>{{ token }}</dd>
</dl>
<pre>
docker run drone/drone-agent --addr={{ addr }} --token={{ token }}
</pre>

View file

@ -3,6 +3,7 @@
<a href="/new">New</a>
<a href="/profile">Settings</a>
<a href="/users" ng-if="user.admin">User Management</a>
<a href="/agents" ng-if="user.admin">Agent Management</a>
<table border="1">
<thead>
@ -27,4 +28,4 @@
<td>{{ repo.last_build.head_commit.sha || repo.last_build.pull_request.source.ref }}</td>
</tr>
</tbody>
</table>
</table>