sonar-api-wrapper


Namesonar-api-wrapper JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummarySonar API Wrapper - a Sonarqube api wrapper
upload_time2024-05-15 09:32:12
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2024 Alessandro Staffolani Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords sonar sonarqube
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Sonar API Wrapper

Sonar API Wrapper - a Sonarqube api wrapper

## Install

```bash
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 with `base_path`. For example, `qualityprofiles/search`.
- `parameters` (`dict` | `None`): Dictionary of parameters for the API call. Default is `None`.
- `body` (`dict` | `None`): Body of the request. Default is `None`.
- `files` (`Any`): Files to be sent in the request. Default is `None`.
- `headers` (`dict` | `None`): Headers of the request. Default is `None`.
- `is_json` (`bool`): If set to `True`, the response will be parsed as JSON. Otherwise, it returns the decoded content. Default is `True`.
- `username` (`str` | `None`): Username used for authentication. Default is set via the environment variable `SONAR_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 variable `SONAR_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 variable `SONAR_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 variable `SONAR_ENDPOINT` 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

```python
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_ENDPOINT'] = '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

```bash
pip install -e '.[dev]'
```

### Build the library

Run the command:

```bash
python -m build -w
```

### Publish the library

```bash
python -m twine upload dist/*
```

### Test the library

Run the test with command:

```bash
pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sonar-api-wrapper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "sonar, sonarqube",
    "author": null,
    "author_email": "Alessandro Staffolani <alestam93@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "# Sonar API Wrapper\n\nSonar API Wrapper - a Sonarqube api wrapper\n\n## Install\n\n```bash\npip install sonar-api-wrapper\n``` \n\n## How to use\n\n### api_call\n\nExecutes an API call to SonarQube. This method wraps the `requests.request` method.\n\n### Parameters\n\n- `method` (`str`): HTTP method to use (e.g., GET, POST, etc.).\n- `route` (`str`): API path that will be concatenated with `base_path`. For example, `qualityprofiles/search`.\n- `parameters` (`dict` | `None`): Dictionary of parameters for the API call. Default is `None`.\n- `body` (`dict` | `None`): Body of the request. Default is `None`.\n- `files` (`Any`): Files to be sent in the request. Default is `None`.\n- `headers` (`dict` | `None`): Headers of the request. Default is `None`.\n- `is_json` (`bool`): If set to `True`, the response will be parsed as JSON. Otherwise, it returns the decoded content. Default is `True`.\n- `username` (`str` | `None`): Username used for authentication. Default is set via the environment variable `SONAR_USERNAME` or \"admin\". Argument value has precedence, followed by environment variable value and lastly default value is used.\n- `password` (`str` | `None`): Password used for authentication. Default is set via the environment variable `SONAR_PASSWORD` or \"admin\". Argument value has precedence, followed by environment variable value and lastly default value is used.\n- `token` (`str` | `None`): Token used for authentication. It overrides username and password if present. Default value is set via the environment variable `SONAR_TOKEN` or None. Argument value has precedence, followed by environment variable value and lastly default value is used.\n- `base_path` (`str` | `None`): The base endpoint used to build the API call. Default is set via the environment variable `SONAR_ENDPOINT` or \"http://localhost:9000/api/\". Argument value has precedence, followed by environment variable value and lastly default value is used.\n\n### Returns\n\nReturns the API response as `list[dict]`, `dict`, or any other type based on the response content or raises an exception.\n\n### Example\n\n```python\nimport os\n\nfrom sonar_api_wrapper import api_call\n\n# override default access config\nos.environ['SONAR_PASSWORD'] = 'Username'\nos.environ['SONAR_PASSWORD'] = 'YourPassword'\nos.environ['SONAR_ENDPOINT'] = 'https://yours.sonarqube/api/'\n\nresponse = api_call('GET', 'qualityprofiles/search', parameters={\n    'defaults': 'true'\n})\n\nprint(f'{response[\"projects\"] = }')\n```\n\n### Exceptions\n\nExceptions are raised based on HTTP errors or other request issues.\n\n## Develop\n\n### Install - Dev\n\nThe dev install is only required if additional development is needed for this library\n\n```bash\npip install -e '.[dev]'\n```\n\n### Build the library\n\nRun the command:\n\n```bash\npython -m build -w\n```\n\n### Publish the library\n\n```bash\npython -m twine upload dist/*\n```\n\n### Test the library\n\nRun the test with command:\n\n```bash\npytest\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Alessandro Staffolani  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Sonar API Wrapper - a Sonarqube api wrapper",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/AlessandroStaffolani/sonar-api-wrapper",
        "Repository": "https://github.com/AlessandroStaffolani/sonar-api-wrapper.git"
    },
    "split_keywords": [
        "sonar",
        " sonarqube"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22f38014514f405920b3a617bd6a228565c4adf041f3a6d04d89563d0095c2e8",
                "md5": "07cf4711ad436158bdca2f3ba39088c9",
                "sha256": "285213e187daa94c07e3f88dbbb8c603bcc2dc54eb37e20d97c2b05222040d62"
            },
            "downloads": -1,
            "filename": "sonar_api_wrapper-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "07cf4711ad436158bdca2f3ba39088c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6201,
            "upload_time": "2024-05-15T09:32:12",
            "upload_time_iso_8601": "2024-05-15T09:32:12.676503Z",
            "url": "https://files.pythonhosted.org/packages/22/f3/8014514f405920b3a617bd6a228565c4adf041f3a6d04d89563d0095c2e8/sonar_api_wrapper-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-15 09:32:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlessandroStaffolani",
    "github_project": "sonar-api-wrapper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sonar-api-wrapper"
}
        
Elapsed time: 0.25719s