Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Unauthorize and authorize agent via groovy #4164

JShelton ·

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
robinshen ADMIN ·

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

Thanks so much Robin, this is perfect.