Skip to content

Commit

Permalink
add oauth interface
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Feb 6, 2024
1 parent 4a5959e commit b082fe6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cli/cli/helpers/github_auth_config/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var (
browser = *gitbrowser.New(defaultLauncher, os.Stdout, os.Stderr)
)

type OAuthFlow interface {
AuthFlow() (string, string, error)
}

func AuthFlow() (string, string, error) {
httpClient := &http.Client{} // nolint: exhaustruct

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/mholt/archiver"
"github.com/sirupsen/logrus"
"io"
"io/fs"
"os"
"path"
"strings"
Expand Down Expand Up @@ -424,10 +425,13 @@ func (provider *GitPackageContentProvider) atomicClone(parsedURL *shared_utils.P
return nil
}

// Returns empty string if no token found in [githubAuthTokenFile]
// Returns empty string if no token found in [githubAuthTokenFile] or [githubAuthTokenFile] doesn't exist
func (provider *GitPackageContentProvider) getGitHubAuthToken() (string, error) {
tokenBytes, err := os.ReadFile(provider.githubAuthTokenFile)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return "", nil
}
return "", stacktrace.Propagate(err, "An error occurred reading contents at '%v' to retrieve GitHub auth token.", provider.githubAuthTokenFile)
}
return string(tokenBytes), nil
Expand Down

0 comments on commit b082fe6

Please sign in to comment.