Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Login with SSO button when Dex is enabled #4538

Merged
merged 12 commits into from
Apr 8, 2024
Merged
3 changes: 3 additions & 0 deletions .codacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- "chaoscenter/web/src/api/auth/**"
namkyu1999 marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 43 additions & 1 deletion chaoscenter/authentication/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@ const docTemplate = `{
}
}
},
"/capabilities": {
"get": {
"description": "Returns capabilities that can be leveraged by frontend services to toggle certain features.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CapabilitiesRouter"
],
"summary": "Get capabilities of Auth Server.",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.CapabilitiesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrServerError"
}
}
}
}
},
"/create_project": {
"post": {
"description": "Create a new project.",
Expand Down Expand Up @@ -1085,6 +1114,19 @@ const docTemplate = `{
}
}
},
"response.CapabilitiesResponse": {
"type": "object",
"properties": {
"dex": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
},
"response.ErrInvalidCredentials": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1159,7 +1201,7 @@ const docTemplate = `{
},
"message": {
"type": "string",
"example": "The authorization server encountered an unexpected condition that prevented it from fulfi"
"example": "The authorization server encountered an unexpected condition that prevented it from fulfilling the request"
}
}
},
Expand Down
44 changes: 43 additions & 1 deletion chaoscenter/authentication/api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@
}
}
},
"/capabilities": {
"get": {
"description": "Returns capabilities that can be leveraged by frontend services to toggle certain features.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"CapabilitiesRouter"
],
"summary": "Get capabilities of Auth Server.",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.CapabilitiesResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/response.ErrServerError"
}
}
}
}
},
"/create_project": {
"post": {
"description": "Create a new project.",
Expand Down Expand Up @@ -1075,6 +1104,19 @@
}
}
},
"response.CapabilitiesResponse": {
"type": "object",
"properties": {
"dex": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
},
"response.ErrInvalidCredentials": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1149,7 +1191,7 @@
},
"message": {
"type": "string",
"example": "The authorization server encountered an unexpected condition that prevented it from fulfi"
"example": "The authorization server encountered an unexpected condition that prevented it from fulfilling the request"
}
}
},
Expand Down
30 changes: 29 additions & 1 deletion chaoscenter/authentication/api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ definitions:
userID:
type: string
type: object
response.CapabilitiesResponse:
properties:
dex:
properties:
enabled:
type: boolean
type: object
type: object
response.ErrInvalidCredentials:
properties:
code:
Expand Down Expand Up @@ -65,7 +73,7 @@ definitions:
type: integer
message:
example: The authorization server encountered an unexpected condition that
prevented it from fulfi
prevented it from fulfilling the request
type: string
type: object
response.ErrStrictPasswordPolicyViolation:
Expand Down Expand Up @@ -176,6 +184,26 @@ paths:
summary: Accept invitaion.
tags:
- ProjectRouter
/capabilities:
get:
consumes:
- application/json
description: Returns capabilities that can be leveraged by frontend services
to toggle certain features.
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.CapabilitiesResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.ErrServerError'
summary: Get capabilities of Auth Server.
tags:
- CapabilitiesRouter
/create_project:
post:
consumes:
Expand Down
6 changes: 6 additions & 0 deletions chaoscenter/authentication/api/handlers/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ type UserResponse struct {
DeactivatedAt *int64 `bson:"deactivated_at,omitempty" json:"deactivatedAt,omitempty"`
}

type CapabilitiesResponse struct {
Dex struct {
Enabled bool `json:"enabled"`
} `json:"dex"`
}

type MessageResponse struct {
Message string
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package rest

import (
"github.com/gin-gonic/gin"
response "github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers"
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/utils"
)

// GetCapabilities godoc
//
// @Summary Get capabilities of Auth Server.
// @Description Returns capabilities that can be leveraged by frontend services to toggle certain features.
// @Tags CapabilitiesRouter
// @Accept json
// @Produce json
// @Failure 500 {object} response.ErrServerError
// @Success 200 {object} response.CapabilitiesResponse{}
// @Router /capabilities [get]
func GetCapabilities() gin.HandlerFunc {
smitthakkar96 marked this conversation as resolved.
Show resolved Hide resolved
return func(c *gin.Context) {
capabilities := new(response.CapabilitiesResponse)
capabilities.Dex.Enabled = utils.DexEnabled
c.JSON(200, capabilities)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package rest_test

import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

response "github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers"
"github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers/rest"
"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestCapabilities(t *testing.T) {

testcases := []struct {
Name string
DexEnabled bool
}{
{
Name: "Dex Enabled",
DexEnabled: true,
},
{
Name: "Dex Disabled",
DexEnabled: false,
},
}

for _, test := range testcases {
test := test
t.Run(test.Name, func(t *testing.T) {
w := httptest.NewRecorder()
ctx := GetTestGinContext(w)
utils.DexEnabled = test.DexEnabled

rest.GetCapabilities()(ctx)
capa := response.CapabilitiesResponse{}
err := json.Unmarshal(w.Body.Bytes(), &capa)

assert.Nil(t, err)
assert.Equal(t, test.DexEnabled, capa.Dex.Enabled)
assert.Equal(t, http.StatusOK, w.Code)
})
}
}
1 change: 1 addition & 0 deletions chaoscenter/authentication/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func runRestServer(applicationService services.ApplicationService) {
routes.MiscRouter(app, applicationService)
routes.UserRouter(app, applicationService)
routes.ProjectRouter(app, applicationService)
routes.CapabilitiesRouter(app)

log.Infof("Listening and serving HTTP on %s", utils.Port)
err := app.Run(utils.Port)
Expand Down
12 changes: 12 additions & 0 deletions chaoscenter/authentication/api/routes/capabilities_router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package routes

import (
"github.com/litmuschaos/litmus/chaoscenter/authentication/api/handlers/rest"

"github.com/gin-gonic/gin"
)

// CapabilitiesRouter creates all the required routes for exposing capabilities.
func CapabilitiesRouter(router *gin.Engine) {
router.GET("/capabilities", rest.GetCapabilities())
}
38 changes: 19 additions & 19 deletions chaoscenter/authentication/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ require (
github.com/coreos/go-oidc/v3 v3.1.0
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.9.1
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/golang/protobuf v1.5.4
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.6.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/swaggo/swag v1.16.2
go.mongodb.org/mongo-driver v1.13.1
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.3
go.mongodb.org/mongo-driver v1.14.0
golang.org/x/crypto v0.21.0
golang.org/x/oauth2 v0.16.0
google.golang.org/grpc v1.61.0
Expand All @@ -24,46 +24,46 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // 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.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading