Skip to content
Open
18 changes: 0 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ require (

require (
cloud.google.com/go/recaptchaenterprise/v2 v2.13.0
github.com/gin-contrib/cors v1.6.0
github.com/gin-contrib/gzip v0.0.6
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/uuid v1.6.0
github.com/kevinburke/twilio-go v0.0.0-20220922200631-8f3f155dfe1f
Expand Down Expand Up @@ -54,18 +50,14 @@ require (
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/bytedance/sonic v1.11.2 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cloudflare/circl v1.6.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -80,7 +72,6 @@ require (
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
Expand All @@ -96,7 +87,6 @@ require (
github.com/redhat-cop/operator-utils v1.3.8 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
Expand All @@ -107,7 +97,6 @@ require (
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
golang.org/x/arch v0.7.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/api v0.177.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirect
Expand All @@ -126,14 +115,10 @@ require (
require (
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.7.0 // indirect
Expand All @@ -144,7 +129,6 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/go-types v0.0.0-20210723172823-2deba1f80ba7 // indirect
github.com/kevinburke/rest v0.0.0-20210506044642-5611499aa33c // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/jwx v1.2.29 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -153,11 +137,9 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
// using latest commit from 'github.com/openshift/api branch release-4.20'
github.com/openshift/api v0.0.0-20251202204302-1cb53e34ca33
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.46.0 // indirect
Expand Down
84 changes: 0 additions & 84 deletions go.sum

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions pkg/application/service/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package service
import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/registration-service/pkg/signup"
"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
)

type SignupService interface {
Signup(ctx *gin.Context) (*toolchainv1alpha1.UserSignup, error)
GetSignup(ctx *gin.Context, username string, checkUserSignupCompleted bool) (*signup.Signup, error)
Signup(ctx echo.Context) (*toolchainv1alpha1.UserSignup, error)
GetSignup(ctx echo.Context, username string, checkUserSignupCompleted bool) (*signup.Signup, error)
}

type VerificationService interface {
InitVerification(ctx *gin.Context, username, e164PhoneNumber, countryCode string) error
VerifyPhoneCode(ctx *gin.Context, username, code string) error
VerifyActivationCode(ctx *gin.Context, username, code string) error
InitVerification(ctx echo.Context, username, e164PhoneNumber, countryCode string) error
VerifyPhoneCode(ctx echo.Context, username, code string) error
VerifyActivationCode(ctx echo.Context, username, code string) error
}

type Services interface {
Expand Down
22 changes: 2 additions & 20 deletions pkg/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,11 @@ package assets
import (
"embed"
"io/fs"
"net/http"

"github.com/gin-contrib/static"
)

//go:embed static/*
var StaticContent embed.FS

func ServeEmbedContent() (static.ServeFileSystem, error) {
fsys, err := fs.Sub(StaticContent, "static") // matches the path in `go:embed` above
if err != nil {
return nil, err
}
return StaticContentFileSystem{
FileSystem: http.FS(fsys),
}, nil
}

type StaticContentFileSystem struct {
http.FileSystem
}

func (e StaticContentFileSystem) Exists(_ string, path string) bool {
_, err := e.Open(path)
return err == nil
func ServeEmbedContent() (fs.FS, error) {
return fs.Sub(StaticContent, "static")
}
28 changes: 28 additions & 0 deletions pkg/context/keys.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
package context

import (
gocontext "context"

"github.com/labstack/echo/v4"
)

// RequestContext extracts the standard context.Context from an Echo request
// for use with Kubernetes client calls. Falls back to context.TODO() when the

Check warning on line 10 in pkg/context/keys.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=codeready-toolchain_registration-service&issues=AZ36QgpiJq2l4d7xX26U&open=AZ36QgpiJq2l4d7xX26U&pullRequest=593
// Echo context or its underlying request is nil (e.g. in tests).
func RequestContext(ctx echo.Context) gocontext.Context {
if ctx != nil && ctx.Request() != nil {
return ctx.Request().Context()
}
return gocontext.TODO()
}

// GetString returns the string value associated with the given key in the echo context.
// Returns empty string if the key doesn't exist or the value is not a string.
func GetString(ctx echo.Context, key string) string {
if ctx == nil {
return ""
}
if val, ok := ctx.Get(key).(string); ok {
return val
}
return ""
}

const (
// UserIDKey is the context key for the user_id claim
UserIDKey = "user_id"
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
)

// Analytics implements the segment endpoint, which is invoked to
Expand All @@ -18,15 +18,15 @@ func NewAnalytics() *Analytics {
}

// GetSandboxSegmentWriteKey returns segment-write-key content for UI.
func (a *Analytics) GetSandboxSegmentWriteKey(ctx *gin.Context) {
func (a *Analytics) GetSandboxSegmentWriteKey(ctx echo.Context) error {
cfg := configuration.GetRegistrationServiceConfig()
segmentWriteKey := cfg.Analytics().SegmentWriteKey()
ctx.String(http.StatusOK, segmentWriteKey)
return ctx.String(http.StatusOK, segmentWriteKey)
}

// GetDevSpacesSegmentWriteKey returns segment-write-key content for DevSpaces
func (a *Analytics) GetDevSpacesSegmentWriteKey(ctx *gin.Context) {
func (a *Analytics) GetDevSpacesSegmentWriteKey(ctx echo.Context) error {
cfg := configuration.GetRegistrationServiceConfig()
segmentWriteKey := cfg.Analytics().DevSpacesSegmentWriteKey()
ctx.String(http.StatusOK, segmentWriteKey)
return ctx.String(http.StatusOK, segmentWriteKey)
}
19 changes: 7 additions & 12 deletions pkg/controller/analytics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"

"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -39,12 +39,9 @@ func (s *TestAnalyticsSuite) TestAnalyticsHandler() {
req, err := http.NewRequest(http.MethodGet, "/api/v1/segment-write-key", nil)
require.NoError(s.T(), err)

handler := gin.HandlerFunc(analyticsCtrl.GetDevSpacesSegmentWriteKey)

// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(rr)
ctx.Request = req
ctx := echo.New().NewContext(req, rr)

s.OverrideApplicationDefault(testconfig.RegistrationService().
Analytics().DevSpacesSegmentWriteKey("testing devspaces segment write key"))
Expand All @@ -53,15 +50,15 @@ func (s *TestAnalyticsSuite) TestAnalyticsHandler() {

assert.Equal(s.T(), "testing devspaces segment write key", cfg.Analytics().DevSpacesSegmentWriteKey())

handler(ctx)
err = analyticsCtrl.GetDevSpacesSegmentWriteKey(ctx)
require.NoError(s.T(), err)

// Check the status code is what we expect.
require.Equal(s.T(), http.StatusOK, rr.Code)

// Check the response body is what we expect.
// get config values from endpoint response
dataEnvelope := rr.Body.String()
require.NoError(s.T(), err)

s.Run("envelope segment write key", func() {
assert.Equal(s.T(), cfg.Analytics().DevSpacesSegmentWriteKey(), dataEnvelope, "wrong 'segment write key' in segment response")
Expand All @@ -75,12 +72,9 @@ func (s *TestAnalyticsSuite) TestAnalyticsHandler() {
req, err := http.NewRequest(http.MethodGet, "/api/v1/analytics/segment-write-key", nil)
require.NoError(s.T(), err)

handler := gin.HandlerFunc(analyticsCtrl.GetSandboxSegmentWriteKey)

// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(rr)
ctx.Request = req
ctx := echo.New().NewContext(req, rr)

s.OverrideApplicationDefault(testconfig.RegistrationService().
Analytics().SegmentWriteKey("testing sandbox segment write key"))
Expand All @@ -89,7 +83,8 @@ func (s *TestAnalyticsSuite) TestAnalyticsHandler() {

assert.Equal(s.T(), "testing sandbox segment write key", cfg.Analytics().SegmentWriteKey())

handler(ctx)
err = analyticsCtrl.GetSandboxSegmentWriteKey(ctx)
require.NoError(s.T(), err)

// Check the status code is what we expect.
require.Equal(s.T(), http.StatusOK, rr.Code)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
)

type configResponse struct {
Expand All @@ -28,12 +28,12 @@ func NewAuthConfig() *AuthConfig {
}

// GetHandler returns raw auth config content for UI.
func (ac *AuthConfig) GetHandler(ctx *gin.Context) {
func (ac *AuthConfig) GetHandler(ctx echo.Context) error {
cfg := configuration.GetRegistrationServiceConfig()
configRespData := configResponse{
AuthClientLibraryURL: cfg.Auth().AuthClientLibraryURL(),
AuthClientConfigRaw: cfg.Auth().AuthClientConfigRaw(),
SignupURL: cfg.RegistrationServiceURL(),
}
ctx.JSON(http.StatusOK, configRespData)
return ctx.JSON(http.StatusOK, configRespData)
}
13 changes: 6 additions & 7 deletions pkg/controller/authconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/configuration"
"github.com/codeready-toolchain/registration-service/test"

"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -40,22 +40,21 @@ func (s *TestAuthConfigSuite) TestAuthClientConfigHandler() {

// Create handler instance.
authConfigCtrl := NewAuthConfig()
handler := gin.HandlerFunc(authConfigCtrl.GetHandler)

s.Run("valid json config", func() {

// We create a ResponseRecorder (which satisfies http.ResponseWriter) to record the response.
rr := httptest.NewRecorder()
ctx, _ := gin.CreateTestContext(rr)
ctx.Request = req
ctx := echo.New().NewContext(req, rr)

handler(ctx)
err = authConfigCtrl.GetHandler(ctx)
require.NoError(s.T(), err)

// Check the status code is what we expect.
require.Equal(s.T(), http.StatusOK, rr.Code)

// check response content-type.
require.Equal(s.T(), cfg.Auth().AuthClientConfigContentType(), rr.Header().Get("Content-Type"))
// Echo's ctx.JSON sets application/json (config may still advertise charset in AuthClientConfigContentType).
require.Contains(s.T(), rr.Header().Get("Content-Type"), "application/json")

// Check the response body is what we expect.
// get config values from endpoint response
Expand Down
20 changes: 9 additions & 11 deletions pkg/controller/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/codeready-toolchain/registration-service/pkg/log"
"github.com/codeready-toolchain/toolchain-common/pkg/status"

"github.com/gin-gonic/gin"
"github.com/labstack/echo/v4"
)

type HealthCheckConfig interface {
Expand All @@ -34,7 +34,7 @@ func NewHealthCheck(checker HealthChecker) *HealthCheck {
}

// getHealthInfo returns the health info.
func (hc *HealthCheck) getHealthInfo(ctx *gin.Context) *HealthStatus {
func (hc *HealthCheck) getHealthInfo(ctx echo.Context) *HealthStatus {
cfg := configuration.GetRegistrationServiceConfig()
return &HealthStatus{
Health: &status.Health{
Expand All @@ -49,19 +49,17 @@ func (hc *HealthCheck) getHealthInfo(ctx *gin.Context) *HealthStatus {
}

// GetHandler returns a default heath check result.
func (hc *HealthCheck) GetHandler(ctx *gin.Context) {
// Default handler for system health
func (hc *HealthCheck) GetHandler(ctx echo.Context) error {
healthInfo := hc.getHealthInfo(ctx)
if healthInfo.Alive {
ctx.JSON(http.StatusOK, healthInfo)
} else {
ctx.JSON(http.StatusServiceUnavailable, healthInfo)
return ctx.JSON(http.StatusOK, healthInfo)
}
return ctx.JSON(http.StatusServiceUnavailable, healthInfo)
}

type HealthChecker interface {
Alive(*gin.Context) bool
APIProxyAlive(*gin.Context) bool
Alive(echo.Context) bool
APIProxyAlive(echo.Context) bool
}

func NewHealthChecker(port string) HealthChecker {
Expand All @@ -72,12 +70,12 @@ type healthCheckerImpl struct {
port string
}

func (c *healthCheckerImpl) Alive(ctx *gin.Context) bool {
func (c *healthCheckerImpl) Alive(ctx echo.Context) bool {
// TODO check if there are errors in configuration
return c.APIProxyAlive(ctx)
}

func (c *healthCheckerImpl) APIProxyAlive(ctx *gin.Context) bool {
func (c *healthCheckerImpl) APIProxyAlive(ctx echo.Context) bool {
resp, err := http.Get(fmt.Sprintf("http://localhost:%s/proxyhealth", c.port))
if err != nil {
log.Error(ctx, err, "API Proxy health check failed")
Expand Down
Loading
Loading