I'm trying to develop a SonarQube (Compute Engine) plugin and I need to use the credentials (sonar.user // sonar.password) in order to invoke web services from within the plugin itself.
I try declaring the use of them in the Plugin class, e.g.:
@Override
public void define(Plugin.Context context) {
...
context.addExtensions(asList(
PropertyDefinition.builder(SONAR_USER)
.name("Sonar user")
.description("SonarQube user")
.onQualifiers(Qualifiers.PROJECT)
.type(PropertyType.STRING)
.defaultValue("admin")
.build()
...
Then in the hook:
public class Hook implements PostProjectAnalysisTask {
private final Server server;
private final Settings settings;
public Hook(Server server, Settings settings) {
this.server = server;
this.settings = settings;
}
@Override
public void finished(ProjectAnalysis projectAnalysis) {
final HttpConnector httpConnector =
HttpConnector.newBuilder()
.url(server.getURL())
.credentials(
settings.getString(CePlugin.SONAR_USER), // null
settings.getString(CePlugin.SONAR_PASSWORD) // null
).build();
final WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
}
}
But when I inject Settings
inside the hook the property is not available.
How do I retrieve sonar.user
and sonar.password
so that I can invoke the Web Service API?