Programmatically create shareable url

Hi all, I think this is a silly question, but I can’t find out how to create a shareable url from my Python code. With the CLI it works great with the --url flag, I was hoping to do something similar programmatically.

I was looking for it under the Access Type in the Go documentation, but I can’t figure it out. Serializing the access seems in the right direction, but how do I create a linkshare from the serialized gibberish?

Have a look at this

I couldn’t find a full api documentation for the Python library, hence was reading the golang docs. Does the Python repo explain how to generate a linkshare somewhere?

Could you please take a look on

However, it will not produce a linksharing URL.
Here how to do this with uplink CLI: share - Storj DCS
I do not think that this third-party binding has an analogue.
Here is the code in GO: uplink-c/edge_share.go at b5a2eed860c6042ca4aa1859f7a2f4f33e06b09d · storj/uplink-c · GitHub

It’s unclear whether the wiki documents the full functionality of the Python bindings.

Is it possible with the go library? (cause I don’t understand how I should read that from the docs)

Yes, you can use our code for uplink as a prototype:

You can also check out this walkthrough: Libuplink Walkthrough · storj/storj Wiki · GitHub

2 Likes

How can I get public link of my video using uplink-python

Hello @tyson,
Welcome to the forum!

Please take a look on messages above:

Since it is possible to construct a linksharing URL by the formula https://link.storjshare.io/s/[access key]/[object prefix + object], I really just need to be able to extract the key from access.share(permissions, shared_prefix). There is access.serialize(), but the Python documentation mentions that “ParseAccess” can be used to get further information out of the serialized access string. However, the Python wrapper doesn’t provide that method, so I’m not sure why the docs mention it.

The “ParseAccess” method in the GO SDK can extract the API Key out of the serialized access string, which I think is what is needed as the access key in the URL. I was going to try to just write my own method by looking at what “ParseAccess” does in the GO SDK, but it calls another function called “parseNodeURL”. I don’t know anything about node URLs or how they work, and so far I haven’t had any luck finding any existing Python modules or methods for parsing them. Is there any easier way to just get the API Key out of the access.share() method, that I’m overlooking? I need some way to be able to programatically generate shareable URLs.

These are different accesses, this one (short) is an Access Key from S3 credentials (you need also the Secret Access Key to manage this (these) bucket(s) or objects in it (them)), so you cannot derive the new access grant using only the access key. You also cannot derive it even if you would have a Secret Access Key too, you need a serialized access grant (the macaroon) instead.
See

By the way, you may construct an URL using the access grant directly, but it’s not recommended exactly for the same reason - anyone can derive an own access grant, and also they may get access to the entire project, if you would publish your root access grant and they will be able to do anything with your buckets as it would be you.
When you register it on the GatewayMT to get S3 credentials, you may specify that it should be public, in this case you will be able to use the Access Key from these S3 credentials to construct an URL safely, because it doesn’t contain your derived API Key, a derived encryption key or restrictions or the satellite URL. However, it’s still not recommended to register the root access grant anyway, it’s better to generate/derive a limited one instead (only for public bucket(s)/prefix(es)/object(s)) with a read only permissions, then register. You may do it using several commands (access restrict - Storj Docs, access register - Storj Docs) or using a single share command:

uplink share --url --not-after=+1h sj://my-bucket1 sj://my-bucket2/my-prefix1 sj://my-bucket2/my-prefix2 sj://my-bucket3/videos/funny-moments.mp4

You will provide a limited read only access to these shared buckets prefixes and the object, and will generate:

  • a serialized access grant (the macaroon);
  • s3 credentials with endpoint and public access;
  • public URL on our linksharing service (you may use your own by the way, or register it under your domain).