-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ipfsconn/ipfshttp: handle cid args passed in url path correctly #392
Conversation
c9c22b8
to
3b636a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail. I am not sure that the handle
is selecting the right thing from ipfs.handlers
anymore. We might have to make more clever route matching..
ipfsconn/ipfshttp/ipfshttp.go
Outdated
|
||
// extractCid extracts the cid argument from a url.URL, either via | ||
// the query string parameters or from the url path itself. | ||
func extractCid(u *url.URL) (string, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to extractArgument
, since the argument doesn't have to be a Cid in all cases (even if now it's always one).
ipfsconn/ipfshttp/ipfshttp.go
Outdated
|
||
if len(segs) > 2 { | ||
return segs[len(segs)-1], true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm starting to get what you were saying yesterday..
In general, we have things like:
pin/ls/<arg>
cat/<arg>
but from here we have no way of distinguishing which commands are valid in order to know what part of the url is the argument.
Let's print a warning "You are using an undocumented form of the IPFS API. Consider passing your command arguments with the '?arg=' query parameter".
For the moment it works like this I guess...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and after our conversation, I had another look at https://github.com/ipfs/go-ipfs-cmds/blob/master/http/parse.go#L42 and realised that it has access to all the possible subcommands and hence why it is able to distinguish between commands and arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll we do know which subcommands we are handling, so that's our list if we want to be strict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's print a warning "You are using an undocumented form of the IPFS API. Consider passing your command arguments with the '?arg=' query parameter".
@hsanjuan should I be returning that in the json response, as it is the client that needs to change?
Also, the way that we have the IPFS-Cluster api documented in the README suggests that pin/ls/<arg>
is the more appropriate way to interact with the api, so that should probably get changed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hsanjuan should I be returning that in the json response, as it is the client that needs to change?
No, just spam the logs
/pin/ls/<arg>
that refers to the cluster API.
This is different from the IPFS API.
3b636a3
to
267c7ba
Compare
e6f0d58
to
d596361
Compare
ipfsErrorResponder(w, "Error: bad argument") | ||
return | ||
} | ||
arg := argA[0] | ||
_, err := cid.Decode(arg) | ||
if err != nil { | ||
ipfsErrorResponder(w, "Error parsing CID: "+err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hsanjuan So for some reason, the tests that attempt to pin/unpin a bad cid are failing on travis/jenkins (they aren't failing locally and I have tried on two separate computers/OSes). It would appear that on travis/jenkins, this cid.Decode
operation is returning an error when passed the test.ErrorCid
. Or the extractArgument
function is failing...
@hsanjuan so I haven't gotten to the bottom of this but it appears to be due to travis/jenkins running |
5b1e2f4
to
fa4fe5c
Compare
The extractCid function was added to enable the extraction of a cid argument from either the url path or query string. This puts the proxy behaviour on par with the current IPFS API. The function does rely on the fact that ipfs-cluster doesn't intercept any command that has more than one subcommand. If that changes, this function will have to be updated. License: MIT Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
query args correctly, requiring both a trailing slash and non-trailing slash handle pattern to be defined for the pin and unpin handlers. License: MIT Signed-off-by: Adrian Lanzafame <adrianlanzafame92@gmail.com>
fa4fe5c
to
b50a05f
Compare
@lanzafame this is ready on your side right? |
I just want to squash done commits otherwise yes.
On Mon., 30 Apr. 2018, 17:51 Hector Sanjuan, ***@***.***> wrote:
@lanzafame <https://github.com/lanzafame> this is ready on your side
right?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#392 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFpnaOwrnj-wUh3r0b-5DJrH5McqBOcjks5ttsKCgaJpZM4Titj5>
.
--
Adrian Lanzafame
m: 0435419266
e: adrianlanzafame92@gmail.com
gh: github.com/lanzafame
|
s/done/some
On Mon., 30 Apr. 2018, 17:52 Adrian Lanzafame, <adrianlanzafame92@gmail.com>
wrote:
I just want to squash done commits otherwise yes.
On Mon., 30 Apr. 2018, 17:51 Hector Sanjuan, ***@***.***>
wrote:
> @lanzafame <https://github.com/lanzafame> this is ready on your side
> right?
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <#392 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFpnaOwrnj-wUh3r0b-5DJrH5McqBOcjks5ttsKCgaJpZM4Titj5>
> .
>
--
Adrian Lanzafame
m: 0435419266
e: ***@***.***
gh: github.com/lanzafame
--
Adrian Lanzafame
m: 0435419266
e: adrianlanzafame92@gmail.com
gh: github.com/lanzafame
|
@hsanjuan Sorry, this PR is fine regarding commits. I was thinking of the pintracker revamp PR. |
Hehe yeah I was thinking so :) |
The extractCid function was added to enable the extraction of
a cid argument from either the url path or query string.
This puts the proxy behaviour on par with the current IPFS API.
The function does rely on the fact that ipfs-cluster doesn't
intercept any command that has more than one subcommand.
If that changes, this function will have to be updated.
License: MIT
Signed-off-by: Adrian Lanzafame adrianlanzafame92@gmail.com