server

package
v0.0.0-...-eb082ec Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger   logging.Logger
	KeyCache cache.Cache[entities.Key]
	// The ApiCache uses the KeyAuthId as cache key, not an apiId
	ApiCache        cache.Cache[entities.Api]
	Database        database.Database
	Ratelimit       ratelimit.Ratelimiter
	GlobalRatelimit ratelimit.Ratelimiter
	Tracer          trace.Tracer
	// Potentially the user does not have tinybird set up or does not want to use it
	// simply pass in nil in that case
	Tinybird          *tinybird.Tinybird
	UnkeyAppAuthToken string
	UnkeyWorkspaceId  string
	UnkeyApiId        string
	UnkeyKeyAuthId    string
	Region            string
	Kafka             *kafka.Kafka
	Version           string
}

type CreateKeyRequest

type CreateKeyRequest struct {
	ApiId      string         `json:"apiId" validate:"required"`
	Prefix     string         `json:"prefix"`
	Name       string         `json:"name"`
	ByteLength int            `json:"byteLength"`
	OwnerId    string         `json:"ownerId"`
	Meta       map[string]any `json:"meta"`
	Expires    int64          `json:"expires"`
	Ratelimit  *struct {
		Type           string `json:"type"`
		Limit          int64  `json:"limit"`
		RefillRate     int64  `json:"refillRate"`
		RefillInterval int64  `json:"refillInterval"`
	} `json:"ratelimit"`
	// ForWorkspaceId is used internally when the frontend wants to create a new root key.
	// Therefore we might not want to add this field to our docs.
	ForWorkspaceId string `json:"forWorkspaceId"`

	// How often this key may be used
	// `undefined`, `0` or negative to disable
	Remaining int64 `json:"remaining,omitempty"`
}

type CreateKeyResponse

type CreateKeyResponse struct {
	Key   string `json:"key"`
	KeyId string `json:"keyId"`
}

type CreateRootKeyRequest

type CreateRootKeyRequest struct {
	Name    string `json:"name"`
	Expires int64  `json:"expires"`

	// ForWorkspaceId is used internally when the frontend wants to create a new root key.
	// Therefore we might not want to add this field to our docs.
	ForWorkspaceId string `json:"forWorkspaceId" validate:"required"`
}

type CreateRootKeyResponse

type CreateRootKeyResponse struct {
	Key   string `json:"key"`
	KeyId string `json:"keyId"`
}

type DeleteKeyRequest

type DeleteKeyRequest struct {
	KeyId string `json:"keyId" validate:"required"`
}

type DeleteKeyResponse

type DeleteKeyResponse struct {
}

type ErrorCode

type ErrorCode = string
const (
	NOT_FOUND             ErrorCode = "NOT_FOUND"
	BAD_REQUEST           ErrorCode = "BAD_REQUEST"
	UNAUTHORIZED          ErrorCode = "UNAUTHORIZED"
	INTERNAL_SERVER_ERROR ErrorCode = "INTERNAL_SERVER_ERROR"
	RATELIMITED           ErrorCode = "RATELIMITED"
	FORBIDDEN             ErrorCode = "FORBIDDEN"
	USAGE_EXCEEDED        ErrorCode = "USAGE_EXCEEDED"
)

type ErrorResponse

type ErrorResponse struct {
	Error string    `json:"error,omitempty"`
	Code  ErrorCode `json:"code"`
}

type GetApiRequest

type GetApiRequest struct {
	ApiId string `json:"apiId" validate:"required"`
}

type GetApiResponse

type GetApiResponse struct {
	Id          string   `json:"id"`
	Name        string   `json:"name"`
	WorkspaceId string   `json:"workspaceId"`
	IpWhitelist []string `json:"ipWhitelist,omitempty"`
}

type GetKeyRequest

type GetKeyRequest struct {
	KeyId string `validate:"required"`
}

type GetKeyResponse

type GetKeyResponse = keyResponse

type ListKeysRequest

type ListKeysRequest struct {
	ApiId   string `validate:"required"`
	Limit   int
	Offset  int
	OwnerId string
}

type ListKeysResponse

type ListKeysResponse struct {
	Keys  []keyResponse `json:"keys"`
	Total int           `json:"total"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(config Config) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) Start

func (s *Server) Start(addr string) error

type UpdateKeyRequest

type UpdateKeyRequest struct {
	KeyId     string                  `json:"keyId" validate:"required"`
	Name      nullish[string]         `json:"name"`
	OwnerId   nullish[string]         `json:"ownerId"`
	Meta      nullish[map[string]any] `json:"meta"`
	Expires   nullish[int64]          `json:"expires"`
	Ratelimit nullish[struct {
		Type           string `json:"type" validate:"required"`
		Limit          int64  `json:"limit" validate:"required"`
		RefillRate     int64  `json:"refillRate" validate:"required"`
		RefillInterval int64  `json:"refillInterval" validate:"required"`
	}] `json:"ratelimit"`
	Remaining nullish[int64] `json:"remaining"`
}

type UpdateKeyResponse

type UpdateKeyResponse struct{}

type VerifyKeyErrorResponse

type VerifyKeyErrorResponse struct {
	ErrorResponse
	Valid     bool               `json:"valid"`
	Ratelimit *ratelimitResponse `json:"ratelimit,omitempty"`
}

type VerifyKeyRequest

type VerifyKeyRequest struct {
	Key string `json:"key"`
}

type VerifyKeyResponse

type VerifyKeyResponse struct {
	Valid     bool               `json:"valid"`
	OwnerId   string             `json:"ownerId,omitempty"`
	Meta      map[string]any     `json:"meta,omitempty"`
	Expires   int64              `json:"expires,omitempty"`
	Remaining *int64             `json:"remaining,omitempty"`
	Ratelimit *ratelimitResponse `json:"ratelimit,omitempty"`
	Code      string             `json:"code,omitempty"`
}

Jump to

Keyboard shortcuts

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