-
Notifications
You must be signed in to change notification settings - Fork 11
/
fakecas.go
68 lines (55 loc) · 1.89 KB
/
fakecas.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
package main
import (
"database/sql"
"flag"
"fmt"
"html/template"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
_ "github.com/lib/pq"
)
var Version string
var (
Host = flag.String("host", "192.168.168.167:8080", "The host to bind to")
OSFHost = flag.String("osfhost", "localhost:5000", "The osf host to bind to")
DatabaseName = flag.String("dbname", "osf", "The name of your OSF database")
DatabaseAddress = flag.String("dbaddress", "postgres://postgres@localhost:5432/osf?sslmode=disable", "The address of your postgres instance. ie: postgres://user:pass@127.0.0.1/dbname?other=args")
DatabaseConnection *sql.DB
)
func main() {
fmt.Printf("Starting FakeCAS %s\n", Version)
flag.Parse()
e := echo.New()
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: "${time_rfc3339} ${method} ${uri} ${status} ${response_time} ${response_size}\n",
Output: os.Stdout,
}))
e.Use(middleware.Recover())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowCredentials: true,
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "PUT", "POST", "DELETE"},
AllowHeaders: []string{"Range", "Content-Type", "Authorization", "X-Requested-With"},
ExposeHeaders: []string{"Range", "Content-Type", "Authorization", "X-Requested-With"},
}))
t, err := template.New("login").Parse(LOGINPAGE)
if err != nil {
panic(err)
}
temp := &Template{templates: t}
e.Renderer = temp
e.GET("/login", LoginGET)
e.POST("/login", LoginPOST)
e.GET("/logout", Logout)
e.GET("/oauth2/profile", OAuth)
e.POST("/oauth2/revoke", OAuthRevoke)
e.GET("/p3/serviceValidate", ServiceValidate)
fmt.Println("Expecting database", *DatabaseName, "to be running at", *DatabaseAddress)
DatabaseConnection, err = sql.Open("postgres", *DatabaseAddress)
if err != nil {
panic(err)
}
defer DatabaseConnection.Close()
e.Start(*Host)
}