-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
126 lines (103 loc) · 2.68 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"flag"
"github.com/gin-gonic/gin"
csh_auth "github.com/liam-middlebrook/csh-auth"
log "github.com/sirupsen/logrus"
"os"
)
type PlugApplication struct {
// Internal
// --------
// Service Connections
db DBConnection
ldap LDAPConnection
s3 S3Connection
router *gin.Engine
auth csh_auth.CSHAuth
// Service Connection Credentials
base_path string
auth_login_route string
}
func (a *PlugApplication) Init(
db_uri,
s3_host,
s3_access_id,
s3_secret_key,
ldap_host,
ldap_bind_dn,
ldap_bind_pw,
base_path,
auth_client_id,
auth_client_secret,
auth_jwt_secret,
auth_state,
auth_server_host,
auth_redirect_uri,
auth_login_route string) {
// Database Connection
a.db.Init(a, db_uri)
// S3 Connection
a.s3.Init(s3_host,
s3_access_id,
s3_secret_key)
// LDAP connection
a.ldap.Init(a, ldap_host, ldap_bind_dn, ldap_bind_pw)
a.base_path = base_path
a.router = a.createGinEngine()
a.auth.Init(
auth_client_id,
auth_client_secret,
auth_jwt_secret,
auth_state,
auth_server_host,
auth_redirect_uri,
auth_login_route,
)
a.auth_login_route = auth_login_route
}
func (a PlugApplication) createGinEngine() *gin.Engine {
var r *gin.Engine
r = gin.Default()
// TODO we should probably look into a different templating solution that
// allows for inheritance so we can have a navigation and base page layout
// not be repeated.
r.LoadHTMLGlob(a.base_path + "templates/*")
r.Static("/static", a.base_path+"static")
return r
}
func main() {
flag.Parse()
var app PlugApplication
app.Init(
os.Getenv("DB_URI"),
os.Getenv("S3_HOST"),
os.Getenv("S3_ACCESS_ID"),
os.Getenv("S3_SECRET_KEY"),
os.Getenv("LDAP_HOST"),
os.Getenv("LDAP_BIND_DN"),
os.Getenv("LDAP_BIND_PW"),
os.Getenv("BASE_PATH"),
os.Getenv("csh_auth_client_id"),
os.Getenv("csh_auth_client_secret"),
os.Getenv("csh_auth_jwt_secret"),
os.Getenv("csh_auth_state"),
os.Getenv("csh_auth_server_host"),
os.Getenv("csh_auth_redirect_uri"),
"/auth/login",
)
log.Info("Starting server...")
var r PlugRoutes
r.app = &app
app.router.GET(app.auth_login_route, app.auth.AuthRequest)
app.router.GET("/auth/redir", app.auth.AuthCallback)
app.router.GET("/auth/logout", app.auth.AuthLogout)
app.router.GET("/", app.auth.AuthWrapper(r.index))
app.router.GET("/data", app.auth.AuthWrapper(r.action))
app.router.GET("/upload", app.auth.AuthWrapper(r.upload_view))
app.router.POST("/upload", app.auth.AuthWrapper(r.upload))
app.router.GET("/admin", app.auth.AuthWrapper(r.get_pending_plugs))
app.router.POST("/admin", app.auth.AuthWrapper(r.plug_approval))
app.router.POST("/admin/delete/:id", app.auth.AuthWrapper(r.plug_deletion))
app.router.Run()
}