Skip to content

Commit

Permalink
Merge branch 'master' into test/jwt-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaitanyaD48 committed Apr 9, 2024
2 parents 48ddf68 + cea879c commit 373d7c0
Show file tree
Hide file tree
Showing 22 changed files with 668 additions and 168 deletions.
3 changes: 3 additions & 0 deletions .codacy.yaml
@@ -0,0 +1,3 @@
---
exclude_paths:
- "chaoscenter/web/src/api/auth/**"
44 changes: 43 additions & 1 deletion chaoscenter/authentication/api/docs/docs.go
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
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
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
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
@@ -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 {
return func(c *gin.Context) {
capabilities := new(response.CapabilitiesResponse)
capabilities.Dex.Enabled = utils.DexEnabled
c.JSON(200, capabilities)
}
}
@@ -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
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
@@ -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
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
)

0 comments on commit 373d7c0

Please sign in to comment.