#4223 Add project createapitoken endpoint
Merged by pingou. Opened by fbo.
fbo/pagure create-token-api-endpoint  into  master

Download 4223.patch

A project owner or admin (with the 'modify_project') acl can
ask the creation of a project user token. The token
description and acl can be passed to the endpoint.

The endpoint return the token id and the description.

1 new commit added

  • Attempt to fix wrong code stype

Wouldn't it be better to do /<repo>/token/create or something? createapitoken is a pretty poorly named endpoint...

1 new commit added

  • Propose a better API endpoint name repo/token/create

Thanks, yes you are right so here is an update.

You could use a wtforms form here to do the validation for you (disable the csrf protection and dynamically load the list of ACLs), there are some examples of this in the code already (let me know if you don't find one)

Let's specify that it's acls=None here :)

We should use a list here, saves us the troubles of splitting the content on comas

You may want to use form.getlist('acl') here ;-)

@fbo if you would have time to update this one it would be nice, this way we could get it into the 5.3-beta I hope to cut tomorrow

Sure, I'll travel tomorrow morning but I'll be able to finish it (and the other PR (hope)) in the train.

1 new commit added

  • Use wtforms to validate a new token in the projects api

I don't think we want the full list here, more likely the USER_ACLS list only

descriptions are not unique, so depending on the ordering you may get an expired token here. Should we make add_token_to_user return the token id instead?

1 new commit added

  • Improve add_token_to_user to return the token

rebased onto 7c5cfacce801976a43080fa0c86fa999ead34e97

Any idea why the CI fails this way ? is it related to the patch ?

pretty please pagure-ci rebuild

pretty please pagure-ci rebuild

rebased onto 969d10ecf6cbe31a380de5b6e65c039ddcaf4cf8

Looks like at least one test is failing (genuinely)

rebased onto fa793fd116352d4495f19364e48a427edbb3b33a

pretty please pagure-ci rebuild

It returns three failing test files:

15:50:35 FAILED test: py-test_pagure_repospanner
15:50:35 FAILED test: py-test_pagure_flask_ui_repo
15:50:35 FAILED test: py-test_pagure_flask_ui_app

The first one currently fails on all tests/PRs (I hope the new way to run the tests will help with this), the other two are more concerning me :(

A local run with the container reports:
Failed tests:
FAILED test: py3-test_style
FAILED test: py3-test_pagure_flask_ui_repo
FAILED test: py3-test_pagure_flask_ui_app

Ok so then let me know if the patch needs more edit or if it ready to be merged :)

pretty please pagure-ci rebuild

pretty please pagure-ci rebuild

91 failed :( should I rebase the branch on master ?

rebased onto 0bf7de9bfcaa7885bca3aa5fa34a1f752d920c01

The UI endpoint seems to be //token/new, should we align the API with the UI?

Ok, I've had to apply the following two patches to get this PR to pass tests:

0001-Fix-the-tests.patch

0002-Black8-fixes.patch

3 new commits added

  • Align new token API endpoint with UI endpoint
  • Black8 fixes
  • Fix the tests

pretty please pagure-ci rebuild

Black seems still unhappy: https://ci.centos.org/job/pagure-pr/2212/artifact/pagure/results_f29-rpms-py3/py3-test_style/view/

This is the change black does locally:

diff --git a/ pagure/api/project.py b/ pagure/api/project.py
index 20c6e8af..e947a306 100644
--- a/ pagure/api/project.py    
+++ b/ pagure/api/project.py    
@@ -2138,9 +2138,7 @@ def api_modify_project_options(repo, username=None, namespace=None):
 @API.route("/<repo>/token/new", methods=["POST"])
 @API.route("/<namespace>/<repo>/token/new", methods=["POST"])
 @API.route("/fork/<username>/<repo>/token/new", methods=["POST"])
-@API.route(
-    "/fork/<username>/<namespace>/<repo>/token/new", methods=["POST"]
-)
+@API.route("/fork/<username>/<namespace>/<repo>/token/new", methods=["POST"])
 @api_login_required(acls=["modify_project"])
 @api_method
 def api_project_create_api_token(repo, namespace=None, username=None):

Thanks I'll fix that.

Curious, I've run the full test suite locally and black has not complain.

1 new commit added

  • Fix black compliance

pretty please pagure-ci rebuild

The failed test is repospanner which fails for everyone, everything pass, so let's get this in :)

Pull-Request has been merged by pingou

Metadata