Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Connection object with Auth Token & Storage URL #80

Closed
reSoley opened this issue Dec 2, 2016 · 3 comments
Closed

Get Connection object with Auth Token & Storage URL #80

reSoley opened this issue Dec 2, 2016 · 3 comments
Labels

Comments

@reSoley
Copy link

reSoley commented Dec 2, 2016

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 ncw added the question label Dec 2, 2016
@ncw
Copy link
Owner

ncw commented Dec 2, 2016

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
Copy link
Author

reSoley commented Dec 7, 2016

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
Copy link
Owner

ncw commented Dec 16, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants