Bug: import-url loses URL path/port when parsing :primary and secret suffixes
Describe the bug
The import-url command parses artifact URLs with strings.Split(f, ":").
This breaks normal URLs that contain additional colons, for example URLs with ports:
http://localhost:8080/spec.yaml:true
The current parsing logic reconstructs the URL from only the first two split parts:
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]
So http://localhost:8080/spec.yaml:true becomes http://localhost, losing the port, path, and filename.
This affects import-url when using the optional :primary and secret suffixes.
Expected behavior
import-url should preserve the full URL, including scheme, host, port, path, query string, and fragment.
For example:
microcks import-url http://localhost:8080/spec.yaml:true
should send this URL to microcks:
http://localhost:8080/spec.yaml
with mainArtifact=true.
URLs without suffixes should also continue to work unchanged.
Actual behavior
The URL is split on every colon. For a URL like:
http://localhost:8080/spec.yaml:true
the parser splits it into parts like:
["http", "//localhost", "8080/spec.yaml", "true"]
Then it reconstructs only:
http://localhost
As a result, Microcks receives an incorrect artifact URL.
How to Reproduce?
Reproducer:
- Run
import-urlwith a URL that contains a port and the:primarysuffix:
microcks import-url http://localhost:8080/spec.yaml:true \
--microcksURL=http://localhost:8080/api \
--keycloakClientId=<client-id> \
--keycloakClientSecret=<client-secret>
- Observe that the CLI parses the artifact URL incorrectly before calling DownloadArtifact.
Microcks version or git rev
Microcks CLI 1.0.2
Install method (docker-compose, helm chart, operator, docker-desktop extension,...)
built from source
Additional information
A possible fix is to avoid splitting the whole URL on every colon.
Options:
- parse suffixes from the right side only, for example with
strings.LastIndex; - use URL-aware parsing and only treat trailing
:true,:false, and optional secret values as CLI metadata; - add focused unit tests for URLs with ports, paths, query strings, and suffixes.
Related code:
urlAndMainAtrifactAndSecretName := strings.Split(f, ":")
n := len(urlAndMainAtrifactAndSecretName)
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]
π @cotishq
Welcome to the Microcks community! π
Thanks and congrats π for opening your first issue here! Be sure to follow the issue template or please update it accordingly.
π’ If you're using Microcks in your organization, please add your company name to this list. π It really helps the project to gain momentum and credibility. It's a small contribution back to the project with a big impact.
If you need to know why and how to add yourself to the list, please read the blog post "Join the Microcks Adopters list and Empower the vibrant open source Community π"
Hope you have a great time there!
@Harsh4902 would love to hear your opinion, and if this looks good i can raise a pr for it
hey, i can take this.. already have a fix using strings.LastIndex to grab the suffix from the right instead of splitting on every : will open a PR once thatβs confirmed π
hey, i can take this.. already have a fix using strings.LastIndex to grab the suffix from the right instead of splitting on every : will open a PR once thatβs confirmed π
Hey, i am working on it, once maintainer approves it, I'll raise the pr too
Okay...Got it, thanks! Iβll hold off π
@lbroudoux hey, whats your opinion on this, can i work on this
Yes, for sure. We don't assign issues to non-codeowners of the repo. So anytime you want to contribute, please signal your interest in joining an issue discussion to advertise that you're ready to tackle this topic. This will let the others know what you're working on.
ya i will keep this in consideration next time
This issue has been automatically marked as stale because it has not had recent activity :sleeping:
It will be closed in 30 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.
There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. Microcks is a Cloud Native Computing Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.
Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.
Thank you for your patience :heart:
It should be /keep-open