Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Read credentials from stdio if they are not available from other sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalnem committed Sep 26, 2016
1 parent d663fc5 commit 4685b66
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"archive/zip"
"bufio"
"bytes"
"context"
"crypto/sha1"
Expand All @@ -19,7 +20,10 @@ import (
"os"
"strconv"
"strings"
"syscall"
"time"

"golang.org/x/crypto/ssh/terminal"
)

const (
Expand Down Expand Up @@ -152,21 +156,40 @@ func setHeaders(header http.Header) {
header.Set(headerDate, t.Format(timeFormat))
}

func getCredentials() (string, string) {
func getCredentials() (string, string, error) {
email := *email
password := *password

if email == "" && password == "" {
email = os.Getenv("RUNTASTIC_EMAIL")
password = os.Getenv("RUNTASTIC_PASSWORD")
if email != "" && password != "" {
return email, password, nil
}

email = os.Getenv("RUNTASTIC_EMAIL")
password = os.Getenv("RUNTASTIC_PASSWORD")

if email != "" && password != "" {
return email, password, nil
}

fmt.Print("Email: ")
email, err := bufio.NewReader(os.Stdin).ReadString('\n')

if err != nil {
return "", "", err
}

if email == "" || password == "" {
flag.Usage()
os.Exit(1)
fmt.Print("Password: ")
pass, err := terminal.ReadPassword(syscall.Stdin)
fmt.Println()

if err != nil {
return "", "", err
}

return email, password
email = email[0 : len(email)-1]
password = string(pass)

return email, password, nil
}

func loginApp(ctx context.Context, email, password string) (*appUser, error) {
Expand Down Expand Up @@ -510,7 +533,12 @@ func archive(filename string, sessions []sessionData) (err error) {
func main() {
flag.Parse()

email, password := getCredentials()
email, password, err := getCredentials()

if err != nil {
log.Fatal(err)
}

format, err := getFormat(*format)

if err != nil {
Expand Down

0 comments on commit 4685b66

Please sign in to comment.