Plugin Agent/Sever Communication - Unidirectional

Answered

We have a custom plugin which we previously configured using XML-RPC which we now want to switch to unidirectional. The problem with this is that the agent requires some details from the server (server-side plugin) to authenticate with an downstream app which currently gets sent via XML-RPC from server to agent.

Is there a way for the server to allow registered agents to request these details?

0
7 comments

Hi, you can register custom a controller (https://confluence.jetbrains.com/display/TCD10/Web+UI+Extensions#WebUIExtensions-DevelopingaCustomController) that will provide the necessary data by HTTP. Then call the controller from the agent.  

0

We've already got a controller configured. How do you call it from agent side though?

0

Just send ordinary http requests using HttpClient instance obtained from the HttpUtil class.

0
Avatar
Permanently deleted user

I am getting error with 401 http status code. I added the my code below.  I require credentials which I don't know how to obtain. Do you have any idea. By the way thank your for support.

import jetbrains.buildServer.http.HttpUtil;

HttpClient httpClient = HttpUtil.createHttpClient(60);
PostMethod httpPost = new PostMethod(scanDataControllerURI.toString());
HttpClientParams httpClientParams = new HttpClientParams();
httpClientParams.setParameter(Scan_Task_ID_Literal, ScanTaskID);
httpClientParams.setParameter(BuildID_Literal, BuildID);
httpClientParams.setParameter(Message_Literal, Message);
httpClientParams.setParameter(Data_Literal, Data);
httpClientParams.setParameter(Is_Error_Literal, IsError);
httpClientParams.setParameter(HTTP_Status_Code_Literal, HTTPStatusCode);
httpClient.setParams(httpClientParams);
0

You are getting 401 response because the Controller requires authorization.

If the Controller doesn't provide any secured data then you can omit the authentication using the following method:

jetbrains.buildServer.controllers.AuthorizationInterceptor#addPathNotRequiringAuth

Another way is to add some user credentials to the request, it depends on the controller logic. Could you share what is the controller responsible for?

0
Avatar
Permanently deleted user

Thank you for your response.

Controller will store scanresult data for viewlogtab by storing data to customdatastore. How can i find userid and password for basic form authentication.

//code form my controller.

Map<String, String> parameters = getParameters(httpServletRequest);
ScanRequestResult scanRequestResult = new ScanRequestResult(parameters);
//todo: test persistence with restarting server.
DataStorage storage=new DataStorage(server);
//Stores scanRequestResult for ScanLogTab. Now scan log tab can access scan report
storage.StoreScanRequestResult(scanRequestResult);
ScanRequestResult validationMap = storage.GetScanRequestResult(scanRequestResult.BuildID);

//code from DataStorage

public DataStorage(SBuildServer server) {
this.server = server;
}

public void StoreScanRequestResult(ScanRequestResult scanRequestResult) {
final SBuild build = server.findBuildInstanceById(scanRequestResult.BuildID);
SBuildType buildType = build.getBuildType();
CustomDataStorage scanRequestStorage = buildType.getCustomDataStorage(ScanRequestStoragePrefix + scanRequestResult.BuildID);
scanRequestStorage.putValues(scanRequestResult.Parameters);
scanRequestStorage.flush();
scanRequestStorage.dispose();
}

public ScanRequestResult GetScanRequestResult(long buildID) {
final SBuild build = server.findBuildInstanceById(buildID);
SBuildType buildType = build.getBuildType();
CustomDataStorage scanRequestStorage = buildType.getCustomDataStorage(ScanRequestStoragePrefix + buildID);
ScanRequestResult scanRequestResult=new ScanRequestResult(scanRequestStorage.getValues());
scanRequestStorage.dispose();
return scanRequestResult;
}
0

Hi, 

you can create a special user with administration permissions for the build configuration and use his credentials for the Basic authentication. But please note that in this case credentials can be become publicly visible. 

0

Please sign in to leave a comment.