api_upstream

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAPIUpstreamForCreate

func BuildAPIUpstreamForCreate(backendID uint, input CreateInput) (models.APIUpstream, error)

BuildAPIUpstreamForCreate normalizes and validates a create input into the database model that Creator may persist. It performs no encryption or I/O.

func EncryptAPIUpstreamCredential

func EncryptAPIUpstreamCredential(cipher *byokcrypto.Cipher, upstreamID uint, authType models.APIUpstreamAuthType, credential APIUpstreamCredential) (string, error)

EncryptAPIUpstreamCredential validates the credential's auth shape and encrypts its JSON representation with the persisted upstream ID as AEAD AAD.

Types

type APIUpstreamCredential

type APIUpstreamCredential = protocol.APIUpstreamCredential

APIUpstreamCredential is the plaintext-only credential input used at the administrative boundary. It is never embedded in a management response.

func DecryptAPIUpstreamCredential

func DecryptAPIUpstreamCredential(cipher *byokcrypto.Cipher, upstreamID uint, authType models.APIUpstreamAuthType, ciphertext string) (APIUpstreamCredential, error)

DecryptAPIUpstreamCredential opens a base64-encoded credential and validates its full shape again, so ciphertext cannot be reused for another auth type.

type APIUpstreamManagementResponse

type APIUpstreamManagementResponse struct {
	ID                   uint                       `json:"id"`
	BackendID            uint                       `json:"backend_id"`
	Name                 string                     `json:"name"`
	BaseURL              string                     `json:"base_url"`
	Weight               int                        `json:"weight"`
	Priority             int                        `json:"priority"`
	AuthType             models.APIUpstreamAuthType `json:"auth_type"`
	Status               int                        `json:"status"`
	CredentialConfigured bool                       `json:"credential_configured"`
	ProxyURLConfigured   bool                       `json:"proxy_url_configured"`
	HeaderOverride       map[string]string          `json:"header_override,omitempty"`
}

APIUpstreamManagementResponse is the credential-safe response shape for administration APIs. Encrypted secret fields never exist on this type, and header overrides are included only after the handler verifies manage access.

func NewAPIUpstreamManagementResponse

func NewAPIUpstreamManagementResponse(upstream models.APIUpstream, includeHeaderOverride ...bool) APIUpstreamManagementResponse

type CreateInput

type CreateInput struct {
	Name           string                     `json:"name" binding:"required,max=64"`
	BaseURL        string                     `json:"base_url" binding:"required"`
	Weight         int                        `json:"weight"`
	Priority       int                        `json:"priority"`
	AuthType       models.APIUpstreamAuthType `json:"auth_type"`
	Credential     *APIUpstreamCredential     `json:"credential"`
	ProxyURL       *string                    `json:"proxy_url"`
	HeaderOverride map[string]string          `json:"header_override"`
	Status         *int                       `json:"status"`
}

type CreateRequest

type CreateRequest struct {
	BackendID uint `json:"backend_id" binding:"required"`
	CreateInput
}

type Creator

type Creator struct {
	Cipher *byokcrypto.Cipher
}

func (Creator) CreateInTx

func (c Creator) CreateInTx(ctx dao.Context, backendID uint, input CreateInput) (models.APIUpstream, error)

type Handler

type Handler struct {
	App       app.Application
	Publisher UpstreamPublisher
	Creator   Creator
}

func (*Handler) Create

func (*Handler) Delete

func (h *Handler) Delete(c *app.Context, req IDRequest) (api.StatusResponse, error)

func (*Handler) Get

func (*Handler) Update

func (h *Handler) Update(c *app.Context, req UpdateRequest) (api.StatusResponse, error)

type IDRequest

type IDRequest struct {
	ID string `uri:"id" binding:"required"`
}

type ListRequest

type ListRequest struct {
	api.PaginationQuery
	APIServiceID *uint  `form:"api_service_id"`
	BackendID    *uint  `form:"backend_id"`
	Search       string `form:"search"`
	Status       *int   `form:"status"`
}

type UpdateRequest

type UpdateRequest struct {
	ID     string         `uri:"id" binding:"required"`
	Fields map[string]any `json:"-"`
}

func (*UpdateRequest) SetBodyMap

func (r *UpdateRequest) SetBodyMap(v map[string]any)

type UpstreamPublisher

type UpstreamPublisher interface {
	PublishUpstream(context.Context, string, models.APIUpstream) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL