This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
77 lines (59 loc) · 2.04 KB
/
main.go
File metadata and controls
77 lines (59 loc) · 2.04 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
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
package main
import (
"database/sql"
"log"
"os"
"path/filepath"
_ "github.com/mattn/go-sqlite3"
"gofr.dev/pkg/gofr"
"gofr.dev/pkg/gofr/service"
applicationHandler "zop.dev/cli/zop/application/handler"
applicationSvc "zop.dev/cli/zop/application/service"
impHandler "zop.dev/cli/zop/cloud/handler"
impService "zop.dev/cli/zop/cloud/service/gcp"
listSvc "zop.dev/cli/zop/cloud/service/list"
impStore "zop.dev/cli/zop/cloud/store/gcp"
depHandler "zop.dev/cli/zop/deploymentspace/handler"
depSvc "zop.dev/cli/zop/deploymentspace/service"
envHandler "zop.dev/cli/zop/environment/handler"
envService "zop.dev/cli/zop/environment/service"
)
const (
//nolint:gosec //This is a tokenURL for google oauth2
tokenURL = "https://oauth2.googleapis.com"
)
func main() {
app := gofr.NewCMD()
app.AddHTTPService(impService.ZopAPIService, app.Config.Get("ZOP_API_URL"))
app.AddHTTPService(impService.GcloudService, tokenURL,
&service.DefaultHeaders{Headers: map[string]string{"Content-Type": "application/x-www-form-urlencoded"}})
homeDir, err := os.UserHomeDir()
if err != nil {
app.Logger().Fatalf("Failed to get the user's home directory: %v", err)
}
// Build the path to the credentials.db file of gcloud
dbPath := filepath.Join(homeDir, ".config", "gcloud", "credentials.db")
db, err := sql.Open("sqlite3", dbPath)
if err != nil {
log.Fatalf("Failed to open the database: %v", err)
}
defer db.Close()
accStore := impStore.New(db)
accSvc := impService.New(accStore)
lSvc := listSvc.New()
h := impHandler.New(accSvc, lSvc)
app.SubCommand("cloud import", h.Import)
app.SubCommand("cloud list", h.List)
appSvc := applicationSvc.New()
appH := applicationHandler.New(appSvc)
app.SubCommand("application add", appH.Add)
app.SubCommand("application list", appH.List)
envSvc := envService.New(appSvc)
envH := envHandler.New(envSvc)
app.SubCommand("environment add", envH.Add)
app.SubCommand("environment list", envH.List)
dSvc := depSvc.New(lSvc, envSvc)
dH := depHandler.New(dSvc)
app.SubCommand("deployment add", dH.Add)
app.Run()
}