Files
query-orchestration/internal/cognitoauth/mapping.go
T

28 lines
976 B
Go
Raw Normal View History

package cognitoauth
import "strings"
// GetResourceFromRoute extracts the resource identifier from the HTTP route
// Returns only the first path segment (e.g., "/document/foo/123" -> "document")
// Removes leading slash to match Permit.io resource naming convention
func GetResourceFromRoute(route string) string {
// Remove leading slash if present
route = strings.TrimPrefix(route, "/")
// Find the first slash and return only the part before it
if slashIndex := strings.Index(route, "/"); slashIndex != -1 {
return route[:slashIndex]
}
// No slash found, return the whole string
return route
}
// GetActionFromMethod maps HTTP methods to Permit.io actions
// Converts HTTP methods to lowercase to match Permit.io action naming conventions
func GetActionFromMethod(method string) string {
// Convert to lowercase to match Permit.io action naming conventions
// This ensures case-insensitive matching with configured actions
return strings.ToLower(method)
}