forked from kennylevinsen/jirafs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (79 loc) · 1.99 KB
/
main.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"flag"
"fmt"
"net"
"net/http"
"net/url"
"github.com/howeyc/gopass"
"github.com/joushou/qp"
"github.com/joushou/qptools/fileserver"
)
var (
address = flag.String("address", "localhost:30000", "address to bind on")
usingOAuth = flag.Bool("oauth", false, "use OAuth 1.0 for authorization")
ckey = flag.String("ckey", "", "consumer key for OAuth")
pkey = flag.String("pkey", "", "private key file for OAuth")
pass = flag.Bool("pass", false, "use password for authorization")
jiraURLStr = flag.String("url", "", "jira URL")
maxlisting = flag.Int("maxlisting", 100, "max directory listing length")
)
func main() {
flag.Parse()
jiraURL, err := url.Parse(*jiraURLStr)
if err != nil {
fmt.Printf("Could not parse JIRA URL: %v\n", err)
return
}
client := &Client{
Client: &http.Client{},
usingOAuth: *usingOAuth,
jiraURL: jiraURL,
maxlisting: *maxlisting,
}
switch {
case *pass:
var username string
fmt.Printf("Username: ")
_, err = fmt.Scanln(&username)
if err == nil {
fmt.Printf("Password: ")
password, err := gopass.GetPasswdMasked()
if err != nil {
fmt.Printf("Could not read password: %v\n", err)
return
}
client.user = username
client.pass = string(password)
} else {
fmt.Printf("Continuing without authentication.\n")
}
case *usingOAuth:
if err := client.oauth(*ckey, *pkey); err != nil {
fmt.Printf("Could not complete oauth handshake: %v\n", err)
return
}
default:
fmt.Printf("Continuing without authentication\n")
}
root, err := NewJiraDir("", 0555|qp.DMDIR, "jira", "jira", client, &JiraView{})
if err != nil {
fmt.Printf("Could not create JIRA view\n")
return
}
l, err := net.Listen("tcp", *address)
if err != nil {
fmt.Printf("Could not listen: %v\n", err)
return
}
for {
conn, err := l.Accept()
if err != nil {
fmt.Printf("Accept failed: %v\n", err)
return
}
f := fileserver.New(conn, root, nil)
f.Verbosity = fileserver.Quiet
go f.Serve()
}
}