Skip to content
Open
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
8 changes: 7 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1008,8 +1010,8 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand Down Expand Up @@ -1141,6 +1143,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -1152,6 +1156,8 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (
"fmt"
"github.com/permitio/permit-golang/pkg/config"
"github.com/permitio/permit-golang/pkg/errors"
"github.com/permitio/permit-golang/pkg/log"
"github.com/permitio/permit-golang/pkg/openapi"
"go.uber.org/zap"
"time"
)

type permitBaseApi struct {
client *openapi.APIClient
config *config.PermitConfig
logger *zap.Logger
logger log.Logger
}

type PermitBaseFactsApi struct {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (a *permitBaseApi) lazyLoadPermitContext(ctx context.Context, methodApiLeve

type PermitApiClient struct {
config *config.PermitConfig
logger *zap.Logger
logger log.Logger
client *openapi.APIClient
ConditionSets *ConditionSets
Elements *Elements
Expand All @@ -112,7 +112,7 @@ type PermitApiClient struct {
func (p *PermitApiClient) SetContext(ctx context.Context, project string, environment string) {
permitContext, err := config.PermitContextFactory(ctx, p.client, project, environment, true)
if err != nil {
p.logger.Error("", zap.Error(err))
p.logger.Error("", err)
}
p.config.Context = permitContext
}
Expand Down
35 changes: 17 additions & 18 deletions pkg/api/condition_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/permitio/permit-golang/pkg/errors"
"github.com/permitio/permit-golang/pkg/models"
"github.com/permitio/permit-golang/pkg/openapi"
"go.uber.org/zap"
)

type ConditionSets struct {
Expand All @@ -33,14 +32,14 @@ func (c *ConditionSets) List(ctx context.Context, page int, perPage int) ([]mode

if !isPaginationInLimit(int32(page), int32(perPage), perPageLimit) {
err := errors.NewPermitPaginationError()
c.logger.Error("error listing condition sets - max per page: "+string(perPageLimit), zap.Error(err))
c.logger.Error("error listing condition sets - max per page: "+string(perPageLimit), err)
return nil, err
}

err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -53,7 +52,7 @@ func (c *ConditionSets) List(ctx context.Context, page int, perPage int) ([]mode
err = errors.HttpErrorHandle(err, httpRes)

if err != nil {
c.logger.Error("error listing condition sets", zap.Error(err))
c.logger.Error("error listing condition sets", err)
return nil, err
}

Expand All @@ -67,7 +66,7 @@ func (c *ConditionSets) Get(ctx context.Context, conditionSetKey string) (*model
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -80,7 +79,7 @@ func (c *ConditionSets) Get(ctx context.Context, conditionSetKey string) (*model
err = errors.HttpErrorHandle(err, httpRes)

if err != nil {
c.logger.Error("error getting condition set: "+conditionSetKey, zap.Error(err))
c.logger.Error("error getting condition set: "+conditionSetKey, err)
return nil, err
}

Expand Down Expand Up @@ -113,7 +112,7 @@ func (c *ConditionSets) Create(ctx context.Context, csCreate models.ConditionSet
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -125,7 +124,7 @@ func (c *ConditionSets) Create(ctx context.Context, csCreate models.ConditionSet
err = errors.HttpErrorHandle(err, httpRes)

if err != nil {
c.logger.Error("error creating condition set: "+csCreate.GetKey(), zap.Error(err))
c.logger.Error("error creating condition set: "+csCreate.GetKey(), err)
return nil, err
}

Expand All @@ -137,7 +136,7 @@ func (c *ConditionSets) Update(ctx context.Context, conditionSetKey string, cond
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -149,7 +148,7 @@ func (c *ConditionSets) Update(ctx context.Context, conditionSetKey string, cond

err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
c.logger.Error("error updating condition set: "+conditionSetKey, zap.Error(err))
c.logger.Error("error updating condition set: "+conditionSetKey, err)
return nil, err
}
return conditionSet, nil
Expand All @@ -160,7 +159,7 @@ func (c *ConditionSets) Delete(ctx context.Context, conditionSetKey string) erro
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return err
}

Expand All @@ -174,7 +173,7 @@ func (c *ConditionSets) Delete(ctx context.Context, conditionSetKey string) erro
err = errors.HttpErrorHandle(err, httpRes)

if err != nil {
c.logger.Error("error deleting condition set: "+conditionSetKey, zap.Error(err))
c.logger.Error("error deleting condition set: "+conditionSetKey, err)
return err
}

Expand All @@ -185,7 +184,7 @@ func (c *ConditionSets) AssignSetPermissions(ctx context.Context, userSetKey str
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -199,7 +198,7 @@ func (c *ConditionSets) AssignSetPermissions(ctx context.Context, userSetKey str

if err != nil {
errString := fmt.Sprintf("error creating condition set rule %s, %s, %s", userSetKey, permission, resourceSetKey)
c.logger.Error("error creating condition set rule: "+errString, zap.Error(err))
c.logger.Error("error creating condition set rule: "+errString, err)
return nil, err
}

Expand All @@ -210,7 +209,7 @@ func (c *ConditionSets) UnassignSetPermissions(ctx context.Context, userSetKey s
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return err
}

Expand All @@ -224,7 +223,7 @@ func (c *ConditionSets) UnassignSetPermissions(ctx context.Context, userSetKey s

if err != nil {
errString := fmt.Sprintf("error creating condition set rule %s, %s, %s", userSetKey, permission, resourceSetKey)
c.logger.Error(errString, zap.Error(err))
c.logger.Error(errString, err)
return err
}

Expand All @@ -235,7 +234,7 @@ func (c *ConditionSets) ListSetPermissions(ctx context.Context, userSetKey strin
err := c.lazyLoadPermitContext(ctx)

if err != nil {
c.logger.Error("", zap.Error(err))
c.logger.Error("", err)
return nil, err
}

Expand All @@ -249,7 +248,7 @@ func (c *ConditionSets) ListSetPermissions(ctx context.Context, userSetKey strin

if err != nil {
errString := fmt.Sprintf("error listing rules condition set rule %s, %s, %s", userSetKey, permission, resourceSetKey)
c.logger.Error(errString, zap.Error(err))
c.logger.Error(errString, err)
return nil, err
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/api/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/permitio/permit-golang/pkg/errors"
"github.com/permitio/permit-golang/pkg/models"
"github.com/permitio/permit-golang/pkg/openapi"
"go.uber.org/zap"
)

type Elements struct {
Expand Down Expand Up @@ -37,7 +36,7 @@ func (e *Elements) LoginAs(ctx context.Context, userLogin models.UserLoginReques
embeddedLoginRequestOutput, httpRes, err := e.client.AuthenticationApi.ElementsLoginAs(ctx).UserLoginRequestInput(userLogin).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error login as: "+userLogin.GetUserId()+"in tenant: "+userLogin.GetTenantId(), zap.Error(err))
e.logger.Error("error login as: "+userLogin.GetUserId()+"in tenant: "+userLogin.GetTenantId(), err)
return nil, err
}
return embeddedLoginRequestOutput, nil
Expand Down
23 changes: 11 additions & 12 deletions pkg/api/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/permitio/permit-golang/pkg/errors"
"github.com/permitio/permit-golang/pkg/models"
"github.com/permitio/permit-golang/pkg/openapi"
"go.uber.org/zap"
"golang.org/x/net/context"
)

Expand All @@ -32,18 +31,18 @@ func (e *Environments) List(ctx context.Context, page int, perPage int) ([]model
perPageLimit := int32(DefaultPerPageLimit)
if !isPaginationInLimit(int32(page), int32(perPage), perPageLimit) {
err := errors.NewPermitPaginationError()
e.logger.Error("error listing environments - max per page: "+string(perPageLimit), zap.Error(err))
e.logger.Error("error listing environments - max per page: "+string(perPageLimit), err)
return nil, err
}
err := e.lazyLoadPermitContext(ctx)
if err != nil {
e.logger.Error("", zap.Error(err))
e.logger.Error("", err)
return nil, err
}
environments, httpRes, err := e.client.EnvironmentsApi.ListEnvironments(ctx, e.config.Context.ProjectId).Page(int32(page)).PerPage(int32(perPage)).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error listing environments", zap.Error(err))
e.logger.Error("error listing environments", err)
return nil, err
}
return environments, nil
Expand All @@ -56,13 +55,13 @@ func (e *Environments) List(ctx context.Context, page int, perPage int) ([]model
func (e *Environments) Get(ctx context.Context, environmentKey string) (*models.EnvironmentRead, error) {
err := e.lazyLoadPermitContext(ctx)
if err != nil {
e.logger.Error("", zap.Error(err))
e.logger.Error("", err)
return nil, err
}
environment, httpRes, err := e.client.EnvironmentsApi.GetEnvironment(ctx, e.config.Context.ProjectId, environmentKey).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error getting environment: "+environmentKey, zap.Error(err))
e.logger.Error("error getting environment: "+environmentKey, err)
return nil, err
}

Expand Down Expand Up @@ -95,13 +94,13 @@ func (e *Environments) GetById(ctx context.Context, environmentId uuid.UUID) (*m
func (e *Environments) Create(ctx context.Context, environmentCreate models.EnvironmentCreate) (*models.EnvironmentRead, error) {
err := e.lazyLoadPermitContext(ctx)
if err != nil {
e.logger.Error("", zap.Error(err))
e.logger.Error("", err)
return nil, err
}
environment, httpRes, err := e.client.EnvironmentsApi.CreateEnvironment(ctx, e.config.Context.ProjectId).EnvironmentCreate(environmentCreate).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error creating environment: "+environmentCreate.GetKey(), zap.Error(err))
e.logger.Error("error creating environment: "+environmentCreate.GetKey(), err)
return nil, err
}

Expand All @@ -119,13 +118,13 @@ func (e *Environments) Create(ctx context.Context, environmentCreate models.Envi
func (e *Environments) Update(ctx context.Context, environmentKey string, environmentUpdate models.EnvironmentUpdate) (*models.EnvironmentRead, error) {
err := e.lazyLoadPermitContext(ctx)
if err != nil {
e.logger.Error("", zap.Error(err))
e.logger.Error("", err)
return nil, err
}
environment, httpRes, err := e.client.EnvironmentsApi.UpdateEnvironment(ctx, e.config.Context.ProjectId, environmentKey).EnvironmentUpdate(environmentUpdate).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error updating environment: "+environmentKey, zap.Error(err))
e.logger.Error("error updating environment: "+environmentKey, err)
return nil, err
}

Expand All @@ -139,13 +138,13 @@ func (e *Environments) Update(ctx context.Context, environmentKey string, enviro
func (e *Environments) Delete(ctx context.Context, environmentKey string) error {
err := e.lazyLoadPermitContext(ctx)
if err != nil {
e.logger.Error("", zap.Error(err))
e.logger.Error("", err)
return err
}
httpRes, err := e.client.EnvironmentsApi.DeleteEnvironment(ctx, e.config.Context.ProjectId, environmentKey).Execute()
err = errors.HttpErrorHandle(err, httpRes)
if err != nil {
e.logger.Error("error deleting environment: "+environmentKey, zap.Error(err))
e.logger.Error("error deleting environment: "+environmentKey, err)
return err
}
return nil
Expand Down
Loading