Skip to main content

Open SonarQube API Handler

Project description

https://img.shields.io/github/license/kako-nawao/python-sonarqube-api.svg https://img.shields.io/pypi/pyversions/sonarqube-api.svg https://img.shields.io/pypi/v/sonarqube-api.svg https://img.shields.io/travis/kako-nawao/python-sonarqube-api.svg https://img.shields.io/codecov/c/github/kako-nawao/python-sonarqube-api.svg

API Handler for SonarQube web service, providing basic authentication (which seems to be the only kind that SonarQube supports) and a few methods to run sonarqube API.

Installation

Install from PyPI:

pip install opn-sonarqube-api

Compatibility

This package is compatible Python versions 2.7, 3.4, 3.5 and 3.6. Probably others, but those are the ones against which we build (by Travis CI).

Usage

The API handler is easy to use, you just need to initialize it with the connection parameters (by default localhost on port 9000 without authentication) and use any of the methods to get the required information or create rules.

Example getting projects with coverage and issues metrics:

from sonarqube_api.sonar import SonarAPI

h = SonarAPI(user='admin', password='admin')
for project in h.get_resources_full_data(metrics=['coverage', 'violations']):
    # do something with project data...

Since the actual response data from SonarQube server is usually paged, all methods return generators to optimize memory as well retrieval performance of the first items.

You can also specify a single resources to fetch, but keep in mind that the resource methods return generators, so you still need to get the next object:

proj = next(h.get_resources_full_data(resource='some:example'))

Sonar authentication tokens can also be used in place of username and password, which is particularly useful when accessing the SonarQube API from a CI server, as tokens can easily be revoked in the event of unintended exposure:

h = SonarAPI(token='f052f55b127bb06f63c31cb2064ea301048d9e5d')

Supported Methods

The methods supported by the SonarAPI are:

  • activate_rule: activate a rule for a given profile in the server

  • create_rule: create a rule in the server

  • get_metrics: yield metrics definition

  • get_rules: yield active rules

  • get_resources_debt: yield projects with their technical debt by category

  • get_resources_metrics: yield projects with some general metrics

  • get_resources_full_data: yield projects with their general metrics and technical debt by category (merge of previous two methods)

  • validate_authentication: validate authentication credentials

  • create_group

  • search_group

  • update_group

  • delete_group

  • create_permission_template

  • update_permission_template

  • search_permission_template

  • delete_permission_template

  • add_group_to_template

  • list_groups_of_template

  • remove_group_from_template

  • add_permission_to_user

  • remove_permission_to_user

  • add_permission_to_group

  • remove_permission_to_group

  • search_permission_for_group

  • generate_token

  • revoke_token

  • user_tokens

  • user_current

  • get_metrics

  • restore_quality_profile_from_xml

  • create_quality_profile

  • add_project_to_quality_profile

  • delete_quality_profile

  • activate_rule

  • get_resources_debt

  • get_resources_metrics

  • create_rule

  • get_rules

  • get_resources_full_data

  • setting

  • getting

  • list_qualitygates

  • show_qualitygates

  • create_qualitygates

  • destroy_qualitygates

  • create_condition_qualitygates

  • create_quality_gate_from_json

  • delete_condition_qualitygates

  • update_condition_qualitygates

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opn_sonarqube_api-2.0.0.320423.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opn_sonarqube_api-2.0.0.320423-py2-none-any.whl (26.1 kB view details)

Uploaded Python 2

File details

Details for the file opn_sonarqube_api-2.0.0.320423.tar.gz.

File metadata

  • Download URL: opn_sonarqube_api-2.0.0.320423.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/2.7.17

File hashes

Hashes for opn_sonarqube_api-2.0.0.320423.tar.gz
Algorithm Hash digest
SHA256 fb2dfb1c8cd5c3440e67fbb958350c16a373fa199fd45500d3590cb4dd94b0bc
MD5 9c3ad19a30ee2ebf27508c52f4b2c6eb
BLAKE2b-256 c97db6e260c292a3903531d733fcf4afad4003816c997b0e57dcc67e4a94059b

See more details on using hashes here.

File details

Details for the file opn_sonarqube_api-2.0.0.320423-py2-none-any.whl.

File metadata

  • Download URL: opn_sonarqube_api-2.0.0.320423-py2-none-any.whl
  • Upload date:
  • Size: 26.1 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/2.7.17

File hashes

Hashes for opn_sonarqube_api-2.0.0.320423-py2-none-any.whl
Algorithm Hash digest
SHA256 8ad95e21c6034dd3a5b72f8c48758cb6cdeba8826cea90ee9d43e2ad62a37708
MD5 6efea7c52ff16786cde023ca6c252570
BLAKE2b-256 ca06760997d0acc2d6ed65b1aff43547cc2ca48e0df2511fc6eb12cf4e8a9277

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page