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

feat: switch to zerolog #24

Merged
merged 6 commits into from
Sep 13, 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
1 change: 0 additions & 1 deletion .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ steps:
command: ["task", "example:generate"]
environment:
- "GOTOOLCHAIN=auto"
- "GODEBUG=gotypesalias=0"
- group: ":closed_lock_with_key: Security Checks"
depends_on: "tests"
key: "security"
Expand Down
1 change: 0 additions & 1 deletion Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ includes:
dir: ./entfga/_examples/basic/

env:
GODEBUG: gotypesalias=0 # remove once the backport fixes the types.Alias bug
GOFLAGS: -buildvcs=false

tasks:
Expand Down
2 changes: 1 addition & 1 deletion auth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/theopenlane/utils/ulids"

"github.com/theopenlane/core/pkg/middleware/echocontext"
"github.com/theopenlane/echox/middleware/echocontext"
)

type AuthenticationType string
Expand Down
2 changes: 1 addition & 1 deletion auth/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/theopenlane/core/pkg/middleware/echocontext"
"github.com/theopenlane/echox/middleware/echocontext"
"github.com/theopenlane/utils/ulids"

"github.com/theopenlane/iam/auth"
Expand Down
2 changes: 1 addition & 1 deletion auth/test_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/golang-jwt/jwt/v5"
echo "github.com/theopenlane/echox"

"github.com/theopenlane/core/pkg/middleware/echocontext"
"github.com/theopenlane/echox/middleware/echocontext"

"github.com/theopenlane/iam/tokens"
)
Expand Down
18 changes: 11 additions & 7 deletions entfga/_examples/basic/ent/auth_from_mutation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions entfga/_examples/basic/ent/authz_checks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions entfga/_examples/basic/ent/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions entfga/_examples/basic/ent/entc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"entgo.io/ent/entc/gen"
"github.com/theopenlane/iam/entfga"
"github.com/theopenlane/iam/fgax"
"go.uber.org/zap"

"entgo.io/ent/entc"
)
Expand Down Expand Up @@ -45,10 +44,6 @@ func main() {
entc.DependencyName("Authz"),
entc.DependencyType(fgax.Client{}),
),
entc.Dependency(
entc.DependencyName("Logger"),
entc.DependencyType(zap.SugaredLogger{}),
),
entc.Extensions(
gqlExt,
entfgaExt,
Expand Down
1 change: 1 addition & 0 deletions entfga/entfga.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"embed"
"fmt"

_ "entgo.io/contrib/entgql"
"entgo.io/ent/entc"
"entgo.io/ent/entc/gen"
)
Expand Down
15 changes: 8 additions & 7 deletions entfga/templates/authzChecks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package {{ .GeneratedPkg }}
import (
"github.com/99designs/gqlgen/graphql"
"entgo.io/ent/privacy"
"github.com/rs/zerolog/log"

"github.com/theopenlane/iam/fgax"
"github.com/theopenlane/iam/auth"
Expand Down Expand Up @@ -113,7 +114,7 @@ import (
reqCtx := privacy.DecisionContext(ctx, privacy.Allow)
ob, err := m.Client().{{ $name }}.Get(reqCtx, id)
if err != nil {
m.Logger.Debugw("error getting object", "error", err)
log.Debug().Err(err).Msg("error getting object")

return err
}
Expand Down Expand Up @@ -168,23 +169,23 @@ import (
return privacy.Allowf("nil request, bypassing auth check")
}

m.Logger.Debugw("checking mutation access")
log.Debug().Msg("checking mutation access")

var err error
ac.SubjectID, err = auth.GetUserIDFromContext(ctx)
if err != nil {
return err
}

m.Logger.Infow("checking relationship tuples", "relation", ac.Relation, "object_id", ac.ObjectID)
log.Info().Str("relation", ac.Relation).Str("object_id", ac.ObjectID).Msg("checking relationship tuples")

access, err := m.Authz.CheckAccess(ctx, ac)
if err != nil {
return privacy.Skipf("unable to check access, %s", err.Error())
}

if access {
m.Logger.Debugw("access allowed", "relation", ac.Relation, "object_id", ac.ObjectID)
log.Debug().Str("relation", ac.Relation).Str("object_id", ac.ObjectID).Msg("access allowed")

return privacy.Allow
}
Expand All @@ -208,23 +209,23 @@ import (
return privacy.Allowf("nil request, bypassing auth check")
}

m.Logger.Debugw("checking mutation access")
log.Debug().Msg("checking mutation access")

var err error
ac.SubjectID, err = auth.GetUserIDFromContext(ctx)
if err != nil {
return err
}

m.Logger.Infow("checking relationship tuples", "relation", ac.Relation, "object_id", ac.ObjectID)
log.Info().Str("relation", ac.Relation).Str("object_id", ac.ObjectID).Msg("checking relationship tuples")

access, err := m.Authz.CheckAccess(ctx, ac)
if err != nil {
return privacy.Skipf("unable to check access, %s", err.Error())
}

if access {
m.Logger.Debugw("access allowed", "relation", ac.Relation, "object_id", ac.ObjectID)
log.Debug().Str("relation", ac.Relation).Str("object_id", ac.ObjectID).Msg("access allowed")

return privacy.Allow
}
Expand Down
Loading
Loading