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

Increase role http error and test quality #222

Merged
merged 5 commits into from
Mar 15, 2024
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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.18, 1.17, 1-bullseye, 1.18-bullseye, 1.17-bullseye, 1-buster, 1.18-buster, 1.17-buster
FROM mcr.microsoft.com/vscode/devcontainers/go:1-1.20-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:1-1.22-bullseye

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module go.infratographer.com/permissions-api

go 1.20
go 1.22

require (
github.com/authzed/authzed-go v0.10.1
github.com/authzed/grpcutil v0.0.0-20240123194739-2ea1e3d2d98b
github.com/cockroachdb/cockroach-go/v2 v2.3.6
github.com/go-jose/go-jose/v4 v4.0.1
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/labstack/echo-jwt/v4 v4.2.0
github.com/labstack/echo/v4 v4.11.4
github.com/lib/pq v1.10.9
github.com/nats-io/nats.go v1.31.0
Expand All @@ -22,6 +25,7 @@ require (
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
google.golang.org/grpc v1.60.1
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -40,7 +44,6 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
Expand All @@ -60,7 +63,6 @@ require (
github.com/jzelinskie/stringz v0.0.2 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/labstack/echo-contrib v0.15.0 // indirect
github.com/labstack/echo-jwt/v4 v4.2.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -99,10 +101,9 @@ require (
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
Expand Down
44 changes: 40 additions & 4 deletions go.sum

Large diffs are not rendered by default.

31 changes: 24 additions & 7 deletions internal/api/assignments.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package api

import (
"errors"
"net/http"

"go.infratographer.com/x/gidx"

"go.infratographer.com/permissions-api/internal/query"
"go.infratographer.com/permissions-api/internal/types"

"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -37,7 +39,7 @@ func (r *Router) assignmentCreate(c echo.Context) error {

assigneeResource, err := r.engine.NewResourceFromID(assigneeID)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "error creating resource").SetInternal(err)
return echo.NewHTTPError(http.StatusBadRequest, "error assigning subject").SetInternal(err)
}

subjectResource, err := r.currentSubject(c)
Expand All @@ -51,8 +53,13 @@ func (r *Router) assignmentCreate(c echo.Context) error {
}

resource, err := r.engine.GetRoleResource(ctx, roleResource)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "error getting resource").SetInternal(err)

switch {
case err == nil:
case errors.Is(err, query.ErrRoleNotFound):
return echo.NewHTTPError(http.StatusNotFound, "role not found").SetInternal(err)
default:
return echo.NewHTTPError(http.StatusInternalServerError, "error getting role").SetInternal(err)
}

if err := r.checkActionWithResponse(ctx, subjectResource, actionRoleUpdate, resource); err != nil {
Expand Down Expand Up @@ -96,8 +103,13 @@ func (r *Router) assignmentsList(c echo.Context) error {
}

resource, err := r.engine.GetRoleResource(ctx, roleResource)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "error getting resource").SetInternal(err)

switch {
case err == nil:
case errors.Is(err, query.ErrRoleNotFound):
return echo.NewHTTPError(http.StatusNotFound, "role not found").SetInternal(err)
default:
return echo.NewHTTPError(http.StatusInternalServerError, "error getting role").SetInternal(err)
}

if err := r.checkActionWithResponse(ctx, subjectResource, actionRoleGet, resource); err != nil {
Expand Down Expand Up @@ -169,8 +181,13 @@ func (r *Router) assignmentDelete(c echo.Context) error {
}

resource, err := r.engine.GetRoleResource(ctx, roleResource)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "error getting resource").SetInternal(err)

switch {
case err == nil:
case errors.Is(err, query.ErrRoleNotFound):
return echo.NewHTTPError(http.StatusNotFound, "role not found").SetInternal(err)
default:
return echo.NewHTTPError(http.StatusInternalServerError, "error getting role").SetInternal(err)
}

if err := r.checkActionWithResponse(ctx, subjectResource, actionRoleUpdate, resource); err != nil {
Expand Down
Loading
Loading