Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 69c8542

Browse files
authored
don't bother user with oauth if exporting from a local file (#347)
1 parent 6b537bc commit 69c8542

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

claat/fetch/fetch.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,16 @@ type Fetcher struct {
7373
authToken string
7474
crcTable *crc64.Table
7575
passMetadata map[string]bool
76+
roundTripper http.RoundTripper
7677
}
7778

7879
func NewFetcher(at string, pm map[string]bool, rt http.RoundTripper) (*Fetcher, error) {
79-
h, err := auth.NewHelper(at, auth.ProviderGoogle, rt)
80-
if err != nil {
81-
return nil, err
82-
}
83-
8480
return &Fetcher{
85-
authHelper: h,
81+
authHelper: nil,
8682
authToken: at,
8783
crcTable: crc64.MakeTable(crc64.ECMA),
8884
passMetadata: pm,
85+
roundTripper: rt,
8986
}, nil
9087
}
9188

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

0 commit comments

Comments
 (0)