Skip to content

Commit

Permalink
chore: Sync & bump Buf Connect RPC packages & implementation
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Oct 13, 2024
1 parent 7b5b7a8 commit 5a2ee4f
Show file tree
Hide file tree
Showing 28 changed files with 422 additions and 452 deletions.
12 changes: 7 additions & 5 deletions auth/jwt_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import (
"net/http"
"time"

"github.com/containerish/OpenRegistry/store/v1/types"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
echo_jwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"

"github.com/containerish/OpenRegistry/store/v1/types"
)

const (
AccessCookieKey = "access_token"
RefreshCookKey = "refresh_token"
Service = "service"
QueryToken = "token"
AccessCookieKey = "access_token"
SessionCookieKey = "session_id"
RefreshCookKey = "refresh_token"
Service = "service"
QueryToken = "token"
)

// JWT basically uses the default JWT middleware by echo, but has a slightly different skipper func
Expand Down
10 changes: 6 additions & 4 deletions auth/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"net/http"
"time"

"github.com/containerish/OpenRegistry/store/v1/types"
"github.com/google/uuid"
"github.com/jackc/pgx/v4"
"github.com/labstack/echo/v4"

"github.com/containerish/OpenRegistry/store/v1/types"
)

func (a *auth) SignIn(ctx echo.Context) error {
Expand Down Expand Up @@ -170,16 +171,17 @@ func (a *auth) SignIn(ctx echo.Context) error {
}

sessionId := fmt.Sprintf("%s:%s", id, userFromDb.ID)
sessionCookie := a.createCookie(ctx, "session_id", sessionId, false, time.Now().Add(time.Hour*750))
sessionCookie := a.createCookie(ctx, SessionCookieKey, sessionId, false, time.Now().Add(time.Hour*750))
accessCookie := a.createCookie(ctx, AccessCookieKey, access, true, time.Now().Add(time.Hour*750))
refreshCookie := a.createCookie(ctx, RefreshCookKey, refresh, true, time.Now().Add(time.Hour*750))

ctx.SetCookie(accessCookie)
ctx.SetCookie(refreshCookie)
ctx.SetCookie(sessionCookie)
err = ctx.JSON(http.StatusOK, echo.Map{
"token": access,
"refresh": refresh,
SessionCookieKey: sessionId,
AccessCookieKey: access,
RefreshCookKey: refresh,
})
a.logger.Log(ctx, err).Send()
return err
Expand Down
7 changes: 4 additions & 3 deletions auth/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"strings"
"time"

"github.com/google/uuid"
"github.com/labstack/echo/v4"

"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/services/email"
store_err "github.com/containerish/OpenRegistry/store/v1"
"github.com/containerish/OpenRegistry/store/v1/types"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
)

