page to get token for workers
This commit is contained in:
parent
6fcae7d80a
commit
0dc79e5886
8 changed files with 89 additions and 1 deletions
6
drone.go
6
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)
|
||||
|
|
18
server/agent.go
Normal file
18
server/agent.go
Normal 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)
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
|
|
22
server/static/scripts/controllers/agents.js
Normal file
22
server/static/scripts/controllers/agents.js
Normal 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);
|
||||
})();
|
|
@ -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',
|
||||
|
|
22
server/static/scripts/services/agents.js
Normal file
22
server/static/scripts/services/agents.js
Normal 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);
|
||||
})();
|
12
server/static/scripts/views/agents.html
Normal file
12
server/static/scripts/views/agents.html
Normal 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>
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue