ncw / swift

Go language interface to Swift / Openstack Object Storage / Rackspace cloud files (golang)
MIT License
313 stars 107 forks source link

Get Connection object with Auth Token & Storage URL #80

Closed reSoley closed 7 years ago

reSoley commented 7 years ago

I'm currently working on this CLI used to interact with SoftLayer Object Storage, specifically on IBM Bluemix.

To get a Connection object, I need to authenticate with each command. This requires a couple of requests to bluemix.net unless I have my Object Storage service credentials saved locally. If I'm not caching creds, it takes ~5-8 seconds for each command. And I often find myself having to string commands together, so those seconds add up fast.

I'm not thrilled about caching service credentials that don't change, and would feel a lot better about storing the expiring Auth Token and taking the longer time to get a new one as needed. Is there currently a way for me to get an active Connection object with just my Auth Token and Storage URL or can I only obtain one with the service credentials?

Thanks!

ncw commented 7 years ago

Is there currently a way for me to get an active Connection object with just my Auth Token and Storage URL or can I only obtain one with the service credentials?

Sure, just stick the StorageUrl and AuthToken in the swift.Connection object and you should be good to go.go

You'll see that the Authenticated function only checks that these are both non empty.

Stuff will go wrong when the auth token expires though...

reSoley commented 7 years ago

Sorry, forgot to get back to you. But that did the trick!

I had tried that earlier but then called Authenticate and when that errored out I figured it wasn't the right approach. Perhaps a different error or none at all if Authenticate is called with those fields already populated?

ncw commented 7 years ago

I had tried that earlier but then called Authenticate and when that errored out I figured it wasn't the right approach. Perhaps a different error or none at all if Authenticate is called with those fields already populated?

The correct way to call it is like this. Calling Authenticate means get a new token now please!


if !c.Authenticated() {
    err = c.Authenticate()
    if err != nil { ... }
}

Anyway, glad it is sorted - I'll close this issue now.