Skip to content

Commit

Permalink
don't bother user with oauth if exporting from a local file (googleco…
Browse files Browse the repository at this point in the history
  • Loading branch information
mco-gh authored Sep 13, 2019
1 parent 6b537bc commit 69c8542
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 69c8542

Please sign in to comment.