scimserverlite

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConflictError is returned when an attempt is made to create a resource that already exists
	ConflictError = iota
	// MissingResourceError is returned if the resource doesn't exist in the backend
	MissingResourceError
	// MalformedResourceError is returned if the client sent a resource that's invalid.
	// For instance missing required attributes or if an attribute has the wrong datatype
	MalformedResourceError
)

Various types of errors the backend can return, which should result in different HTTP error codes according to the SCIM spec.

View Source
const SCIMDeprecatedMediaType = "application/json"
View Source
const SCIMMediaType = "application/scim+json"

Variables

This section is empty.

Functions

func CreateIDFromExternalID

func CreateIDFromExternalID(resource string) (string, error)

CreateIDFromExternalID will use the externalId attribute as internal ID

Types

type Backend

type Backend interface {
	Create(tenant, resourceType, resource string) (string, error)
	Update(tenant, resourceType, resourceID, resource string) (string, error)
	Delete(tenant, resourceType, resourceID string) error
	Clear(tenant string) error
	GetResources(tenant, resourceType string) (map[string]string, error)
	GetResource(tenant, resourceType string, id string) (string, error)
	GetParsedResources(tenant, resourceType string) (map[string]interface{}, error)
	GetParsedResource(tenant, resourceType string, id string) (interface{}, error)
}

Backend is where the SCIM server stores, modifies and gets the resources

type IDGenerator

type IDGenerator func(string) (string, error)

IDGenerator is a function which takes a resource and generates an ID for the resource

type InMemoryBackend

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

InMemoryBackend is a simple SCIM backend which stores all resources in memory

func NewInMemoryBackend

func NewInMemoryBackend(gen IDGenerator, parser ObjectParser) *InMemoryBackend

NewInMemoryBackend allocates and returns a new InMemoryBackend

func (*InMemoryBackend) Clear

func (backend *InMemoryBackend) Clear(tenant string) error

Clear will remove all resources for a given tenant in the backend

func (*InMemoryBackend) CountResources

func (backend *InMemoryBackend) CountResources(tenant, resourceType string) int

CountResources returns number of objects for a resource type for a given tenant

func (*InMemoryBackend) Create

func (backend *InMemoryBackend) Create(tenant, resourceType, resource string) (string, error)

Create will create a resource in the backend

func (*InMemoryBackend) Delete

func (backend *InMemoryBackend) Delete(tenant, resourceType, resourceID string) error

Delete will delete a resource from the backend

func (*InMemoryBackend) GetParsedResource

func (backend *InMemoryBackend) GetParsedResource(tenant, resourceType string, id string) (interface{}, error)

GetParsedResource returns a specific parsed resource for a given tenant If no ObjectParser was given, or if the ObjectParser returns nil for some resource types, the returned interface{} may be nil.

func (*InMemoryBackend) GetParsedResources

func (backend *InMemoryBackend) GetParsedResources(tenant, resourceType string) (map[string]interface{}, error)

GetParsedResources returns all parsed resources If no ObjectParser was given, or if the ObjectParser returns nil for some resource types, the returned map may contain nils.

func (*InMemoryBackend) GetResource

func (backend *InMemoryBackend) GetResource(tenant, resourceType string, id string) (string, error)

GetResource returns a specific resource for a given tenant

func (*InMemoryBackend) GetResourceTypes

func (backend *InMemoryBackend) GetResourceTypes(tenant string) []string

GetResourceTypes returns the resource types for which we have objects for a given tenant

func (*InMemoryBackend) GetResources

func (backend *InMemoryBackend) GetResources(tenant, resourceType string) (map[string]string, error)

GetResources returns all resources for a type

func (*InMemoryBackend) Load

func (backend *InMemoryBackend) Load(serializedForm []byte) error

Load reads all resources from serialized form

func (*InMemoryBackend) Serialize

func (backend *InMemoryBackend) Serialize() ([]byte, error)

Serialize returns all resources in a format which can later be read with Load()

func (*InMemoryBackend) Update

func (backend *InMemoryBackend) Update(tenant, resourceType, resourceID, resource string) (string, error)

Update will update a resource in the backend

type ObjectParser

type ObjectParser func(resourceType, resource string) (interface{}, error)

ObjectParser is a function which parses the resource from JSON to a Go object It is optional to supply an ObjectParser when creating the backend, and the ObjectParser doesn't need to be able to parse any resource type (it can just return nil for types it won't parse). In those cases the "parsed" representation of a resource will be nil in the backend.

type ParsedResourceSet

type ParsedResourceSet map[string]map[string]interface{}

A ParsedResourceSet contains all parsed resources for one tenant

type ResourceSet

type ResourceSet map[string]map[string]string

A ResourceSet contains all resources for one tenant

type SCIMErrorType

type SCIMErrorType int

SCIMErrorType is a standard type of error the backend can return

type SCIMTypedError

type SCIMTypedError interface {
	error
	Type() SCIMErrorType
}

SCIMTypedError should be used by the backend when possible At least for the methods that modify resources the SCIM server needs to know what kind of error occurred so the correct error code can be given to the client

func NewError

func NewError(t SCIMErrorType, msg string) SCIMTypedError

NewError creates a new SCIMTypedError

type Server

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

Server is a light weight SCIM server

func NewServer

func NewServer(endpoints []string, backend Backend, tenantGetter TenantGetter) *Server

NewServer will create allocate and return a new Server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type TenantGetter

type TenantGetter func(c context.Context) string

A TenantGetter is a function which provides the authenticated tenant from the context Typically scimserverlite's http handler will sit behind a middleware which handles authentication and figures out which tenant the client represents. The middlware can then store the tenant in the context and provide a TenantGetter which retrieves it.

If no authentication is used the TenantGetter should simply return "".

Jump to

Keyboard shortcuts

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