I'm looking to be able to unauthorize a build agent using groovy, as well as to later authorize. Is this possible in QB8 (and QB9)? If so, what's the best way to go about doing this?
- solved #2
- replies 2
- views 399
- stars 0
Yes this is possible. Just translate below (from agent authorization/unauthorization source) into groovy script:
@Path("authorize")
@GET
public Long authorize(@QueryParam("ip") String ip, @QueryParam("port") int port) {
if (!SecurityHelper.isAdmin())
throw new AccessDeniedException(SecurityHelper.getAccessDeniedMessage());
if (ip == null)
throw new RuntimeException("ip address should be specified");
if (port == 0)
throw new RuntimeException("port should be specified");
Token token = new Token();
token.setIp(ip);
token.setPort(port);
token.setHostName("<Unknown>");
token.setValue(UUID.randomUUID().toString());
TokenManager.instance.save(token);
return token.getId();
}
@Path("unauthorize")
@GET
public Long unauthorize(@QueryParam("ip") String ip, @QueryParam("port") int port) {
if (!SecurityHelper.isAdmin())
throw new AccessDeniedException(SecurityHelper.getAccessDeniedMessage());
if (ip == null)
throw new RuntimeException("ip address should be specified");
if (port == 0)
throw new RuntimeException("port should be specified");
Token token = CacheManager.instance.getToken(ip, port);
if (token == null)
return null;
else {
TokenManager.instance.delete(token);
return token.getId();
}
}