server

package
v0.0.0-...-362a82f Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: GPL-3.0 Imports: 34 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
	Analytics         analytics.Analytics
	UnkeyAppAuthToken string
	UnkeyWorkspaceId  string
	UnkeyApiId        string
	UnkeyKeyAuthId    string
	Region            string
	EventBus          events.EventBus
	Version           string
	WorkspaceService  workspaces.WorkspaceService
	ApiService        apis.ApiService
	Metrics           metrics.Metrics
}

type CreateApiRequest

type CreateApiRequest struct {
	Name string `json:"name" validate:"required"`
}

type CreateApiResponse

type CreateApiResponse struct {
	ApiId string `json:"apiId"`
}

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" validate:"required,oneof=fast consistent"`
		Limit          int32  `json:"limit" validate:"required"`
		RefillRate     int32  `json:"refillRate" validate:"required"`
		RefillInterval int32  `json:"refillInterval"  validate:"required"`
	} `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 int32 `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"`

	OwnerId string `json:"ownerId"`
}

type CreateRootKeyResponse

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

type CreateWorkspaceRequestV1

type CreateWorkspaceRequestV1 struct {
	Name     string `json:"name" validate:"required"`
	TenantId string `json:"tenantId" validate:"required"`
}

type CreateWorkspaceResponseV1

type CreateWorkspaceResponseV1 struct {
	Id string `json:"id"`
}

type DeleteRootKeyRequest

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

type DeleteRootKeyResponse

type DeleteRootKeyResponse struct {
}

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 GetKeyRequestV1

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

type GetKeyResponse

type GetKeyResponse = keyResponse

type GetKeyResponseV1

type GetKeyResponseV1 = keyResponse

type GetKeyStatsRequest

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

type GetKeyStatsResponse

type GetKeyStatsResponse struct {
	Usage []usageRecord `json:"usage"`
}

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 int64         `json:"total"`
}

type RemoveApiRequest

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

type RemoveApiResponse

type RemoveApiResponse struct {
}

type RemoveKeyRequestV1

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

type RemoveKeyResponseV1

type RemoveKeyResponseV1 struct {
}

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          int32  `json:"limit" validate:"required"`
		RefillRate     int32  `json:"refillRate" validate:"required"`
		RefillInterval int32  `json:"refillInterval" validate:"required"`
	}] `json:"ratelimit"`
	Remaining nullish[int32] `json:"remaining"`
}

type UpdateKeyResponse

type UpdateKeyResponse struct{}

type VerifyKeyRequestV1

type VerifyKeyRequestV1 struct {
	Key   string `json:"key" validate:"required"`
	ApiId string `json:"apiId"`
	X     struct {
		Resource string `json:"resource,omitempty"`
	} `json:"x,omitempty"`
}

type VerifyKeyResponseV1

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

Jump to

Keyboard shortcuts

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