Sonar API Wrapper - a Sonarqube api wrapper
Project description
Sonar API Wrapper
Sonar API Wrapper - a Sonarqube api wrapper
Install
pip install sonar-api-wrapper
How to use
api_call
Executes an API call to SonarQube. This method wraps the requests.request
method.
Parameters
method
(str
): HTTP method to use (e.g., GET, POST, etc.).route
(str
): API path that will be concatenated withbase_path
. For example,qualityprofiles/search
.parameters
(dict
|None
): Dictionary of parameters for the API call. Default isNone
.body
(dict
|None
): Body of the request. Default isNone
.files
(Any
): Files to be sent in the request. Default isNone
.headers
(dict
|None
): Headers of the request. Default isNone
.is_json
(bool
): If set toTrue
, the response will be parsed as JSON. Otherwise, it returns the decoded content. Default isTrue
.username
(str
|None
): Username used for authentication. Default is set via the environment variableSONAR_USERNAME
or "admin". Argument value has precedence, followed by environment variable value and lastly default value is used.password
(str
|None
): Password used for authentication. Default is set via the environment variableSONAR_PASSWORD
or "admin". Argument value has precedence, followed by environment variable value and lastly default value is used.token
(str
|None
): Token used for authentication. It overrides username and password if present. Default value is set via the environment variableSONAR_AUTH_TOKEN
or None. Argument value has precedence, followed by environment variable value and lastly default value is used.base_path
(str
|None
): The base endpoint used to build the API call. Default is set via the environment variableSONAR_HOST_URL
or "http://localhost:9000/api/". Argument value has precedence, followed by environment variable value and lastly default value is used.
Returns
Returns the API response as list[dict]
, dict
, or any other type based on the response content or raises an exception.
Example
import os
from sonar_api_wrapper import api_call
# override default access config
os.environ['SONAR_PASSWORD'] = 'Username'
os.environ['SONAR_PASSWORD'] = 'YourPassword'
os.environ['SONAR_HOST_URL'] = 'https://yours.sonarqube/api/'
response = api_call('GET', 'qualityprofiles/search', parameters={
'defaults': 'true'
})
print(f'{response["projects"] = }')
Exceptions
Exceptions are raised based on HTTP errors or other request issues.
Develop
Install - Dev
The dev install is only required if additional development is needed for this library
pip install -e '.[dev]'
Build the library
Run the command:
python -m build -w
Publish the library
python -m twine upload dist/*
Test the library
Run the test with command:
pytest
Multiple python environments:
tox
Note: this command requires in the local machine python versions: 3.8
, 3.9
, 3.10
, 3.11
, and 3.12
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file sonar_api_wrapper-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: sonar_api_wrapper-1.3.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41f1b67a27bc525c38dfea386f05f8f3494ce8a11da93defce06d535d33ecab |
|
MD5 | f4f11f9d24e796af47894949244ecef8 |
|
BLAKE2b-256 | 7e98f6c9740ad1c7a9f78bcea856f00a4ab17598823356dba33509b6d2feef1f |