Go Fiber 한글 공식 문서
  • 🙇‍♀️안녕하세요
  • 🏠Home
    • 👋Welcome
    • 📁API
      • 📦Fiber
      • 🚀App
      • 🧠Ctx
      • 📋Constants
      • 🌎Client
      • 📃Log
      • 🧬Middleware
        • Adaptor
        • BasicAuth
        • Cache
        • Compress
        • CORS
        • CSRF
        • EarlyData
        • Encrypt Cookie
        • EnvVar
        • ETag
        • ExpVar
        • Favicon
        • FileSystem
        • Health Check
        • Helmet
        • Idempotency
        • Keyauth
        • Limiter
        • Logger
        • Monitor
        • Pprof
        • Proxy
        • Recover
        • Redirect
        • RequestID
        • Rewrite
        • Session
        • Skip
        • Timeout
    • 📁Guide
      • 🔌Routing
      • 🎭Grouping
      • 📝Templates
      • 🐛Error Handling
      • 🔎Validation
      • 🎣Hooks
      • ⚡Make Fiber Faster
    • 📁Extra
      • 🤔FAQ
      • 📊Benchmarks
  • 🧩Extra
    • 🧬Contrip
      • 👋Welcome
      • Casbin
      • Fgprof
      • Fiberi18n
      • Fibernewrelic
      • Fibersentry
      • Fiberzap
      • Fiberzerolog
      • JWT
      • LoadShed
      • Opafiber
      • Otelfiber
        • Example
      • Paseto
      • README
      • Swagger
      • Websocket
    • 📦Storage
      • 👋Welcome
      • ArangoDB
      • Azure Blob
      • Badger
      • Bbolt
      • Coherence
      • Couchbase
      • DynamoDB
      • Etcd
      • Memcache
      • Memory
      • Minio
      • MongoDB
      • MSSQL
      • MySQL
      • Nats
      • Pebble
      • Postgres
      • Redis
      • Ristretto
      • Rueidis
      • S3
      • ScyllaDb
      • SQLite3
    • 📃Template
      • 👋Welcome
      • Ace
      • Amber
      • Django
      • Handlebars
      • HTML
        • Golang Templates Cheatsheet
      • Jet
      • Mustache
      • Pug
      • Slim
Powered by GitBook
On this page
  • Installation
  • Signatures
  • Config
  • Types
  • Examples
  1. Extra
  2. Contrip

Opafiber

PreviousLoadShedNextOtelfiber

Last updated 1 year ago


Fiber를 위한 지원.

참고: Go 1.19 이상 필요

Installation

go get -u github.com/gofiber/fiber/v2
go get -u github.com/gofiber/contrib/opafiber/v2

Signatures

opafiber.New(config opafiber.Config) fiber.Handler

Config

Property
Type
설명
Default

RegoQuery

string

필수 - Rego 쿼리

-

RegoPolicy

io.Reader

필수 - Rego 정책

-

IncludeQueryString

bool

쿼리 문자열을 Rego 정책의 입력으로 포함

false

DeniedStatusCode

int

정책이 요청을 거부할 때 반환할 HTTP 상태 코드

400

DeniedResponseMessage

string

정책이 요청을 거부할 때 반환할 HTTP 응답 본문 텍스트

""

IncludeHeaders

[]string

헤더를 Rego 정책의 입력으로 포함

-

InputCreationMethod

InputCreationFunc

OPA에 대한 입력을 제공할 사용자 정의 함수 사용

func defaultInput(ctx *fiber.Ctx) (map[string]interface{}, error)

Types

type InputCreationFunc func(c *fiber.Ctx) (map[string]interface{}, error)

Examples

OPA Fiber 미들웨어는 다음과 같은 예시 데이터를 정책 엔진에 입력으로 전송합니다:

{
  "method": "GET",
  "path": "/somePath",
  "query": {
    "name": ["John Doe"]
  },
  "headers": {
    "Accept": "application/json",
    "Content-Type": "application/json"
  }
}
package main

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/contrib/opafiber/v2"
)

func main() {
  app := fiber.New()

  module := `
    package example.authz

    default allow := false
    
    allow {
      input.method == "GET"  
    }
  `

  cfg := opafiber.Config{
    RegoQuery:             "data.example.authz.allow",
    RegoPolicy:            bytes.NewBufferString(module),
    IncludeQueryString:    true,
    DeniedStatusCode:      fiber.StatusForbidden,
    DeniedResponseMessage: "상태 금지됨",
    IncludeHeaders:        []string{"Authorization"},
    InputCreationMethod: func(ctx *fiber.Ctx) (map[string]interface{}, error) {
      return map[string]interface{}{
        "method": ctx.Method(),
        "path":   ctx.Path(),
      }, nil
    },
  }

  app.Use(opafiber.New(cfg))

  app.Get("/", func(ctx *fiber.Ctx) error {
    return ctx.SendStatus(200)
  })

  app.Listen(":8080")
}
🧩
🧬
Open Policy Agent