Coder Social home page Coder Social logo

Comments (6)

kurin avatar kurin commented on August 15, 2024

I wish I knew how often people just wanted to share one object vs wanting an auth token for a common prefix of many objects.

What about something like

type Token string

func (t Token) URL(o *Object) (*url.URL, error)

so that getting auth tokens is still essentially a bucket operation, but has a convenience method for individual objects.

from blazer.

kennylevinsen avatar kennylevinsen commented on August 15, 2024

I can't really come up with a real use-case for issuing a token for a prefix of many objects, instead of just using a token per object, but that may of course just be because I am a bit too focused on the use-cases I have experienced myself.

That interface would seem slightly quirky. First of all, it's a bit repetitive:

token, _ := bucket.AuthToken(ctx, objectName, validity)
obj := bucket.Object(objectName)
url, _ := token.URL(obj)

Second, it would blindly generate URL's for objects that the token is incapable of serving, making it a bit error-prone. In case of b2ContentDisposition, the token will be even more limited in use (which I unfortunately need...).

I personally like the idea of having automatic token issue on Object convenience methods better, as it is both more convenient and more robust. I won't cry myself to sleep if that doesn't happen, though. :)

from blazer.

kurin avatar kurin commented on August 15, 2024

I'm interested in avoiding API bloat, but I think you're right that your use case is probably fairly common, enough so to warrant these helpers.

I would like to avoid two different methods though. I'm starting to worry that I'm overusing the ThingOption pattern a little bit, but it could apply here. Alternatively we could just leave that argument empty for no b2ContentDisposition argument.

from blazer.

kurin avatar kurin commented on August 15, 2024

B2 doesn't have any documentation that I've found specifying how many auth tokens you're able to get. (You also apparently can't revoke them once you have them.) So I guess it could just generate a new token each time.

from blazer.

kurin avatar kurin commented on August 15, 2024

Take a look at that PR and see if it's something that would fit your use case.

It requests a new token for every call to AuthURL(), which I figure if people want to cache it they can probably do that themselves.

from blazer.

kennylevinsen avatar kennylevinsen commented on August 15, 2024

I haven't tested it, but that PR fits my use-case perfectly, and in the most convenient way it could be done, so I couldn't be happier!

I would have commented that you should add a few url.QueryEscape calls, but you beat me to it.

from blazer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.