Skip to content

Commit

Permalink
feat: update pocketbase to 0.23 (#13)
Browse files Browse the repository at this point in the history
* feat: update pocketbase Go to 0.23

* try to update pb_hooks to pocketbase 0.23

* feat: remove migrations and start from the pb_schema export file

* feat: add starters schema

* chore: update pocketbase sdk

* feat: add lint checks to PRs and local toolchain (#16)

* feat: add lint checks to PR and tool for local

* fix: add the package comment on package main

* feat: add format tools (#17)

* refactor: create cmd, add temportal dep and proc (#18)

* refactor: create cmd, add temportal dep and proc

* doc: the package doc and fix the email public path

* fix: remove duplicate docker compose file

* chore: add vuln check on go packages

* fix: codegen

* fix: type issues

* refactor: remove useless import()

* feat: fix lint and add vulncheck to linting

* fix: remove double checks on pr and push

---------

Co-authored-by: Puria Nafisi Azizi <puria@dyne.org>
Co-authored-by: Giovanni Abbatepaolo <30571828+bbtgnn@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent 701a407 commit d483b1f
Show file tree
Hide file tree
Showing 141 changed files with 3,101 additions and 5,940 deletions.
1 change: 0 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: 🐹 lint

on:
pull_request:
push:
paths:
- '**.go'
- 'go.mod'
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ test: ## 🧪 run tests with coverage
$(GOTEST) $(SUBDIRS) -v -cover

lint: tools ## 📑 lint rules checks
$(REVIVE) -formatter stylish github.com/$(ORGANIZATION)/$(PROJECT_NAME) pocketbase/...
$(REVIVE) -formatter stylish cmd
$(GOVULNCHECK) $(SUBDIRS)

fmt: tools ## 🗿 format rules checks
$(GOFUMPT) -l -w pocketbase *.go
Expand Down
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pocketbase: air
ui: ./scripts/wait-for-it.sh localhost:8090 && cd webapp && bun i && bun dev
ui: ./scripts/wait-for-it.sh -t 0 localhost:8090 && cd webapp && bun i && bun dev
docs: cd docs && bun i && bun run docs:dev
temporal: temporal server start-dev --db-filename pb_data/temporal.db
131 changes: 62 additions & 69 deletions cmd/didimo/didimo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import (
"github.com/forkbombeu/didimo/pocketbase/webauthn"
"github.com/forkbombeu/didimo/pocketbase/zencode"

"github.com/labstack/echo/v5"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/plugins/jsvm"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
)
Expand All @@ -37,77 +35,72 @@ func main() {
" \033[48;2;0;0;139m\033[38;2;255;255;255m :(){ :|:& };: \033[0m\n" + // Forkbomb with padding
" \033[48;2;0;0;139m\033[38;2;255;255;255m by The Forkbomb Company \033[0m\n" // Company name aligned to right

app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: "localhost:5100"})
e.Router.Any("/*", echo.WrapHandler(proxy))
e.Router.Any("/", echo.WrapHandler(proxy))

e.Router.AddRoute(echo.Route{
Method: http.MethodPost,
Path: "/api/keypairoom-server",
Handler: func(c echo.Context) error {
var body map[string]map[string]interface{}

conf, err := feature.FetchKeypairoomConfig(app)
if err != nil {
return err
}

err = json.NewDecoder(c.Request().Body).Decode(&body)
if err != nil {
return err
}
hmac, err := zencode.KeypairoomServer(conf, body["userData"])
if err != nil {
return err
}

return c.JSON(http.StatusOK, map[string]string{"hmac": hmac})
},
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
},
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
proxy := httputil.NewSingleHostReverseProxy(&url.URL{
Scheme: "http",
Host: "localhost:5100",
})
se.Router.Any("/*", func(req *core.RequestEvent) error {
proxy.ServeHTTP(req.Response, req.Request)
return nil
})
se.Router.Any("/", func(req *core.RequestEvent) error {
proxy.ServeHTTP(req.Response, req.Request)
return nil
})

se.Router.POST("/api/keypairoom-server", func(e *core.RequestEvent) error {
var body map[string]map[string]interface{}

conf, err := feature.FetchKeypairoomConfig(app)
if err != nil {
return err
}

err = json.NewDecoder(e.Request.Body).Decode(&body)
if err != nil {
return err
}
hmac, err := zencode.KeypairoomServer(conf, body["userData"])
if err != nil {
return err
}

return e.JSON(http.StatusOK, map[string]string{"hmac": hmac})
})

e.Router.AddRoute(echo.Route{
Method: http.MethodGet,
Path: "/api/did",
Handler: func(c echo.Context) error {
authRecord, _ := c.Get(apis.ContextAuthRecordKey).(*models.Record)
if authRecord == nil {
return apis.NewForbiddenError("Only auth records can access this endpoint", nil)
}

publicKeys, err := app.Dao().FindFirstRecordByFilter("users_public_keys", "owner = {:owner_id}", dbx.Params{"owner_id": authRecord.Id})
if err != nil {
return apis.NewForbiddenError("Only users with public keys can access this endpoint", nil)
}

conf, err := feature.FetchDidConfig(app)
if err != nil {
return err
}

did, err := did.ClaimDid(conf, &did.DidAgent{
BitcoinPublicKey: publicKeys.Get("bitcoin_public_key").(string),
EcdhPublicKey: publicKeys.Get("ecdh_public_key").(string),
EddsaPublicKey: publicKeys.Get("eddsa_public_key").(string),
EthereumAddress: publicKeys.Get("ethereum_address").(string),
ReflowPublicKey: publicKeys.Get("reflow_public_key").(string),
Es256PublicKey: publicKeys.Get("es256_public_key").(string),
})
if err != nil {
return err
}

return c.JSON(http.StatusOK, did)
},
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
},
se.Router.GET("/api/did", func(e *core.RequestEvent) error {
authRecord := e.Auth
if authRecord == nil {
return apis.NewForbiddenError("Only auth records can access this endpoint", nil)
}

publicKeys, err := app.FindFirstRecordByFilter("users_public_keys", "owner = {:owner_id}", dbx.Params{"owner_id": authRecord.Id})
if err != nil {
return apis.NewForbiddenError("Only users with public keys can access this endpoint", nil)
}

conf, err := feature.FetchDidConfig(app)
if err != nil {
return err
}

did, err := did.ClaimDid(conf, &did.DidAgent{
BitcoinPublicKey: publicKeys.Get("bitcoin_public_key").(string),
EcdhPublicKey: publicKeys.Get("ecdh_public_key").(string),
EddsaPublicKey: publicKeys.Get("eddsa_public_key").(string),
EthereumAddress: publicKeys.Get("ethereum_address").(string),
ReflowPublicKey: publicKeys.Get("reflow_public_key").(string),
Es256PublicKey: publicKeys.Get("es256_public_key").(string),
})
if err != nil {
return err
}

return e.JSON(http.StatusOK, did)
})

return nil
return se.Next()
})

webauthn.Register(app)
Expand Down
124 changes: 98 additions & 26 deletions docs/public/API/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ info:
url: https://forkbomb.solutions

servers:
- url: https://s.api.didimo.forkbomb.eu/v1
description: Staging server
- url: http://localhost:8090/
description: Localhost server
- url: https://t.api.didimo.forkbomb.eu/v1
description: Test server
- url: https://s.api.didimo.forkbomb.eu/v1
description: Staging server

paths:
/auth/register:
/api/collections/users/records:
post:
summary: Register a new user
description: >
Expand All @@ -37,32 +39,95 @@ paths:
schema:
$ref: '#/components/schemas/RegisterRequest'
responses:
'201':
description: User registered successfully.
'200':
description: Successfully created the record
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessResponse'
type: object
properties:
id:
type: string
description: Unique identifier for the user record
collectionId:
type: string
description: Identifier of the user collection
collectionName:
type: string
description: Name of the user collection
username:
type: string
description: Username of the registered user
verified:
type: boolean
description: Whether the user is verified
emailVisibility:
type: boolean
description: Whether the user's email is visible
email:
type: string
format: email
description: Email of the registered user
created:
type: string
format: date-time
description: Timestamp when the user was created
updated:
type: string
format: date-time
description: Timestamp when the user was last updated
name:
type: string
description: Name of the user
avatar:
type: string
description: Avatar filename for the user
'400':
description: Invalid registration data.
description: Bad request - validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'409':
description: User already exists.
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal server error during registration.
type: object
properties:
code:
type: integer
example: 400
message:
type: string
description: Error message
example: "Failed to create record."
data:
type: object
additionalProperties:
type: object
properties:
code:
type: string
description: Validation error code
example: "validation_required"
message:
type: string
description: Validation error message
example: "Missing required value."
'403':
description: Forbidden - access denied
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'

/auth/login:
type: object
properties:
code:
type: integer
example: 403
message:
type: string
description: Error message
example: "You are not allowed to perform this request."
data:
type: object
description: Additional data (if any)
additionalProperties: false
/api/collections/users/auth-with-password:
post:
summary: Log in user
description: >
Expand Down Expand Up @@ -947,34 +1012,41 @@ components:
RegisterRequest:
type: object
properties:
username:
name:
type: string
description: The username of the user to register.
description: The name of the user to register.
password:
type: string
format: password
description: The password for the user.
passwordConfirm:
type: string
format: password
description: The password confirmation for the user.
email:
type: string
format: email
description: The email address of the user.
emailVisibility:
type: boolean
description: Whether to show/hide the auth record email when fetching the record data.
required:
- username
- name
- password
- email
- passwordConfirm

LoginRequest:
type: object
properties:
username:
identiry:
type: string
description: The username of the user.
description: The username or the email of the user.
password:
type: string
format: password
description: The password for the user.
required:
- username
- identity
- password

LoginResponse:
Expand Down
Loading

0 comments on commit d483b1f

Please sign in to comment.