func (a *auth) parseSignUpRequest(ctx echo.Context) (*types.User, error) {
Expand Down Expand Up @@ -95,7 +96,7 @@ func (a *auth) SignUp(ctx echo.Context) error {
if strings.Contains(err.Error(), store_err.ErrDuplicateConstraintEmail) {
echoErr := ctx.JSON(http.StatusInternalServerError, echo.Map{
"error": err.Error(),
"message": "this email already taken, try sign in?",
"message": "this email is already taken, try sign in?",
})
a.logger.Log(ctx, err).Send()
return echoErr
Expand Down
17 changes: 7 additions & 10 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
version: v1
version: v2
managed:
enabled: true
plugins:
- plugin: buf.build/protocolbuffers/go
- remote: buf.build/protocolbuffers/go
out: .
opt:
- paths=source_relative
- plugin: buf.build/bufbuild/validate-go
opt: paths=source_relative
- remote: buf.build/bufbuild/validate-go
out: .
opt:
- paths=source_relative
- plugin: buf.build/bufbuild/connect-go
opt: paths=source_relative
- remote: buf.build/connectrpc/go
out: .
opt:
- paths=source_relative
opt: paths=source_relative
9 changes: 9 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/envoyproxy/protoc-gen-validate
commit: 6607b10f00ed4a3d98f906807131c44a
digest: b5:ade405ac4328bd0a2cf83c93bcb4bc389d4897afd86a0096df4537b180916882da4e4f0c2d45f0b1554d7a6c87f6c5bc94b71b3555ca71cc31a9a8baed26a9f9
- name: buf.build/googleapis/googleapis
commit: 5ae7f88519b04fe1965da0f8a375a088
digest: b5:ac717f02b210c53aeaa5d8801b118cae7a1883dab531034859889622dcb389979ee731ab42192c16c3cdb39b40f2dda72a8c1ebeefa3bcdf95f9e5739dc30cca
3 changes: 0 additions & 3 deletions buf.work.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v2
modules:
- path: protos
name: buf.build/containerish/openregistry
deps:
- buf.build/envoyproxy/protoc-gen-validate
- buf.build/googleapis/googleapis
lint:
use:
- STANDARD
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
toolchain go1.23.0

require (
connectrpc.com/connect v1.17.0
github.com/alexliesenfeld/health v0.8.0
github.com/alphadose/haxmap v1.4.0
github.com/aws/aws-sdk-go-v2 v1.32.2
Expand All @@ -14,7 +15,6 @@ require (
github.com/aws/smithy-go v1.22.0
github.com/axiomhq/axiom-go v0.21.1
github.com/bradleyfalzon/ghinstallation/v2 v2.11.0
github.com/bufbuild/connect-go v1.10.0
github.com/fatih/color v1.17.0
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2k
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk=
connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 h1:cTp8I5+VIoKjsnZuH8vjyaysT/ses3EvZeaV/1UkF2M=
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
Expand Down Expand Up @@ -79,8 +81,6 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bradleyfalzon/ghinstallation/v2 v2.11.0 h1:R9d0v+iobRHSaE4wKUnXFiZp53AL4ED5MzgEMwGTZag=
github.com/bradleyfalzon/ghinstallation/v2 v2.11.0/go.mod h1:0LWKQwOHewXO/1acI6TtyE0Xc4ObDb2rFN7eHBAG71M=
github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg=
github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
github.com/calebcase/tmpfile v1.0.3 h1:BZrOWZ79gJqQ3XbAQlihYZf/YCV0H4KPIdM5K5oMpJo=
github.com/calebcase/tmpfile v1.0.3/go.mod h1:UAUc01aHeC+pudPagY/lWvt2qS9ZO5Zzof6/tIUzqeI=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
Expand Down
11 changes: 0 additions & 11 deletions protos/buf.lock

This file was deleted.

11 changes: 0 additions & 11 deletions protos/buf.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions router/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func RegisterGitHubRoutes(
)
go func() {
addr := net.JoinHostPort(cfg.Host, fmt.Sprintf("%d", cfg.Port))
color.Green("connect-go GitHub Automation gRPC service running on: %s", addr)
color.Green("connectrpc GitHub Automation gRPC service running on: %s", addr)
ghCors := cors.New(cors.Options{
AllowedOrigins: allowedOrigins,
AllowOriginFunc: func(origin string) bool {
Expand All @@ -79,7 +79,7 @@ func RegisterGitHubRoutes(
})
handler := ghCors.Handler(h2c.NewHandler(githubMux, &http2.Server{}))
if err := http.ListenAndServe(addr, handler); err != nil {
color.Red("connect-go GitHub Automation service listen error: %s", err)
color.Red("connectrpc GitHub Automation service listen error: %s", err)
}
}()
}
Expand Down
4 changes: 2 additions & 2 deletions router/vuln_scanning_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func RegisterVulnScaningRoutes(
})

handler := h2c.NewHandler(vulnScanningCors.Handler(clairApi), &http2.Server{})
color.Green("connect-go Clair gRPC service running on: %s", addr)
color.Green("connectrpc Clair gRPC service running on: %s", addr)
if err := http.ListenAndServe(addr, handler); err != nil {
color.Red("connect-go listen error: %s", err)
color.Red("connectrpc listen error: %s", err)
}
}()
}
Expand Down
Loading

0 comments on commit 5a2ee4f

Please sign in to comment.