Comments (6)
Implementation Idea:
interface
type AuthenticationProvider interface {
Authenticate() (AccessToken, error)
}
usage
travis.NewClient(TRAVIS_API_DEFAULT_URL, GithubAuthProvider("mytoken"))
// or
travis.NewClient(TRAVIS_API_DEFAULT_URL, TravisAuthProvider())
from go-travis.
A possible implementation of it would consist in the following:
interface implementation
type GithubAuthProvider struct {
GithubToken string
}
type TravisAuthProvider struct {
TravisToken string
}
func (*GithubAuthProvider) Authenticate() (AccessToken, error) {
// get and return a travis token from the api using the github token
}
func (*TravisAuthProvider) Authenticate() (AccessToken, error) {
// return the TravisToken
}
client implementation
func (c *Client) Authenticate(auth AuthenticationProvider) error {
c.client.Headers["Authorization"] = "token " + auth.Authenticate()
}
from go-travis.
Spotted a problem in the implementation of this design: the GithubAuthProvider would need the client instance to query travis for a travis token. Which would actually lead to an impossible design as the client constructor would need to pass himself to the provider.
# Not possible
client := NewClient(TRAVIS_API_DEFAULT_URL, GithubAuthProvider(clientIHaventBuiltJustYet, token))
from go-travis.
A workaround could be to add a client attribute to the provider when relevant. To pass the provider to the constructor with its client attribute uninitialized. And when calling Client.Authenticate
initializing the provider client attribute, and calling its Authenticate
method.
func (c *Client) Authenticate(auth AuthenticationProvider) error {
auth.client = c.client
c.client.Headers["Authorization"] = "token " + auth.Authenticate()
}
But this sounds super hacky, and introduces mutability, which was exactly the aspect of current implementation we are trying to get rid of.
from go-travis.
Hey @tcr-ableton, do you think it would make sense to close this?
from go-travis.
Given the state of things, I don't think this issue will be addressed anytime soon.
from go-travis.
Related Issues (7)
- Expose a NewDefaultClient constructor
- Replace old organisation with new one in integration tests
- Running integration tests without token does not exit with status 1 HOT 1
- Imported "testing" outside of a "_test.go" file HOT 1
- No way to set base http.Transport/http.Client HOT 6
- 404 link in README. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-travis.