Skip to content

Commit 300557e

Browse files
core: Use idp-go-sdk models
1 parent 4868ec8 commit 300557e

11 files changed

Lines changed: 37 additions & 79 deletions

File tree

services/core/cmd/local/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/fancyinnovations/fancyspaces/core/internal/app"
1717
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
1818
"github.com/fancyinnovations/fancyspaces/core/internal/fflags"
19+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1920
"github.com/justinas/alice"
2021
_ "github.com/mattn/go-sqlite3"
2122
)
@@ -41,13 +42,13 @@ func main() {
4142
mio := containers.ConnectToMinIOE2E()
4243

4344
// Setup default admin user
44-
auth.Users["oliver"] = &auth.User{
45+
auth.Users["oliver"] = &idp.User{
4546
ID: "oliver",
46-
Provider: auth.ProviderBasic,
47+
Provider: idp.ProviderBasic,
4748
Name: "Oliver",
4849
Email: "oliver@fancyinnovations.com",
4950
Verified: true,
50-
Password: auth.Hash("hello"),
51+
Password: idp.PasswordHash("hello"),
5152
Roles: []string{"admin", "user"},
5253
CreatedAt: time.Date(2025, 12, 3, 19, 0, 0, 0, time.UTC),
5354
IsActive: true,

services/core/cmd/prod/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/OliverSchlueter/goutils/sloki"
1717
"github.com/fancyinnovations/fancyspaces/core/internal/app"
1818
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
19+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1920
"github.com/justinas/alice"
2021
)
2122

@@ -133,7 +134,7 @@ func loadUsers() {
133134
return
134135
}
135136

136-
var users []auth.User
137+
var users []idp.User
137138
if err := json.Unmarshal(data, &users); err != nil {
138139
slog.Error("Could not parse users file", sloki.WrapError(err))
139140
os.Exit(1)

services/core/internal/auth/middleware.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package auth
22

33
import (
44
"context"
5-
"crypto/sha256"
6-
"fmt"
75
"net/http"
6+
7+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
88
)
99

1010
type contextKey string
1111

1212
const userContextKey contextKey = "user"
1313

14-
var Users = map[string]*User{}
14+
var Users = map[string]*idp.User{}
1515

1616
func Middleware(next http.Handler) http.Handler {
1717
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -39,7 +39,7 @@ func Middleware(next http.Handler) http.Handler {
3939
}
4040

4141
u, found := Users[username]
42-
if !found || u.Password != Hash(password) {
42+
if !found || u.Password != idp.PasswordHash(password) {
4343
next.ServeHTTP(w, r)
4444
return
4545
}
@@ -50,17 +50,10 @@ func Middleware(next http.Handler) http.Handler {
5050
})
5151
}
5252

53-
func UserFromContext(ctx context.Context) *User {
54-
user, ok := ctx.Value(userContextKey).(*User)
53+
func UserFromContext(ctx context.Context) *idp.User {
54+
user, ok := ctx.Value(userContextKey).(*idp.User)
5555
if !ok {
5656
return nil
5757
}
5858
return user
5959
}
60-
61-
func Hash(password string) string {
62-
h := sha256.New()
63-
h.Write([]byte(password))
64-
bs := h.Sum(nil)
65-
return fmt.Sprintf("%x", bs)
66-
}

services/core/internal/auth/model.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

services/core/internal/issues/handler/issues_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ import (
1010

1111
"github.com/OliverSchlueter/goutils/problems"
1212
"github.com/OliverSchlueter/goutils/sloki"
13-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
1413
"github.com/fancyinnovations/fancyspaces/core/internal/issues"
1514
"github.com/fancyinnovations/fancyspaces/core/internal/spaces"
15+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1616
)
1717

1818
type Handler struct {
1919
store *issues.Store
2020
spaces *spaces.Store
21-
userFromCtx func(ctx context.Context) *auth.User
21+
userFromCtx func(ctx context.Context) *idp.User
2222
}
2323

2424
type Configuration struct {
2525
Store *issues.Store
2626
Spaces *spaces.Store
27-
UserFromCtx func(ctx context.Context) *auth.User
27+
UserFromCtx func(ctx context.Context) *idp.User
2828
}
2929

3030
func New(cfg Configuration) *Handler {

services/core/internal/maven/handler/maven_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ import (
1414
"github.com/OliverSchlueter/goutils/ratelimit"
1515
"github.com/OliverSchlueter/goutils/sloki"
1616
"github.com/fancyinnovations/fancyspaces/core/internal/analytics"
17-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
1817
"github.com/fancyinnovations/fancyspaces/core/internal/maven"
1918
"github.com/fancyinnovations/fancyspaces/core/internal/spaces"
19+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
2020
)
2121

2222
type Handler struct {
2323
store *maven.Store
2424
spaces *spaces.Store
2525
analytics *analytics.Store
26-
userFromCtx func(ctx context.Context) *auth.User
26+
userFromCtx func(ctx context.Context) *idp.User
2727
downloadRatelimit *ratelimit.Service
2828
}
2929

3030
type Configuration struct {
3131
Store *maven.Store
3232
Spaces *spaces.Store
3333
Analytics *analytics.Store
34-
UserFromCtx func(ctx context.Context) *auth.User
34+
UserFromCtx func(ctx context.Context) *idp.User
3535
}
3636

3737
func New(cfg Configuration) *Handler {

services/core/internal/spaces/handler/spaces_handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import (
1010
"github.com/OliverSchlueter/goutils/problems"
1111
"github.com/OliverSchlueter/goutils/sloki"
1212
"github.com/fancyinnovations/fancyspaces/core/internal/analytics"
13-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
1413
"github.com/fancyinnovations/fancyspaces/core/internal/spaces"
14+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1515
)
1616

1717
type Handler struct {
1818
store *spaces.Store
1919
analytics *analytics.Store
20-
userFromCtx func(ctx context.Context) *auth.User
20+
userFromCtx func(ctx context.Context) *idp.User
2121
}
2222

2323
type Configuration struct {
2424
Store *spaces.Store
2525
Analytics *analytics.Store
26-
UserFromCtx func(ctx context.Context) *auth.User
26+
UserFromCtx func(ctx context.Context) *idp.User
2727
}
2828

2929
func New(cfg Configuration) *Handler {

services/core/internal/spaces/model.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package spaces
33
import (
44
"time"
55

6-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
6+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
77
)
88

99
type Space struct {
@@ -92,7 +92,7 @@ const (
9292
CategoryOther Category = "other"
9393
)
9494

95-
func (s *Space) IsMember(u *auth.User) bool {
95+
func (s *Space) IsMember(u *idp.User) bool {
9696
for _, m := range s.Members {
9797
if m.UserID == u.ID {
9898
return true
@@ -102,7 +102,7 @@ func (s *Space) IsMember(u *auth.User) bool {
102102
return false
103103
}
104104

105-
func (s *Space) IsOwner(u *auth.User) bool {
105+
func (s *Space) IsOwner(u *idp.User) bool {
106106
for _, m := range s.Members {
107107
if m.UserID == u.ID {
108108
return m.Role == RoleOwner
@@ -112,7 +112,7 @@ func (s *Space) IsOwner(u *auth.User) bool {
112112
return false
113113
}
114114

115-
func (s *Space) HasFullAccess(u *auth.User) bool {
115+
func (s *Space) HasFullAccess(u *idp.User) bool {
116116
for _, m := range s.Members {
117117
if m.UserID == u.ID {
118118
return m.Role == RoleOwner || m.Role == RoleAdmin
@@ -122,7 +122,7 @@ func (s *Space) HasFullAccess(u *auth.User) bool {
122122
return false
123123
}
124124

125-
func (s *Space) HasWriteAccess(u *auth.User) bool {
125+
func (s *Space) HasWriteAccess(u *idp.User) bool {
126126
for _, m := range s.Members {
127127
if m.UserID == u.ID {
128128
return m.Role == RoleOwner || m.Role == RoleAdmin || m.Role == RoleMember

services/core/internal/spaces/spaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"time"
77

88
"github.com/OliverSchlueter/goutils/idgen"
9-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
9+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1010
)
1111

1212
type DB interface {
@@ -61,7 +61,7 @@ func (s *Store) GetAll() ([]Space, error) {
6161
return s.db.GetAll()
6262
}
6363

64-
func (s *Store) Create(creator *auth.User, req *CreateOrUpdateSpaceReq) (*Space, error) {
64+
func (s *Store) Create(creator *idp.User, req *CreateOrUpdateSpaceReq) (*Space, error) {
6565
if !creator.IsActive {
6666
return nil, ErrUserNotActive
6767
}

services/core/internal/spaces/spaces_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/fancyinnovations/fancyspaces/core/internal/auth"
98
"github.com/fancyinnovations/fancyspaces/core/internal/spaces"
109
"github.com/fancyinnovations/fancyspaces/core/internal/spaces/database/fake"
10+
"github.com/fancyinnovations/fancyspaces/integrations/idp-go-sdk/idp"
1111
"github.com/google/go-cmp/cmp"
1212
"github.com/google/uuid"
1313
)
@@ -398,9 +398,9 @@ func TestStore_GetAll(t *testing.T) {
398398
func TestStore_Create(t *testing.T) {
399399
now := time.Now()
400400

401-
normalUser := auth.User{
401+
normalUser := idp.User{
402402
ID: "user-1",
403-
Provider: auth.ProviderBasic,
403+
Provider: idp.ProviderBasic,
404404
Name: "User",
405405
Email: "user@fancyspaces.net",
406406
Verified: true,
@@ -414,7 +414,7 @@ func TestStore_Create(t *testing.T) {
414414
for _, tc := range []struct {
415415
Name string
416416
Exiting []spaces.Space
417-
Creator *auth.User
417+
Creator *idp.User
418418
Req *spaces.CreateOrUpdateSpaceReq
419419
Exp *spaces.Space
420420
ExpErr error
@@ -448,7 +448,7 @@ func TestStore_Create(t *testing.T) {
448448
{
449449
Name: "User is not active",
450450
Exiting: []spaces.Space{},
451-
Creator: &auth.User{
451+
Creator: &idp.User{
452452
ID: "user-2",
453453
Verified: true,
454454
IsActive: false,
@@ -467,7 +467,7 @@ func TestStore_Create(t *testing.T) {
467467
{
468468
Name: "User is not verified",
469469
Exiting: []spaces.Space{},
470-
Creator: &auth.User{
470+
Creator: &idp.User{
471471
ID: "user-2",
472472
Verified: false,
473473
IsActive: true,

0 commit comments

Comments
 (0)