-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.go
More file actions
51 lines (38 loc) · 1.28 KB
/
auth.go
File metadata and controls
51 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package lab
import (
"bufio"
"fmt"
"io"
"strings"
)
type AuthService struct {
Git Git
Browser Browser
Reader io.Reader
Writer io.Writer
}
// AuthService will ensure the user logs in if the remote project requires it
func (service *AuthService) RemoteProject() (RemoteProject, error) {
remote, err := service.Git.RemoteProject()
reader := bufio.NewReader(service.Reader)
if missingToken, ok := err.(MissingToken); ok {
fmt.Fprintf(service.Writer, "No access token for https://%s/ found. Please create a new access token with api scopes.\n", missingToken.Host)
fmt.Fprintln(service.Writer, "Press enter to open your browser to your access tokens page.")
reader.ReadString('\n')
url := fmt.Sprintf("https://%s/profile/personal_access_tokens", missingToken.Host)
err = service.Browser.Open(url)
if err != nil {
fmt.Fprintf(service.Writer, "Error trying open personal access token page.\n")
return remote, missingToken
}
if err != nil {
fmt.Fprintf(service.Writer, "Error trying to read string.\n")
return remote, missingToken
}
fmt.Fprint(service.Writer, "Please paste the access token here: ")
text, err := reader.ReadString('\n')
err = service.Git.SetAccessToken(remote, strings.Trim(text, "\n"))
return remote, err
}
return remote, err
}