Skip to content

Commit

Permalink
fix CheckPermission func
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyatomohiro committed Oct 31, 2024
1 parent 9f60602 commit e97753a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions cerbos/client/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ type GraphQLQuery struct {
Variables interface{} `json:"variables"`
}

func CheckPermission(ctx context.Context, dashboardURL string, input CheckPermissionInput) (bool, error) {
au := getAuthInfo(ctx)
if au == nil {
return false, fmt.Errorf("auth info not found")
func CheckPermission(ctx context.Context, dashboardURL string, authInfo *appx.AuthInfo, input CheckPermissionInput) (bool, error) {
if authInfo == nil {
return false, fmt.Errorf("auth info is required")
}

query := `
Expand Down Expand Up @@ -60,7 +59,7 @@ func CheckPermission(ctx context.Context, dashboardURL string, input CheckPermis
return false, fmt.Errorf("failed to create request: %w", err)
}

req.Header.Set("Authorization", "Bearer "+au.Token)
req.Header.Set("Authorization", "Bearer "+authInfo.Token)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
Expand All @@ -77,12 +76,3 @@ func CheckPermission(ctx context.Context, dashboardURL string, input CheckPermis

return response.Data.CheckPermission.Allowed, nil
}

func getAuthInfo(ctx context.Context) *appx.AuthInfo {
if v := ctx.Value("authinfo"); v != nil {
if v2, ok := v.(appx.AuthInfo); ok {
return &v2
}
}
return nil
}

0 comments on commit e97753a

Please sign in to comment.