Skip to content

Commit

Permalink
Revert "added token refresh function"
Browse files Browse the repository at this point in the history
This reverts commit 7463104.
  • Loading branch information
bradrydzewski committed Jul 15, 2018
1 parent 7463104 commit 5ec7008
Show file tree
Hide file tree
Showing 18 changed files with 9 additions and 287 deletions.
1 change: 0 additions & 1 deletion scm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type (
PullRequests PullRequestService
Repositories RepositoryService
Reviews ReviewService
Tokens TokenService
Users UserService
Webhooks WebhookService

Expand Down
25 changes: 3 additions & 22 deletions scm/driver/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,17 @@ import (
"strings"

"github.com/drone/go-scm/scm"
"github.com/drone/go-scm/scm/transport/oauth2"
)

// ClientID string
// ClientSecret string
// Endpoint string

// Source scm.TokenSource
// Client *http.Client

// New returns a new Bitbucket API client.
func New(uri string, opt ...Option) (*scm.Client, error) {
func New(uri string) (*scm.Client, error) {
base, err := url.Parse(uri)
if err != nil {
return nil, err
}
if !strings.HasSuffix(base.Path, "/") {
base.Path = base.Path + "/"
}
opts := new(Options)
for _, o := range opt {
o(opts)
}
refresher := &oauth2.Refresher{
Endpoint: tokenEndpoint,
ClientID: opts.clientID,
ClientSecret: opts.clientSecret,
Client: opts.client,
}
client := &wrapper{new(scm.Client)}
client.BaseURL = base
// initialize services
Expand All @@ -54,16 +36,15 @@ func New(uri string, opt ...Option) (*scm.Client, error) {
client.PullRequests = &pullService{&issueService{client}}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{refresher}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
}

// NewDefault returns a new Bitbucket API client using the
// default api.bitbucket.org address.
func NewDefault(opt ...Option) *scm.Client {
client, _ := New("https://api.bitbucket.org", opt...)
func NewDefault() *scm.Client {
client, _ := New("https://api.bitbucket.org")
return client
}

Expand Down
41 changes: 0 additions & 41 deletions scm/driver/bitbucket/option.go

This file was deleted.

29 changes: 0 additions & 29 deletions scm/driver/bitbucket/token.go

This file was deleted.

74 changes: 0 additions & 74 deletions scm/driver/bitbucket/token_test.go

This file was deleted.

1 change: 0 additions & 1 deletion scm/driver/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func New(uri string) (*scm.Client, error) {
client.PullRequests = &pullService{client}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
Expand Down
20 changes: 0 additions & 20 deletions scm/driver/gitea/token.go

This file was deleted.

1 change: 0 additions & 1 deletion scm/driver/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func New(uri string) (*scm.Client, error) {
client.PullRequests = &pullService{&issueService{client}}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
Expand Down
20 changes: 0 additions & 20 deletions scm/driver/github/token.go

This file was deleted.

2 changes: 0 additions & 2 deletions scm/driver/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func New(uri string) (*scm.Client, error) {
client.PullRequests = &pullService{client}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
}

Expand Down
20 changes: 0 additions & 20 deletions scm/driver/gitlab/token.go

This file was deleted.

1 change: 0 additions & 1 deletion scm/driver/gogs/gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func New(uri string) (*scm.Client, error) {
client.PullRequests = &pullService{client}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
Expand Down
20 changes: 0 additions & 20 deletions scm/driver/gogs/token.go

This file was deleted.

1 change: 0 additions & 1 deletion scm/driver/stash/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func New(uri string) (*scm.Client, error) {
client.PullRequests = &pullService{client}
client.Repositories = &repositoryService{client}
client.Reviews = &reviewService{client}
client.Tokens = &tokenService{}
client.Users = &userService{client}
client.Webhooks = &webhookService{client}
return client.Client, nil
Expand Down
20 changes: 0 additions & 20 deletions scm/driver/stash/token.go

This file was deleted.

12 changes: 2 additions & 10 deletions scm/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ type (
Token(context.Context) (*Token, error)
}

// TokenService provides token refresh capabilities.
TokenService interface {
// Refresh refreshes the token if necessary. The
// function returns a boolean value indicating
// whether or not the token is refreshed.
Refresh(context.Context, *Token) (bool, error)
}

// TokenKey is the key to use with the context.WithValue
// function to associate an Token value with a context.
TokenKey struct{}
)

// WithToken returns a copy of parent in which the token value is set
func WithToken(parent context.Context, token *Token) context.Context {
// WithContext returns a copy of parent in which the token value is set
func WithContext(parent context.Context, token *Token) context.Context {
return context.WithValue(parent, TokenKey{}, token)
}
Loading

0 comments on commit 5ec7008

Please sign in to comment.