This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (57 loc) · 1.29 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
package main
import (
"context"
"encoding/json"
"io/ioutil"
"log"
"github.com/google/go-github/github"
"goftp.io/server"
"golang.org/x/oauth2"
)
var conf = &Configuration{
FTP: &FTPConfigure{
Port: 21,
Username: "anonymous",
},
GitHub: &GitHubConfigure{
Prefix: "Juniper",
},
}
func init() {
cfgPath := "./configure.json"
if data, err := ioutil.ReadFile(cfgPath); err != nil {
panic(err)
} else if err = json.Unmarshal(data, conf); err != nil {
panic(err)
}
}
func main() {
factory := &junosDriver{
GitHubConfigure: conf.GitHub,
client: github.NewClient(
oauth2.NewClient(
context.Background(),
oauth2.StaticTokenSource(&oauth2.Token{AccessToken: conf.GitHub.Token}),
),
),
}
serve := server.NewServer(&server.ServerOpts{
Name: "JunOS Archive",
WelcomeMessage: "JunOS FTP Archive Server",
Port: conf.FTP.Port,
Hostname: conf.FTP.Host,
Auth: makeAuth(),
Factory: factory,
})
if err := serve.ListenAndServe(); err != nil {
log.Fatal("Error starting server:", err)
}
}
func makeAuth() server.Auth {
name := conf.FTP.Username
password := conf.FTP.Password
if (name == "anonymous" || name == "") && password == "" {
return &AnonymousAuth{}
}
return &server.SimpleAuth{Name: name, Password: password}
}