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

API cleanup #47

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions internal/api/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,6 @@ import (
"go.infratographer.com/permissions-api/internal/query"
)

func (r *Router) checkGlobalScope(c *gin.Context) {
scope := c.Param("scope")

ctx, span := tracer.Start(c.Request.Context(), "api.checkGlobalScope")
defer span.End()

actor, err := currentActor(c)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": "failed to get the actor"})
return
}

actorResource, err := query.NewResourceFromURN(actor.urn)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"message": "error processing actor URN", "error": err.Error()})
return
}

err = query.ActorHasGlobalPermission(ctx, r.authzedClient, actorResource, scope, "")
if err != nil {
if errors.Is(err, query.ErrScopeNotAssigned) {
c.JSON(http.StatusForbidden, gin.H{"message": "actor does not have requested scope"})
return
}

c.JSON(http.StatusInternalServerError, gin.H{"message": "an error occurred checking actor scopes", "error": err.Error()})

return
}

c.JSON(http.StatusOK, gin.H{})
}

func (r *Router) resourcesAvailable(c *gin.Context) {
ctx, span := tracer.Start(c.Request.Context(), "api.resourcesAvailable")
defer span.End()

resourceURN := c.Param("type")
scope := c.Param("scope")

actor, err := currentActor(c)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": "failed to get the actor"})
return
}

resources, err := query.ActorResourceList(ctx, r.authzedClient, actor.urn, resourceURN, scope, "")
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": "failed to get the resources"})
return
}

c.JSON(http.StatusOK, gin.H{"ids": resources})
}

func (r *Router) checkScope(c *gin.Context) {
resourceURN := c.Param("urn")
scope := c.Param("scope")
Expand Down
9 changes: 0 additions & 9 deletions internal/api/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ func (r *Router) resourceCreate(c *gin.Context) {
c.JSON(http.StatusCreated, gin.H{"token": zedToken})
}

func (r *Router) resourceUpdate(c *gin.Context) {
resourceURN := c.Param("urn")

_, span := tracer.Start(c.Request.Context(), "api.resourceUpdate", trace.WithAttributes(attribute.String("urn", resourceURN)))
defer span.End()

c.JSON(http.StatusInternalServerError, gin.H{"message": "not implemented"})
}

func (r *Router) resourceDelete(c *gin.Context) {
resourceURN := c.Param("urn")

Expand Down
4 changes: 0 additions & 4 deletions internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ func (r *Router) Routes(rg *gin.RouterGroup) {
{
// Creating an OU gets a special
v1.POST("/resources/:urn", r.resourceCreate)
v1.PUT("/resources/:urn", r.resourceUpdate)
v1.DELETE("/resources/:urn", r.resourceDelete)
// Check resource access
v1.GET("/available/:type/:scope", r.resourcesAvailable)
v1.GET("/has/:scope/on/:urn", r.checkScope)
// Check Global Scope
v1.GET("/global/check/:scope", r.checkGlobalScope)
}
}

Expand Down
9 changes: 9 additions & 0 deletions internal/query/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package query

import "errors"

var (
// ErrScopeNotAssigned represents an error condition where the actor is not able to complete
// the given request.
ErrScopeNotAssigned = errors.New("the actor does not have permissions to complete this request")
)
71 changes: 0 additions & 71 deletions internal/query/global.go

This file was deleted.

89 changes: 0 additions & 89 deletions internal/query/global_test.go

This file was deleted.

9 changes: 9 additions & 0 deletions internal/query/stores.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package query

import "github.com/authzed/authzed-go/v1"

// Stores represents a SpiceDB store.
type Stores struct {
SpiceDB *authzed.Client
SpiceDBPrefix string
}
Loading