Coder Social home page Coder Social logo

tuleap-rest-api-client's Introduction

REST API client for Tuleap open ALM

The purpose of this project is to create a python module that can be used for accessing a Tuleap instance using its REST API.

Usage example:

from Tuleap.RestClient.Connection import Connection, CertificateVerification
from Tuleap.RestClient.Projects import Projects
from Tuleap.RestClient.Trackers import Tracker, FieldValues

connection = Connection()
success = connection.set_access_key("https://tuleap.example.com/api",
                                    "this-is-my-access-key")


if success:
    # Projects
    projects = Projects(connection)
    success = projects.request_project_list()

    if success:
        project_list = projects.get_data()

    # Trackers
    tracker = Tracker(connection)
    success = tracker.request_artifact_list(tracker_id=20,
                                            field_values=FieldValues.All,
                                            limit=None)

    if success:
        artifact_list = tracker.get_data()

connection.logout()

Upload example:

from Tuleap.RestClient.Connection import Connection, CertificateVerification
from Tuleap.RestClient.FileRelease import FileRelease
from tusclient import client
from tusclient.client import TusClient
import os

tuleapURL = "https://tuleap.example.com"
userKey = "this-is-a-user-key"
filePath = "/directory/filepath.txt"
projectID = 123
packageName = "Package Name"
releaseName = "Release Name"
fileName = "File Name"

connection = Connection()
success = connection.set_access_key(tuleapURL+"/api",
                                    userKey)

if success:
    # Projects
    frs = FileRelease(connection)
    success = frs.create_package(projectID, packageName)
    if success:
        package = frs.get_data()
        success = frs.create_release(package['id'],releaseName)
        if success:
            release = frs.get_data()
            success = frs.create_file(release['id'], fileName, os.path.getsize(filePath))
            if success:
                file = frs.get_data()
                my_client = client.TusClient(tuleapURL+file['upload_href'],
                                             headers={'X-Auth-AccessKey':userKey})
                uploader = my_client.uploader(filePath, url=tuleapURL+file['upload_href'])
                uploader.upload()

connection.logout()

Supported versions:

  • 2.7
  • 3.3
  • 3.6

tuleap-rest-api-client's People

Contributors

andrejn avatar auvraym avatar djurodrljaca avatar gbonnefille avatar larrycai avatar moreauxh avatar nguedon avatar pbouda95 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

tuleap-rest-api-client's Issues

ModuleNotFoundError: No module named 'Tuleap'

from Tuleap.RestClient.Connection import Connection, CertificateVerification
ModuleNotFoundError: No module named 'Tuleap'
I'm trying to use the module with Python 3.7, but I'm not able access it after using it in development.

It installs, with easy_install and python but I'm not able to import in production.

(Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)

Hi there,
I am trying to setup this in my system , but it is throwing an SSL error. It says that 'certificate verify failed.'

whole output is here,

/usr/lib/python3/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.26.5) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/urllib3/contrib/pyopenssl.py", line 498, in wrap_socket
    cnx.do_handshake()
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/SSL.py", line 1828, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/SSL.py", line 1566, in _raise_ssl_error
    _raise_current_error()
  File "/usr/local/lib/python3.6/dist-packages/OpenSSL/_util.py", line 57, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 706, in urlopen
    chunked=chunked,
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connection.py", line 421, in connect
    tls_in_tls=tls_in_tls,
  File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 450, in ssl_wrap_socket
    sock, context, tls_in_tls, server_hostname=server_hostname
  File "/usr/local/lib/python3.6/dist-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python3.6/dist-packages/urllib3/contrib/pyopenssl.py", line 504, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/dist-packages/urllib3/connectionpool.py", line 756, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/usr/local/lib/python3.6/dist-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='tuleap.local', port=443): Max retries exceeded with url: /api/projects?limit=10 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "example.py", line 24, in <module>
    success = projects.request_project_list()
  File "/repo/tuleap-rest-api-client/Tuleap/RestClient/Projects.py", line 85, in request_project_list
    success = self._connection.call_get_method(relative_url, parameters)
  File "/repo/tuleap-rest-api-client/Tuleap/RestClient/Connection.py", line 273, in call_get_method
    verify=self._verifyCertificate)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='tuleap.local', port=443): Max retries exceeded with url: /api/projects?limit=10 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

