Skip to content

Commit

Permalink
chore(clients): improve clients nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelovicentegc committed Nov 6, 2021
1 parent a6d650e commit 139adb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
"google.golang.org/api/option"
)

func getClient(ctx context.Context, oauthConfig *oauth2.Config) *http.Client {
func getDriveClient(ctx context.Context, oauthConfig *oauth2.Config) *http.Client {
authURL := oauthConfig.AuthCodeURL("state-token", oauth2.AccessTypeOffline)
utils.OpenBrowser(authURL)

authCode := runLocalOAuthServer()
authCode := runLocalOAuthServer(config.GoogleDriveOAuthCallback)

token, err := oauthConfig.Exchange(context.TODO(), authCode)
if err != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func UploadFileToDrive() {
if err != nil {
log.Fatalf("Unable to parse client secret file to config: %v", err)
}
client := getClient(ctx, configFromJson)
client := getDriveClient(ctx, configFromJson)

service, err := drive.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions clients/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
"net/http"
"os"

"github.com/marcelovicentegc/kontrolio-cli/config"
"github.com/marcelovicentegc/kontrolio-cli/messages"
)

func runLocalOAuthServer() string {
func runLocalOAuthServer(oauthEndpoint string) string {
mux := http.NewServeMux()
server := http.Server{Addr: ":8080", Handler: mux}
authCodeChannel := make(chan string)

mux.HandleFunc(config.GoogleDriveOAuthCallback, func(writer http.ResponseWriter, request *http.Request) {
mux.HandleFunc(oauthEndpoint, func(writer http.ResponseWriter, request *http.Request) {
err := request.ParseForm()
if err != nil {
fmt.Fprintf(os.Stdout, "could not parse query: %v", err)
Expand Down

0 comments on commit 139adb0

Please sign in to comment.