Code Monkey home page Code Monkey logo

python-sonarqube-api's Introduction

https://pepy.tech/badge/python-sonarqube-api https://static.pepy.tech/badge/python-sonarqube-api/month https://sonarcloud.io/api/project_badges/measure?project=shijl0925_python-sonarqube-api&metric=alert_status

Python Client library for interacting with Community, Developer, and Enterprise Editions SonarQube's REST APIs and SonarCloud's REST APIs.

python-sonarqube-api provides a simple interface for clients to interact with SonarQube via the REST API.

Editions

There are two editions of python-sonarqube-api:

Notice: Professional Edition's extra features have been remarked by using Only available on the professional edition in API Document.

Differences Community Edition Professional Edition
License GNU AGPLv3 License MIT License
Commercial Use No Yes
Supported APIs (SonarQube Web APIs) 40 more than 280
Compatibility (SonarQube Versions) 7.9.x - 8.9.x 7.9.x - 10.x

Payment only needs to be made once, and library updates will be provided for free.

Change Log

Community Edition

See the CHANGELOG-CE.md file for Community Edition.

Professional Edition

See the CHANGELOG-PE.md file for Professional Edition.

Installation

Community Edition

The easiest way to install the latest version is by using pip to pull it from PyPI:

pip install  --upgrade python-sonarqube-api

Professional Edition

Use command pip to install the Python wheel or source package, Use --force-reinstall to force an installation If necessary:

pip install python_sonarqube_pro_api-x.y.z-py3-none-any.whl

where x, y, and z should be replaced by the current version number.

Documentation

The full documentation for API is available on readthedocs.

Compatibility

  • This package is compatible Python versions 2.7, 3.3+.
  • Tested with SonarQube Community Edition 8.9.x LTS and SonarCloud Server.

Donate

donations are not mandatory but very welcomed If you like my work and want to support development or buy me a coffee PayPal Donate

Usage

