/
main.go
92 lines (74 loc) · 2.02 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 (
"context"
"fmt"
"log"
"net/http"
"time"
"github.com/alexflint/go-arg"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"github.com/google/go-github/v28/github"
"golang.org/x/oauth2"
)
type args struct {
Mountpoint string `arg:"positional,required"`
Owner string `arg:"positional,required"`
Repo string `arg:"positional,required"`
AccessToken string `arg:"--token" help:"GitHub access token for authorization"`
AllowOther bool `arg:"--allow-other" help:"use FUSE allow_other mode (allow_root doesn't work, so not available)"`
RefreshThreshold uint32 `arg:"--refresh" default:"30" help:"number of seconds that must elapsed before subsequent assets refresh can occur"`
}
func (args) Description() string {
return "GitHub Release Assets FUSE CLI"
}
func (args) Version() string {
return "ghafs 0.1.3"
}
func main() {
var args args
arg.MustParse(&args)
// GitHub Set-up
ctx := context.Background()
var tc *http.Client
if args.AccessToken != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: args.AccessToken},
)
tc = oauth2.NewClient(ctx, ts)
}
client := github.NewClient(tc)
mgmt, err := makeReleaseMgmt(makeGhContext(ctx, client, args.Owner, args.Repo, time.Duration(args.RefreshThreshold)*time.Second))
if err != nil {
log.Fatal(err)
}
mountOptions := []fuse.MountOption{
fuse.FSName("ghafs"),
fuse.Subtype("ghafs"),
fuse.LocalVolume(),
fuse.VolumeName(fmt.Sprintf("GitHub Release Assets Filesystem for %s/%s", args.Owner, args.Repo)),
fuse.ReadOnly(),
}
if args.AllowOther {
mountOptions = append(mountOptions, fuse.AllowOther())
}
// FUSE Set-up
c, err := fuse.Mount(
args.Mountpoint,
mountOptions...,
)
if err != nil {
log.Fatal(err)
}
defer c.Close()
// Prepare to pass around the token via reference
err = fs.Serve(c, newGhaFS(mgmt, &args.AccessToken))
if err != nil {
log.Fatal(err)
}
// check if the mount process has an error to report
<-c.Ready
if err := c.MountError; err != nil {
log.Fatal(err)
}
}