-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproton.go
96 lines (88 loc) · 2.05 KB
/
proton.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
93
94
95
96
package main
import "fmt"
import "encoding/json"
import "os"
import "github.com/codegangsta/cli"
import "io/ioutil"
import "log"
type ObjectStore interface {
Auth() string
ListBuckets() string
CreateBucket(bucketName string) string
DeleteBucket(bucketName string) string
Put(src string, dst string) string
Get() string
Del() string
}
type ObjectStoreService struct {
ObjectStore string
AuthInfo json.RawMessage
}
func main() {
objstore := loadConfig()
objstore.Auth()
app := cli.NewApp()
app.Name = "proton"
app.Usage = "Object Storage Abstractor"
app.Action = func(c *cli.Context) {
println("Hello friend!")
}
app.Commands = []cli.Command{
{
Name: "list",
ShortName: "l",
Usage: "list all avaiable buckets/container",
Action: func(c *cli.Context) {
objstore.ListBuckets()
},
},
{
Name: "delete",
ShortName: "d",
Usage: "delete a bucket/container",
Action: func(c *cli.Context) {
objstore.DeleteBucket(c.Args().First())
},
},
{
Name: "create",
ShortName: "c",
Usage: "create a bucket/container",
Action: func(c *cli.Context) {
objstore.CreateBucket(c.Args().First())
},
},
}
app.Run(os.Args)
}
func loadConfig() ObjectStore {
var oss ObjectStoreService
var filename = ""
if os.Getenv("PROTON_CONFIG") != "" {
filename = os.Getenv("PROTON_CONFIG")
} else if _, err := os.Stat("/etc/proton/proton.cfg"); !os.IsNotExist(err) {
filename = "/etc/proton/proton.cfg"
} else if _, err := os.Stat("~/.proton/proton.cfg"); !os.IsNotExist(err) {
filename = "~/.proton/proton.cfg"
} else if _, err := os.Stat("proton.cfg"); !os.IsNotExist(err) {
filename = "proton.cfg"
} else {
log.Fatal("Config file not found")
}
file, _ := ioutil.ReadFile(filename)
err := json.Unmarshal(file, &oss)
var objstore ObjectStore
switch oss.ObjectStore {
case "s3":
objstore = new(AWS_S3)
case "swift":
objstore = new(OS_Swift)
case "local":
objstore = new(Local)
}
if err != nil {
fmt.Println("error:", err)
}
json.Unmarshal(oss.AuthInfo, objstore)
return objstore
}