#1573 frontend, python: deduplicate APIv3 build-chroot parameters
Merged 3 years ago by praiskup. Opened 3 years ago by frostyx.
copr/ frostyx/copr build-chroot-duplicate-params  into  master

@@ -36,12 +36,15 @@ 

      return dict_data

  

  

- @apiv3_ns.route("/build-chroot/<int:build_id>/<chrootname>", methods=GET)

+ @apiv3_ns.route("/build-chroot", methods=GET)

+ @apiv3_ns.route("/build-chroot/<int:build_id>/<chrootname>", methods=GET)  # deprecated

+ @query_params()

  def get_build_chroot(build_id, chrootname):

      chroot = ComplexLogic.get_build_chroot(build_id, chrootname)

      return flask.jsonify(to_dict(chroot))

  

  

+ @apiv3_ns.route("/build-chroot/list", methods=GET)

  @apiv3_ns.route("/build-chroot/list/<int:build_id>", methods=GET)

  @pagination()

  @query_params()
@@ -52,7 +55,9 @@ 

      return flask.jsonify(items=chroots, meta=paginator.meta)

  

  

- @apiv3_ns.route("/build-chroot/build-config/<int:build_id>/<chrootname>", methods=GET)

+ @apiv3_ns.route("/build-chroot/build-config", methods=GET)

+ @apiv3_ns.route("/build-chroot/build-config/<int:build_id>/<chrootname>", methods=GET)  # deprecated

+ @query_params()

  def get_build_chroot_config(build_id, chrootname):

      chroot = ComplexLogic.get_build_chroot(build_id, chrootname)

      return flask.jsonify(build_config(chroot))

@@ -15,7 +15,7 @@ 

          :param str chrootname:

          :return: Munch

          """

-         endpoint = "/build-chroot/{build_id}/{chrootname}"

+         endpoint = "/build-chroot"

          params = {

              "build_id": build_id,

              "chrootname": chrootname,
@@ -33,7 +33,7 @@ 

          :param pagination:

          :return: Munch

          """

-         endpoint = "/build-chroot/list/{build_id}"

+         endpoint = "/build-chroot/list"

          params = {

              "build_id": build_id,

          }
@@ -50,7 +50,7 @@ 

          :param str chrootname:

          :return: Munch

          """

-         endpoint = "/build-chroot/build-config/{build_id}/{chrootname}"

+         endpoint = "/build-chroot/build-config"

          params = {

              "build_id": build_id,

              "chrootname": chrootname,

Fix #1352

We were sending build_id and chrootname values as a part of the
URL path as well as query parameters. I am dropping them from the URL
path, they are unnecessary there (and IMHO not really used).

I am not changing the original route on frontend to avoid breaking a
backward compatibility, but rather adding a new simple route.

So, at this point, both old URL, e.g.

/api_3/build-chroot/1341930/fedora-rawhide-x86_64?build_id=1341930&chrootname=fedora-rawhide-x86_64

and new URL

/api_3/build-chroot?build_id=1341930&chrootname=fedora-rawhide-x86_64

will work

This way, or the possibility is to go the other way around, and fix the old route so
it can work without the "useless" parameters (but also with them).
I'm just not sure why this variant, can you state it in the commit message?

Side note: what #1352 shows us is that people care and will care more about
the API quality. And it seems that we should really pay attention to consistency,
and/or start documenting even the API.

rebased onto 2be98c4

3 years ago

This way, or the possibility is to go the other way around, and fix the old route so
it can work without the "useless" parameters (but also with them).
I'm just not sure why this variant, can you state it in the commit message?

Actually, I think I did this. By "I am not changing the original route
on frontend to avoid breaking a backward compatibility, but rather
adding a new simple route." I didn't mean copy-pasting the whole
route/view function (argh, I always mistake them because Flask uses a
different teminology then some other web frameworks). By adding a new
"route" I meant simply adding a new @apiv3_ns.route decorator for
the existing function ... so it can be accessed via URL with or
without the "useless" parameters.

I updated the commit message so hopefully it is not that confusing anymore.

Side note: what #1352 shows us is that people care and will care more about
the API quality. And it seems that we should really pay attention to consistency,
and/or start documenting even the API.

I totally agree, we should investigate how to document our API
properly.

I meant that there's an option to make this work:

1) /api_3/build-chroot/1341930/fedora-rawhide-x86_64

... as well as compat variant:

 2) /api_3/build-chroot/1341930/fedora-rawhide-x86_64?build_id=1341930&chrootname=fedora-rawhide-x86_64

I have no problem with the variant you prefer:

3) /api_3/build-chroot?build_id=1341930&chrootname=fedora-rawhide-x86_64

But I'm not sure whether we shouldn't make 1) work as well.

Ah, I see, thank you for the explanation.

But I'm not sure whether we shouldn't make 1) work as well.

IMHO no, for other GET routes, we use just 3), e.g.

endpoint = "/project"
params = {
"ownername": ownername,
"projectname": projectname,
}

---

endpoint = "/project/list"
params = {
"ownername": ownername,
}

---

endpoint = "/project/search"
params = {
"query": query,
}

---

endpoint = "/project-chroot"
params = {
"ownername": ownername,
"projectname": projectname,
"chrootname": chrootname,
}

---

endpoint = "/project-chroot/build-config"
params = {
"ownername": ownername,
"projectname": projectname,
"chrootname": chrootname,
}

---

endpoint = "/build/list"
params = {
"ownername": ownername,
"projectname": projectname,
"packagename": packagename,
"status": status,
}

and the 1) format is not supported. There is a couple of exceptions though, regarding getting a single build:

endpoint = "/build/{0}".format(build_id)
endpoint = "/build/source-chroot/{0}".format(build_id)
endpoint = "/build/source-build-config/{0}".format(build_id)

If we wanted to unify all of that, my preference would be to migrate
everything to 3) instead of 1) because it is IMHO superior. It is a
bit longer, yes, but it allows to pass arguments in a random order as
well as passing optional arguments in the same way as the required
ones, which is really cool in routes like /build/list, see above.

If we wanted to unify all routes and support both 1) and 3) format for
all of them, I wouldn't be against, but it needs to be done in a
separate PR and I would stick with exclusively using 3) in python-copr client.

What do you think?

Commit 5bfd679 fixes this pull-request

Pull-Request has been merged by praiskup

3 years ago