-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show
Login with SSO
button when Dex is enabled (#4538)
* feat: expose dex login enabled through capabilities route Signed-off-by: smit thakkar <[email protected]> * chore: generate docs Signed-off-by: smit thakkar <[email protected]> * chore: generate client functions for capabilities Signed-off-by: smit thakkar <[email protected]> * feat: show login with sso button when dex is enabled Signed-off-by: smit thakkar <[email protected]> * style: fix codacy errors Signed-off-by: smit thakkar <[email protected]> * chore: go mod tidy Signed-off-by: smit thakkar <[email protected]> --------- Signed-off-by: smit thakkar <[email protected]> Co-authored-by: Saranya Jena <[email protected]>
- Loading branch information
1 parent
77336cb
commit cea879c
Showing
22 changed files
with
668 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
exclude_paths: | ||
- "chaoscenter/web/src/api/auth/**" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
chaoscenter/authentication/api/handlers/rest/capabilities_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
return func(c *gin.Context) { | ||
capabilities := new(response.CapabilitiesResponse) | ||
capabilities.Dex.Enabled = utils.DexEnabled | ||
c.JSON(200, capabilities) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
chaoscenter/authentication/api/handlers/rest/capabilities_handler_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
chaoscenter/authentication/api/routes/capabilities_router.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.