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

don't bother user with oauth if exporting from a local file #347

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions claat/fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,16 @@ type Fetcher struct {
authToken string
crcTable *crc64.Table
passMetadata map[string]bool
roundTripper http.RoundTripper
}

func NewFetcher(at string, pm map[string]bool, rt http.RoundTripper) (*Fetcher, error) {
h, err := auth.NewHelper(at, auth.ProviderGoogle, rt)
if err != nil {
return nil, err
}

return &Fetcher{
authHelper: h,
authHelper: nil,
authToken: at,
crcTable: crc64.MakeTable(crc64.ECMA),
passMetadata: pm,
roundTripper: rt,
}, nil
}

Expand All @@ -96,6 +93,16 @@ func NewFetcher(at string, pm map[string]bool, rt http.RoundTripper) (*Fetcher,
// The function will also fetch and parse fragments included
// with types.ImportNode.
func (f *Fetcher) SlurpCodelab(src string) (*codelab, error) {
_, err := os.Stat(src)
// Only setup oauth if this source is not a local file.
if os.IsNotExist(err) {
if f.authHelper == nil {
f.authHelper, err = auth.NewHelper(f.authToken, auth.ProviderGoogle, f.roundTripper)
if err != nil {
return nil, err
}
}
}
res, err := f.fetch(src)
if err != nil {
return nil, err
Expand Down