-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initialize keto client + add a test rbac route
- Loading branch information
Showing
7 changed files
with
146 additions
and
8 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
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,49 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
client "github.com/ory/client-go" | ||
"github.com/sdslabs/nymeria/config" | ||
"github.com/sdslabs/nymeria/log" | ||
) | ||
|
||
func HandleRbac(c *gin.Context) { | ||
log.Logger.Debug("RBAC") | ||
cookie, err := c.Cookie("sdslabs_session") | ||
|
||
if err != nil { | ||
log.ErrorLogger("Initialize Rbac Failed", err) | ||
errCode, _ := strconv.Atoi(strings.Split(err.Error(), " ")[0]) | ||
c.JSON(errCode, gin.H{ | ||
"error": err.Error(), | ||
"message": "Initialize Rbac failed.", | ||
}) | ||
return | ||
} | ||
|
||
apiClient := client.NewAPIClient(config.KratosClientConfig) | ||
session, _, err := apiClient.V0alpha2Api.ToSession(context.Background()).Cookie(cookie).Execute() | ||
if err != nil { | ||
log.ErrorLogger("Invalid Cookie", err) | ||
c.JSON(http.StatusInternalServerError, gin.H{ | ||
"error": err.Error(), | ||
"message": "Initialize Rbac failed.", | ||
}) | ||
return | ||
} | ||
|
||
identity := session.GetIdentity() | ||
traits := identity.GetTraits() | ||
role := traits.(map[string]interface{})["role"] | ||
|
||
c.JSON(http.StatusOK, gin.H{ | ||
"message": "RBAC passed", | ||
"traits": traits, | ||
"role": role, | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package config | ||
|
||
import ( | ||
client "github.com/ory/client-go" | ||
) | ||
|
||
func getKetoClientConfig() (*client.Configuration, *client.Configuration){ | ||
readConfiguration := client.NewConfiguration() | ||
readConfiguration.Servers = []client.ServerConfiguration{ | ||
{ | ||
URL: NymeriaConfig.URL.KetoReadURL, | ||
}, | ||
} | ||
|
||
writeConfiguration := client.NewConfiguration() | ||
writeConfiguration.Servers = []client.ServerConfiguration{ | ||
{ | ||
URL: NymeriaConfig.URL.KetoWriteURL, | ||
}, | ||
} | ||
|
||
return readConfiguration, writeConfiguration | ||
} | ||
|
||
var ( | ||
KetoReadConfig, KetoWriteConfig = getKetoClientConfig() | ||
) |
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
Oops, something went wrong.