Skip to content

Commit 3f17b28

Browse files
committed
I totally forgot about git 😭
1 parent e850756 commit 3f17b28

40 files changed

Lines changed: 6000 additions & 65 deletions

go.mod

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,59 @@ module makedotcsh
33
go 1.26.4
44

55
require (
6+
github.com/computersciencehouse/csh-auth/v2 v2.0.1
67
github.com/gin-contrib/cors v1.7.7
78
github.com/gin-contrib/gzip v1.2.6
89
github.com/gin-contrib/logger v1.2.7
910
github.com/gin-gonic/gin v1.12.0
1011
github.com/golang-migrate/migrate/v4 v4.19.1
12+
github.com/joho/godotenv v1.5.1
1113
github.com/mattn/go-sqlite3 v1.14.45
1214
)
1315

1416
require (
15-
github.com/bytedance/gopkg v0.1.3 // indirect
16-
github.com/bytedance/sonic v1.15.0 // indirect
17-
github.com/bytedance/sonic/loader v0.5.0 // indirect
18-
github.com/cloudwego/base64x v0.1.6 // indirect
19-
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
20-
github.com/gin-contrib/sse v1.1.0 // indirect
17+
github.com/bytedance/gopkg v0.1.4 // indirect
18+
github.com/bytedance/sonic v1.15.1 // indirect
19+
github.com/bytedance/sonic/loader v0.5.1 // indirect
20+
github.com/cloudwego/base64x v0.1.7 // indirect
21+
github.com/coreos/go-oidc/v3 v3.18.0 // indirect
22+
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
23+
github.com/gin-contrib/sse v1.1.1 // indirect
24+
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
2125
github.com/go-playground/locales v0.14.1 // indirect
2226
github.com/go-playground/universal-translator v0.18.1 // indirect
23-
github.com/go-playground/validator/v10 v10.30.1 // indirect
24-
github.com/goccy/go-json v0.10.5 // indirect
27+
github.com/go-playground/validator/v10 v10.30.2 // indirect
28+
github.com/goccy/go-json v0.10.6 // indirect
2529
github.com/goccy/go-yaml v1.19.2 // indirect
30+
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
2631
github.com/google/uuid v1.6.0 // indirect
2732
github.com/json-iterator/go v1.1.12 // indirect
2833
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
2934
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
3035
github.com/leodido/go-urn v1.4.0 // indirect
3136
github.com/mattn/go-colorable v0.1.14 // indirect
32-
github.com/mattn/go-isatty v0.0.20 // indirect
37+
github.com/mattn/go-isatty v0.0.22 // indirect
3338
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3439
github.com/modern-go/reflect2 v1.0.2 // indirect
35-
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
40+
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
3641
github.com/quic-go/qpack v0.6.0 // indirect
3742
github.com/quic-go/quic-go v0.59.0 // indirect
3843
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
3944
github.com/rs/zerolog v1.34.0 // indirect
45+
github.com/sirupsen/logrus v1.9.4 // indirect
4046
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4147
github.com/ugorji/go/codec v1.3.1 // indirect
42-
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
43-
golang.org/x/arch v0.23.0 // indirect
44-
golang.org/x/crypto v0.48.0 // indirect
45-
golang.org/x/mod v0.33.0 // indirect
46-
golang.org/x/net v0.51.0 // indirect
48+
go.mongodb.org/mongo-driver/v2 v2.6.0 // indirect
49+
golang.org/x/arch v0.27.0 // indirect
50+
golang.org/x/crypto v0.51.0 // indirect
51+
golang.org/x/mod v0.35.0 // indirect
52+
golang.org/x/net v0.54.0 // indirect
53+
golang.org/x/oauth2 v0.36.0 // indirect
4754
golang.org/x/sync v0.20.0 // indirect
48-
golang.org/x/sys v0.41.0 // indirect
49-
golang.org/x/text v0.35.0 // indirect
50-
golang.org/x/tools v0.42.0 // indirect
51-
google.golang.org/protobuf v1.36.10 // indirect
55+
golang.org/x/sys v0.44.0 // indirect
56+
golang.org/x/text v0.37.0 // indirect
57+
golang.org/x/tools v0.44.0 // indirect
58+
google.golang.org/protobuf v1.36.11 // indirect
5259
lukechampine.com/uint128 v1.2.0 // indirect
5360
modernc.org/cc/v3 v3.36.3 // indirect
5461
modernc.org/ccgo/v3 v3.16.9 // indirect

go.sum

Lines changed: 52 additions & 38 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import (
55
"log"
66
"makedotcsh/database"
77
"makedotcsh/routes"
8+
"os"
89

10+
cshauth "github.com/computersciencehouse/csh-auth/v2"
911
"github.com/gin-contrib/cors"
1012
"github.com/gin-contrib/gzip"
1113
"github.com/gin-contrib/logger"
1214
"github.com/gin-gonic/gin"
15+
"github.com/joho/godotenv"
1316
)
1417

1518
func errorHandler(c *gin.Context) {
@@ -23,26 +26,60 @@ func errorHandler(c *gin.Context) {
2326
}
2427
}
2528

26-
func notFoundHandler(context *gin.Context) {
27-
context.JSON(404, gin.H{
28-
"status": "error",
29-
"message": fmt.Sprintf("path %s was not found", context.Request.URL.Path),
30-
})
29+
func serveIndex(c *gin.Context) {
30+
c.File("./web/dist/index.html")
3131
}
3232

3333
func main() {
34+
godotenv.Load()
3435
router := gin.New()
3536

37+
host := os.Getenv("MAKE_HOST")
38+
39+
fmt.Println(os.Getenv("MAKE_OIDC_ID"))
40+
3641
// init db
3742
database.Init()
3843

44+
// init auth
45+
auth, err := cshauth.Init(
46+
os.Getenv("MAKE_OIDC_ID"),
47+
os.Getenv("MAKE_OIDC_SECRET"),
48+
host,
49+
host+"/auth/login",
50+
host+"/auth/callback",
51+
[]string{"profile", "email", "groups"},
52+
)
53+
54+
if err != nil {
55+
log.Panicf("Error initializing CSH auth %v", err)
56+
}
57+
3958
router.Use(gzip.Gzip(gzip.DefaultCompression))
4059
router.Use(cors.Default())
4160
router.Use(logger.SetLogger())
4261
router.Use(errorHandler)
43-
router.NoRoute(notFoundHandler)
4462

45-
routes.SetRoutes(router)
63+
// auth
64+
router.GET("/auth/login", auth.HandleLogin) // This endpoint should match the path for loginURL
65+
router.GET("/auth/callback", auth.HandleCallback) // This endpoint should match the path for callbackURL
66+
router.GET("/auth/logout", auth.HandleLogout)
67+
68+
// api
69+
routes.SetRoutes(router, auth)
70+
71+
// frontend
72+
frontend := router.Group("/")
73+
frontend.Use(auth.CookieMiddleware())
74+
75+
if os.Getenv("DEV") == "true" {
76+
router.NoRoute(createViteProxy())
77+
} else {
78+
frontend.Static("/assets", "./web/dist/assets")
79+
frontend.GET("/", serveIndex)
80+
frontend.GET("/:path", serveIndex)
81+
frontend.GET("/:path/*rest", serveIndex)
82+
}
4683

4784
log.Println("running")
4885
router.Run()

routes/api/me/me.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package me
2+
3+
import (
4+
"errors"
5+
6+
csh_auth "github.com/computersciencehouse/csh-auth/v2"
7+
"github.com/gin-gonic/gin"
8+
)
9+
10+
func test(c *gin.Context) {
11+
authAny, exists := c.Get("cshauth")
12+
if !exists {
13+
err := errors.New("cshauth does not exist in context")
14+
c.Error(err)
15+
return
16+
}
17+
18+
auth, ok := authAny.(*csh_auth.Claims)
19+
if !ok {
20+
err := errors.New("authentication data in gin context does not match structure")
21+
c.Error(err)
22+
return
23+
}
24+
25+
user := csh_auth.UserInfo{
26+
Uuid: auth.Uuid,
27+
Email: auth.Email,
28+
Username: auth.Username,
29+
FullName: auth.FullName,
30+
Groups: auth.Groups,
31+
}
32+
33+
c.JSON(200, user)
34+
}
35+
36+
func Routes(route *gin.RouterGroup) {
37+
me := route.Group("/me")
38+
me.GET("/", test)
39+
}

routes/routes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package routes
22

33
import (
44
"makedotcsh/routes/api/areas"
5+
"makedotcsh/routes/api/me"
56

7+
csh_auth "github.com/computersciencehouse/csh-auth/v2"
68
"github.com/gin-gonic/gin"
79
)
810

9-
func SetRoutes(router *gin.Engine) {
11+
func SetRoutes(router *gin.Engine, auth csh_auth.Auth) {
1012
api := router.Group("/api")
13+
api.Use(auth.CookieMiddleware())
1114
areas.Routes(api)
15+
me.Routes(api)
1216
}

tmp/build-errors.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

tmp/main

39.4 MB
Binary file not shown.

util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"net/http/httputil"
5+
"net/url"
6+
7+
"github.com/gin-gonic/gin"
8+
)
9+
10+
func createViteProxy() gin.HandlerFunc {
11+
viteURL, _ := url.Parse("http://localhost:5173")
12+
proxy := httputil.NewSingleHostReverseProxy(viteURL)
13+
14+
return func(c *gin.Context) {
15+
proxy.ServeHTTP(c.Writer, c.Request)
16+
}
17+
}

web/.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue,css,scss,sass,less,styl}]
2+
charset = utf-8
3+
indent_size = 2
4+
indent_style = space
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
end_of_line = lf
8+
max_line_length = 100

web/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

0 commit comments

Comments
 (0)