Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for static and dynamic analyzer tools.
https://codechecker.readthedocs.io
Apache License 2.0
2.27k stars 382 forks source link

API documentation #1870

Open polskikh opened 5 years ago

polskikh commented 5 years ago

Hi there,

Sorry for dummy question, but where can I find documentation regarding API? I want to send requests to CodeChecker store, get results and filter them (e.g. by severity) for my dashboard. Is it possible? If yes, where can information about it? Because right now it's not clear for me.

gyorb commented 5 years ago

Hi,

You can use the command line (CodeChecker cmd) to query the results. You can checkout the documentation here. You can filter in the command line and get back the results in various formats (json, csv, text). You can build a custom client, but I would suggest to try to use the built-in first.

polskikh commented 5 years ago

@gyorb Good, but I want to send http request to CodeChecker and get results. Is it possible? I found only this documentation https://github.com/Ericsson/codechecker/tree/master/docs/api, but no information about how I can use it.

I can't run CodeChecker CLI, I can(want) use only network communication. Is it possible to get results by http request? How CLI communicate with storage?

gyorb commented 5 years ago

Hi,

We are using thrift to communicate between the server and the clients. It can generate the client and server side stubs which automatically encode and decode the api endpoint and the transferred data (in json in this case). Communication is done over HTTP POST messages. You do not have to manually handle the json data which is sent over the wire.

The api definition files are here for our multiple api endpoints (authentication, result management ...) The web browse and the command line client use the same api.

The thrift api definition to get the results is here: https://github.com/Ericsson/codechecker/blob/41e4ebcb8835abb0cad3069b0942b75181c8efa4/api/v6/report_server.thrift#L331-L340

Our package build system calls the thrift compiler to generate the client and server side stubs. https://github.com/Ericsson/codechecker/blob/41e4ebcb8835abb0cad3069b0942b75181c8efa4/api/v6/Makefile#L13-L15

Getting the results in our command line client is done like this without authentication (handled by another api endpoint)

  1. Initialize the thrift client stub: https://github.com/Ericsson/codechecker/blob/41e4ebcb8835abb0cad3069b0942b75181c8efa4/libcodechecker/cmd/cmd_line_client.py#L278

  2. Setup query filters/limits and query the results: https://github.com/Ericsson/codechecker/blob/41e4ebcb8835abb0cad3069b0942b75181c8efa4/libcodechecker/cmd/cmd_line_client.py#L287-L296

  3. print out the results in various formats

Here you can find a high level architecture overview which is a bit outdated, but I will update it.

polskikh commented 5 years ago

Perfect! Thank you for help!