XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Encoding a URL with : and / in their queries (tags)

    Scheduled Pinned Locked Moved Solved REST API
    7 Posts 3 Posters 458 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      Rhodderz
      last edited by

      I have already created a StackOverflow question about this as having some issues around searching vms based on their tags using the api;
      StackOverflow Q here

      I am writing a Spring app to help us generate reports and daily checks with a per-client basis, which are tagged by the clients short hand names.
      I have the basic curl query working for getting vms based on a tag however due to tags including : and / it gets a bit awkward with URI encoding.

      From testing (as shown in the SO question) XO will only accept the tag filter if : and / are encoded, however the URI encoder used in java strictly abides by RFC 3986 and wont allow me to encode them (found this when checking in C# as well.). Even manually encoding them breaks as the % then gets encoded as well (so a bit of fun double encoding).

      Is there a way to get XO to accept un-encoded : and / or if there is another way i can pass the tags across without having to put them in the URI?

      Kind Regards
      Rhodri MM-D

      julien-fJ 1 Reply Last reply Reply Quote 0
      • julien-fJ Offline
        julien-f Vates 🪐 Co-Founder XO Team @Rhodderz
        last edited by

        @Rhodderz I'm not able to reproduce the issue on my side.

        I successfully filtered VMs by a /foo tag and was able to filter for it (tags:/^\/foo$/) in the REST API, either by using filter=tags%3A%2F%5E%5C%2Ffoo%24%2F (encoded with encodeURIComponent()) or by using filter=tags:/%5E%5C/foo$/ (encoded using encodeURI() which does not encode / or :).

        R 1 Reply Last reply Reply Quote 0
        • olivierlambertO Offline
          olivierlambert Vates 🪐 Co-Founder CEO
          last edited by

          Hi,

          Question for @julien-f I assume

          1 Reply Last reply Reply Quote 0
          • julien-fJ Offline
            julien-f Vates 🪐 Co-Founder XO Team @Rhodderz
            last edited by julien-f

            @Rhodderz First of all, this filter param is using the same syntax as xo-web and there is documentation on it: https://xen-orchestra.com/docs/manage_infrastructure.html#live-filter-search

            Can you show me an example of your filter that is not properly working and I'll try it directly in xo-web?

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              Rhodderz @julien-f
              last edited by

              @julien-f
              Afternoon
              The filter i am using atm the moment as a test is a tag of Staff-RMD as shown below which was generated from the UI as well (selecting the tag from the tag dropdown)
              XOA Search Peram.png

              Testing via Postman, it works if everything (including the colon and forward slash) are encoded as shown:

              Working with everything encoded.png

              Problem with this is alot of libraries follow the RFC3986 (1.2.3) quite strictly and will not encode the colons or forward slash (Some even throw an invalid exception). This results in a query as below which returns an internal error:

              Not working following RFC.png

              And as a test checked running it with no encoding works and i get no results (but no error)

              Not working Raw.png

              More than happy to test other methods or workarounds. Though I have noticed I can seem to override the URIBuilder for the Java/Spring RestClient sadly.

              julien-fJ 1 Reply Last reply Reply Quote 0
              • julien-fJ Offline
                julien-f Vates 🪐 Co-Founder XO Team @Rhodderz
                last edited by

                @Rhodderz I'm not able to reproduce the issue on my side.

                I successfully filtered VMs by a /foo tag and was able to filter for it (tags:/^\/foo$/) in the REST API, either by using filter=tags%3A%2F%5E%5C%2Ffoo%24%2F (encoded with encodeURIComponent()) or by using filter=tags:/%5E%5C/foo$/ (encoded using encodeURI() which does not encode / or :).

                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  Rhodderz @julien-f
                  last edited by

                  @julien-f Thanks for the help
                  Having a look at what you tried I had found my mistake on the testing being i removed %24 ($) and not %2F (/) when testing in postman
                  What appears to likley caused my confusion in the first place as well is when logging is set to Info, spring removed the trailing /, so it appeared as not there.
                  Setting logging to Debug shows the full URL string that it was sending including the trailing /
                  The other part that compounded the above is INFO throws a warning that URI will not encode certain characters, which i incorrectly followed as the source of the problem.

                  For the final "How I confused the hell out of myself", the inital URI was actually working, however it was returning a single json object (correctly as well), however Spring silently ignored this expecting an array and just returned an empty array with it. This is fixed by setting the body from a Record to "new ParameterizedTypeReference<>() {}"
                  Which I did at one point however did not test again with the original working string and by this time the / was either in the wrong place, which would return no objects, or %24 was removed causing a 500 as having 2 /'s isnt accepted.

                  Apologies for the confusion and the circle dance.

                  1 Reply Last reply Reply Quote 0
                  • olivierlambertO olivierlambert marked this topic as a question on
                  • olivierlambertO olivierlambert has marked this topic as solved on
                  • olivierlambertO Offline
                    olivierlambert Vates 🪐 Co-Founder CEO
                    last edited by

                    No worries @Rhodderz happy to know it works for you now!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post