The Client is easy to use, you just need to initialize it with the connection parameters (default sonarqube url is http://localhost:9000).

Example:

from sonarqube import SonarQubeClient

sonar = SonarQubeClient(sonarqube_url="http://localhost:9000", username='admin', password='admin')

Sonar authentication tokens can also be used in place of username and password:

sonar = SonarQubeClient(sonarqube_url="http://localhost:9000", token='*****************')

API example

The example documentation for SonarQubeClient APIs is available on API examples.

Licensing

See the LICENSE file for licensing information as it pertains to files in this repository.

python-sonarqube-api's People

Contributors

0x646e78 avatar ckho avatar crystal-cat-529 avatar donhui avatar drgarcia1986 avatar eschellerup avatar gerhardhellmann avatar gjabouley-invn avatar iklv avatar joker234 avatar king-king-eng avatar kravvcu avatar lo764640 avatar rantoniuk avatar rgl avatar samirtahir91 avatar shaijujanardhanan avatar shijl0925 avatar stastnypremysl avatar synapticarbors avatar vinod827 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-sonarqube-api's Issues

Calling sonar.alm_settings cause an project_key error

After update to the latest version(1.3.2) getting an error when calling command:
sonar.alm_settings.get_binding(project_key)
Stack trace:

Traceback (most recent call last):
  File "main.py", line 19, in <module>
    alm = sonar.alm_settings.get_binding(project_key)
  File "~/.local/lib/python3.10/site-packages/sonarqube/utils/common.py", line 132, in inner_func
    response = self._get(url_pattern, params=params)
  File "~/.local/lib/python3.10/site-packages/sonarqube/utils/rest_client.py", line 141, in _get
    return self.request("GET", path=path, params=params, data=data, headers=headers)
  File "~/.local/lib/python3.10/site-packages/sonarqube/utils/rest_client.py", line 79, in request
    raise ValidationError(msg)
sonarqube.utils.exceptions.ValidationError: Error in request. Possibly validation error [400]: The 'project' parameter is missing

Downgrading package to 1.3.1 and running works as expected. Believe the problem is with added payload: sonarqube/utils/common.py

missing `organisation` parameter for some api calls

Hello @shijl-0925 👋

Thank you for the great work! It is a handy python library to deal with Sonar's api.

I would like to raise an issue I noticed: for some api, there the field organisation is required, and there is no way to pass it.
For example:
https://sonarcloud.io/web_api/api/rules/tags?query=rules

GET api/rules/tags

>>> list(sonar.rules.get_rule(rule_key=rule))
sonarqube.exceptions.ValidationError: Error in request. Possibly validation error [400]: The 'organization' parameter is missing

and some, even though documentation says "optional" it is still needed, like in GET api/rules/search:

>>> list(sonar.rules.search_rules(q=rule))
sonarqube.exceptions.ValidationError: Error in request. Possibly validation error [400]: The 'organization' parameter is missing

Besides adding the missing parameters, maybe it's possible to allow extra ones? or add organization as part of session?

Thank you very much!

关于 sonarqube-api 的 issue 部分

我想统计不同严重程度 Issue 的个数,但是您的代码里好像只读取了issue列表,没有将其它返回值拿出来,能否增加一下该功能呢?
image
image

get_rule() is broken for SonarCloud

This snippet:

from sonarqube import SonarCloudClient

token = "..."
sonar = SonarCloudClient(sonarcloud_url="https://sonarcloud.io", token=token)
issues = sonar.issues.search_issues(componentKeys="...")
for issue in issues:
    print(f"key: {issue['key']}")
    print(f"rule: {sonar.rules.get_rule(issue['rule'])}")

Generate:

key: AXxbH--R-dDKUnsQv6k7
Traceback (most recent call last):
  File "/home/damien/python-sonarqube-api/test_cloud.py", line 8, in <module>
    print(f"rule: {sonar.rules.get_rule(issue['rule'])}")
  File "/home/damien/python-sonarqube-api/sonarqube/utils/common.py", line 132, in inner_func
    response = self._get(url_pattern, params=params)
  File "/home/damien/python-sonarqube-api/sonarqube/utils/rest_client.py", line 144, in _get
    return self.request("GET", path=path, params=params, data=data, headers=headers)
  File "/home/damien/python-sonarqube-api/sonarqube/utils/rest_client.py", line 82, in request
    raise ValidationError(msg)
sonarqube.utils.exceptions.ValidationError: Error in request. Possibly validation error [400]: The 'organization' parameter is missing

Can't connect via SSL

I'm trying to connect to a SQ server 9.6 via SSL and I'm receiving an error:

HTTPSConnectionPool(host='company.name.com', port=443): Max retries exceeded with url: /sonar/api/server/version (Caused by SSLError(SSLError(9, '[SSL] PEM lib (_ssl.c:4065)')))

The code I'm using is:

`URL = 'https://company.name.com/sonar'
USERNAME = 'admin'
PASSWORD = 'admin'
CERT = 'company.name.com.pem'

cert_path = Path(CERT)

if cert_path.is_file():
sonar = SonarQubeClient(sonarqube_url=URL, username=USERNAME, password=PASSWORD, cert=CERT)
version = sonar.server.get_server_version()
print(version)`

If I try the same api request using a curl command, it works. Is there any chance getting SSL working with this API

Historical data isn't fully returned

Hi, after using the answer to my first issue I successfully collected instant data, but when I tried to return the historical data it returned me nothing, except for the dates.

Illustrating what I did:

sonarqube.measures.search_measures_history('key:path', branch = 'master', fields = "metrics", metrics = 'code_smells')

[{'metric': 'code_smells', 'history': [{'date': '2021-10-06T17:29:17+0000'}, {'date': '2021-11-19T13:25:36+0000'}, {'date': '2021-12-31T21:18:26+0000'}, {'date': '2022-01-04T22:39:37+0000'}, {'date': '2022-01-14T11:32:41+0000'}, {'date': '2022-01-15T11:41:10+0000'}, {'date': '2022-01-16T11:45:23+0000'}, {'date': '2022-01-17T11:43:45+0000'}, {'date': '2022-01-17T22:54:13+0000'}, {'date': '2022-01-18T11:54:03+0000'}, {'date': '2022-01-19T17:04:46+0000'}, {'date': '2022-01-20T05:51:13+0000'}, {'date': '2022-01-21T05:41:53+0000'}, {'date': '2022-01-22T05:44:52+0000'}, {'date': '2022-01-23T05:46:08+0000'}, {'date': '2022-01-24T05:42:13+0000'}, {'date': '2022-01-24T20:50:30+0000'}, {'date': '2022-01-25T05:45:52+0000'}, {'date': '2022-01-26T05:48:10+0000'}, {'date': '2022-01-27T05:44:23+0000'}, {'date': '2022-01-27T19:23:21+0000'}, {'date': '2022-01-28T05:54:39+0000'}, {'date': '2022-01-28T18:17:28+0000'}, {'date': '2022-01-29T05:50:29+0000'}, {'date': '2022-01-30T05:48:26+0000'}, {'date': '2022-01-31T05:51:34+0000'}, {'date': '2022-02-01T05:52:32+0000'}}]
Why is this happening? And how to return properly the value of a folder?

Thank you in advance.

sonar.projects.search_projects() returning unexpected results in version 1.3.6

After upgrading from 1.3.5 to 1.3.6, searching for projects in sonarcloud by organization is no longer returning the expected results.

This is an example line of code

sonar.projects.search_projects(organization="org")

The expected return is a list of project objects that you can then iterate through, this is the behavior still seen with version 1.3.5

Instead when using 1.3.6 the returned value ends up being an array of strings: ['paging', 'components']

In order to resolve this in the meantime, I am targeting version 1.3.5 explicitly

(Question) Unable to increase timeout

Hi, I am trying to increase the default timeout value and I am not able to do it.

Reading the docs I can see:

Timeout in RestClient

But when coding I'm not sure where I should change the value, as when I check the debugging I don't see any effect.

Regards.

Validation failure for summaryCommentEnabled when configuring GitHub ALM from 1.2.6 onwards

Relevant line of code:

sonar.alm_settings.set_github_binding(almSetting="github", project=project_name, repository=github_repo, summaryContentEnabled=True)

Gives the following exception from 1.2.6 onwards

Traceback (most recent call last):
  File "./scripts/sonarqube-project-setup.py", line 45, in <module>
    sonar.alm_settings.set_github_binding(almSetting="github", project=project_name, repository=github_repo, summaryContentEnabled=True)
  File "/usr/local/lib/python3.7/site-packages/sonarqube/utils/common.py", line 134, in inner_func
    response = self._post(url_pattern, params=params)
  File "/usr/local/lib/python3.7/site-packages/sonarqube/utils/rest_client.py", line 165, in _post
    params=params,
  File "/usr/local/lib/python3.7/site-packages/sonarqube/utils/rest_client.py", line 82, in request
    raise ValidationError(msg)
sonarqube.utils.exceptions.ValidationError: Error in request. Possibly validation error [400]: Property summaryCommentEnabled is not a boolean value: True

get_component_tree_with_specified_measures(..) returns null for code_smells and coverage

I am using SonarQubeClient(..).measuers.get_component_tree_with_specified_measures(metricKeys="code_smells,bugs,vulnerabilities,coverage")
returns proper value for bugs and vulnerabilies but returns 0 for code_smells and coverage most of the times.

This behaviour happens randomly. ( Some days it gives proper values and some days it just returns 0 ) [ No code change ]

Is there going to be a fix here or it this already fixed?

How to get status of current project?

Hi,

I am using measures.get_component_with_specified_measures to connect to the relevant endpoint to get the metrics of a project.

Thing is, I am doing this right after I run a scan, and for bigger projects, this can take some time.

So for those projects, my script then fails and gives an error.

I could implement a time.sleep() method to pause execution of the script for a while, but this is not needed for smaller code scans.

Is there any way I can check from the API itself if the analysis and background tasks have been completed or not?

API breaking changes in 1.3.6

I spent two days debugging an issue with the sonarqube package. Even after digging into the docs and open issues, I had to write tests against all versions since 1.3.0 to find out that 1.3.6 was breaking results format.

The only explanation is in this closed issue: #70 (comment)

Is it possible:

  1. to mention this API breaking change in a more prominent way, in the docs, in the changelogs or on the GitHub page;
  2. to bump the minor version number if the API has breaking changes in the future ?

Retrieving security hotspot information

I want to pull just security hotspot information from my projects so I try this:

sonar.issues.search_issues(componentKeys=keys[3], types='SECURITY_HOTSPOT')

And the error thrown is:

sonarqube.utils.exceptions.ValidationError: Error in request. Possibly validation error [400]: Value of parameter 'types' (SECURITY_HOTSPOT) must be one of: [CODE_SMELL, BUG, VULNERABILITY]

I am using version Community 8.6.1. I see the web api has a specific hotspots API but I don't see it's use in this library.

search_user_groups and search_users api call is not working

Hi,

I am having weird issue from 2 days that the users list and user groups are not giving proper result.

user_groups = list(sonar.user_groups.search_user_groups())
users = list(sonar.users.search_users())

below is the output for the above api call:

<class 'list'>
['paging', 'groups']
<class 'list'>
['paging', 'users']

Initially it used to give correct result. I am using https://python-sonarqube-api.readthedocs.io/en/latest/examples/user_groups.html page.
Any help would be appreciated.

Missing explanation about the professional license

Before purchasing the professional license, please clarify the following and add the info on the website for other who are interested in buying it:

  • no of users allowed per license
  • deployable on any machine (developer/CI build)?
  • expiration time?
  • other limitations?

Thanks!

@shijl0925

Organisation filter for user searches

I was experimenting with the Sonarcloud API and the Python-Sonarqube-API project and noticed that while I am able to filter all users in the API request to Sonarcloud:

https://sonarcloud.io/api/organizations/search_members?organization=XXXXXX&ps=100'

The library function search_users returns me all users known within Sonarcloud and does not allow for a org filter:

sonarconn = SonarCloudClient(sonarcloud_url="https://sonarcloud.io", token="XXXXXX")
users = list(sonarconn.users.search_users()

and returns ALL users of sonarcloud (or at least the first paging results).

Where the function search_groups_user_belongs_to does allow an organisation input:

   @PAGES_GET(API_USERS_GROUPS_ENDPOINT, item="groups")
    def search_groups_user_belongs_to(
        self, login, organization, q=None, selected="selected"
    ):
        """
        Lists the groups a user belongs to.

        :param login:
        :param organization: organization key.
        :param q: Limit search to group names that contain the supplied string.
        :param selected: Depending on the value, show only selected items (selected=selected), deselected items
          (selected=deselected), or all items with their selection status (selected=all).Possible values are for:
            * all
            * deselected
            * selected
          default value is selected.
        :return:
        """

ps parameter in issue/hotspots search doesn't work

I want to get the number of issues/hotspots in a certain project. I only want the total number of these issues, however when i do a search i get the JSON with all the issues f.e :

sonar.hotspots.search_hotspots(projectKey=component)

When i do len on this result i get the total number, but i've requested the whole JSON (which is really heavy).


If i do a curl request i can actually filter with the ps parameter to get a lightweight JSON :

curl -sX GET -u <TOKEN>: "http://<SONAR_URL>:9000/api/hotspots/search?projectKey=<PROJECTKEY>&ps=1"

This also returns the total number of hotspots in the result which is good since it is what i'm aiming for.

But when i try to use the same parameter in the python api i get the same result with or without the ps parameter.

Is this a normal API behavior, also is their any other way to get only the total number of issues / hotspots ?

===========
sonarqube is 9.1
python-sonarqube-api is 1.2.4

list of Issues always linked with the default Quality profile

this works fine

issues1 = list(sonar.issues.search_issues(componentKeys="my_project", branch="develop"))

but...OK only if the default quality profile is the default one ('sonar way').

If a given rule has been modified (let's say its severity CRITICAL in sonar way -> MAJOR in the new quality profile),
then the command above will provide the same issue (i.e. same default severity CRITICAL -not MAJOR- even if the quality profile set to the new one).

without changing the current code, Is it possible to know all the rules linked with a given quality profile ?

possibility of secure connection with ca file & which variable to use for passing ca file ?

getting SSL Certificate error with https..is it possible to pass ca file parameter while connection?

projects = list(sonar.projects.search_projects())

File "/sonarqube/utils/common.py", line 176, in inner_func
response = self._get(url_pattern, params=params).json()
File "/sonarqube/utils/rest_client.py", line 144, in _get
return self.request("GET", path=path, params=params, data=data, headers=headers)
File "/sonarqube/utils/rest_client.py", line 65, in request
timeout=timeout,
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='XXXXXXXXXXXXXX', port=443): Max retries exceeded with url: /api/projects/search?onProvisionedOnly=false&qualifiers=TRK (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618)'),))

How can I extract the severity data only for vulnerability in the issues field?

Hello,
I’m trying to extract the severity data reported for the vulnerability but I’m having it extremely difficult. I’m using the python-api and when it returns the blocking and critical severities, it returns the total (the sum of bugs, vulnerabilities and code smells). Is there a way to disaggregate this information.
Can anyone help me to know if it is possible to separate this data?
Thanx

JSON Decoding Error

Hello,

When I try to list the items of generators which are return values of functions such as sonar.users.search_users or sonar.projects.search_projects(), I am getting the following error. I updated the simplejson package to 3.17.6 and still getting the same error.

simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Improve the reporting of a 404 response status code

While trying to test whether a given SonarQube project already has alm settings, I'm currently doing:

c = sonarqube.SonarEnterpriseClient(sonarqube_url=sonarqube_address, token=sonarqube_api_token)
binding = c.alm_settings.get_binding(sonarqube_project_key)

When there is no alm settings defined at the project, get_binding raises a generic sonarqube.utils.exceptions.ClientError with the message Error in request. Possibly client error [404]: Project 'xxx' is not bound to any ALM.

But there is no straightforward way to deal with this expected error without looking at the exception message for Possibly client error [404].

Can we have a better way of reporting a 404?

For example, maybe with a class named NotFoundClientError?

Also, maybe add a response_code property to the ClientError class too?

AuthError when sonar.projects.search_projects()

Hi, I'm getting the following auth error, when doing list(sonar.projects.search_projects()):

AuthError: Error in request. Possibly authentication failed [403]: 
{"errors":[{"msg":"Insufficient privileges"}]}

However other api requests like list(sonar.issues.search_issues(componentKeys="my_project_key", branch="master")) or
list(sq.hotspots.search_hotspots(projectKey="my_project_key", branch="master")) are working like a charm.

I am using a token to authenticate ... is it possible my user is simply not allowed to access this API endpoint?
I can browse the /projects page of our SQ server, but auth works differently then ... so maybe its a problem on our side.

403 with project search

Hey there:
@shijl0925
I've been trying to figure out if this is something silly that I'm getting wrong on my end, or is a legitimate bug with the projects.search_projects() endpoint.

I've confirmed that my token isn't related to the 403 error I've been getting via a curl to the underlying project search endpoint directly and get a 200 with the expected response. I've used the same token with a few other methods to test and no issues.

Quickly testing out the endpoint here as such:

   output = list(sq_obj.projects.search_projects())
   print(output)

Here's the stack trace I get when I try to call the method:

Traceback (most recent call last):
  File "/Users/apho/Documents/Dev/xwing/automation-pipelines/sonarqube-config-pipeline/permissions.py", line 186, in <module>
    print(sq_obj.projects.get("access-api-dev"))
  File "/usr/local/lib/python3.8/site-packages/sonarqube/community/projects.py", line 33, in get
    result = list(self.search_projects(projects=key))
  File "/usr/local/lib/python3.8/site-packages/sonarqube/utils/common.py", line 160, in inner_func
    response = self._get(url_pattern, params=params).json()
  File "/usr/local/lib/python3.8/site-packages/sonarqube/utils/rest_client.py", line 113, in _get
    return self.request('GET', path=path, params=params, data=data, headers=headers)
  File "/usr/local/lib/python3.8/site-packages/sonarqube/utils/rest_client.py", line 73, in request
    raise AuthError(msg)
sonarqube.utils.exceptions.AuthError: Error in request. Possibly authentication failed [403]: Forbidden
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
</body>
</html>
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->

Any ideas?

Sonar.qualityprofiles.get_projects_associate_with_quality_profile is not working for sonarqube -v7.1 but for 7.9.6

sonar.qualityprofiles.get_projects_associate_with_quality_profile(key="") api call is not working with sonarQube version - 7.1 but working with version : 7.9.6

Hi Team,

I am writing python script using “python-sonarqube-api” module to get a list of projects associated with particular qualityProfile
Code Snippet as below:

from sonarqube import SonarQubeClient
sonar = SonarQubeClient(sonarqube_url=url, token=sonar_token)
print(sonar.qualityprofiles.get_projects_associate_with_quality_profile(key=""))
I am refering below document for python scripting:
https://python-sonarqube-api.readthedocs.io/en/latest/

When I try above code with sonarqube version 7.1, It giving below response which is unexpected:
image

and When I try same code with sonarqube version 7.9.6, It giving below response as expecteted:
image

and when I try same code with sonarqube version 8.8, it is again giving below response which unexpected:
image

Any one can help me with this issue for this particular api of python?

Allow certificate verification from Requests

We have a need to validate the certificate from the SonarQube host via the chain we have in the environment. We would like to have the 'verify' option from requests exposed as a variable that can be set in the SonarQube Client.

AttributeError: 'module' object has no attribute 'getfullargspec'

I am using python 2.7 virutlenv and getting below error messages.I cloned repo and done setup.
I am getting same kind of error with any api call.

result = sonar.auth.check_credentials()
Traceback (most recent call last):
File "", line 1, in
File "sonarqube/utils/common.py", line 116, in inner_func
func_params = translate_params(f, *args, **kwargs)
File "sonarqube/utils/common.py", line 59, in translate_params
all_params = dict(get_default_kwargs(f))
File "sonarqube/utils/common.py", line 43, in get_default_kwargs
argspec = inspect.getfullargspec(func)
AttributeError: 'module' object has no attribute 'getfullargspec'

Restore quality profile failes with message: Error in request. Possibly validation error [400]: A backup file must be provided

When using qualityprofiles.restore_quality_profile() method and providing proper xml file with backup, the method failes with message:

Error in request. Possibly validation error [400]: A backup file must be provided

Code snippet:
with open('C:\\restore.xml', 'r') as f: sonar.qualityprofiles.restore_quality_profile(backup=f.read())

restore.xml:
<?xml version='1.0' encoding='UTF-8'?><profile><name>BackUp</name><language>java</language><rules/></profile>

I believe it is caused because backup file is passed as query parameter (so - /api/qualityprofiles/restore?backup=<?xml...) not as body:form-data parameter

Passwords in logs is unmasked

The password, which is given to debug logs in logger is unmasked. For example (stars are replacements for sensitive information):

  | https://*******:443 "POST /api/users/create?login=*****&name=*******&local=true&email=******&password=unmasked_password HTTP/1.1" 200 150

I consider it as a bug. Can it be fixed please? :)

Thanks.

super() argument 1 must be type, not classobj

在macOS環境下python 2.7 / 3.8 會無法執行

Traceback (most recent call last):
File "/Users/xxx/xxx/test.py", line 26, in
getSonarqubeInfo()
File "/Users/xxx/xxx/test.py", line 5, in getSonarqubeInfo
sonar.auth.authenticate_user(login=username, username=username, password=password)
File "/Users/xxx/xxx/venv/lib/python2.7/site-packages/sonarqube/community/init.py", line 229, in auth
return SonarQubeAuth(api=self)
File "/Users/xxx/xxx/venv/lib/python2.7/site-packages/sonarqube/community/auth.py", line 23, in init
super(SonarQubeAuth, self).init(**kwargs)
TypeError: super() argument 1 must be type, not classo

API breaking changes on 2.x not documented + previous packages wiped from everywhere

I know this has similarities with this issue but I believe this is a more serious problem.

I do not really understand how it is possible that previous releases has been completely removed from everywhere and all the breaking changes are not mentioned anywhere. These changes broke functionality in a complex tool that we were close to put to production and the team is not confident anymore to use this library.

It's not my intention to blame no one, I just want to note that this is a problem that should be prevented.

In my opinion:

  • Previous releases shouldn't be removed, not only from pip repositories but also from the code repo (why even the previous tags has been removed?).
  • If there is some kind of security issues with previous versions -which would be understandable to remove- then it should be documented somewhere.
  • Breaking changes between versions should be documented, even more when there is a major release. Now it's all trial and error or just look at the latest docs (not sure if they're up-to-date, though).

If I'm just missing something, please, I kindly apologize and I'd appreciate any clarification to understand it.

Again, it's not my intention to blame somebody! I appreciate all the effort from contributors to open-source, I want that to be clear :-)

Cant use add_permission_to_user for a project

I´m not able to grant permissions to user for a project. Looks like the request dont recognize the "projectKey" param. When I add it sonar api still ask for "global permissions".
funtion: def add_permission_to_user(self, login, permission, project_key)

I tested the request using other tools (POSTMAN) and it work.
Can anybody check if this feature works on this library on his enviroment?
I dont know how to solve it

Is there a way of iterate through the repo's folders and retrieve its metrics?

Hello.

I was looking for a way to get the metrics from the repo, but also from a specific folder inside the repo. The "Code" window present the folders and the files of the project, can we access it like we access the full repo? Returning metrics for a specific folder, for example?

I know your API can look into a file,

duplications = sonar.duplications.get_duplications(key="my_project:/src/foo/Bar.php")

But can we do this?

sonar.measures.get_component_with_specified_measures(component: "my_project:/src/foo/")

Thank you for your attention.

AttributeError: 'SonarEnterpriseClient' object has no attribute 'permissions'

Hello,

I'm facing an issue that the function permissions don't exist anymore. Can anyone help me?

import os
import yaml
import re
from sonarqube import SonarEnterpriseClient
from sonarqube.utils.exceptions import ValidationError, NotFoundError

URL = "https://sonar.example.com"
USERNAME = os.environ.get('USERNAME', 'admin')
PASSWORD = os.environ.get('PASSWORD')
PAGESIZE = 10

sonar = SonarEnterpriseClient(sonarqube_url=URL, username=USERNAME, password=PASSWORD)
sonar.permissions
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'SonarEnterpriseClient' object has no attribute 'permissions'

Version 1.3.6 was working.

I checked the code, and it looks like the permissions class is missing.

'SonarQubeClient' object has no attribute 'settings'

I can no longer update the settings although the documentation indicates that it is possible.
This commit breaks the compatibility of my app, is there a workaround to update SonarQube settings?

I am getting this error on my app: 'SonarQubeClient' object has no attribute 'settings'
Below is a part of my code:

def update_settings(args):
    # oidc configuration
    sonar = SonarQubeClient(sonarqube_url=args.Url, username=args.Username, password=args.Password)
    sonar.settings.update_setting_value(key='sonar.core.serverBaseURL', value=args.Url)
    sonar.settings.update_setting_value(key='sonar.auth.oidc.enabled', value='true')
    sonar.settings.update_setting_value(key='sonar.auth.oidc.issuerUri', value=args.IssuerURI)
    sonar.settings.update_setting_value(key='sonar.auth.oidc.clientId.secured', value=args.ClientID)
    sonar.settings.update_setting_value(key='sonar.auth.oidc.clientSecret.secured', value=args.ClientSecret)
    sonar.settings.update_setting_value(key='sonar.auth.oidc.groupsSync', value='true')
    sonar.settings.update_setting_value(key='sonar.auth.oidc.groupsSync.claimName', value=args.GroupsClaimName)

I appreciate if you can help me.

Error in request. Possibly Not Found error [404]: Component 'XXXX' on branch 'master' not found

def get_sonarqube_info(self, branch="master", component=None, url=None, username=None, password=None):
try:
sonar = SonarQubeClient(sonarqube_url=url)
sonar.auth.authenticate_user(login=username, password=password)
component_data = sonar.measures.get_component_with_specified_measures(
component=component,
branch=branch,
metricKeys=METRICKEYS

)
........

In this code lien, have a except as:
Error in request. Possibly Not Found error [404]: Component 'XXXX' on branch 'master' not found

but in another project ,this code can run normally. the XXXX project is the first scan. In sonarquebe server, [MEASURES]-->[new code ] show result as:
Measures on New Code will appear after the second analysis of this branch.

So, how can I revole it?

Unknown url error when trying to list alm_settings

Hello, I’m trying to list the alm settings for my sonarcloud project via the python API.

I’ve initialized my sonarqube enterprise client and am able to invoke the alm_settings.list() method, but I’m getting the following error:

sonarqube.utils.exceptions.NotFoundError: Error in request. Possibly Not Found error [404]: Unknown url : /api/alm_settings/list

Here’s the python code I’m using:

from sonarqube.enterprise import SonarEnterpriseClient

sonarqube_ent_client = SonarEnterpriseClient(
    sonarqube_url=SONARCLOUD_URL, token=SONARCLOUD_TOKEN
)

response = sonarqube_ent_client.alm_settings.list()

I've verified that my sonarqube_ent_client has a valid token and url because I'm able to create projects with it just fine and the sonarqube_ent_client.auth.check_credentials() method returns "true".

Any advice about how to proceed would be greatly appreciated!

I’m using Python 3.9.7 and the python-sonarqube-api python package (version 1.3.4)

Steps to reproduce:

  1. Install python-sonarqube-api==1.3.4
  2. Run the following code, replacing the temporary variables with values for your sonarcloud account:
from sonarqube.enterprise import SonarEnterpriseClient

sonarqube_ent_client = SonarEnterpriseClient(
    sonarqube_url=SONARCLOUD_URL, token=SONARCLOUD_TOKEN
)

response = sonarqube_ent_client.alm_settings.list()

#  sonarqube.utils.exceptions.NotFoundError: Error in request. Possibly Not Found error [404]: Unknown url : /api/alm_settings/list

How to get ALM setting key for sonarqube?

Hi,
I want to get project name's git lab repository url, but I don't know how to get ALM setting key. Please help me, thanks!
SonarQube Server Version: Community EditionVersion 8.9.3 (build 48735)

from sonarqube.enterprise import SonarEnterpriseClient

def sonar_ent_connector() -> SonarEnterpriseClient:
    sonarqube_ent_client = SonarEnterpriseClient(sonarqube_url=SQ_URL, token=SQ_TOKEN)
    sonar_ent_credential = sonarqube_ent_client.auth.check_credentials()

    if "true" not in sonar_ent_credential.lower():
        raise Exception("Permission authentication failure.")
    return sonarqube_ent_client

prj_key = "ABDevUtils"
sqe_connector.alm_integrations.search_gitlab_repos(almSettings="xxxx", projectName=prj_key)

Missing GET api/permissions/users and api/permissions/groups

This library has methods to add/remove user permissions to/from projects/groups, but has no way of getting the existing permissions. Without these, there is no way to fully manage the user permissions.

Can these APIs be exposed here?

In the meantime, I will try to prepare a PR.

For reference, SonarQube has those APIs hidden behind the "internal" flag:

GET api/permissions/users INTERNAL SINCE 5.2
Lists the users with their permissions as individual users rather than through group affiliation.
This service defaults to global permissions, but can be limited to project permissions by providing project id or project key.
This service defaults to all users, but can be limited to users with a specific permission by providing the desired permission.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.