Kindly please help me in this one.

empty table return for link and reverse link using ArtifactParser

When I do:

print(artifact.get_links())
print(artifact.get_reverse_links())

I have

[]
[]

The response given by my request is like:

{
    "id": 42,
    "uri": "artifacts/42",
    "xref": "bugs #42",
    "tracker": {
        "id": 6,
        "uri": "trackers/6",
        "label": "Bug"
    },
    "project": {
    "id": 7,
    "uri": "projects/7",
    "label": "MyProject"
    },
    "submitted_by": 7,
    "submitted_by_user": {
        "id": 7,
        "uri": "users/07",
        "user_url": "/users/user1",
        "real_name": "User 1",
        "display_name": "User 1",
        "username": "user1",
        "ldap_id": null,
        "avatar_url": "",
        "is_anonymous": false
    },
    "submitted_on": "2017-05-19T11:46:21+02:00",
    "html_url": "/plugins/tracker/?aid=42",
    "changesets_uri": "artifacts/42/changesets",
    "values": [
        {
            "field_id": 153,
            "type": "string",
            "label": "Summary",
            "value": "Display error on name field"
        },
        {
            "field_id": 166,
            "type": "art_link",
            "label": "Links",
            "links": [
            {
                "id": 101,
                "uri": "artifacts/101",
                "tracker": {
                    "id": 1,
                    "uri": "trackers/1",
                    "label": "Issue"
                    }
            },
            {
                "id": 102,
                "uri": "artifacts/102",
                "tracker": {
                    "id": 1,
                    "uri": "trackers/1",
                    "label": "Issue"
                }
            }
            ],
            "reverse_links": [
            {
                "id": 21,
                "uri": "artifacts/21",
                "tracker": {
                    "id": 7,
                    "uri": "trackers/7",
                    "label": "Bug"
                }
            }
            ]
        },
        {
            "field_id": 142,
            "type": "aid",
            "label": "Artifact ID",
            "value": 42
        }
    ],
    "values_by_field": null,
    "last_modified_date": "2017-05-19T11:46:21+02:00",
    "status": "New",
    "title": "bug1",
    "assignees": []
}

I have art_link fields but the parser don't find them.

Unit Test

Do you recommend a library for unit tests ?

Project still alive ?

Hello guys,

I'm currently writing a StackStorm pack for Tuleap. These packs use python to create the actions the tool can perform. Your library is what I exactly need to ease my pack creation.

So I'm asking you if your project is still alive ? If yes, I can help you by contributing to it if necessary.

Many thanks.

Connect object does not handle PATCH requests

Hello folks,

I am not sure if this could be useful but I have a project on which I need to perform some PATCH requests to my server.
I am williful to develop the method but I am not an expert so maybe somebody could be faster than me ...

Thanks,
Pascal

Artifacts.py:171, should use "values" as key

With Tuleap 9.9.99.120, if use "values_by_field" as key, server will return

{'error': {'code': 400, 'message': 'Bad Request: Field 0 does not exist in the tracker'}}

I've changed it to "values", and can successfully create artifact under Trackers.

How to contribute my changes

Hello,

I am currently using your client for a python application and it helps me a lot. Thank you for that. However I had to add some features for my work:

In ArtifactParser.py, I added the possibility to get

  • link types (_is_child, None, …)
  • artifact full name (story #1234)
  • git references (commit hash)

In Commit.py, I added the repository ID as class attribute and added a function to request the path of the repository (tuleap/stable/ for example)

I added a file CommitParser.py that parses a commit json dictionary to extract Tuleap references from the commit’s message.

I would like to know how do you prefer to review those contributions. One PR for each function ? One PR with everything ? Something else ?
Thanks in advance.

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.